/* ==========================================================================
   小镇造梦师 · 海屿手账与瓷釉工坊 (Coastal Tactile Atelier)
   100% 本地静态资源 · 移动优先 · 离线容器安全 · 兼顾无障碍与减少动效
   ========================================================================== */

:root {
  color-scheme: light;
  /* Core Coastal Atelier Palette */
  --ink: #1e3832;
  --ink-soft: #4e6961;
  --ink-muted: #70877f;
  --paper: #fcfaf2;
  --paper-deep: #f2eee0;
  --paper-card: #fffdf7;
  --glass-bg: rgb(252 250 242 / 88%);
  --glass-strong: rgb(253 251 245 / 95%);
  --glass-border: rgb(35 66 58 / 15%);
  --glass-highlight: inset 0 1px 0 rgb(255 255 255 / 88%);
  --shadow-sm: 0 2px 8px rgb(22 52 46 / 10%), 0 1px 2px rgb(22 52 46 / 8%);
  --shadow-md: 0 8px 26px rgb(22 52 46 / 14%), 0 2px 6px rgb(22 52 46 / 8%);
  --shadow-lg: 0 20px 56px rgb(18 44 40 / 24%), 0 4px 14px rgb(18 44 40 / 10%);

  /* Accents: Terracotta Roof + Harbor Teal */
  --accent: #c85a3b;
  --accent-hover: #b34c2f;
  --accent-soft: #fae8e0;
  --teal: #235c50;
  --teal-hover: #1b4b41;
  --teal-soft: #dfece6;
  --danger: #b24034;
  --danger-hover: #973329;
  --danger-soft: #fbe8e5;
  --warn: #b46924;
  --warn-soft: #fcf0df;
  --ok: #2e7d58;
  --ok-soft: #e2f2e9;
  --blossom: #b85870;
  --blossom-soft: #fbeaf0;
  --focus: #c85a3b;

  /* Typography */
  --font-sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-serif: "Songti SC", "STSong", "Noto Serif SC", "SimSun", Georgia, serif;

  /* Safe-area & Spacing Tokens */
  --native-top: 0px;
  --native-bottom: 0px;
  --safe-top: var(--native-top);
  --safe-bottom: var(--native-bottom);
  --safe-left: 0px;
  --safe-right: 0px;
  --gap: 12px;
  --radius-pill: 999px;
  --radius-md: 14px;
  --radius-lg: 20px;

  font-family: var(--font-sans);
  color: var(--ink);
}

@supports (top: max(env(safe-area-inset-top, 0px), 0px)) {
  :root {
    --safe-top: max(env(safe-area-inset-top, 0px), var(--native-top));
    --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--native-bottom));
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
  }
}
@supports (width: clamp(12px, 1.8vw, 24px)) {
  :root { --gap: clamp(12px, 1.8vw, 24px); }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body, #world {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: #9ec9c9;
  -webkit-font-smoothing: antialiased;
}

#world {
  position: relative;
  isolation: isolate;
  user-select: none;
  -webkit-user-select: none;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: not-allowed;
  opacity: .38;
}

button:focus-visible,
summary:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2.5px solid var(--focus);
  outline-offset: 2px;
}

svg:not(.icon-bank) {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
  flex: none;
}

button svg {
  width: 20px;
  height: 20px;
  display: block;
}

.icon-bank, .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  pointer-events: none;
  overflow: hidden;
  clip-path: inset(100%);
}

/* 3D Canvas — Never block pointer/touch gestures */
#scene {
  display: block;
  width: 100%;
  height: 100%;
  transform: scaleX(-1);
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: crosshair;
  outline: 0;
}
#scene[data-drag] { cursor: grabbing; }

/* Shared Tactile Porcelain Glass Surface */
.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-highlight), var(--shadow-sm);
  backdrop-filter: blur(16px) saturate(1.25);
  -webkit-backdrop-filter: blur(16px) saturate(1.25);
}

/* ==========================================================================
   Loading Screen & WebGL Fallback
   ========================================================================== */
#loading {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 35%, #c5e3df 0%, #99c5c6 100%);
  transition: opacity .28s ease;
}

#loading.done {
  opacity: 0;
  pointer-events: none;
}

.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 26px 32px;
  border-radius: 24px;
  background: rgb(252 250 242 / 86%);
  border: 1px solid rgb(255 255 255 / 72%);
  box-shadow: var(--shadow-lg);
  max-width: min(360px, 90vw);
  text-align: center;
}

.loading-emblem {
  border-radius: 16px;
  box-shadow: 0 6px 18px rgb(30 56 50 / 18%);
}

.loading-brand {
  font: 700 20px/1.25 var(--font-serif);
  letter-spacing: .12em;
  color: var(--ink);
}

.loading-ripple {
  width: 34px;
  height: 12px;
  border: 2px solid var(--teal);
  border-radius: 50%;
  animation: ripple 1.3s infinite ease-out;
}

#loading p {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-soft);
}

#loading.failed .loading-ripple { display: none; }
#loading > canvas {
  width: min(440px, 88vw);
  height: auto;
  border-radius: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-md);
}

@keyframes ripple {
  from { transform: scale(.45); opacity: .95; }
  to { transform: scale(1.65); opacity: .05; }
}

/* ==========================================================================
   Top HUD Bar
   ========================================================================== */
.hud-top {
  position: absolute;
  top: calc(var(--gap) + var(--safe-top));
  left: calc(var(--gap) + var(--safe-left));
  right: calc(var(--gap) + var(--safe-right));
  z-index: 4;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  transition: opacity .24s ease, transform .24s ease;
}

.hud-top button { pointer-events: auto; }

.brand { min-width: 0; max-width: min(300px, 46vw); }

.town-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: 100%;
  min-height: 44px;
  padding: 5px 11px 5px 6px;
  border-radius: 16px;
  text-align: left;
  transition: transform .14s ease, background-color .16s ease, border-color .16s ease;
}

.town-pill:hover {
  background: var(--glass-strong);
  border-color: rgb(35 92 80 / 28%);
}

.town-pill:active { transform: scale(.97); }

.brand-emblem {
  border-radius: 10px;
  flex: none;
  box-shadow: 0 2px 6px rgb(30 56 50 / 16%);
}

.brand-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 1px;
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.brand h1 {
  margin: 0;
  font: 700 14px/1.2 var(--font-serif);
  letter-spacing: .08em;
  color: var(--ink);
  white-space: nowrap;
}

.hud-count {
  font-size: 10.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--teal-soft);
  color: var(--teal);
  white-space: nowrap;
}

.brand-town-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  min-width: 0;
}

#town-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
  background: var(--ok);
  box-shadow: 0 0 0 2.5px rgb(46 125 88 / 18%);
  transition: background-color .2s ease, box-shadow .2s ease;
}

