:root {
  font-family: 'Avenir Next', 'Nunito', 'Trebuchet MS', system-ui, sans-serif;
  color: #47463f;
  background: #ece6dc;
  font-synthesis: none;
  --ink: #48473f;
  --muted: #8c877b;
  --paper: #f6f1e8;
  --gold: #dbaf69;
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  min-height: 100svh;
  background: radial-gradient(ellipse at 30% 12%, #fbf8f1 0%, #f0e9de 46%, #e2d9cb 100%) fixed;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
button, input { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; border: 0; }
button:focus-visible { outline: 3px solid #6c9986; outline-offset: 4px; }
button:disabled { cursor: default; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
[hidden] { display: none !important; }

.game {
  max-width: 450px;
  margin: 0 auto;
  min-height: 100svh;
  padding: max(14px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
}
.topbar { width: 100%; display: flex; align-items: center; justify-content: space-between; padding: 0 8px; height: 52px; margin-bottom: 10px; }
.wordmark { color: var(--ink); font-size: 38px; letter-spacing: -2.6px; font-weight: 850; line-height: 1; width: 80px; }
.wordmark span { color: var(--gold); font-size: 22px; letter-spacing: 0; margin-left: 3px; }
.level-pill {
  display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; letter-spacing: .3px;
  padding: 10px 16px; border-radius: 22px; background: #f8f4ecd0;
  box-shadow: 0 1px 0 #fffdf8 inset, 0 3px 10px -4px #8a744f40;
}
.level-pill svg { width: 15px; height: 15px; opacity: .55; }
.quiet-button { display: grid; place-items: center; background: transparent; width: 44px; height: 44px; border-radius: 50%; color: #6f6a60; }
.top-actions { display: flex; justify-content: flex-end; width: 80px; }
.top-actions .quiet-button { width: 40px; }
.goalbar {
  display: flex; align-items: center; justify-content: center; gap: 14px; height: 40px; margin-bottom: 12px;
  border-radius: 22px; padding: 0 18px; background: #f8f4eab8; max-width: 100%;
  box-shadow: 0 1px 0 #fffdf8 inset, 0 3px 10px -5px #8474563a;
}
.goalbar > div { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.goalbar svg { width: 18px; height: 18px; color: #c4708a; }
.move-indicator svg { color: #9c8a72; }
.goalbar strong { font-size: 15px; font-weight: 750; font-variant-numeric: tabular-nums; transition: transform .25s cubic-bezier(.3, 1.8, .5, 1); display: inline-block; }
.goalbar strong.bump { transform: scale(1.28); }
.goalbar span:not(.goal-divider) { font-size: 11px; color: var(--muted); }
.goal-divider { height: 16px; width: 1px; background: #dbd2c3; }

.board-wrap {
  position: relative; z-index: 4; width: 100%; aspect-ratio: 400 / 540; flex-shrink: 0; isolation: isolate; /* toasts that leave the board stay above the toolbar */
  background: url('assets/tray.webp') center / 100% 100%;
  border-radius: 28px; box-shadow: 0 18px 34px -20px #6f5c40b0, 0 4px 10px -6px #6f5c4040;
  touch-action: none;
}
.board-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#board { touch-action: none; }
.puff-controls { position: absolute; inset: 0; pointer-events: none; }
.puff-target {
  position: absolute; border-radius: 50%; padding: 0; background: transparent; pointer-events: none;
  color: transparent; transform: translate(-50%, -50%);
}
.puff-target:focus-visible { outline: 3px solid #9a762e !important; outline-offset: 2px; background: #ffffc01a; }
.board-caption { position: absolute; top: 9%; left: 10%; right: 10%; text-align: center; pointer-events: none; animation: appear .8s .2s both; }
.eyebrow { font-size: 9px; letter-spacing: 2px; font-weight: 750; color: #a38b62; }
.board-caption h1 { font-size: 30px; line-height: 1.12; font-weight: 750; letter-spacing: -1.1px; margin: 10px 0; color: #666153; }

.instruction {
  font-size: 13px; color: #857c6d; line-height: 1.45; min-height: 38px; margin: 14px 0 8px; text-align: center; max-width: 92%;
  transition: opacity .25s;
}
.instruction.fade { opacity: 0; }
.toolbar { display: flex; width: 82%; justify-content: space-between; gap: 18px; position: relative; }
/* Proven dead end: a free, explicit way back (never game over). Sits above Undo. */
.rewind-pill { position: absolute; left: -6px; bottom: calc(100% + 10px); display: flex; align-items: center; gap: 6px; padding: 8px 14px 8px 10px; border-radius: 999px; background: #fffaf2; color: #85661f; font: inherit; font-size: 13.5px; font-weight: 750; white-space: nowrap; box-shadow: 0 10px 22px -10px #5a3e2270, 0 0 0 2px #e6c374 inset; animation: toast-in .34s cubic-bezier(.2, 1.5, .4, 1) both; z-index: 5; }
.rewind-pill[hidden] { display: none; }
.rewind-pill svg { width: 18px; height: 18px; color: #85661f; }
.rewind-pill:active { scale: .96; }
.tool-button { display: flex; flex-direction: column; align-items: center; gap: 8px; background: transparent; font-size: 11px; font-weight: 650; color: #8e8577; padding: 0; min-width: 66px; transition: opacity .2s; }
.tool-button:disabled { opacity: .4; }
.tool-disc {
  width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; background: #f6f1e8;
  box-shadow: 0 1px 0 #fffaf2 inset, 0 3px 2px #8d785717, 0 8px 16px -9px #806b45a6, inset 0 -3px 4px #c6b89d30;
  transition: transform .18s cubic-bezier(.3, 1.6, .5, 1), box-shadow .18s;
}
.tool-button:active:not(:disabled) .tool-disc { transform: scale(.92); box-shadow: 0 1px 0 #fffaf2 inset, 0 1px 2px #8d785717, inset 0 2px 5px #b9a98a50; }
.tool-disc svg { width: 23px; height: 23px; color: #7f725e; }
.tool-button.glow .tool-disc { box-shadow: 0 0 0 3px #f3d78a80, 0 8px 16px -9px #806b45a6; }

.game { position: relative; }
.win-card {
  position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); left: 16px; right: 16px; z-index: 5; text-align: center; background: #fbf8efee;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border: 1px solid #fffff6; border-radius: 24px;
  padding: 16px 16px 14px; box-shadow: 0 -4px 30px #8a734630; animation: rise .55s cubic-bezier(.2, 1.4, .4, 1) both;
}
.win-eyebrow { font-size: 9px; letter-spacing: 2px; color: #a78c52; font-weight: 800; }
.win-card h2 { font-size: 26px; font-weight: 750; letter-spacing: -.7px; margin: 5px 0; }
.win-card p { font-size: 12px; color: #93866f; margin: 4px 0 12px; line-height: 1.5; }
.win-card button {
  background: #647f68; color: #fff9e9; border-radius: 16px; padding: 14px 22px; font-size: 14px; font-weight: 650;
  display: flex; justify-content: center; align-items: center; gap: 18px; margin: auto; box-shadow: 0 5px 10px #43594530;
  transition: transform .15s;
}
.win-card button:active { transform: scale(.96); }
.win-card button svg { width: 18px; height: 18px; }

.sheet {
  width: min(414px, calc(100vw - 32px)); padding: 24px; border: 1px solid #fffaf1; background: #f6f1e7; border-radius: 26px;
  color: var(--ink); box-shadow: 0 20px 90px #3f352b40; max-height: 86svh; overflow: auto;
}
.sheet[open] { animation: rise .35s cubic-bezier(.2, 1.3, .4, 1) both; }
.sheet::backdrop { background: #39332755; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 18px; }
.sheet h2 { font-size: 25px; letter-spacing: -.7px; font-weight: 750; margin: 6px 0; }
.sheet .quiet-button { flex-shrink: 0; background: #eae3d8; }
.levels-list { display: grid; gap: 8px; }
.level-option { display: flex; text-align: left; align-items: center; gap: 14px; border: 1px solid #e8e0d3; background: #fcf8f1; border-radius: 16px; padding: 12px 14px; }
.level-option.current { border-color: #92ab91; background: #eef1e6; }
.level-option .num { font-size: 18px; font-weight: 750; color: #a09278; width: 28px; font-variant-numeric: tabular-nums; }
.level-option strong { font-size: 14px; display: block; }
.level-option small { font-size: 11px; color: #a49989; display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: #e2d8c7; }
.dots i.on { background: #d6a65a; }
.level-option svg { margin-left: auto; width: 17px; height: 17px; color: #9aaa92; }
.level-option.done svg { color: #6f9076; }
.sheet-note { font-size: 11px; line-height: 1.7; color: #958975; margin: 18px 0 0; }
.setting { display: flex; justify-content: space-between; align-items: center; padding: 16px 0; border-bottom: 1px solid #e4dccf; font-size: 14px; }
.setting span { display: flex; align-items: center; gap: 12px; }
.setting svg { width: 20px; height: 20px; color: #938775; }
.setting input { accent-color: #6f9076; width: 21px; height: 21px; cursor: pointer; }
.rules { font-size: 12px; line-height: 1.75; color: #958772; margin-top: 22px; }
.rules strong { color: #655e51; font-size: 14px; }
.rules p { margin: 8px 0; }
.rules .tip { color: #a89a83; font-style: italic; }
.haptic-switch { position: fixed; left: -100px; top: 0; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
/* On-board teaching: level intro card, anchored toasts, coach marks */
.level-intro {
  position: absolute; top: 3%; left: 6%; right: 6%; z-index: 3; text-align: center; pointer-events: none;
  background: #fcf9f1eb; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  border: 1px solid #fffdf6; border-radius: 18px; padding: 11px 16px 13px;
  box-shadow: 0 10px 22px -12px #6f5c4080; transition: opacity .35s, translate .35s;
  animation: appear .5s .1s both;
}
.level-intro.out { opacity: 0; translate: 0 -10px; }
.level-intro.bottom { top: auto; bottom: 3%; }
.level-intro.bottom.out { translate: 0 10px; }
.level-intro h2 { font-size: 19px; line-height: 1.2; margin: 4px 0 3px; letter-spacing: -.4px; color: #49473f; }
.level-intro p { font-size: 14px; line-height: 1.4; margin: 0; color: #6c6457; }
.board-toast {
  position: absolute; z-index: 4; width: max-content; max-width: min(320px, calc(100% - 16px)); box-sizing: border-box; pointer-events: none; text-align: center;
  background: #fffaf2f5; border-radius: 16px; padding: 10px 15px 11px;
  box-shadow: 0 12px 26px -10px #5a3e2270, 0 0 0 2px #eab3a0 inset;
}
.board-toast.above { translate: -50% -100%; transform-origin: 50% 100%; }
.board-toast.below { translate: -50% 0; transform-origin: 50% 0; }
.board-toast.show { animation: toast-in .34s cubic-bezier(.2, 1.5, .4, 1) both; }
.board-toast.out { animation: toast-out .25s both; }
.board-toast strong { display: block; font-size: 17px; color: #a24b36; letter-spacing: -.2px; }
.board-toast span { display: block; font-size: 13.5px; color: #6c5d4f; margin-top: 3px; line-height: 1.35; overflow-wrap: anywhere; }
.board-toast span:empty { display: none; }
.board-toast.hint { box-shadow: 0 12px 26px -10px #5a3e2270, 0 0 0 2px #e6c374 inset; }
.board-toast.hint strong { color: #85661f; }
.board-toast { background: #fffaf2; }
.board-toast.outside { padding: 7px 13px 8px; }
.board-toast.outside strong { font-size: 15px; }
.board-toast.outside span { font-size: 12.5px; margin-top: 1px; }
.instruction.covered { opacity: 0; }
.instruction.muted { opacity: 0; } /* the rewind pill sits over it */
.coach { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.coach-label {
  position: absolute; translate: -50% 0; white-space: nowrap; font-size: 13px; font-weight: 750; color: #6d5521;
  background: #fff7dff2; border-radius: 12px; padding: 5px 10px; box-shadow: 0 4px 10px -4px #8a6a2466;
  animation: appear .5s .3s both, bob 2.4s 1s ease-in-out infinite;
}
.coach-label.up { translate: -50% -100%; }
.coach-label::after { content: ''; position: absolute; left: calc(50% + var(--tail, 0px)); top: -6px; translate: -50% 0; border: 6px solid transparent; border-top: 0; border-bottom-color: #fff7dff2; }
.coach-label.up::after { top: auto; bottom: -6px; border-bottom: 0; border-top: 6px solid #fff7dff2; }
.coach-hand { position: absolute; width: 46px; height: 46px; translate: -12% -8%; animation: appear .5s .6s both, tap 1.5s 1.1s ease-in-out infinite; }
.coach-hand.assist { animation: appear .4s both, tap 1.3s .3s ease-in-out infinite; }
.coach-hand svg { width: 46px; height: 46px; fill: #fffdf7; stroke: #4c4a41; stroke-width: 1.4; filter: drop-shadow(0 3px 4px #0003); }
@keyframes toast-in { from { opacity: 0; scale: .85; } to { opacity: 1; scale: 1; } }
@keyframes toast-out { to { opacity: 0; scale: .92; } }
@keyframes bob { 50% { transform: translateY(-3px); } }
@keyframes tap { 0%, 100% { transform: translate(0, 0) scale(1); } 45% { transform: translate(-3px, -5px) scale(1.06); } 60% { transform: translate(0, 0) scale(.94); } }

.howto { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.howto li { display: grid; gap: 7px; }
.howto-art { width: 100%; height: 84px; border-radius: 14px; background: #efe8db; display: block; }
.howto strong { font-size: 15px; color: #4f4c43; }
.howto p { font-size: 13.5px; margin: 2px 0 0; line-height: 1.5; color: #6f675a; }
.howto b { color: #4f4c43; }
.howto-note { text-align: center; font-size: 12px; color: #958975; margin: 14px 0 10px; }
.howto-sheet { padding-bottom: 0; }
.howto-sheet .primary-button { position: sticky; bottom: 0; margin-bottom: 16px; box-shadow: 0 -10px 18px 6px #f6f1e7, 0 5px 10px #43594530; }
.primary-button { width: 100%; background: #647f68; color: #fff9e9; border-radius: 16px; padding: 15px; font-size: 15px; font-weight: 700; box-shadow: 0 5px 10px #43594530; }
.primary-button:active { transform: scale(.98); }
.secondary-button { display: flex; gap: 8px; align-items: center; justify-content: center; width: 100%; margin-top: 18px; background: #eae3d8; border-radius: 14px; padding: 12px; font-weight: 650; font-size: 14px; color: #5f594d; }
.secondary-button svg { width: 18px; height: 18px; }

@keyframes appear { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.97); } to { opacity: 1; transform: none; } }

@media (min-width: 650px) {
  .game { width: min(430px, calc((100svh - 250px) * .74074 + 32px)); }
}
@media (max-height: 760px) {
  .game { padding-top: max(8px, env(safe-area-inset-top)); }
  .topbar { height: 44px; margin-bottom: 6px; }
  .goalbar { height: 34px; margin-bottom: 8px; }
  .instruction { margin: 10px 0 6px; min-height: 34px; }
  .tool-disc { width: 52px; height: 52px; }
}
@media (max-height: 760px) and (min-width: 400px) {
  .game { max-width: calc((100svh - 230px) * .74074 + 32px); }
}
@media (max-width: 360px) {
  .game { padding-left: 10px; padding-right: 10px; }
  .wordmark { font-size: 32px; width: 64px; }
  .instruction { font-size: 12px; }
  .toolbar { width: 92%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.sheet h2:focus { outline: none; }

/* Levels 11–60: night counter, hint quota and undo badges, garden headings */
.night-indicator svg { color: #4a4f8a; }
.night-indicator[hidden] + .night-divider { display: none; }
.tool-disc { position: relative; }
.tool-badge { position: absolute; top: -3px; right: -3px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: #d0533e; color: #fff; font-size: 11.5px; font-weight: 800; line-height: 20px; text-align: center; box-shadow: 0 2px 5px #0002; }
.tool-badge.hint { background: #c79a3a; }
.tool-button.empty .tool-disc { opacity: .45; }
.garden-head { font-size: 11px; letter-spacing: 1.6px; font-weight: 800; color: #a38b62; text-transform: uppercase; margin: 10px 2px 2px; }
