:root {
  --ink: #24160f;
  --plum: #4a2c1a;      /* walnut 1: panel rows */
  --plum-2: #2f1c12;    /* walnut 0: panel body */
  --plum-3: #6b4026;    /* walnut 2: ghost buttons, borders */
  --cream: #f6ead2;
  --cream-2: #d9c6a0;
  --mint: #a9bf94;      /* sage 3 */
  --mint-d: #5f7a52;
  --pink: #e58a3a;      /* warm orange for alerts */
  --pink-d: #c8553d;
  --sun: #ddb55a;       /* brass */
  --sun-d: #7a5a1e;
  --red: #c8553d;
  --lilac: #cfdcbc;
  --muted: #e2cfaa;
  --paper-ink: #2b1a10; --paper-sub: #5b3d26; --paper-line: rgba(107, 63, 22, .22); --paper-well: rgba(160, 110, 50, .12);
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Source Han Sans SC", sans-serif;
  --unused-step: polygon(0 4px, 4px 4px, 4px 0, calc(100% - 4px) 0, calc(100% - 4px) 4px, 100% 4px, 100% calc(100% - 4px), calc(100% - 4px) calc(100% - 4px), calc(100% - 4px) 100%, 4px 100%, 4px calc(100% - 4px), 0 calc(100% - 4px));
  --step-sm: polygon(0 2px, 2px 2px, 2px 0, calc(100% - 2px) 0, calc(100% - 2px) 2px, 100% 2px, 100% calc(100% - 2px), calc(100% - 2px) calc(100% - 2px), calc(100% - 2px) 100%, 2px 100%, 2px calc(100% - 2px), 0 calc(100% - 2px));
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--ink); color: var(--cream);
  font-family: var(--font); -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none; touch-action: manipulation;
}
body { overflow: hidden; }
::selection { background: var(--sun); color: var(--ink); }

#stage {
  position: fixed;
  inset: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: grid; place-items: center; overflow: hidden;
}
#game {
  background: #2f1c12;
  display: block; /* backing store is 1:1 with device pixels; no CSS resampling */
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: pointer;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

button { font: inherit; color: inherit; }
button:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }

/* ---------------------------------------------------------------- generated UI skin
   Border images come from assets/ui-runtime (ImageGen materials sheet, source pixels):
   --bi-parchment (menu panel), --bi-button (sage button), --bi-plaque (walnut HUD plaque).
   ui-sprites.js sets them from the manifest after verifying every file loaded; pressed /
   disabled looks are CSS filters + offset on the same images (documented, not generated). */