.save-dot.warning {
  background: var(--warn);
  box-shadow: 0 0 0 3px rgb(180 105 36 / 24%);
}

.pill-chevron {
  width: 15px;
  height: 15px;
  color: var(--ink-muted);
  margin-left: 1px;
}

.hud-top-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.hud-capsule {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 16px;
}

.hud-capsule button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 38px;
  height: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 600;
  transition: background-color .15s ease, color .15s ease, transform .12s ease;
}

.hud-capsule button:not(:disabled):hover {
  background: rgb(35 92 80 / 9%);
}

.hud-capsule button:not(:disabled):active {
  transform: scale(.93);
}

.hud-capsule button[aria-pressed="true"]:not(#sound-btn) {
  background: var(--teal);
  color: #fffcf4;
}

.hud-capsule button.danger-icon:not(:disabled):hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.hud-capsule button.share-accent {
  background: var(--accent);
  color: #fffcf5;
  padding: 0 12px;
}

.hud-capsule button.share-accent:hover {
  background: var(--accent-hover);
}

.hud-capsule #menu-btn {
  padding: 0 11px;
}

.rail-sep {
  display: block;
  width: 1px;
  height: 18px;
  margin: 0 3px;
  background: rgb(35 66 58 / 15%);
}

/* Light Preset Micro Indicator Dot on #light-btn */
.light-dot {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #e6a832;
  border: 1px solid var(--paper);
}
#light-btn[data-light="1"] .light-dot { background: #de6b3c; }
#light-btn[data-light="2"] .light-dot { background: #4875b4; }

/* ==========================================================================
   Zen Mode (Clean Unobstructed Canvas Preview)
   ========================================================================== */
#world[data-zen="true"] .hud-top,
#world[data-zen="true"] #workbench,
#world[data-zen="true"] .hint-wrap {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(14px);
}

#world[data-zen="true"] .hud-top {
  transform: translateY(-14px);
}

.zen-exit {
  position: absolute;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 8;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 42px;
  padding: 0 18px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  box-shadow: var(--glass-highlight), var(--shadow-md);
  animation: pop-up .22s cubic-bezier(.2, .85, .3, 1.05) both;
}

.zen-exit:hover { background: var(--glass-strong); }

/* ==========================================================================
   Operation Hint & Toast
   ========================================================================== */
.hint-wrap {
  position: absolute;
  top: calc(var(--gap) + var(--safe-top) + 56px);
  left: calc(var(--gap) + var(--safe-left));
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: min(460px, calc(100vw - 88px));
  padding: 5px 6px 5px 12px;
  border-radius: var(--radius-pill);
  background: rgb(252 250 242 / 78%);
  border: 1px solid rgb(35 66 58 / 12%);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity .24s ease, transform .24s ease;
}

.hint-wrap.dismissed { display: none; }

.hint {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--ink-soft);
}

.hint span {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  row-gap: 2px;
}

.hint i {
  display: inline-block;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  opacity: .45;
  margin: 0 7px;
}

.hint .for-touch { display: none; }

#hint-dismiss {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-muted);
  flex: none;
}

#hint-dismiss:hover { background: rgb(35 66 58 / 10%); color: var(--ink); }
#hint-dismiss svg { width: 13px; height: 13px; }

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(134px + var(--safe-bottom));
  z-index: 12;
  transform: translate(-50%, 8px);
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  background: rgb(26 52 46 / 92%);
  color: #fffaf0;
  border: 1px solid rgb(255 255 255 / 14%);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 500;
  max-width: min(86vw, 480px);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s ease, transform .18s ease;
}

.toast.on {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ==========================================================================
   Bottom Creative Workbench (Mode Banner + Tool Dock + Ceramic Palette)
   ========================================================================== */
#workbench {
  position: absolute;
  left: 50%;
  left: calc(50% + (var(--safe-left) - var(--safe-right)) / 2);
  bottom: calc(12px + var(--safe-bottom));
  bottom: calc(clamp(10px, 1.4vw, 18px) + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: max-content;
  max-width: calc(100vw - 12px - var(--safe-left) - var(--safe-right));
  pointer-events: none;
  transition: opacity .24s ease, transform .24s ease;
}

#workbench #tool-dock,
#workbench .mode-banner { pointer-events: auto; }

/* Active Mode Status Banner */
.mode-banner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  padding: 5px 6px 5px 12px;
  border-radius: var(--radius-pill);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  background: var(--glass-strong);
  animation: pop-up .18s ease-out both;
}

.mode-badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
  flex: none;
}

.mode-banner[data-mode="erase"] {
  background: rgb(253 240 238 / 96%);
  border-color: rgb(178 64 52 / 28%);
  color: #7c261d;
}
.mode-banner[data-mode="erase"] .mode-badge-dot { background: var(--danger); }

.mode-banner[data-mode="replace"] {
  background: rgb(235 247 241 / 96%);
  border-color: rgb(35 92 80 / 28%);
  color: #19483e;
}
.mode-banner[data-mode="replace"] .mode-badge-dot { background: var(--teal); }

.mode-banner[data-mode="item"] {
  background: rgb(253 241 245 / 96%);
  border-color: rgb(184 88 112 / 28%);
  color: #7c3145;
}
.mode-banner[data-mode="item"] .mode-badge-dot { background: var(--blossom); }

#mode-exit-btn {
  min-height: 28px;
  padding: 0 11px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--ink);
  color: #fffcf4;
  font-size: 12px;
  font-weight: 600;
}
#mode-exit-btn:hover { background: var(--teal); }

/* Tool Dock Row */
#dock-row {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
}

#tool-dock {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 5px;
  border-radius: 18px;
}

#tool-dock > button,
#foundation-trigger,
#items-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--ink);
  transition: background-color .15s ease, color .15s ease, transform .12s ease;
}

#tool-dock > button svg,
#items-btn svg {
  width: 17px;
  height: 17px;
}

#tool-dock > button:hover,
#foundation-trigger:hover,
#items-btn:hover {
  background: rgb(35 92 80 / 9%);
}

#build-btn[aria-pressed="true"] {
  background: var(--teal);
  color: #fffcf5;
}

.build-color-dot {
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--current-swatch, #ec4444);
  border: 1.5px solid rgb(255 255 255 / 90%);
  box-shadow: 0 1px 2px rgb(0 0 0 / 20%);
}

#erase-btn[aria-pressed="true"] {
  background: var(--danger);
  color: #fffaf5;
}

#items-btn[aria-pressed="true"],
#items-btn[aria-expanded="true"] {
  background: var(--blossom);
  color: #fffafd;
}

/* Foundations Inline on Desktop, Expandable Tray on Compact/Mobile */
#foundation-wrap {
  position: relative;
  display: flex;
  align-items: center;
  padding-left: 6px;
  margin-left: 2px;
  border-left: 1px solid rgb(35 66 58 / 14%);
}

