/* The canvas stays clear between the resource strip and the two primary actions. */
:root {
  --surface: #fffaf0;
  --sand: #efe9d9;
  --line: #cbcbb8;
  --text: #223d34;
  --muted: #4d6157;
  --pine: #205548;
  --float: 0 3px 14px #172e292b;
  --edge: max(12px, env(safe-area-inset-right));
  --foot: calc(12px + var(--safe-bottom, env(safe-area-inset-bottom, 0px)));
}
/* Netlify sets the frame position inline. Keep it above the dock and let
   open town panels receive taps wherever they cover the badge. */
body:has(.town-dock) :is(#nl-badge-frame, #nl-hud-frame) {
  bottom: calc(var(--foot) + 54px) !important;
  z-index: 1 !important;
}
body { color: var(--text); }
body :is(button, h1, h2, h3, .eyebrow, .brand-name, .brand-small) {
  text-shadow: none;
  -webkit-text-stroke: 0;
}
body :focus-visible { outline: 3px solid #007d77; outline-offset: 2px; }
/* Keep the playfield out of Safari's document scroll. Menus scroll internally. */
html:has(body > #world) { overflow: clip; overscroll-behavior: none; }
body:has(> #world) { position: fixed; inset: 0; overflow: clip; overscroll-behavior: none; }
body .topbar {
  position: fixed; z-index: 15; top: calc(10px + env(safe-area-inset-top));
  height: 46px; gap: 10px;
}
body .brand, body .brand::after { background: none; border: 0; box-shadow: none; }
body .brand-name, body .brand-small { color: var(--text); }
body .brand { min-width: 44px; width: 44px; height: 44px; padding: 0; }
body .brand-name { display: none; }
body .brand-mark { inset: 4px; width: 36px; height: 36px; }
body .resources {
  gap: 0; margin: 0 0 0 auto; padding: 3px 5px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 15px; box-shadow: var(--float);
}
body .resource-chip {
  min-width: 0; width: auto; height: auto; padding: 2px 9px; gap: 5px;
  border: 0; border-radius: 0; background: none; box-shadow: none;
}
body .resource-chip + .resource-chip { border-left: 1px solid var(--line); }
body .resource-icon { position: static; width: 23px; height: 23px; filter: none; }
body .resource-chip small { color: var(--muted); font-size: 10px; line-height: 1.5; }
body .resource-chip strong { color: var(--text); font-size: 16px; text-shadow: none; }
body .resource-chip em { color: var(--muted); }
body .game-button, body .close-button {
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
  box-shadow: var(--float); border-radius: 14px;
}
body .bottom-bar { inset: auto auto var(--foot) var(--edge); width: auto; height: auto; }
.bottom-bar .save-badge, .bottom-bar .camera-help { display: none; }
body .day-badge {
  background: #203d34; border: 0; box-shadow: var(--float); border-radius: 12px;
  min-width: 0; padding: 5px 10px; gap: 5px;
}
body .day-badge b, body .day-badge small { color: #fffaf0; }
body .day-badge > [data-ui-icon] { width: 24px; height: 24px; }

.town-dock {
  position: fixed; z-index: 6; bottom: var(--foot); right: var(--edge);
  display: flex; gap: 4px; padding: 4px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 17px; box-shadow: var(--float);
}
.town-dock :is(#toggle-goals-panel, #toggle-build-panel) {
  position: static; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; width: auto; height: auto; min-height: 44px; padding: 5px 11px;
  border: 0; border-radius: 12px; background: transparent; color: var(--text);
  font-size: 14px; line-height: 1.6;
}
.town-dock #toggle-build-panel { background: var(--pine); color: white; }
.town-dock #toggle-goals-panel[aria-expanded=true] { background: var(--sand); }
.town-dock #toggle-build-panel[aria-expanded=true] { background: #143d33; }
.town-dock button > span[data-ui-icon] { width: 24px; height: 24px; transform: none; }
body:not(.goals-open) #goals-sheet, body:not(.build-open) #build-sheet,
.visit-mode .town-dock, .building-mode .town-dock,
body:has(#inspector:not([hidden]), #town-menu:not([hidden])) .town-dock { display: none; }

#build-sheet, #goals-sheet, body .inspector, body .town-menu, body .dialog,
body .account-panel, body .social-panel, body .guest-intro, body .online-away {
  color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: var(--float);
}
#build-sheet, #goals-sheet {
  position: fixed; inset: auto var(--edge) calc(var(--foot) + 63px) auto;
  z-index: 4;
  width: min(410px, calc(100vw - 24px)); max-height: min(60dvh, calc(100dvh - 135px));
  overflow: auto; padding: 14px; transform: none; overscroll-behavior: contain;
}
#build-sheet {
  --build-card-width: clamp(124px, 18vw, 146px);
  --build-art-height: clamp(58px, 9dvh, 78px);
  width: min(720px, calc(100vw - 24px));
  height: clamp(320px, 41dvh, 340px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
@media (orientation: landscape) and (max-height: 500px) {
  #build-sheet {
    max-height: calc(100dvh - var(--foot) - 63px - max(12px, env(safe-area-inset-top)));
  }
}
#goals-sheet::before, #goals-sheet::after, #build-sheet::before, #build-sheet::after { display: none; }
#goals-sheet .quest-title, #build-sheet .tray-heading {
  display: flex; align-items: center; justify-content: flex-start; position: static;
  gap: 8px; padding: 0 0 9px; margin: 0; height: auto; background: none;
  border: 0; border-bottom: 1px solid var(--line); box-shadow: none; border-radius: 0;
}
#goals-sheet .quest-emblem, #build-sheet .build-title > span {
  position: static; width: 26px; height: 26px; transform: none; filter: none;
}
#goals-sheet h1, #build-sheet .build-title {
  color: var(--text); font-size: 17px; line-height: 1.6; background: none;
  padding: 0; border: 0; box-shadow: none; text-shadow: none; -webkit-text-stroke: 0;
}
#build-sheet .tray-heading small { display: none; }
body.goals-open #goals-sheet {
  display: flex; flex-direction: column; width: min(370px, calc(100vw - 24px));
  padding: 0; overflow: hidden;
}
#goals-sheet .quest-title {
  flex: none; gap: 8px; min-height: 48px; padding: 2px 6px 2px 16px;
}
#goals-sheet #close-goals {
  width: 44px; height: 44px; margin-inline-start: auto; border: 0; border-radius: 10px;
  background: transparent; color: var(--muted); font: 24px/1 sans-serif;
}
#goals-sheet #close-goals:focus-visible { outline-offset: -4px; }
#goals-sheet .goal-body {
  min-height: 0; padding: 0 16px 4px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
}
#town-level:not([hidden]) {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline;
  gap: 2px 10px; padding: 8px 0; border-bottom: 1px solid var(--line);
  color: var(--pine); font-size: 14px; line-height: 1.6;
}
#town-level small { font-size: 12px; color: var(--muted); }
#goals-sheet .goal-current { padding: 14px 0 0; animation: none; }
#goals-sheet #active-goal { padding-bottom: 12px; }
#goals-sheet .quest-reward { background: none; box-shadow: none; color: #74511a; font-size: 13px; }
#goals-sheet .goal-current p { margin: 0; font-size: 13px; line-height: 1.6; }
#goals-sheet .goal-progress { margin-top: 10px; }
#goals-sheet .district-action { margin: 0 0 10px; min-height: 44px; font-size: 14px; line-height: 1.6; }
#goals-sheet .ferry-journal-entry, #goals-sheet summary {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; min-height: 44px; padding: 8px 2px; border: 0; border-top: 1px solid var(--line);
  color: var(--text); background: transparent; text-align: start; cursor: pointer;
}
#goals-sheet .ferry-journal-entry[hidden] { display: none; }
.ferry-entry-copy { display: grid; }
.ferry-entry-copy small { color: var(--muted); font-size: 11px; line-height: 1.6; }
.ferry-entry-copy strong, #goals-sheet summary { font-size: 14px; line-height: 1.6; }
.journal-arrow { font: 22px/1 sans-serif; color: var(--pine); }
#goals-sheet summary { list-style: none; font-weight: 700; }
#goals-sheet summary::-webkit-details-marker { display: none; }
#goals-sheet summary::after {
  content: ''; width: 7px; height: 7px; margin-inline-end: 4px;
  border: solid var(--pine); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
