/* cairn: washi tokens (zen-lab/design/direction.md), game colour lichen */
:root {
  --paper: #F4EFE6; --paper-sunk: #EAE3D6; --card: #FBF8F2; --lip: #DCD3C2; --line: #E1D9CA;
  --ink: #24221F; --ink-soft: #5F5A52; --ink-faint: #9A9387; --scrim: rgba(36,34,31,.28);
  --accent: #6F9460; --accent-deep: #55764A; --accent-btn: #55876A; --on-accent: #FFFFFF;
  /* the board */
  --sky: #F7F2EA; --earth: #B49A78; --earth-top: #8D7556; --steel: #8F96A0; --steel-hi: #A9AFB8;
  --brick: #C9A86A; --brick-line: #A98A52; --water: #9DBFD0; --water-top: #C9DEE8;
  --spirit: #8E897E; --spirit-base: #6F6A60; --eye: #FBF8F2; --door: #F2E6C0; --arch: #5F5A52; --hatch: #4A4640;
  --leaf: #6F9460;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #131518; --paper-sunk: #0D0E10; --card: #1C1F24; --lip: #08090B; --line: #2A2E35;
    --ink: #ECE7DD; --ink-soft: #A9A397; --ink-faint: #6C6A66; --scrim: rgba(0,0,0,.55);
    --accent: #8FB37F; --accent-deep: #6F9460; --accent-btn: #8FB37F; --on-accent: #131518;
    --sky: #191C20; --earth: #6E5C46; --earth-top: #9A8364; --steel: #5D646E; --steel-hi: #737B86;
    --brick: #A68A55; --brick-line: #7E683F; --water: #2E5568; --water-top: #44738A;
    --spirit: #B9B3A6; --spirit-base: #8E897E; --eye: #1C1F24; --door: #D9C995; --arch: #A9A397; --hatch: #08090B;
    --leaf: #8FB37F;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #131518; --paper-sunk: #0D0E10; --card: #1C1F24; --lip: #08090B; --line: #2A2E35;
  --ink: #ECE7DD; --ink-soft: #A9A397; --ink-faint: #6C6A66; --scrim: rgba(0,0,0,.55);
  --accent: #8FB37F; --accent-deep: #6F9460; --accent-btn: #8FB37F; --on-accent: #131518;
  --sky: #191C20; --earth: #6E5C46; --earth-top: #9A8364; --steel: #5D646E; --steel-hi: #737B86;
  --brick: #A68A55; --brick-line: #7E683F; --water: #2E5568; --water-top: #44738A;
  --spirit: #B9B3A6; --spirit-base: #8E897E; --eye: #1C1F24; --door: #D9C995; --arch: #A9A397; --hatch: #08090B;
  --leaf: #8FB37F;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--ink); }
body {
  font-family: Figtree, -apple-system, system-ui, "Segoe UI", sans-serif;
  font-size: 17px; line-height: 1.35;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation; overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
button:focus { outline: none; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { display: block; }

.app {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.screen[hidden] { display: none; }

/* round 44 pt header buttons */
.round {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  background: var(--card); box-shadow: 0 0 0 1px var(--line), 0 2px 0 var(--lip);
  display: grid; place-items: center; transition: transform 60ms;
}
.round svg { width: 24px; height: 24px; }
.round:active { transform: translateY(2px); box-shadow: 0 0 0 1px var(--line); }
.round .glow { opacity: 0; }
.round.glowing .glow { opacity: 1; animation: glow 1.6s ease-in-out 1; }
@keyframes glow { 0% { opacity: 0; } 50% { opacity: 1; } 100% { opacity: .9; } }

/* ---------- level select ---------- */
.levels-top { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px 0; }
.wordmark { font-family: Fraunces, Georgia, serif; font-weight: 500; font-variation-settings: "SOFT" 100; font-size: 34px; margin: 0; letter-spacing: .01em; }
.levels-buttons { display: flex; gap: 12px; }
.levels-sub { margin: 4px 20px 16px; color: var(--ink-soft); font-size: 15px; }
.level-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 0 20px 20px;
  overflow-y: auto; -webkit-overflow-scrolling: touch; align-content: start; flex: 1;
}
.level {
  position: relative; min-height: 92px; border-radius: 16px; background: var(--card);
  box-shadow: 0 0 0 1px var(--line), 0 3px 0 var(--lip); padding: 10px 10px 8px;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; text-align: left;
  transition: transform 60ms;
}
.level:active { transform: translateY(2px); box-shadow: 0 0 0 1px var(--line), 0 1px 0 var(--lip); }
.level .n { font-family: Fraunces, Georgia, serif; font-size: 26px; line-height: 1; font-variant-numeric: tabular-nums; }
.level .nm { font-size: 13px; font-weight: 500; color: var(--ink-soft); line-height: 1.2; }
.level .best { position: absolute; top: 10px; right: 10px; font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 4px; }
.level .best i { width: 12px; height: 8px; border-radius: 50%; background: var(--accent); display: inline-block; }
.level.next { box-shadow: 0 0 0 2px var(--accent), 0 3px 0 var(--lip); }
.ver { text-align: center; color: var(--ink-faint); font-size: 13px; margin: 0 0 6px; }

/* ---------- game ---------- */
.top { display: flex; align-items: center; justify-content: space-between; height: 52px; padding: 4px 16px 0; flex: none; }
.counter { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.counter-cairn { width: 26px; height: 32px; }
.counter-cairn .st { fill: var(--spirit); }
.counter-cairn .st-top { fill: var(--accent); }
.counter-cairn .st-dot { fill: none; stroke: var(--ink-faint); stroke-dasharray: 2 2; }
.count-home { font-size: 22px; font-weight: 600; }
.count-need { font-size: 17px; color: var(--ink-soft); }
.counter.bump .count-home { animation: bump 300ms cubic-bezier(.2,.9,.25,1.15); }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.3); } 100% { transform: scale(1); } }
.count-home { display: inline-block; }

.hatchline { height: 18px; display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 13px; color: var(--ink-soft); flex: none; }
.hatchline i { width: 4px; height: 4px; border-radius: 50%; background: var(--ink-faint); display: inline-block; }
.hatchline span { margin-left: 6px; }

.board-wrap { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; padding: 4px 16px; }
#board { display: block; border-radius: 16px; background: var(--sky); touch-action: none; transition: opacity 240ms cubic-bezier(.3,.7,.2,1); }
#board.dim { opacity: .6; }
.pill {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  min-height: 44px; padding: 0 20px; border-radius: 22px; background: var(--ink); color: var(--paper);
  font-size: 15px; font-weight: 600; box-shadow: 0 3px 0 var(--lip); animation: rise 420ms cubic-bezier(.2,.9,.25,1.15);
}
.pill[hidden] { display: none; }
@keyframes rise { from { transform: translate(-50%, 16px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

.skills { display: flex; justify-content: center; gap: 8px; padding: 6px 16px 4px; flex: none; }
.skill {
  position: relative; flex: 0 1 84px; min-width: 0; height: 60px; border-radius: 14px; background: var(--card);
  box-shadow: 0 0 0 1px var(--line), 0 3px 0 var(--lip);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 13px; font-weight: 500; transition: transform 120ms cubic-bezier(.2,.9,.25,1.15), background 120ms;
}
.skill svg { width: 24px; height: 24px; }
.skill .badge {
  position: absolute; top: -6px; right: -4px; min-width: 22px; height: 22px; border-radius: 11px; padding: 0 6px;
  background: var(--ink); color: var(--paper); font-size: 12px; font-weight: 700; line-height: 22px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.skill[aria-checked="true"] { background: var(--accent); color: var(--on-accent); transform: translateY(-3px); box-shadow: 0 0 0 1px var(--accent), 0 6px 0 var(--accent-deep); font-weight: 600; }
.skill:disabled { color: var(--ink-faint); cursor: default; }
.skill:disabled .badge { background: var(--ink-faint); }
.skill.lift { transform: translateY(-6px); }
.skill.shake { animation: shake 300ms; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.skills.small .skill { width: 72px; }

.controls {
  margin: 8px 16px 8px; height: 52px; border-radius: 26px; background: var(--card);
  box-shadow: 0 0 0 1px var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 4px; flex: none;
}
.ctl { min-width: 88px; height: 44px; border-radius: 22px; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 13px; color: var(--ink-soft); }
.ctl svg { width: 22px; height: 22px; color: var(--ink); }
.ctl:disabled { opacity: .4; cursor: default; }
.ctl[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.ctl[aria-pressed="true"] svg { color: var(--on-accent); }
.tally { font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- sheets ---------- */
.veil { position: fixed; inset: 0; background: var(--scrim); display: flex; align-items: flex-end; justify-content: center; z-index: 10; animation: fade 240ms cubic-bezier(.3,.7,.2,1); }
.veil[hidden] { display: none; }
.veil.clear { background: transparent; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  width: 100%; max-width: 520px; background: var(--card); border-radius: 28px 28px 0 0;
  padding: 10px 24px calc(20px + env(safe-area-inset-bottom)); text-align: center;
  animation: sheet 420ms cubic-bezier(.2,.9,.25,1.15); max-height: 88vh; overflow-y: auto;
}
@keyframes sheet { from { transform: translateY(40%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--lip); margin: 0 auto 14px; }
.sheet .over { font-size: 13px; color: var(--ink-soft); margin: 0; }
.sheet h2 { font-family: Fraunces, Georgia, serif; font-weight: 500; font-variation-settings: "SOFT" 100; font-size: 34px; margin: 4px 0 6px; line-height: 1.1; }
.sheet .line { font-size: 17px; margin: 0 0 14px; }
.sheet .caption { font-size: 13px; color: var(--ink-soft); margin: 14px 0 0; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 4px 0 18px; }
.chip { display: flex; align-items: center; gap: 6px; height: 44px; padding: 0 16px; border-radius: 22px; background: var(--paper); box-shadow: 0 0 0 1px var(--line); font-size: 15px; font-weight: 500; }
.chip svg { width: 20px; height: 20px; }
.primary {
  display: block; width: 100%; min-height: 56px; border-radius: 16px; background: var(--accent-btn); color: var(--on-accent);
  font-size: 17px; font-weight: 600; box-shadow: 0 3px 0 var(--accent-deep); margin: 6px 0 0;
}
.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--accent-deep); }
.quiet { display: flex; justify-content: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.quiet button, .listbtn { min-height: 44px; padding: 0 16px; border-radius: 22px; font-size: 15px; color: var(--ink); background: var(--paper); box-shadow: 0 0 0 1px var(--line); }
.list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.listbtn { width: 100%; text-align: center; }
.row { display: flex; align-items: center; justify-content: space-between; min-height: 52px; border-bottom: 1px solid var(--line); text-align: left; font-size: 17px; }
.row:last-child { border-bottom: 0; }
.switch { width: 52px; height: 32px; border-radius: 16px; background: var(--line); position: relative; transition: background 160ms; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform 160ms cubic-bezier(.2,.9,.25,1.15); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.seg { display: flex; background: var(--paper-sunk); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { min-height: 38px; min-width: 60px; padding: 0 10px; border-radius: 9px; font-size: 15px; color: var(--ink-soft); }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 0 var(--lip); }
.helpgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; text-align: left; margin: 8px 0 6px; }
.helpgrid div { display: flex; gap: 8px; align-items: flex-start; font-size: 15px; line-height: 1.25; }
.helpgrid svg { width: 22px; height: 22px; flex: none; margin-top: 1px; }
.helpgrid b { font-weight: 600; }
.howto { font-size: 15px; color: var(--ink-soft); margin: 4px 0 10px; }

/* ghost finger (level 1 demo) */
.ghost { position: fixed; width: 56px; height: 56px; left: 0; top: 0; z-index: 20; pointer-events: none; opacity: .82; transform: translate(-14px, -6px); }
.ghost[hidden] { display: none; }
.ghost svg { width: 56px; height: 56px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.25)); }
.ghost.tap svg { animation: press 360ms ease-in-out; }
@keyframes press { 0%,100% { transform: scale(1); } 45% { transform: scale(.82); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 150ms !important; animation-iteration-count: 1 !important; transition-duration: 150ms !important; }
  .sheet { animation-name: fade; }
  .skill[aria-checked="true"], .skill.lift { transform: none; }
}
@media (max-height: 700px) {
  .top { height: 48px; }
  .skill { height: 54px; }
  .controls { height: 48px; margin: 6px 16px; }
}