#foundation-trigger {
  display: none;
}

#foundation-trigger .mini-chevron {
  width: 14px;
  height: 14px;
  opacity: .7;
  transition: transform .18s ease;
}

#foundation-trigger[aria-expanded="true"] {
  background: var(--teal-soft);
  color: var(--teal);
}
#foundation-trigger[aria-expanded="true"] .mini-chevron {
  transform: rotate(180deg);
}

#foundations {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

#foundations .tray-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  padding: 0 4px 0 2px;
}

#foundations button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 34px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--ink);
  transition: background-color .14s ease, border-color .14s ease, transform .12s ease;
}

#foundations button:hover {
  background: rgb(35 92 80 / 9%);
}

#foundations [data-foundation][aria-pressed="true"] {
  background: var(--paper-card);
  border-color: rgb(35 92 80 / 36%);
  box-shadow: 0 2px 6px rgb(22 52 46 / 12%);
  color: var(--teal);
}

#foundations i,
#foundation-chip-preview,
#template-choices i {
  display: block;
  width: 18px;
  height: 15px;
  border: 1px solid rgb(56 64 52 / 42%);
  border-radius: 4px;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 45%);
  flex: none;
}

.grass-chip { background: linear-gradient(165deg, transparent 45%, #739455 46% 56%, transparent 57%), linear-gradient(to bottom, #a8c576 48%, #839e5c 49% 59%, #d7bc8a 60%); }
.snow-chip { background: linear-gradient(166deg, #fafdfb 0 46%, #d4e7eb 48% 70%, #98b7cc 72%); }
.sand-chip { background: repeating-linear-gradient(167deg, transparent 0 4px, #dba86a 5px, transparent 6px), #efd095; }
.brick-chip { background: repeating-linear-gradient(90deg, transparent 0 5px, #625e663d 5px 6px), linear-gradient(to bottom, #cbada3 35%, #a98176 36% 48%, #8e9398 49% 70%, #666f7c 71% 78%, #9c9a97 79%); }

#foundations #replace-foundation {
  margin-left: 3px;
  padding: 0 10px;
  border-left: 1px solid rgb(35 66 58 / 14%);
  border-radius: 10px;
  color: var(--ink-soft);
}

#foundations #replace-foundation[aria-pressed="true"] {
  background: var(--teal);
  color: #fffcf5;
  border-color: var(--teal);
}

/* Items Popover Drawer */
#item-tools {
  position: relative;
  padding-left: 4px;
  margin-left: 2px;
  border-left: 1px solid rgb(35 66 58 / 14%);
}

#item-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  width: 224px;
  padding: 12px;
  border-radius: 18px;
  background: var(--paper);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-highlight), var(--shadow-lg);
  z-index: 10;
}

#item-panel[data-open="true"] {
  transform-origin: bottom right;
  animation: open-drawer .2s cubic-bezier(.16, .84, .26, 1.08) both;
}

#item-panel[data-open="false"] {
  animation: close-drawer .14s ease-in both;
  pointer-events: none;
}

#item-panel h2 {
  margin: 0 0 8px 4px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .05em;
  color: var(--ink-muted);
}

#item-panel button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 7px 10px 7px 7px;
  border: 1px solid rgb(35 66 58 / 14%);
  border-radius: 13px;
  background: var(--paper-card);
  text-align: left;
  transition: background-color .14s ease, border-color .14s ease, transform .12s ease;
}

#item-panel button:hover {
  background: var(--blossom-soft);
  border-color: rgb(184 88 112 / 34%);
}

#item-panel button[aria-pressed="true"] {
  background: var(--blossom-soft);
  border-color: var(--blossom);
  box-shadow: inset 0 0 0 1px var(--blossom);
}

#item-panel img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  background: #f5e6e8;
  border-radius: 10px;
  flex: none;
}

.item-card-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.item-card-meta strong {
  font-size: 13.5px;
  color: var(--ink);
}

.item-card-meta small {
  font-size: 11px;
  line-height: 1.35;
  color: var(--ink-muted);
}

/* Transparent color rail */
#palette-rail {
  --chip: 38px;
  display: flex;
  align-items: center;
  width: max-content;
  max-width: 100%;
  margin-top: 6px;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
@supports (width: clamp(34px, 2.9vw, 42px)) {
  #palette-rail { --chip: clamp(34px, 2.9vw, 42px); }
}

#palette {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 7px 4px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  touch-action: pan-x;
  scrollbar-width: none;
  pointer-events: auto;
}

#palette-rail.scrollable #palette { margin: 0 2px; }
#palette::-webkit-scrollbar { display: none; }

.palette-arrow {
  display: none;
  flex: 0 0 24px;
  align-items: center;
  justify-content: center;
  height: 28px;
  border: 1px solid rgba(35, 66, 58, .16);
  padding: 0;
  border-radius: 9px;
  background: rgba(252, 250, 242, .88);
  box-shadow: 0 2px 6px rgba(22, 52, 46, .18);
  color: var(--ink);
  pointer-events: auto;
}

#palette-rail.scrollable .palette-arrow { display: flex; }
.palette-arrow:hover:not(:disabled) { background: var(--paper); }
.palette-arrow:disabled { visibility: hidden; }
.palette-arrow svg { width: 18px; height: 18px; }

.swatch {
  position: relative;
  flex: 0 0 var(--swatch-width, var(--chip));
  width: var(--swatch-width, var(--chip));
  height: var(--chip);
  padding: 0;
  border: 0;
  background: transparent;
  touch-action: pan-x;
}

.swatch::before {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  bottom: 5px;
  left: 5px;
  border-radius: 6px;
  background: var(--swatch);
  border: 1.25px solid rgba(28, 44, 40, .48);
  box-shadow: 0 2px 4px rgba(20, 44, 42, .24);
  transition: transform .15s cubic-bezier(.2, .85, .3, 1.2), box-shadow .15s ease;
}

.swatch:hover::before {
  transform: translateY(-2px) scale(1.04);
}

.swatch[aria-pressed="true"]::before {
  transform: translateY(-2px) scale(1.06);
  border-color: var(--ink);
  box-shadow: 0 0 0 2.5px var(--paper), 0 0 0 4.5px var(--ink), 0 4px 10px rgba(22, 52, 46, .32);
}

.swatch:focus-visible { outline-offset: -2px; }
.swatch.picked::before, [data-foundation].picked i { animation: pick-chip .26s ease-out; }