#goal-journal[open] summary::after { rotate: 180deg; }
#goals-sheet #goal-list { max-height: none; overflow: visible; }
#goals-sheet .goal-list-row { border-top: 1px solid #e4dfd1; align-items: center; }
body.goals-open .town-dock #toggle-goals-panel { background: var(--pine); color: white; }
body.goals-open .town-dock #toggle-build-panel { background: transparent; color: var(--text); }
#goals-sheet .goal-current h3 { color: var(--text); font-size: 19px; line-height: 1.55; margin: 6px 0; }
#goals-sheet .goal-current p, #goals-sheet .goal-heading,
#build-sheet .food-flow { color: var(--muted); text-shadow: none; }
#goals-sheet .goal-track, .inspector .construction-progress {
  border: 0; height: 7px; background: #dbe3d7; box-shadow: none;
}
#goals-sheet .goal-track i, .inspector .construction-progress i { background: var(--pine); box-shadow: none; }
#goals-sheet .goal-list-row { font-size: 13px; line-height: 1.65; }
#goals-sheet .goal-list-row > span:last-child { color: var(--pine); }
#build-sheet .tray-heading { flex: none; }
#build-sheet .build-options {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-auto-flow: column;
  grid-template-columns: none;
  grid-auto-columns: var(--build-card-width);
  grid-template-rows: max-content;
  align-content: start;
  gap: 8px;
  padding: 5px 3px 6px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  scroll-padding: 3px;
}
#build-sheet :is(.build-option, .land-card) {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  width: 100%; min-width: 0; height: auto; min-height: 150px; gap: 4px; padding: 8px;
  color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  background: #f3efdf; box-shadow: none; text-align: center; transform: none;
  scroll-snap-align: start;
}
#build-sheet :is(.build-option, .land-card) > * { flex-shrink: 0; }
#build-sheet .build-option[aria-pressed=true], #build-sheet button.land-card { background: #e2eddd; }
#build-sheet .build-option[aria-pressed=true] { border-color: var(--pine); }
#build-sheet .build-art {
  flex: none; width: 100%; max-width: none; height: var(--build-art-height); position: relative;
  display: grid; place-items: center;
}
#build-sheet .build-art img {
  display: block; width: 100%; height: 100%; max-width: none; min-height: 0;
  object-fit: contain; transform: none;
}
#build-sheet .build-name, #build-sheet .land-card strong {
  display: block; align-self: stretch; min-width: 0; min-height: 0; color: var(--text);
  font-size: 13px; line-height: 1.65; white-space: normal; overflow-wrap: anywhere;
}
#build-sheet .cost {
  min-width: 0; height: auto; margin: auto 0 0; background: transparent; box-shadow: none; color: var(--text);
  white-space: normal; overflow-wrap: anywhere;
}
#build-sheet .cost > span { min-width: 0; }
#build-sheet .locked .cost { font-size: 11px; line-height: 1.65; }
#build-sheet:lang(my) :is(.build-name, .cost, .land-card strong, .land-card small, .land-card > span:not(.build-art)) {
  line-height: 2.05;
}
#build-sheet .food-flow {
  flex: none; margin: 3px 0 0; max-height: 25%; overflow: auto;
  text-align: start; line-height: 1.65;
}
#build-sheet .build-categories button { color: var(--text); background: var(--sand); border: 0; box-shadow: none; }
#build-sheet .build-categories button[aria-pressed=true] { background: var(--pine); color: white; }