.btn {
  height: 44px; min-width: 88px; padding: 0 10px; border: 0 solid transparent; border-width: 0 18px; cursor: pointer;
  border-image: var(--bi-button); background: none;
  color: var(--ink); font-weight: 800; font-size: 16px; line-height: 44px; white-space: nowrap;
  text-shadow: 0 1px 0 rgba(220, 235, 200, .45);
  filter: brightness(1.22); /* same readability lift as the canvas sage face (ui-sprites FACE_LIFT) */
  transition: transform 220ms cubic-bezier(.34, 1.8, .64, 1), filter 120ms;
}
.btn:active { transform: translateY(2px); filter: brightness(1.02); transition-duration: 40ms; }
.btn.ghost { border-image: var(--bi-plaque); border-width: 0 20px; color: var(--cream); text-shadow: 0 1px 0 var(--ink); filter: none; }
.btn.ghost:active { filter: brightness(.86); }
.btn.mint { filter: saturate(1.15) brightness(1.28); }
.btn.mint:active { filter: brightness(1.06); }
.btn:disabled { filter: grayscale(.7) brightness(1.15); color: var(--ink); cursor: not-allowed; transform: none; }
.btn.ghost:disabled { color: #e6d6b8; }
.icon-btn {
  height: 44px; min-width: 64px; border: 0 solid transparent; border-width: 0 20px; border-image: var(--bi-plaque); background: none;
  color: var(--cream); font-size: 14px; font-weight: 800; padding: 0 4px; line-height: 44px; cursor: pointer; white-space: nowrap;
  transition: transform 220ms cubic-bezier(.34, 1.8, .64, 1);
}
.icon-btn:active { transform: translateY(2px); filter: brightness(.86); transition-duration: 40ms; }

/* toast: walnut plaque, cream text */
.toast {
  position: absolute; left: 50%; top: 30%; transform: translateX(-50%);
  max-width: min(320px, 86vw); min-height: 44px; padding: 10px 6px; z-index: 30;
  border: 0 solid transparent; border-width: 0 14px; border-image: var(--bi-plaque-sm); background: none;
  color: var(--cream); font-size: 14px; font-weight: 700; line-height: 1.4; text-align: center; text-shadow: 0 1px 0 var(--ink);
  pointer-events: none; animation: toast-in 160ms cubic-bezier(.16,1,.3,1);
}
.toast.good { color: #e4f0d2; }
@keyframes toast-in { from { transform: translate(-50%, 6px); opacity: 0; } }

/* overlay dialogs: parchment panel */
.overlay {
  position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; padding: 12px;
  background: rgba(36, 22, 15, .72);
}
.overlay[hidden], .drawer[hidden], .toast[hidden] { display: none; }
.panel {
  width: min(380px, 100%); max-height: 100%; overflow: auto; overscroll-behavior: contain;
  border: 20px solid transparent; border-image: var(--bi-parchment); background: none;
  padding: 4px 4px 2px; color: var(--paper-ink);
  scrollbar-color: #a07a4a transparent; scrollbar-width: thin;
}
.panel h2 { margin: 0 0 4px; font-size: 22px; line-height: 1.25; letter-spacing: .02em; color: #6b3f16; }
.panel .sub { margin: 0 0 12px; font-size: 14px; line-height: 1.5; color: var(--paper-sub); }
.panel .actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.panel .actions .btn { flex: 1 1 120px; min-width: 0; padding: 0 6px; overflow: hidden; text-overflow: ellipsis; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.steps li {
  display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: center;
  padding: 6px 4px; border-bottom: 1px solid var(--paper-line); font-size: 14px; line-height: 1.45;
}
.steps li:last-child { border-bottom: 0; }
.steps li b { color: #6b3f16; font-weight: 800; }
.steps img, .pix { display: block; } /* bitmaps are pre-rendered at box size x DPR */
.steps img { width: 40px; height: 40px; object-fit: contain; object-position: center bottom; }

/* result */
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 8px 0 4px; }
.stat { padding: 6px 8px; background: var(--paper-well); border-radius: 6px; box-shadow: inset 0 0 0 1px var(--paper-line); }
.stat span { display: block; font-size: 12px; color: var(--paper-sub); }
.stat strong { font-size: 22px; color: var(--paper-ink); font-variant-numeric: tabular-nums; }
.stat.win strong { color: #3f6229; }
.stat.lose strong { color: #9a3520; }
.badge { display: inline-block; padding: 2px 10px; font-size: 13px; font-weight: 800; border-radius: 4px; }
.badge.win { background: #6f9a4e; color: #fff8e8; }
.badge.lose { background: #b24a33; color: #fff8e8; }

/* recipe book */
.book { display: grid; gap: 0; }
.recipe {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center;
  padding: 6px 2px; border-bottom: 1px solid var(--paper-line);
}
.recipe.locked { opacity: .55; }
.recipe.off { opacity: .75; }
.recipe h3 { margin: 0; font-size: 15px; color: var(--paper-ink); }
.recipe .price { font-weight: 800; color: #6b3f16; font-variant-numeric: tabular-nums; white-space: nowrap; }
.recipe .ings { display: flex; flex-wrap: wrap; gap: 2px 6px; margin-top: 3px; font-size: 12px; color: var(--paper-sub); align-items: center; }
.recipe .ings span { display: inline-flex; align-items: center; gap: 2px; }
.recipe .ings img { width: 20px; height: 20px; }
.recipe .note { font-size: 12px; color: #3f6229; margin-top: 2px; }
.recipe img.drink { width: 44px; height: 64px; object-fit: contain; object-position: center bottom; }
.book-tip { font-size: 13px; color: var(--paper-sub); line-height: 1.5; margin: 0 0 8px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 10px 0 0; font-size: 14px; }

/* drawer: parchment sheet sliding up */
.drawer {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 35;
  max-height: min(56%, 470px); display: flex; flex-direction: column;
  border: 18px solid transparent; border-bottom-width: 0; border-image: var(--bi-parchment); border-image-width: 18px 18px 0 18px; background: none;
  color: var(--paper-ink);
  width: min(480px, 100%); margin: 0 auto;
  animation: drawer-in 220ms cubic-bezier(.2,.9,.3,1);
}
@keyframes drawer-in { from { transform: translateY(40px); opacity: .4; } }
.drawer-head { display: flex; align-items: center; gap: 6px; padding: 0 0 6px; }
.tabs { display: flex; gap: 4px; flex: 1; min-width: 0; }
.tabs button {
  height: 44px; flex: 1; min-width: 0; border: 0 solid transparent; border-width: 0 16px; border-image: var(--bi-plaque); background: none;
  color: var(--cream); font-weight: 800; font-size: 15px; padding: 0; cursor: pointer; text-shadow: 0 1px 0 var(--ink);
  transition: transform 220ms cubic-bezier(.34, 1.8, .64, 1);
}
.tabs button:active { transform: translateY(2px); filter: brightness(.86); transition-duration: 40ms; }
.tabs button[aria-selected="true"] { border-image: var(--bi-button); border-width: 0 16px; color: var(--ink); text-shadow: none; filter: brightness(1.22); }
.money-chip { font-weight: 800; color: #6b3f16; white-space: nowrap; font-variant-numeric: tabular-nums; }
.drawer-body { overflow: auto; padding: 2px 0 calc(12px + env(safe-area-inset-bottom)); overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #a07a4a transparent; }
.drawer-note { font-size: 13px; color: var(--paper-sub); margin: 2px 2px 6px; line-height: 1.45; }
.row {
  display: grid; grid-template-columns: 36px 1fr auto; gap: 10px; align-items: center;
  padding: 5px 2px; border-bottom: 1px solid var(--paper-line);
}
.row img { width: 36px; height: 36px; object-fit: contain; object-position: center bottom; }
.row .name { font-weight: 800; font-size: 15px; }
.row .meta { font-size: 12px; color: var(--paper-sub); font-variant-numeric: tabular-nums; }
.row .btn { min-width: 92px; font-size: 14px; padding: 0 6px; }
.pips { display: inline-flex; gap: 3px; vertical-align: middle; margin-left: 4px; }
.pips i { width: 8px; height: 8px; border-radius: 50%; background: #c9ad84; box-shadow: inset 0 0 0 1px #8a6a44; }
.pips i.on { background: #ddb55a; box-shadow: inset 0 0 0 1px #7a5a1e; }
.check {
  height: 44px; min-width: 76px; border: 0 solid transparent; border-width: 0 16px; border-image: var(--bi-plaque); background: none; cursor: pointer;
  color: var(--cream); font-weight: 800; font-size: 13px; padding: 0; text-shadow: 0 1px 0 var(--ink);
  transition: transform 220ms cubic-bezier(.34, 1.8, .64, 1);
}
.check:active { transform: translateY(2px); transition-duration: 40ms; }
.check[aria-checked="true"] { border-image: var(--bi-button); border-width: 0 16px; color: var(--ink); text-shadow: none; filter: brightness(1.22); }
.check:disabled { filter: grayscale(.6); opacity: .8; cursor: not-allowed; }

@media (prefers-reduced-motion: reduce) {
  .toast, .drawer { animation: none; }
  .btn, .icon-btn, .tabs button, .check { transition: none; }
}

.panel code { font-size: 12px; background: var(--paper-well); padding: 1px 4px; color: #6b3f16; }
.missing { margin: 0 0 8px; padding: 6px 8px 6px 24px; max-height: 180px; overflow: auto; background: var(--paper-well); font-size: 12px; color: #9a3520; line-height: 1.5; }
html, body { background: #1c100a; }
#panel-title small { font-size: 12px; font-weight: 700; color: var(--paper-sub); margin-left: 6px; }
.panel .actions.sticky { position: sticky; bottom: -2px; margin: 8px -4px -2px; padding: 8px 4px 4px; background: #efe0c2; box-shadow: 0 -1px 0 var(--paper-line); }

/* art provenance tag: tiny, in help/pause panels only */
.art-tag { margin: 8px 0 0; font-size: 10px; line-height: 1.2; color: #7d6040; text-align: right; letter-spacing: .02em; }
/* explicit missing-UI-asset marker (set by ui-sprites.js): magenta outline instead of any old look */
:root[data-ui-missing] .panel, :root[data-ui-missing] .btn, :root[data-ui-missing] .drawer { outline: 3px solid #ff00c8; }

/* ---------------------------------------------------------------- customization + economy (UI overhaul) */
/* quality feedback is an accepted serve with a note, not a failure: amber, longer, no shake */
.toast.review { color: #ffe2a8; }
.note-sm { margin: 4px 0 8px; font-size: 12px; line-height: 1.45; color: var(--paper-sub); }
.warn { margin: 8px 0; padding: 6px 8px; font-size: 13px; line-height: 1.45; color: #7a2a18; background: rgba(200, 85, 61, .12); box-shadow: inset 0 0 0 1px rgba(154, 53, 32, .25); border-radius: 4px; }
.goal { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 0 8px; padding: 6px 8px; margin: 4px 0 2px; border-radius: 6px; background: var(--paper-well); box-shadow: inset 0 0 0 1px var(--paper-line); }
.goal span { grid-column: 1 / -1; font-size: 12px; color: var(--paper-sub); }
.goal strong { font-size: 24px; font-variant-numeric: tabular-nums; }
.goal em { font-style: normal; font-weight: 800; font-size: 13px; padding: 1px 8px; border-radius: 4px; color: #fff8e8; }
.goal.win strong { color: #3f6229; } .goal.win em { background: #6f9a4e; }
.goal.lose strong { color: #9a3520; } .goal.lose em { background: #b24a33; }
.ledger { width: 100%; border-collapse: collapse; margin: 2px 0 8px; font-size: 14px; font-variant-numeric: tabular-nums; }
.ledger th { text-align: left; font-weight: 700; color: var(--paper-ink); padding: 3px 2px; }
.ledger th small { display: block; font-size: 11px; font-weight: 600; color: var(--paper-sub); }
.ledger td { text-align: right; padding: 3px 2px; font-weight: 800; white-space: nowrap; }
.ledger tr { border-bottom: 1px solid var(--paper-line); }
.ledger tr.neg td { color: #9a3520; }
.ledger tr.sum { background: var(--paper-well); }
.ledger tr.sum td { font-size: 16px; }
.ledger tr.sum.pos td { color: #3f6229; }
.result-grid { grid-template-columns: repeat(4, 1fr); }
.result-grid .stat strong { font-size: 18px; }
.tops { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 0 0 6px; }
.tops span { display: grid; justify-items: center; text-align: center; font-size: 12px; color: var(--paper-ink); padding: 4px 2px; background: var(--paper-well); border-radius: 4px; }
.tops em { font-style: normal; font-size: 11px; color: var(--paper-sub); }
.drawer-warn { margin: 2px 2px 6px; padding: 6px 8px; font-size: 13px; line-height: 1.4; color: #7a2a18; background: rgba(200, 85, 61, .14); border-radius: 4px; }
.money-chip.debt { color: #9a3520; }
.money-chip { font-size: 13px; }
/* drawer head: cash + close on the first row, tabs full width below (no wrapped tab labels at 360) */
.drawer-head { flex-wrap: wrap; row-gap: 4px; }
.drawer-head .tabs { order: 2; flex: 1 1 100%; }
.drawer-head .money-chip { order: 0; flex: 1 1 auto; }
.drawer-head .icon-btn { order: 1; }
.tabs button { white-space: nowrap; }
.toast { max-width: min(352px, 94vw); }
.toast.review { font-size: 13px; line-height: 1.35; }
/* centre without left:50% (which halved the shrink-to-fit width and wrapped review notes to 4 lines) */
.toast { left: 0; right: 0; margin: 0 auto; width: fit-content; transform: none; animation-name: toast-in2; }
@keyframes toast-in2 { from { transform: translateY(6px); opacity: 0; } }

/* ---------------------------------------------------------------- guided practice coach card
   DOM so it is focusable and readable (cream on deep walnut, >= 4.5:1). Positioned by app.js
   above or below the highlighted target; the target itself is never covered. */
.coach {
  position: absolute; z-index: 32; box-sizing: border-box;
  padding: 8px 12px 10px; color: var(--cream);
  background: rgba(36, 22, 15, .96); border-radius: 10px;
  box-shadow: 0 0 0 2px #ddb55a, 0 6px 18px rgba(0, 0, 0, .45);
  animation: coach-in 180ms cubic-bezier(.16, 1, .3, 1);
}
.coach[hidden] { display: none; }
@keyframes coach-in { from { transform: translateY(6px); opacity: 0; } }
.coach-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.coach-step { font-size: 12px; font-weight: 800; color: #f6dd92; letter-spacing: .04em; font-variant-numeric: tabular-nums; }
.coach-skip {
  height: 32px; min-width: 44px; padding: 0 10px; border: 1px solid rgba(246, 221, 146, .55); border-radius: 6px;
  background: transparent; color: #f6dd92; font-size: 12px; font-weight: 800; cursor: pointer;
}
.coach-skip:active { background: rgba(246, 221, 146, .15); }
.coach h3 { margin: 4px 0 2px; font-size: 16px; line-height: 1.3; color: #fff8e8; }
.coach p { margin: 0; font-size: 14px; line-height: 1.45; color: #f6ead2; }
.coach-hint { margin-top: 4px !important; font-weight: 800; color: #ffe2a8 !important; }
.coach-hint[hidden] { display: none; }
.coach-hint::before { content: '→ '; }
.coach-actions { display: flex; justify-content: flex-end; margin-top: 8px; }
.coach-actions .btn[hidden] { display: none; }
.coach-actions .btn { min-width: 120px; }
@media (prefers-reduced-motion: reduce) { .coach { animation: none; } }