#hold-cue {
  position: fixed;
  z-index: 14;
  pointer-events: none;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  height: 26px;
  padding: 0 10px 0 7px;
  border: 1px solid rgba(178, 64, 52, .28);
  border-radius: 999px;
  background: rgba(253, 240, 238, .92);
  color: #7c261d;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  animation: cue-in .12s ease-out both;
}
#hold-cue svg { width: 14px; height: 14px; margin-right: 4px; fill: none; stroke: currentColor; stroke-width: 1.5; }
#hold-cue svg circle:first-child { opacity: .25; }
.hold-progress { transform: rotate(-90deg); transform-origin: center; stroke-dasharray: 37.7; }
#hold-cue[data-phase="erase"] .hold-progress { animation: hold-progress 1.249s linear both; }
#hold-cue[data-phase="rebound"] { background: rgba(235, 247, 241, .94); border-color: rgba(35, 92, 80, .24); color: var(--teal); }
#hold-cue[data-phase="rebound"] .hold-progress { stroke-dashoffset: 0; }
@keyframes cue-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes hold-progress { from { stroke-dashoffset: 37.7; } to { stroke-dashoffset: 0; } }

#onboarding-layer {
  position: absolute;
  z-index: 7;
  right: 0;
  bottom: calc(var(--workbench-h, 108px) + var(--safe-bottom) + 12px);
  left: 0;
  display: flex;
  justify-content: center;
  padding: 0 calc(12px + var(--safe-right)) 0 calc(12px + var(--safe-left));
  pointer-events: none;
}
#onboarding-card {
  width: 100%;
  max-width: 360px;
  min-height: 76px;
  padding: 6px 12px 10px;
  border: 1px solid rgba(143, 104, 78, .25);
  border-radius: 18px;
  background: rgba(253, 251, 245, .94);
  box-shadow: 0 6px 18px rgba(45, 57, 45, .16);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  animation: guide-enter .22s ease-out both;
}
.guide-top, .guide-main { display: flex; align-items: center; }
.guide-top { min-height: 32px; color: var(--teal); font-size: 11.5px; font-weight: 700; }
.guide-dots { display: flex; align-items: center; margin-right: 6px; }
.guide-dots i { width: 11px; height: 11px; margin-right: 4px; border-radius: 50%; background: #dddcd2; text-align: center; }
#onboarding-card[data-step="1"] .guide-dots i:nth-child(1),
#onboarding-card[data-step="2"] .guide-dots i:nth-child(2),
#onboarding-card[data-step="3"] .guide-dots i:nth-child(3) { background: var(--accent); animation: guide-breathe 1.8s ease-in-out infinite; }
#onboarding-card[data-step="2"] .guide-dots i:nth-child(1),
#onboarding-card[data-step="3"] .guide-dots i:nth-child(-n+2),
#onboarding-card[data-step="4"] .guide-dots i,
#onboarding-card[data-checked="true"] .guide-dots i { animation: none; }
#onboarding-card[data-step="2"] .guide-dots i:nth-child(1),
#onboarding-card[data-step="3"] .guide-dots i:nth-child(-n+2),
#onboarding-card[data-step="4"] .guide-dots i,
#onboarding-card[data-step="1"][data-checked="true"] .guide-dots i:nth-child(1),
#onboarding-card[data-step="2"][data-checked="true"] .guide-dots i:nth-child(2),
#onboarding-card[data-step="3"][data-checked="true"] .guide-dots i:nth-child(3) { background: var(--ok); }
.guide-top button, #guide-start { pointer-events: auto; min-height: 32px; border: 0; padding: 0 8px; }
#guide-skip { margin-left: auto; background: transparent; color: var(--ink-soft); }
#guide-start { flex: none; margin-left: 7px; border-radius: 999px; background: var(--accent); color: var(--paper); font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.guide-copy { min-width: 0; flex: 1; }
#guide-title, #guide-detail { display: block; line-height: 1.35; }
#guide-title { font-size: 13.5px; color: var(--ink); }
#guide-detail { margin-top: 2px; font-size: 11.5px; color: var(--ink-soft); }
#guide-icon { position: relative; width: 30px; height: 30px; flex: none; display: flex; align-items: center; justify-content: center; margin-right: 8px; color: var(--teal); background: var(--teal-soft); border-radius: 9px; }
#guide-icon i { display: block; }
#guide-icon svg { display: none; width: 20px; height: 20px; }
#onboarding-card[data-step="1"] #guide-icon i { position: absolute; width: 20px; height: 20px; border: 1px solid currentColor; border-radius: 50%; animation: guide-ripple 1.6s ease-out infinite; }
#onboarding-card[data-step="1"] #guide-icon i:nth-child(2) { animation-delay: .45s; }
#onboarding-card[data-step="1"] #guide-icon i:nth-child(3) { width: 5px; height: 5px; border: 0; background: currentColor; animation: none; }
#onboarding-card[data-step="2"] #guide-icon i { width: 6px; height: 10px; margin: 0 1px; border-radius: 2px; background: var(--teal); animation: guide-chip 1.6s ease-in-out infinite; }
#onboarding-card[data-step="2"] #guide-icon i:nth-child(2) { background: var(--accent); animation-delay: .12s; }
#onboarding-card[data-step="2"] #guide-icon i:nth-child(3) { background: #ca9b36; animation-delay: .24s; }
#onboarding-card[data-step="3"] #guide-icon i { position: absolute; width: 18px; height: 18px; border: 2px solid transparent; border-top-color: currentColor; border-bottom-color: currentColor; border-radius: 50%; animation: guide-turn 1.8s ease-in-out infinite; }
#onboarding-card[data-step="3"] #guide-icon i:not(:first-child) { display: none; }
#onboarding-card[data-checked="true"] #guide-icon i, #onboarding-card[data-step="4"] #guide-icon i { display: none; }
#onboarding-card[data-checked="true"] #guide-icon svg, #onboarding-card[data-step="4"] #guide-icon svg { display: block; animation: guide-enter .18s ease-out both; }
#palette-rail[data-guide-cue="palette"] .swatch[aria-pressed="true"]::before { animation: guide-breathe 1.8s ease-in-out infinite; }
#world.guide-active #hint-wrap { display: none; }
#world.guide-active .toast { bottom: calc(var(--workbench-h, 108px) + var(--safe-bottom) + 105px); }
@keyframes guide-enter { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes guide-breathe { 50% { opacity: .62; } }
@keyframes guide-ripple { from { transform: scale(.42); opacity: .95; } to { transform: scale(1.15); opacity: .2; } }
@keyframes guide-chip { 50% { transform: translateY(-3px); } }
@keyframes guide-turn { 50% { transform: rotate(95deg); } }

#replay-guide-btn { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 44px; padding: 7px 10px; border: 1px solid rgba(35, 66, 58, .15); border-radius: 11px; background: var(--paper-deep); color: var(--ink); text-align: left; }
#replay-guide-btn small { display: block; margin-top: 3px; color: var(--ink-soft); }
#replay-guide-btn svg { transform: rotate(-90deg); }
#guide-storage-status { margin: 8px 0 0; font-size: 12px; color: var(--warn); }

/* Long-press Touch Rebound Ring */
#release-fx {
  position: fixed;
  z-index: 15;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

#release-fx.picked::before,
#release-fx.picked::after {
  content: "";
  position: absolute;
  left: -20px;
  top: -20px;
  width: 40px;
  height: 40px;
  border: 2px solid #fff8dc;
  border-radius: 50%;
  animation: release-ring .44s ease-out both;
}

#release-fx.picked::after {
  border: 1.5px dashed #ffe6b8;
  animation-delay: 75ms;
}