#inspector {
  padding: 0;
  overflow: hidden;
  max-height: calc(100dvh - 128px - var(--foot));
}
#inspector:not([hidden]) { display: flex; flex-direction: column; }
#inspector .inspector-hero {
  position: static; flex: none; display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 44px; gap: 8px; align-items: center;
  margin: 0; padding: 10px; min-height: 68px;
  background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: none;
}
#inspector-art { width: 48px; height: 48px; object-fit: contain; }
#inspector-title { overflow-wrap: anywhere; }
#inspector #close-inspector {
  position: static; float: none; margin: 0; padding: 11px; width: 44px; height: 44px;
  align-self: start; display: grid; place-items: center;
  background: transparent; border: 0; box-shadow: none;
}
#inspector #close-inspector:hover { background-color: var(--sand); }
.inspector-body {
  padding: 12px 16px 16px; min-height: 0; overflow-y: auto;
  overscroll-behavior: contain; overflow-wrap: anywhere; scrollbar-width: thin;
}
#dialog-backdrop .dialog {
  max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto; overscroll-behavior: contain; overflow-wrap: anywhere;
}
#dialog-backdrop .dialog > div { flex-wrap: wrap; }
#inspector-description { color: var(--muted); font-size: 13px; line-height: 1.65; }
#inspector :is(.detail-row, #inspector-actions button) > span { min-width: 0; }
#inspector .detail-row {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px;
}
body .inspector h2, body .account-heading h1, body .social-panel h2 { color: var(--text); text-shadow: none; }
body .inspector .eyebrow, body .detail-row span:first-child,
body .account-hint, body .account-footer, body .account-intro { color: var(--muted); }
body .inspector .eyebrow { text-shadow: none; }
body .detail-row span:last-child { color: var(--text); }
.building-stats { margin: 8px 0; border-block: 1px solid var(--line); }
.building-stats summary { min-height: 44px; padding: 12px 0; font-weight: 700; cursor: pointer; }
body #inspector-actions button, body .primary, body #confirm-placement,
body .district-action, body .account-content .account-primary {
  background: var(--pine); color: white; border: 1px solid var(--pine); box-shadow: none; text-shadow: none;
}
body #inspector-actions [data-action="demolish"] { color: #6b3e35; background: transparent; border-color: #d8c8ba; box-shadow: none; }
body #inspector-actions button:disabled, body #confirm-placement:disabled {
  color: #50574f; background: #e2e3d8; border-color: #d2d4c9; opacity: 1; filter: none;
}
body .account-heading, body .social-panel > header { color: var(--text); text-shadow: none; background: #e2ebde; box-shadow: none; border-color: var(--line); }
body #placement-hint { inset: auto var(--edge) var(--foot) auto; width: min(430px,calc(100% - 24px)); max-width: none; background: var(--surface); color: var(--text); border: 1px solid var(--line); box-shadow: var(--float); transform: none; }
#placement-hint .shortcut-label, #placement-hint kbd { display: none; }
@media (any-pointer: fine) {
  body #placement-hint:not([hidden]) {
    display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 8px; padding: 10px;
  }
  #placement-hint .placement-tool, #placement-hint .game-button > [data-ui-icon] { display: none; }
  #placement-hint #placement-text { grid-column: 1 / -1; max-width: none; }
  #placement-hint #rotate, #placement-hint #cancel-build {
    grid-row: 2; width: auto; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 9px;
    color: var(--text); background: var(--surface); border: 1px solid var(--line); box-shadow: none;
  }
  #placement-hint #rotate { grid-column: 1; }
  #placement-hint #cancel-build { grid-column: 2; }
  #placement-hint #confirm-placement { grid-area: 2 / 3; min-width: 0; }
  #placement-hint .shortcut-label {
    display: inline; width: auto; height: auto; font-size: 13px; font-weight: 600; line-height: 1.5;
  }
  #placement-hint kbd {
    display: inline-block; position: static; font: 600 12px/1.3 monospace;
    color: var(--text); background: var(--surface); border: 1px solid var(--line);
    border-bottom-width: 2px; border-radius: 4px; padding: 1px 4px; text-shadow: none;
  }
}
body #placement-hint.path-mode:not([hidden]) {
  display: flex; align-items: center; gap: 12px; width: fit-content;
  max-width: calc(100vw - 2 * var(--edge)); padding: 8px 10px 8px 14px;
}
#path-angle { display: none; }
#placement-hint.path-mode #rotate { display: inline-flex; flex: none; align-items: center; gap: 4px; width: auto; padding-inline: 8px; }
#placement-hint.path-mode #path-angle { display: inline; width: auto; height: auto; font-variant-numeric: tabular-nums; }
#placement-hint.path-mode .placement-tool { display: none; }
#placement-hint.path-mode #placement-text { max-width: 28ch; font-size: 13px; line-height: 1.5; }
#placement-hint.path-mode #cancel-build { display: inline-flex; flex: none; align-items: center; justify-content: center; gap: 5px; width: auto; min-height: 44px; padding-inline: 9px; }
#placement-hint.path-mode #cancel-build .shortcut-label { display: inline; width: auto; height: auto; font: inherit; }
@media (max-width: 480px) {
  body #placement-hint.path-mode:not([hidden]) { flex-wrap: wrap; gap: 6px 10px; }
  #placement-hint.path-mode #placement-text { flex-basis: 100%; max-width: none; }
}
body.building-mode .bottom-bar { display: none; }
body #toast {
  inset: calc(66px + env(safe-area-inset-top)) auto auto 50%; transform: translateX(-50%);
  width: max-content; max-width: min(380px,calc(100% - 24px)); padding: 8px 14px;
  background: #233e34; color: white; border: 0; border-radius: 7px; box-shadow: var(--float);
  font-size: 13px; line-height: 1.6; text-shadow: none;
}
body #toast.error { background: #753c32; }

