:root {
  color-scheme: dark;
  font-family: Georgia, 'Times New Roman', serif;
  --night: #172321;
  --ink: #25362f;
  --sage: #77937c;
  --sage-light: #b9cbb1;
  --cream: #fff4d5;
  --paper: #f1dfb8;
  --amber: #e5a84b;
  --rose: #bf6e5b;
  --line: rgba(255, 244, 213, .2);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--night); overflow-x: clip; }
body {
  min-width: 320px;
  margin: 0;
  color: var(--cream);
  background:
    radial-gradient(circle at 50% -8%, rgba(229, 168, 75, .17), transparent 32rem),
    linear-gradient(180deg, #21302d, var(--night) 58%);
  overflow-x: clip;
}
button { font: inherit; touch-action: manipulation; }
button:focus-visible, .hub-link:focus-visible, .app:focus-visible { outline: 3px solid #ffd883; outline-offset: 3px; }
.hub-link { display: inline-flex; min-height: 44px; align-items: center; margin-bottom: .25rem; color: var(--sage-light); font: 800 .76rem/1 system-ui, sans-serif; text-decoration-thickness: 1px; text-underline-offset: .18rem; }
.app {
  width: min(100%, 44rem);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top)) max(.5rem, env(safe-area-inset-right)) max(2rem, env(safe-area-inset-bottom)) max(.5rem, env(safe-area-inset-left));
}
.masthead, .puzzle-heading, .board-heading, .tray-heading, .scene-heading { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.masthead { margin-bottom: 1rem; }
.eyebrow, .kicker { margin: 0 0 .22rem; color: var(--sage-light); font: 700 .7rem/1.2 system-ui, sans-serif; letter-spacing: .13em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.85rem, 8vw, 2.7rem); line-height: .95; }
h1 em { color: #f0c36f; font-weight: 400; }
h2 { margin-bottom: .25rem; font-size: 1.18rem; }
h3 { margin: 0; font-size: 1rem; }
.mosaic-mark { display: grid; place-items: center; width: 48px; height: 48px; color: var(--amber); border: 1px solid var(--line); transform: rotate(45deg); box-shadow: inset 0 0 18px rgba(229,168,75,.12); }
.puzzle-heading { align-items: flex-start; margin-bottom: .8rem; }
.puzzle-heading p { margin-bottom: 0; color: #d4ddce; font-size: .9rem; line-height: 1.35; }
.stats { flex: 0 0 auto; display: grid; gap: .15rem; text-align: right; font: .72rem/1.2 system-ui, sans-serif; color: var(--sage-light); }
.stats strong { color: var(--cream); font-size: .92rem; }
.scene-panel, .board-panel, .clue-panel, .results {
  border: 1px solid var(--line);
  background: rgba(28, 42, 38, .87);
  box-shadow: 0 10px 28px rgba(4, 10, 8, .2);
}
.scene-panel { padding: .65rem; border-radius: 1rem 1rem .35rem .35rem; }
.scene-heading { padding: .1rem .25rem .45rem; }
.scene-heading h2 { font-size: .98rem; }
.scene { position: relative; min-height: 138px; border-radius: .65rem; overflow: hidden; background: #101918; border: 1px solid rgba(255,255,255,.09); }
.scene svg { display: block; width: 100%; height: auto; }
.scene-part { opacity: .07; filter: saturate(.35); transition: opacity .55s ease, filter .55s ease; }
.scene-part.revealed { opacity: 1; filter: none; }
.sky { fill: #344d50; }
.water { fill: #4f7e82; }
.house { fill: #b96f55; stroke: #f2c476; stroke-width: 2; }
.roof { fill: #5d4035; stroke: #d99754; stroke-width: 2; }
.window { fill: #ffd56f; stroke: #fff0bf; stroke-width: 2; }
.door { fill: #5a382c; }
.moon { fill: #ffe39a; filter: drop-shadow(0 0 9px rgba(255,213,111,.7)); }
.spark { fill: #fff4bd; }
.boat { fill: #bd7659; stroke: #f4d49b; stroke-width: 2; }
.sail { fill: #f3dfb6; }
.trees { fill: #3f654d; stroke: #84a574; stroke-width: 2; }
.path { fill: #d2a86f; }
.garden { fill: none; stroke: #7fa06a; stroke-width: 5; }
.garden circle { fill: #d9856d; stroke: #f4cf88; stroke-width: 2; }
.reveal-meter { display: flex; gap: .35rem; justify-content: center; margin-top: .55rem; }
.reveal-meter > span { width: 2.2rem; height: .3rem; border-radius: 1rem; background: #46534b; }
.reveal-meter > span.revealed { background: var(--amber); box-shadow: 0 0 8px rgba(229,168,75,.45); }
.board-panel { margin-top: .75rem; padding: .65rem .35rem .85rem; border-radius: .35rem 1rem 1rem 1rem; }
.board-heading { padding: .1rem .3rem .6rem; }
.restart, .next {
  min-height: 44px;
  border: 1px solid rgba(255,244,213,.28);
  border-radius: .55rem;
  color: var(--cream);
  background: #344d43;
  padding: .55rem .85rem;
  font: 700 .82rem/1 system-ui, sans-serif;
}
.grid-wrap { display: grid; place-items: center; width: 100%; overflow: visible; }
.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), 44px);
  grid-template-rows: repeat(var(--rows), 44px);
  gap: 3px;
  width: max-content;
  padding: .35rem;
  background: rgba(12, 21, 18, .6);
  border: 1px solid rgba(255,244,213,.1);
  border-radius: .6rem;
}
.grid-cell {
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid #9aa884;
  border-radius: .28rem;
  color: var(--ink);
  background: linear-gradient(145deg, #f7e8c6, #d8c293);
  box-shadow: inset 0 -3px 0 rgba(69, 55, 34, .16), 0 2px 4px rgba(0,0,0,.24);
  font: 800 1.22rem/1 system-ui, sans-serif;
}
.grid-cell:not(:disabled):active { transform: translateY(2px); box-shadow: inset 0 -1px 0 rgba(69,55,34,.18); }
.grid-cell.given { color: var(--cream); background: #526d5b; border-color: #89a58e; opacity: 1; -webkit-text-fill-color: var(--cream); }
.grid-cell.filled { border-color: #f1bf64; }
.grid-gap { width: 44px; height: 44px; }
.message { min-height: 2.8rem; margin: .65rem .3rem .35rem; padding: .62rem .7rem; border-left: 3px solid var(--sage); color: #dfe8da; background: rgba(119,147,124,.09); font: .82rem/1.35 system-ui, sans-serif; }
.message.good { border-color: var(--amber); color: #ffe6aa; }
.message.bad { border-color: var(--rose); color: #ffd2c7; }
.tray-heading { padding: .15rem .35rem .45rem; font: .78rem/1 system-ui, sans-serif; color: var(--sage-light); }
.tile-tray { display: flex; flex-wrap: wrap; justify-content: center; gap: .42rem; min-height: 52px; padding: .15rem; }
.letter-tile {
  min-width: 48px;
  min-height: 48px;
  border: 1px solid #c89d58;
  border-radius: .18rem .55rem .18rem .55rem;
  color: #352919;
  background: linear-gradient(145deg, #ffe7a9, #dba75b);
  box-shadow: inset 0 -4px 0 rgba(96,58,19,.18), 0 4px 7px rgba(0,0,0,.25);
  font: 800 1.12rem/1 system-ui, sans-serif;
}
.letter-tile.selected { color: var(--cream); background: #9c5c45; border: 3px solid #ffe29a; transform: translateY(-4px) rotate(-2deg); box-shadow: 0 7px 12px rgba(0,0,0,.3); }
.letter-tile:disabled { opacity: .16; box-shadow: none; }
.clue-panel { margin-top: .75rem; padding: .85rem; border-radius: 1rem .35rem 1rem 1rem; }
.clue-panel ol { display: grid; gap: .48rem; margin: .7rem 0 0; padding: 0; list-style: none; }
.clue-panel li { display: grid; grid-template-columns: 2rem 1fr auto; align-items: center; gap: .55rem; min-height: 48px; padding: .45rem .55rem; border-bottom: 1px dashed rgba(255,244,213,.18); }
.clue-panel li.complete { color: #ffe3a0; }
.clue-number { display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid var(--sage); transform: rotate(45deg); font: 700 .75rem/1 system-ui, sans-serif; }
.clue-panel strong, .clue-panel small { display: block; }
.clue-panel strong, .clue-state { font: 700 .7rem/1.2 system-ui, sans-serif; text-transform: uppercase; letter-spacing: .07em; }
.clue-panel small { margin-top: .14rem; color: #d8e0d3; font: .83rem/1.25 system-ui, sans-serif; }
.clue-state { color: var(--sage-light); font-size: .62rem; }
.results { margin-top: .75rem; padding: 1.15rem; text-align: center; border-color: rgba(229,168,75,.55); border-radius: 1rem; }
.results > span { color: var(--amber); font-size: 1.7rem; }
.results p { color: #dce4d7; }
.results strong { display: block; margin-bottom: .8rem; color: #ffe3a0; }
.next { color: #2b3025; background: var(--amber); border-color: #f4d795; }
.experiment-note { margin: 1rem 0 0; text-align: center; color: #91a095; font: .7rem/1.3 system-ui, sans-serif; }
.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; }

@media (min-width: 390px) {
  .app { padding-inline: max(.8rem, env(safe-area-inset-left)); }
  .board-panel { padding-inline: .8rem; }
  .grid { grid-template-columns: repeat(var(--cols), 48px); grid-template-rows: repeat(var(--rows), 48px); gap: 4px; }
  .grid-cell, .grid-gap { width: 48px; min-width: 48px; min-height: 48px; height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
  .letter-tile.selected { transform: none; }
}