@keyframes release-ring { from { transform: scale(.3); opacity: .95; } to { transform: scale(1.75); opacity: 0; } }
@keyframes pop-up { from { opacity: 0; transform: translateY(8px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes open-drawer { from { opacity: 0; transform: translateY(8px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes open-drawer-centered { from { opacity: 0; transform: translate(-50%, 8px) scale(.94); } to { opacity: 1; transform: translateX(-50%); } }
@keyframes close-drawer { to { opacity: 0; transform: translateY(6px) scale(.97); } }
@keyframes pick-chip { 0% { transform: scale(.86); } 60% { transform: translateY(-3px) scale(1.1); } 100% { transform: translateY(-2px) scale(1.06); } }
@keyframes button-tap { 0% { transform: scale(.93); } 60% { transform: scale(1.04); } 100% { transform: scale(1); } }
@keyframes card-away { to { opacity: 0; transform: scale(.88); } }
@keyframes sheet-in { from { opacity: .6; transform: translateY(28px); } to { opacity: 1; transform: none; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }

dialog button.picked,
dialog summary.picked,
dialog label.picked,
.hud-capsule button.picked,
#tool-dock button.picked {
  animation: button-tap .24s ease-out;
}

/* ==========================================================================
   Dialogs & Studio Sheets (Menu, Template, Share, Confirm)
   ========================================================================== */
dialog {
  width: 490px;
  width: min(490px, calc(100vw - 28px));
  max-width: calc(100vw - 28px);
  max-height: 86vh;
  max-height: min(86dvh, calc(100dvh - 32px));
  padding: 0;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid rgb(35 66 58 / 18%);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  overscroll-behavior: contain;
}

dialog[open] {
  display: flex;
  flex-direction: column;
  animation: modal-in .2s cubic-bezier(.18, .85, .28, 1) both;
}

dialog::backdrop {
  background: rgb(20 44 40 / 34%);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.sheet-handle {
  display: none;
  justify-content: center;
  padding: 9px 0 2px;
  flex: none;
}

.sheet-handle span {
  width: 38px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: rgb(35 66 58 / 20%);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 12px;
  margin: 0;
  background: var(--paper);
  flex: none;
}

.dialog-head h2 {
  margin: 0;
  font: 700 20px/1.3 var(--font-serif);
  letter-spacing: .06em;
  color: var(--ink);
}

.game-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-title img {
  border-radius: 10px;
  box-shadow: 0 2px 8px rgb(24 54 48 / 16%);
}

.icon-lg {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid rgb(35 66 58 / 14%);
  border-radius: 50%;
  background: var(--paper-card);
  color: var(--ink-soft);
  transition: background-color .14s ease, color .14s ease;
}

.icon-lg:hover {
  background: var(--paper-deep);
  color: var(--ink);
}

/* Menu 3-Tab Navigation */
.menu-tabs-wrap {
  padding: 0 20px 12px;
  border-bottom: 1px solid rgb(35 66 58 / 10%);
  flex: none;
}

.menu-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--paper-deep);
}

.menu-tabs button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color .15s ease, color .15s ease, box-shadow .15s ease;
}

.menu-tabs button svg { width: 15px; height: 15px; }

.menu-tabs button[aria-selected="true"] {
  background: var(--paper-card);
  color: var(--ink);
  box-shadow: 0 2px 6px rgb(22 52 46 / 10%);
}

.dialog-body {
  padding: 16px 20px 22px;
  overflow-y: auto;
  flex: 1 1 auto;
  font-size: 13.5px;
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Author Module & Save Warning Banner */
#author-module {
  padding: 10px 13px;
  border-radius: 15px;
  background: linear-gradient(135deg, #f3f7f2, #f9f3e7);
  border: 1px solid rgb(35 92 80 / 16%);
}

.author-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.author-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  color: var(--ink);
}

.author-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
}

#follow-author {
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #fffcf5;
  font-size: 12.5px;
  font-weight: 650;
}

#follow-author:hover:not(:disabled) { background: var(--accent-hover); }
#follow-author:disabled { background: var(--teal-soft); color: var(--teal); opacity: .88; }
#follow-status:empty { display: none; }
#follow-status { margin: 7px 0 0; font-size: 12px; color: var(--warn); }

.alert-banner {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 13px;
  background: var(--warn-soft);
  border: 1px solid rgb(180 105 36 / 26%);
  color: #7d4512;
  font-size: 12.5px;
  line-height: 1.5;
}

.alert-banner svg { width: 17px; height: 17px; margin-top: 1px; flex: none; }
.alert-banner p { margin: 0; }

/* Current Town Card (Tab 1) */
.current-town-card {
  border: 1px solid rgb(35 66 58 / 14%);
  border-radius: 18px;
  background: var(--paper-card);
  overflow: hidden;
  box-shadow: 0 2px 10px rgb(22 52 46 / 6%);
}

.menu-cover {
  position: relative;
  height: clamp(106px, 18vh, 148px);
  background: linear-gradient(120deg, #7fb3b3, #b5d2c5 55%, #84b4b3);
  overflow: hidden;
}

.menu-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.menu-cover img:not([src]) { visibility: hidden; }

.cover-badges {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: flex;
  gap: 6px;
}

.cover-pill {
  font-size: 11px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  background: rgb(25 50 45 / 76%);
  color: #fffaf0;
  backdrop-filter: blur(6px);
}

.current-town-body {
  padding: 13px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 650;
  color: var(--ink-soft);
}

.name-row {
  display: flex;
  gap: 7px;
}

.name-row input,
textarea {
  min-width: 0;
  border: 1.25px solid rgb(35 66 58 / 20%);
  background: var(--paper);
  border-radius: 11px;
  padding: 9px 12px;
  color: var(--ink);
  transition: border-color .15s ease, background-color .15s ease;
}

.name-row input:focus,
textarea:focus {
  border-color: var(--teal);
  background: #fff;
}

.name-row input {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
}

.name-row button,
.quick-town-strip button,
.menu-actions button,
#read-code,
#default-light {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid rgb(35 66 58 / 16%);
  border-radius: 11px;
  background: var(--paper-deep);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color .14s ease, border-color .14s ease, transform .12s ease;
}

.name-row button:hover:not(:disabled),
.quick-town-strip button:hover:not(:disabled),
.menu-actions button:hover:not(:disabled),
#default-light:hover:not(:disabled) {
  background: #e5ebd9;
  border-color: rgb(35 92 80 / 28%);
}

.dialog-body button svg { width: 16px; height: 16px; }

.accent-btn,
.name-row #save-name:not(:disabled) {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #fffcf5 !important;
}