.town-tools { margin: 10px 0; }
.town-tools h3 { font-size: 14px; margin: 12px 0 6px; }
.town-tools .view-controls, .town-tools .time-controls {
  position: static; display: flex; width: auto; gap: 4px; flex-wrap: wrap;
  justify-content: flex-start; transform: none;
}
#town-menu .view-controls {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; gap: 6px;
}
#town-menu .view-controls button { width: 100%; grid-template-columns: 24px minmax(0, 1fr); height: auto; min-width: 0; display: grid; align-items: center; gap: 6px; padding: 8px; text-align: start; margin: 0; background: var(--sand); box-shadow: none; border: 0; }
#town-menu .view-controls button span { width: 24px; height: 24px; }
#town-menu .view-controls small { font-size: 11px; line-height: 1.5; color: var(--text); }
#town-menu .view-controls [aria-pressed=true], #town-menu .speed-buttons [aria-pressed=true] { background: #cbdcc6; color: var(--text); }
#town-menu .time-controls button { width: 44px; min-height: 44px; margin: 0; }
#town-menu #neighbors-button { position: static; width: 100%; height: auto; }
#town-menu #neighbors-button .ui-icon { width: 26px; height: 26px; }
@media (max-width:720px), (max-height:500px) {
  body .topbar {
    top: calc(10px + env(safe-area-inset-top) + var(--hud-top, 0px));
    left: calc(max(12px, env(safe-area-inset-left)) + var(--hud-left, 0px));
    right: calc(var(--edge) + var(--hud-right, 0px)); gap: 4px;
  }
  body .resource-chip { min-width: 0; padding: 2px 6px; }
  body .resource-chip small { font-size: 10px; }
  body #inspector { inset: auto var(--edge) var(--foot); width: min(400px,calc(100% - 24px)); margin-left: auto; max-height: min(56dvh,calc(100dvh - 75px)); }
  body:has(#inspector:not([hidden])) .bottom-bar { display: none; }
  .town-tools .speed-buttons { display: flex; }
}
@media (prefers-reduced-motion:no-preference) {
  body:is(.goals-open,.build-open) :is(#goals-sheet,#build-sheet) { animation: sheet-in .15s ease-out; }
  @keyframes sheet-in { from { opacity: .4; translate: 0 6px; } to { opacity: 1; translate: 0; } }
}

body:has(#town-menu:not([hidden])) :is(#goals-sheet, #build-sheet, #inspector) { display: none; }
.day-badge #guest-status { max-width: 8ch; border-left: 1px solid #708777; padding-left: 6px; }
@media (max-width:350px) {
  .town-dock :is(#toggle-goals-panel, #toggle-build-panel) { padding-inline: 6px; }
  .guest-game .day-badge > [data-ui-icon] { display: none; }
}

/* Only the active tab scrolls. The close button and exit link stay in reach. */
#town-menu {
  position:fixed; inset:calc(88px + env(safe-area-inset-top) + var(--hud-top, 0px)) calc(var(--edge) + var(--hud-right, 0px)) auto auto;
  display:flex; flex-direction:column; width:min(380px,calc(var(--hud-width, 100vw) - 24px));
  max-height:calc(var(--hud-height, 100dvh) - 102px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  padding:0; overflow:hidden; z-index:12;
}
#town-menu .town-menu-heading {
  display:flex; flex:none; align-items:center; justify-content:space-between;
  gap:12px; padding:12px 16px 5px;
}
#town-menu h2 { margin:0; font-size:22px; line-height:1.4; color:var(--text); overflow-wrap:anywhere; }
#town-menu #close-menu {
  display:grid; place-items:center; flex:none; width:44px; height:44px; padding:10px;
  border:0; border-radius:50%; background:var(--sand); color:var(--text);
}
#close-menu > span { width:20px; height:20px; }
.town-menu-tabs {
  display:grid; grid-template-columns:1fr 1fr; flex:none; gap:4px; margin:4px 16px 10px;
  border-radius:12px; padding:3px; background:var(--sand);
}
.town-menu-tabs button {
  min-height:40px; padding:5px 8px; background:transparent; color:var(--muted);
  font:inherit; font-weight:700; font-size:14px; border:0; border-radius:9px;
}
.town-menu-tabs [aria-selected=true] { color:#fffaf0; background:var(--pine); }
.town-menu-panel {
  min-height:0; overflow:auto; overscroll-behavior:contain; scrollbar-width:thin;
  padding:2px 16px 14px; scroll-padding:8px; border-top:1px solid var(--line);
}
#town-menu .town-menu-section, #town-menu #language {
  display:block; border:0; min-width:0; padding:12px 0 0; margin:0;
}
#town-menu .town-menu-panel > * + .town-menu-section { margin-top:12px; border-top:1px solid var(--line); }
#town-menu h3, #town-menu legend {
  margin:0 0 6px; padding:0; font-weight:700; font-size:14px; line-height:1.55; color:var(--text);
}
#town-menu #language { position:relative; padding-top:12px; }
#town-menu #language legend { float:left; width:100%; margin:0 0 6px; }
#town-menu p:not(.eyebrow) { margin:0 0 8px; color:var(--muted); line-height:1.6; font-size:13px; }
#town-wardrobe-action:not(:empty) { padding-top:10px; }
#town-player-actions { padding-top:2px; }
.town-menu-list, .town-menu-list .guest-menu-actions { display:grid; gap:2px; }
#town-menu .town-menu-list :is(button,a) {
  display:flex; align-items:center; justify-content:space-between; gap:8px;
  position:static; width:100%; min-height:44px; height:auto; padding:8px 12px; margin:0;
  color:var(--text); font:inherit; font-size:14px; font-weight:700; line-height:1.55;
  border:0; border-radius:8px; text-align:start; text-decoration:none; text-shadow:none;
  background:transparent; box-shadow:none; transform:none;
}
#town-menu .town-menu-list :is(button,a):hover { background:var(--sand); }
#town-menu .town-menu-list .menu-icon { flex:none; width:21px; height:21px; }
#town-menu .town-menu-list #open-wardrobe { background:#e5eee2; min-height:52px; color:var(--pine); }
#town-menu .town-menu-list #new-town { color:#86493b; }
#town-menu .town-menu-footer { flex:none; border-top:1px solid var(--line); padding:5px 16px; }
#town-menu .return-main-menu {
  display:flex; align-items:center; justify-content:center; min-height:44px; padding:4px;
  border-radius:7px; color:var(--pine); background:transparent; text-decoration:none; font-size:14px; font-weight:700;
}
#town-menu .return-main-menu:hover { background:var(--sand); }
#town-menu [data-town-audio] {
  display:grid; grid-template-columns:minmax(0,1.15fr) minmax(84px,1fr); gap:0 12px; align-items:center;
}
#town-menu [data-town-audio] label { min-height:40px; font-size:13px; line-height:1.6; gap:8px; }
#town-menu [data-town-audio] input[type=checkbox] { flex:none; }
#town-menu [data-town-audio] input[type=range] { min-width:0; width:100%; margin:0; height:40px; }
#town-menu .view-controls small { font-size:12px; line-height:1.55; }
#town-menu .view-controls button { min-height:44px; border-radius:8px; }
#town-menu .time-controls { gap:8px; }
#town-menu .time-controls button { border:0; border-radius:8px; box-shadow:none; background:var(--sand); color:var(--text); }
#town-menu .speed-buttons { padding:2px; background:var(--sand); border:0; box-shadow:none; }
#town-menu .speed-buttons button { background:transparent; }
#town-menu .speed-buttons [aria-pressed=true], #town-menu #pause[aria-pressed=true] { background:#cbdcc6; }
#town-menu .language-choices { display:grid; grid-template-columns:1fr 1fr; gap:6px; clear:both; }
#language label {
  display:flex; align-items:center; gap:8px; min-height:44px; padding:5px 10px;
  color:var(--text); background:var(--surface); border:1px solid var(--line); border-radius:8px;
}
#language input { margin:0; accent-color:var(--pine); }
#language label:has(:checked) { border-color:var(--pine); background:#e4eee3; }
#language label:focus-within { outline:2px solid var(--pine); outline-offset:1px; }
#town-menu #name-town summary, #town-menu #placement-conflicts summary {
  padding:9px 0; font-size:14px; font-weight:700; color:var(--pine); cursor:pointer;
}
@media (max-width:720px), (max-height:500px) {
  #town-menu { top:calc(61px + env(safe-area-inset-top) + var(--hud-top, 0px)); max-height:calc(var(--hud-height, 100dvh) - 72px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  #town-menu .town-menu-heading { padding-top:7px; }
}
/* Keep pending earnings for when the player returns to the town. */
body:has(#account-overlay:not([hidden]), #dialog-backdrop:not([hidden])) #absence-summary { display:none; }
#name-town form { display:grid; gap:10px; margin:12px 0; }
#name-town label { display:grid; gap:3px; }
#name-town input { font:inherit; font-size:16px; color:#302f27; background:#fffdf6; min-width:0; padding:8px; border:1px solid #9b886b; border-radius:8px; }
#name-town button { background:#225c50; color:white; }

body:has(#town-menu:not([hidden])) #absence-summary { display:none; }

.name-preview:not([hidden]) { display:block; border:3px solid #84603c; border-radius:4px; background:#fff1c9; margin:4px auto; padding:4px 12px; line-height:1.6; overflow-wrap:anywhere; max-width:100%; }

@media (min-width:721px) and (min-height:501px) {
  body .topbar {
    top:calc(24px + env(safe-area-inset-top) + var(--hud-top, 0px));
    left:calc(24px + var(--hud-left, 0px)); right:calc(24px + var(--hud-right, 0px));
    height:auto; min-height:54px;
  }
}

[data-town-audio] { display:flex; align-items:center; flex-wrap:wrap; gap:4px 16px; }
[data-town-audio] label { display:inline-flex; align-items:center; gap:6px; min-height:40px; font-size:13px; cursor:pointer; }
[data-town-audio] input[type="checkbox"] { width:16px; height:16px; margin:0; accent-color:#416c4c; }

/* Keep all four readings in the HUD even when the phone has a short or narrow viewport. */
body .resources :is(.wellbeing-chip,.supply-resource) { display:flex; }
@media (max-width:560px) {
  body .topbar .brand, body .topbar #menu-button { flex:none; }
  body .topbar .resources {
    display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); flex:1;
    min-width:0; max-width:290px; padding:3px 6px; gap:2px 6px;
  }
  body .topbar .resource-chip {
    display:flex; min-width:0; width:auto; height:auto; max-width:none; justify-content:flex-start;
    border:0; gap:4px; padding:0; white-space:nowrap;
  }
  body .topbar .resource-chip small {
    position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%);
  }
  body .topbar .resource-icon { width:17px; height:17px; flex:none; }
  body .topbar .resource-chip strong { font-size:14px; line-height:1.4; }
}

:is(#market-project,#park-request) {
  position:fixed; top:calc(88px + env(safe-area-inset-top)); left:max(12px,env(safe-area-inset-left)); z-index:14;
  width:min(295px,calc(100vw - 28px)); padding:10px 14px; border-radius:12px;
  color:var(--text); background:var(--surface); box-shadow:var(--float); font-size:14px; line-height:1.5;
}
:is(#market-project,#park-request) header { display:flex; align-items:center; justify-content:space-between; gap:12px; }
:is(#market-project,#park-request) header button { min-width:40px; min-height:40px; color:var(--text); background:transparent; border:0; font-size:22px; }
:is(#market-project,#park-request) p { margin:2px 0 8px; }
:is(#market-project,#park-request) .primary, #build-market-sign { min-height:40px; }
:is(#ferry-target,#park-path-tile) { position:fixed; transform:translate(-50%,-110%); z-index:10; border:2px solid #ffcd69; border-radius:12px; background:#284d41; color:white; padding:6px 12px; font:inherit; font-weight:bold; }
body:is(.goals-open,.build-open) :is(#market-project,#ferry-target,#park-request,#park-path-tile,#park-pin),
body:has(#town-menu:not([hidden]),#inspector:not([hidden])) :is(#market-project,#ferry-target,#park-request,#park-path-tile,#park-pin) { display:none; }
@media(max-height:520px){ :is(#market-project,#park-request) { top:calc(60px + env(safe-area-inset-top)); max-width:235px; } }

body:has(#market-project:not([hidden]),#park-request:not([hidden])) #absence-summary { display:none; }

#park-pin { position:fixed; transform:translate(-50%,-100%); pointer-events:none; z-index:8; border-radius:8px; padding:3px 9px; background:#244e40; color:#fff; font-size:12px; }

#goal-list details summary { font-weight:650; }
#goal-list details .goal-list-row { padding-inline-start:12px; }
#goal-journal[open] details:not([open]) > summary::after { rotate:0deg; }
#side-projects:not(:has(button:not([hidden]))) { display:none; }

body.goals-open #absence-summary { display:none; }

[data-town-audio] input[type=range]{width:65px;min-height:44px;accent-color:#416c4c}


#goals-sheet .character-speech {display:grid;grid-template-columns:clamp(62px,18vw,88px) 1fr;gap:12px;align-items:start;margin:11px 0 12px;padding:10px;border:1px solid #ddcbae;border-radius:12px;background:#fbf0da}
.character-speech img {width:100%;height:auto;border-radius:9px}
.character-speech strong,.character-speech small {display:block;line-height:1.5}
.character-speech strong {color:#3f372b}
.character-speech small {color:#62563e;font-size:12px}
#goals-sheet .character-speech p {margin:5px 0 0;font-weight:500}
#goals-sheet .goal-conversation {flex:1;min-width:0}
#goals-sheet .goal-conversation summary {border:0}
.map-goal-marker {position:fixed;top:0;left:0;z-index:9;width:52px;height:52px;pointer-events:none}
.map-goal-marker .pinned-town-marker {position:absolute;left:50%;bottom:calc(100% + 6px);width:max-content;max-width:min(185px,calc(100vw - 16px));transform:translateX(-50%);pointer-events:auto}
.map-goal-marker.label-below .pinned-town-marker {top:calc(100% + 10px);bottom:auto}
.goal-portrait {
  position:relative;pointer-events:auto;cursor:pointer;
  width:52px;height:52px;padding:3px;border:2px solid #82663d;border-radius:50%;
  background:#fff8e7;box-shadow:0 3px 8px #34271966;
}
.goal-portrait::after {content:"";position:absolute;left:19px;bottom:-6px;width:9px;height:9px;transform:rotate(45deg);border:solid #82663d;border-width:0 2px 2px 0;background:#fff8e7}
.goal-portrait img {display:block;width:100%;height:100%;border-radius:50%}
.goal-portrait:focus-visible {outline:3px solid #215c48;outline-offset:3px}
:is(.map-goal-dialog,.parcel-dialog) {box-sizing:border-box;width:min(380px,calc(100vw - 24px));max-height:calc(100dvh - 32px);overflow:auto;border:1px solid #b6aa88;border-radius:16px;padding:16px;background:#fff9ee;color:#30453b;box-shadow:var(--float);font:inherit}
:is(.map-goal-dialog,.parcel-dialog)::backdrop {background:#172b2438}
:is(.map-goal-dialog,.parcel-dialog) header {display:flex;align-items:start;justify-content:space-between;gap:10px}
:is(.map-goal-dialog,.parcel-dialog) h2 {margin:0;font-size:1.2rem;line-height:1.5}
.map-goal-close {background:transparent;border:0;color:inherit;min-width:44px;min-height:44px;font-size:24px;cursor:pointer}
:is(.map-goal-dialog,.parcel-dialog) .character-speech {display:grid;grid-template-columns:70px 1fr;gap:12px;align-items:start}
:is(.map-goal-dialog,.parcel-dialog) p {margin:8px 0;line-height:1.6}
:is(.map-goal-dialog,.parcel-dialog) .map-goal-objective {margin:14px 0;font-size:.9rem}
:is(.map-goal-dialog,.parcel-dialog) .district-action {width:100%;min-height:44px}

#build-sheet .build-categories {
  display: flex; flex: none; flex-wrap: nowrap; align-items: flex-start; gap: 4px;
  height: 57px; margin: 4px 0 0; padding: 3px; overflow-y: hidden;
  overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin;
  scrollbar-color: #bcb49d transparent;
}
#build-sheet .build-categories button {
  position: relative; flex: none; display: inline-flex; align-items: center; justify-content: center;
  gap: 5px; min-width: 44px; min-height: 44px; padding: 5px 7px; border-radius: 10px;
  white-space: nowrap; line-height: 1.6;
}
#build-sheet .build-categories button[aria-pressed=true] { padding-inline: 8px 12px; }
#build-sheet .build-categories button [data-ui-icon] { width: 30px; height: 30px; }
#build-sheet .build-categories button[aria-pressed=false] .category-label {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%);
}
#build-sheet .build-categories button:focus-visible {
  outline: 2px solid var(--pine); outline-offset: 1px;
}

.chapter-celebration{
  position:fixed;z-index:90;left:50%;top:max(1rem,env(safe-area-inset-top));
  transform:translateX(-50%);width:min(30rem,calc(100vw - 2rem));box-sizing:border-box;
  max-height:85dvh;overflow:auto;display:grid;grid-template-columns:4.6rem 1fr;gap:1rem;
  padding:1.5rem 1.15rem 1rem;color:#213e36;background:#fff9eb;border:2px solid #bc9558;
  border-radius:1.2rem;box-shadow:0 .4rem 1.4rem #172f3340;
}
.chapter-celebration::before{content:"";position:absolute;inset:0 0 auto;height:.6rem;
  background:repeating-linear-gradient(110deg,#d8ab51 0 18px,#fcdf9e 18px 28px,#457466 28px 46px,#eb9d7a 46px 60px);}
.chapter-celebration img{width:100%;border-radius:50%;border:3px solid #e0bc78;box-sizing:border-box;}
.chapter-celebration h2,.chapter-celebration p{margin:.3rem 0 .55rem;line-height:1.45;}
.chapter-celebration small{font-weight:800;color:#75501d;}
.chapter-celebration aside{font-size:.9em;}
.chapter-celebration button{margin-top:.6rem;border:0;border-radius:.65rem;padding:.65rem 1rem;background:#205648;color:white;font:inherit;font-weight:700;}
@media(prefers-reduced-motion:no-preference){
  .chapter-celebration{animation:chapter-arrival .48s ease-out;}
  @keyframes chapter-arrival{from{opacity:0;translate:0 -1rem;}to{opacity:1;translate:0 0;}}
}

.chapter-celebration strong{display:block;font-size:.9em;margin:-.2rem 0 .7rem;color:#75501d;}
.chapter-paper{display:none;}
@media(prefers-reduced-motion:no-preference){
  .chapter-paper{display:block;position:absolute;inset:0;overflow:hidden;pointer-events:none;}
  .chapter-paper i{position:absolute;left:calc(3% + var(--i)*8%);top:-1rem;width:.4rem;height:.65rem;
    animation:chapter-paper-fall 1.35s ease-in calc(var(--i)*40ms) both;}
  @keyframes chapter-paper-fall{
    0%{opacity:0;transform:translateY(0) rotate(0);}
    12%{opacity:.9;}
    100%{opacity:0;transform:translate(.7rem,8rem) rotate(200deg);}
  }
}

.land-card { position: relative; overflow-wrap: anywhere; }
.land-card small, .land-card > span { color: var(--muted); font-size: 12px; line-height: 1.55; }
.land-card .parcel-lock { position: absolute; bottom: 2px; right: 0; width: 19px; height: 19px; }
button.land-card > span { color: var(--pine); font-weight: 700; }

.parcel-invite {
  position:fixed;left:0;top:0;z-index:10;pointer-events:auto;
  display:flex;align-items:center;gap:8px;min-height:48px;max-width:min(195px,70vw);
  background:#fff7e6;color:#254a3b;border:2px solid #ac8953;border-radius:28px;
  padding:3px 12px 3px 3px;box-shadow:0 3px 8px #34271944;text-align:start;
}
.parcel-invite img {border-radius:50%}
.parcel-invite strong,.parcel-invite small {display:block;line-height:1.4}
.parcel-invite small {font-size:11px;color:#6a5031}
.parcel-invite strong {font-size:14px}
.parcel-invite:not(.offscreen)::after {content:'';position:absolute;bottom:-6px;left:calc(50% - 4px);width:8px;height:8px;border:solid #ac8953;border-width:0 2px 2px 0;background:#fff7e6;transform:rotate(45deg)}
.parcel-invite i {width:14px;text-align:center;font-style:normal}
.parcel-invite:not(.offscreen) i {visibility:hidden;width:0}
.parcel-invite[hidden] {display:none}
.parcel-dialog .district-action {margin-top:12px}
.parcel-dialog .parcel-dismiss {width:100%;min-height:44px;margin-top:4px;border:0;border-radius:8px;background:transparent;color:var(--pine)}

.parcel-invite.below:not(.offscreen)::after {bottom:auto;top:-6px;transform:rotate(225deg)}

@media (max-width:560px) {
  body .topbar .coins-chip { grid-column:2; grid-row:1; }
}
#money { font-variant-numeric: tabular-nums; }
.coins-chip.collecting-coins #money { color:#845409; }
.flying-coins { position:fixed; inset:0; overflow:hidden; pointer-events:none; z-index:1000; }
.flying-coins .resource-icon {
  position:absolute; top:0; left:0; width:28px; height:28px;
  filter:drop-shadow(0 2px 2px #674b2355); will-change:transform;
}
.flying-coins [hidden] { display:none; }

#owner-tea-walk {
  position: fixed; z-index: 94; top: max(86px, 14vh); left: 50%; transform: translateX(-50%);
  width: min(370px, calc(100vw - 24px)); max-height: 67dvh; overflow-y: auto;
  padding: 12px; border: 2px solid #bfa46b; border-radius: 14px; background: #fff8e4;
  color: #263f34; box-shadow: 0 6px 22px #19372b44;
}
#owner-tea-walk[hidden], #owner-tea-walk [hidden] {display:none}
#owner-tea-walk header, #owner-tea-walk .walk-choices, #owner-tea-walk .walk-actions {display:flex;align-items:center;gap:8px}
#owner-tea-walk header img {width:42px;height:50px;object-fit:contain}
#owner-tea-walk header strong {flex:1}
#owner-tea-walk header button {min-width:38px;min-height:38px;font-size:1.3rem}
#owner-tea-walk p {margin:6px 0 10px;line-height:1.55}
#owner-tea-walk select {max-width:66%;min-width:0;min-height:40px;font:inherit;border-radius:6px;color:inherit}
#owner-tea-walk .walk-actions {margin-top:8px;justify-content:flex-end;flex-wrap:wrap}
#owner-tea-walk .walk-actions button {min-height:44px;padding:6px 10px}
@media(min-width:780px){#owner-tea-walk{left:20px;transform:none;top:14vh}}

#open-wardrobe{display:flex;align-items:center;justify-content:space-between;min-height:44px}
#open-wardrobe .wardrobe-portrait{width:36px;height:36px;border-radius:50%;overflow:hidden;background:var(--sand)}
.wardrobe-portrait img{width:100%;height:100%;object-fit:contain}
#open-wardrobe .wardrobe-portrait:empty{display:none}