.accent-btn:hover:not(:disabled),
.name-row #save-name:not(:disabled):hover {
  background: var(--accent-hover) !important;
}

.quick-town-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.quick-town-strip button {
  min-height: 36px;
  padding: 0 8px;
  font-size: 12px;
  background: var(--paper);
}

.quick-town-strip .danger-quiet {
  color: var(--danger);
  border-color: rgb(178 64 52 / 22%);
  background: rgb(251 232 229 / 55%);
}

.quick-town-strip .danger-quiet:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: rgb(178 64 52 / 40%);
}

/* Town Shelf & Cards */
#town-shelf,
#landmarks {
  margin: 0;
}

#town-shelf > summary,
#landmarks > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 2px 10px;
  list-style: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

#town-shelf > summary::-webkit-details-marker,
#landmarks > summary::-webkit-details-marker { display: none; }

.count-badge {
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  background: var(--paper-deep);
  color: var(--ink-soft);
}

.sub-hint {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-muted);
}

#town-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.town-card {
  position: relative;
  min-width: 0;
}

.town-card.leaving { animation: card-away .16s ease-in both; }

#town-cards .town-open {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0;
  overflow: hidden;
  text-align: left;
  border: 1.25px solid rgb(35 66 58 / 15%);
  border-radius: 14px;
  background: var(--paper-card);
  transition: transform .14s ease, border-color .15s ease, box-shadow .15s ease;
}

#town-cards .town-open:hover {
  border-color: rgb(35 92 80 / 40%);
  box-shadow: 0 4px 14px rgb(22 52 46 / 10%);
}

#town-cards .town-open[aria-current="true"] {
  border-color: var(--teal);
  box-shadow: 0 0 0 1.5px var(--teal);
}

#town-cards .town-open[aria-current="true"]::after {
  content: "当前";
  position: absolute;
  left: 7px;
  top: 7px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--teal);
  color: #fffcf4;
  font-size: 10.5px;
  font-weight: 700;
}

#town-cards img {
  display: block;
  width: 100%;
  aspect-ratio: 1.75;
  object-fit: cover;
  background: #b5d6ce;
}

.town-card-info {
  padding: 8px 36px 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.town-card-title {
  font-size: 13px;
  font-weight: 650;
  color: var(--ink);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.town-card-meta {
  font-size: 11px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

#town-cards .town-delete {
  position: absolute;
  right: 4px;
  bottom: 5px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-muted);
}

#town-cards .town-delete:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

#town-cards .town-delete svg { width: 15px; height: 15px; }

.empty-note {
  margin: 6px 0;
  padding: 16px;
  border-radius: 14px;
  background: var(--paper-deep);
  color: var(--ink-soft);
  text-align: center;
  font-size: 12.5px;
}

/* Landmarks & Starters (Tab 2) */
#landmark-list {
  display: grid;
  gap: 9px;
}

#landmark-list button {
  display: grid;
  grid-template-columns: 116px 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 0 12px 0 0;
  overflow: hidden;
  text-align: left;
  border: 1px solid rgb(35 66 58 / 15%);
  border-radius: 15px;
  background: var(--paper-card);
  transition: transform .14s ease, border-color .15s ease, box-shadow .15s ease;
}

#landmark-list button:hover {
  border-color: var(--teal);
  box-shadow: 0 4px 14px rgb(22 52 46 / 10%);
}

#landmark-list img {
  width: 100%;
  height: 100%;
  min-height: 78px;
  object-fit: cover;
  display: block;
  background: #9ec5c4;
}

#landmark-list .landmark-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 8px 0;
}

#landmark-list b {
  font-size: 14px;
  color: var(--ink);
}

#landmark-list small {
  font-size: 11.5px;
  color: var(--ink-muted);
}

.landmark-go {
  font-size: 11.5px;
  font-weight: 650;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  background: var(--teal-soft);
  color: var(--teal);
  white-space: nowrap;
}

#landmark-status {
  margin: 8px 0 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--paper-deep);
  font-size: 12.5px;
  color: var(--ink-soft);
}

.panel-card {
  padding: 14px;
  border-radius: 16px;
  background: var(--paper-card);
  border: 1px solid rgb(35 66 58 / 13%);
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.card-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

.card-head span {
  font-size: 11.5px;
  color: var(--ink-muted);
}

.examples {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.starter-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 11px 12px;
  border: 1px solid rgb(35 66 58 / 15%);
  border-radius: 13px;
  background: var(--paper);
  text-align: left;
  transition: background-color .14s ease, border-color .14s ease;
}

.starter-btn:hover {
  background: var(--teal-soft);
  border-color: rgb(35 92 80 / 32%);
}

.starter-btn strong { font-size: 13px; color: var(--ink); }
.starter-btn small { font-size: 11.5px; line-height: 1.4; color: var(--ink-muted); }

.starter-accent {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, #fdf3ec, #f9f5e8);
  border-color: rgb(200 90 59 / 26%);
}

.starter-accent:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* Save / Share / Audio / Lighting (Tab 3) */
.menu-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.menu-actions button {
  background: var(--paper);
  min-height: 42px;
}

#code-box {
  padding: 11px;
  border-radius: 13px;
  background: var(--paper-deep);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

textarea {
  display: block;
  width: 100%;
  resize: vertical;
  font: 12px/1.55 ui-monospace, "Cascadia Mono", Consolas, monospace;
}

.code-box-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#code-info,
.inline-status {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink-soft);
}

#code-info.is-error,
.inline-status.is-error { color: var(--danger); }

#code-info.is-ok,
.inline-status.is-ok { color: var(--ok); }

/* Audio & Lighting Controls */
.volume-control {
  display: grid;
  grid-template-columns: 36px auto minmax(0, 1fr) 4.2ch;
  align-items: center;
  gap: 8px;
}

#menu-sound-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid rgb(35 66 58 / 14%);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
}

.volume-control label { font-size: 13px; font-weight: 600; white-space: nowrap; }
.volume-control input,
.sun-controls input,
.template-control input {
  width: 100%;
  margin: 0;
  height: 24px;
  accent-color: var(--teal);
}

.volume-control output,
.sun-controls output,
.template-control output {
  text-align: right;
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--teal);
}

.light-presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.light-presets button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 6px;
  border: 1.25px solid rgb(35 66 58 / 15%);
  border-radius: 13px;
  background: var(--paper);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

.light-presets button:hover {
  background: var(--paper-deep);
  color: var(--ink);
}

.light-presets button[aria-pressed="true"] {
  background: var(--teal);
  border-color: var(--teal);
  color: #fffcf5;
}

.light-presets button[data-light-preset="1"][aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
}

.light-presets button[data-light-preset="2"][aria-pressed="true"] {
  background: #365985;
  border-color: #365985;
}

.sun-controls {
  padding-top: 8px;
  border-top: 1px solid rgb(35 66 58 / 10%);
}

.sun-controls summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--ink-soft);
}

.sun-sliders {
  display: grid;
  gap: 8px;
  margin: 10px 0;
}

.sun-controls label {
  display: grid;
  grid-template-columns: 36px 1fr 40px;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
}

#default-light {
  width: 100%;
  min-height: 36px;
  font-size: 12.5px;
  background: var(--paper);
}

/* Shortcuts Card */
.shortcut-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  margin: 0;
}

.shortcut-grid div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
}

.shortcut-grid dt { color: var(--ink); font-weight: 600; }
.shortcut-grid dd { margin: 0; color: var(--ink-muted); }

kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid rgb(35 66 58 / 22%);
  background: var(--paper);
  font: 600 11px/1.4 var(--font-sans);
  box-shadow: 0 1px 0 rgb(35 66 58 / 12%);
}

/* ==========================================================================
   Template Configurator Dialog
   ========================================================================== */
#template-dialog { width: min(468px, calc(100vw - 26px)); }
#template-form { display: flex; flex-direction: column; min-height: 0; height: 100%; margin: 0; }

.template-body {
  padding: 4px 20px 22px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.template-map {
  position: relative;
  margin: 0;
  border: 1px solid rgb(35 92 80 / 24%);
  border-radius: 16px;
  overflow: hidden;
  background: linear-gradient(160deg, #b8dbd2, #8bc0be);
}

.template-map canvas {
  display: block;
  width: 100%;
  height: auto;
}

.template-map figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 13px;
  background: rgb(252 250 242 / 92%);
  color: var(--ink);
  font-size: 13.5px;
}

.template-map figcaption span {
  font-size: 12px;
  font-weight: 600;
  color: var(--teal);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--teal-soft);
}

.template-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.template-presets button {
  min-height: 34px;
  padding: 0 6px;
  border: 1px solid rgb(35 66 58 / 16%);
  border-radius: 10px;
  background: var(--paper-card);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  transition: background-color .14s ease, border-color .14s ease, color .14s ease;
}

.template-presets button:hover,
.template-presets button[aria-pressed="true"] {
  background: var(--teal-soft);
  border-color: var(--teal);
  color: var(--teal);
}

.template-materials {
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
}

.template-materials legend {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.template-materials small {
  margin-left: 6px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-muted);
}

#template-choices {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 8px;
}

#template-choices label {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 11px 4px 8px;
  border: 1.5px solid rgb(35 66 58 / 16%);
  border-radius: 13px;
  background: var(--paper-card);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  transition: border-color .14s ease, background-color .14s ease, transform .12s ease;
}

#template-choices label:has(:checked) {
  border-color: var(--teal);
  background: var(--teal-soft);
  color: var(--teal);
}

#template-choices label:has(:focus-visible) {
  outline: 2.5px solid var(--focus);
  outline-offset: 2px;
}

#template-choices input {
  position: absolute;
  right: 6px;
  top: 6px;
  margin: 0;
  width: 14px;
  height: 14px;
  accent-color: var(--teal);
}

#template-choices i { width: 32px; height: 22px; border-radius: 6px; }

.template-sliders {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--paper-card);
  border: 1px solid rgb(35 66 58 / 12%);
}

.template-control {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 3px 8px;
}

.template-control label { font-size: 13px; font-weight: 650; }
.template-control input { grid-column: 1 / -1; }
.range-ends {
  display: flex;
  justify-content: space-between;
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--ink-muted);
}

#template-error {
  margin: 0;
  padding: 8px 11px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 500;
}

/* ==========================================================================
   Share Postcard Dialog
   ========================================================================== */
#share-dialog { width: 440px; max-width: calc(100vw - 26px); }

.share-body {
  padding: 4px 20px 22px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#postcard {
  margin: 0;
  padding: 10px 10px 0;
  border: 1px solid rgb(35 66 58 / 16%);
  background: #fffef9;
  border-radius: 16px;
  box-shadow: 0 6px 20px rgb(24 54 48 / 11%);
}

.postcard-frame {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: #b1d5d3;
}

#share-image {
  display: block;
  width: 100%;
  height: 192px;
  height: clamp(152px, 28vh, 236px);
  object-fit: cover;
}

#postcard figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 4px;
}

#postcard strong {
  font: 700 17px/1.35 var(--font-serif);
  color: var(--ink);
  overflow-wrap: anywhere;
}

.postcard-brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
}

.postcard-brand img { border-radius: 7px; }

#share-status:empty { display: none; }
#share-status {
  margin: 0;
  padding: 8px 12px;
  border-radius: 11px;
  background: var(--paper-deep);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-soft);
}

.primary-action,
.quiet-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  min-height: 46px;
  padding: 0 16px;
  border-radius: 13px;
  font-size: 14px;
  font-weight: 650;
  transition: background-color .15s ease, border-color .15s ease, transform .12s ease;
}

.primary-action {
  border: 0;
  background: var(--accent);
  color: #fffcf5;
}
.primary-action:hover:not(:disabled) { background: var(--accent-hover); }

.quiet-action {
  border: 1.25px solid rgb(35 66 58 / 18%);
  background: var(--paper-card);
  color: var(--ink);
}
.quiet-action:hover:not(:disabled) { background: var(--teal-soft); border-color: var(--teal); color: var(--teal); }
#share-save[data-saved] {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: rgb(46 125 88 / 35%);
}

.share-code-card {
  padding: 6px 12px 10px;
  border-radius: 14px;
  background: var(--paper-card);
  border: 1px solid rgb(35 66 58 / 13%);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.share-code-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.share-code-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.share-code-option input {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--teal);
}

#share-copy {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid rgb(35 66 58 / 18%);
  border-radius: 9px;
  background: var(--paper-deep);
  font-size: 12px;
  font-weight: 650;
  color: var(--ink);
}

#share-copy:hover:not(:disabled) { background: var(--teal-soft); color: var(--teal); }
#share-copy-status:empty { display: none; }
#share-copy-status { font-size: 12px; color: var(--ok); font-weight: 500; }
#album-feedback:empty { display: none; }
#album-feedback { margin: 0; font-size: 12.5px; color: var(--warn); text-align: center; }

/* ==========================================================================
   Destructive Confirm Dialogs
   ========================================================================== */
.confirm-dialog {
  width: min(320px, calc(100vw - 32px));
  border-radius: 22px;
}

.confirm-dialog form {
  padding: 22px 20px 18px;
  text-align: center;
}

.confirm-icon {
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-bottom: 12px;
  border-radius: 14px;
}

.confirm-icon.warn { background: var(--warn-soft); color: var(--warn); }
.confirm-icon.danger { background: var(--danger-soft); color: var(--danger); }
.confirm-icon svg { width: 22px; height: 22px; }

.confirm-title {
  margin: 0 0 6px;
  font: 700 18px/1.35 var(--font-serif);
  color: var(--ink);
}

.confirm-note {
  margin: 0 0 18px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.confirm-actions button {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1.25px solid rgb(35 66 58 / 18%);
  background: var(--paper-card);
  font-size: 13.5px;
  font-weight: 650;
  color: var(--ink);
}

.confirm-actions button:hover:not(:disabled) { background: var(--paper-deep); }

.confirm-actions .danger-btn {
  background: var(--danger);
  border-color: var(--danger);
  color: #fffaf4;
}

.confirm-actions .danger-btn:hover:not(:disabled) {
  background: var(--danger-hover);
}

/* ==========================================================================
   Responsive Adaptation — Mobile-First Compact Mode (<= 860px)
   ========================================================================== */
@media (pointer: coarse) {
  .hint .for-touch { display: flex; }
  .hint .for-mouse { display: none; }
}

@media (max-width: 1120px) {
  .hint-wrap {
    top: calc(var(--gap) + var(--safe-top) + 54px);
    bottom: auto;
    max-width: calc(100vw - 88px);
  }
  .hud-capsule button .btn-label { display: none; }
  .hud-capsule button.share-accent,
  .hud-capsule #menu-btn { padding: 0 9px; }
}

@media (max-width: 860px), (pointer: coarse) and (max-width: 1100px) {
  :root { --gap: 10px; }

  .brand { max-width: calc(100vw - 186px); }
  .brand-emblem { width: 24px; height: 24px; border-radius: 8px; }
  .brand h1 { display: none; }
  .brand-title-row { display: none; }
  .town-pill { min-height: 40px; padding: 4px 9px 4px 6px; border-radius: 14px; gap: 7px; }
  .brand-town-row { font-size: 12.5px; color: var(--ink); }

  .hud-top-right { gap: 6px; }
  .hud-capsule { padding: 3px; border-radius: 14px; }
  .hud-capsule button { min-width: 34px; height: 34px; padding: 0; border-radius: 10px; }
  .hud-capsule button svg { width: 18px; height: 18px; }

  /* Right-Edge Vertical View Rail on Mobile — Keeps top bar airy & thumb-friendly */
  .view-rail {
    position: fixed;
    right: calc(var(--gap) + var(--safe-right));
    top: calc(var(--gap) + var(--safe-top) + 48px);
    flex-direction: column;
    padding: 4px 3px;
    border-radius: 15px;
    z-index: 4;
  }

  .view-rail .rail-sep {
    width: 18px;
    height: 1px;
    margin: 3px 0;
  }

  .view-rail #sound-btn { display: none; }

  /* Expandable Foundation Popover Tray on Mobile — Centered cleanly on #tool-dock */
  #tool-dock { position: relative; }
  #foundation-wrap { position: static; }
  #foundation-trigger { display: inline-flex; height: 38px; padding: 0 10px; }

  #foundations {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 10px);
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100vw - 16px);
    padding: 5px;
    gap: 2px;
    border-radius: 16px;
    background: var(--glass-strong);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-highlight), var(--shadow-lg);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    z-index: 9;
    animation: open-drawer-centered .18s cubic-bezier(.16, .84, .26, 1.08) both;
  }

  #foundations:not([data-open="true"]) { display: none; }
  #foundations .tray-label { display: none; }
  #foundations button { height: 38px; padding: 0 8px; gap: 4px; font-size: 12px; }
  #foundations #replace-foundation { margin-left: 2px; padding: 0 8px; }

  #tool-dock { gap: 3px; padding: 4px; border-radius: 17px; }
  #tool-dock > button,
  #foundation-trigger,
  #items-btn { height: 38px; padding: 0 11px; font-size: 12.5px; }

  #workbench { bottom: calc(6px + var(--safe-bottom)); }
  #palette-rail { --chip: 38px; }
  .hint-wrap { display: none; }

  .toast { bottom: calc(122px + var(--safe-bottom)); font-size: 12.5px; }

  /* Mobile Bottom Sheet Presentation for Menu, Template & Share */
  #menu,
  #template-dialog,
  #share-dialog {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    width: min(100vw, 520px);
    max-width: 100vw;
    max-height: calc(100vh - var(--safe-top) - 12px);
    max-height: min(88dvh, calc(100dvh - var(--safe-top) - 12px));
    margin: 0 auto;
    padding-bottom: var(--safe-bottom);
    border-radius: 26px 26px 0 0;
    border-bottom: 0;
  }

  #menu[open],
  #template-dialog[open],
  #share-dialog[open] {
    animation: sheet-in .24s cubic-bezier(.18, .82, .24, 1) both;
  }

  #menu .sheet-handle,
  #template-dialog .sheet-handle,
  #share-dialog .sheet-handle {
    display: flex;
  }

  .dialog-head { padding: 8px 18px 10px; }
  .menu-tabs-wrap { padding: 0 16px 10px; }
  .dialog-body, .template-body, .share-body { padding: 14px 16px 18px; }
  .shortcut-card { display: none; }
}

html.pocket #hint-wrap, html.pocket .shortcut-card { display: none; }

@media (max-width: 360px) {
  #palette-rail { --chip: 36px; }
}

@media (max-width: 390px) {
  .brand { max-width: calc(100vw - 170px); }
  #tool-dock > button,
  #foundation-trigger,
  #items-btn { padding: 0 8px; gap: 4px; font-size: 12px; }
  #foundations { max-width: calc(100vw - 16px); }
  #foundations button { padding: 0 7px; font-size: 11.5px; }
  .quick-town-strip { grid-template-columns: 1fr 1fr; }
  .quick-town-strip #menu-reset-btn { grid-column: 1 / -1; }
  .template-presets { grid-template-columns: repeat(2, 1fr); }
  #landmark-list button { grid-template-columns: 96px 1fr; }
  #landmark-list .landmark-go { display: none; }
}

/* Short Landscape Mobile Screens */
@media (max-height: 480px) and (min-width: 480px) {
  .hint-wrap { display: none; }
  #workbench { bottom: calc(6px + var(--safe-bottom)); }
  #palette-rail { --chip: 32px; margin-top: 4px; }
  #tool-dock > button, #foundation-trigger, #items-btn { height: 32px; }
  .view-rail { top: calc(var(--gap) + var(--safe-top) + 46px); }
}

/* Reduced Motion Respect */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  #release-fx.picked::before, #release-fx.picked::after { animation: none; opacity: 0; }
  #hold-cue[data-phase="erase"] .hold-progress { animation: none; stroke-dashoffset: 18.85; }
  #onboarding-card, #onboarding-card *, #palette-rail[data-guide-cue] .swatch::before { animation: none !important; }
}
