:root {
  color-scheme: light;
  --paper: #e9d8b4;
  --ink: #2b241e;
  --mocha: #6b503d;
  --brown: #5b4435;
  --coffee: #c5a47d;
  --deep-coffee: #3b2a22;
  --line: rgba(91, 68, 53, .34);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  background: var(--paper);
  background-image: radial-gradient(circle at 20% 10%, rgba(255,255,255,.16), transparent 32%), radial-gradient(circle at 80% 90%, rgba(91,68,53,.05), transparent 36%);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
button, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible { outline: 1px solid var(--deep-coffee); outline-offset: 8px; }
.view { position: fixed; inset: 0; overflow: auto; overscroll-behavior: contain; padding: clamp(24px, 5vw, 76px); opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity 300ms ease, transform 380ms ease; }
.view.is-active { opacity: 1; transform: none; pointer-events: auto; }
.input-layout, .solving-layout, .result-layout { width: min(100%, 980px); height: 100%; margin: auto; }
.input-layout { display: flex; flex-direction: column; justify-content: center; align-items: flex-start; padding-top: 3vh; }
.eyebrow { margin: 0 0 28px; max-width: 720px; color: var(--mocha); font-size: .76rem; letter-spacing: .045em; line-height: 1.55; }
.intro-copy { max-width: 700px; margin-bottom: 12px; color: var(--ink); font-size: clamp(.95rem, 1.5vw, 1.15rem); letter-spacing: .01em; line-height: 1.42; }
.input-hint { margin-bottom: 28px; }
h1, h2 { margin: 0; font-family: ui-serif, Georgia, "Times New Roman", serif; font-weight: 500; letter-spacing: -.045em; }
h1 { font-size: clamp(3.2rem, 8vw, 7rem); line-height: .95; }
h2 { font-size: clamp(2.6rem, 6vw, 5.8rem); line-height: .95; }
.entry-area { margin-top: clamp(38px, 7vh, 74px); }
.puzzle-grid { display: grid; grid-template-columns: repeat(4, minmax(44px, 1fr)); gap: clamp(10px, 3vw, 34px) clamp(24px, 5vw, 66px); width: min(83vw, 570px); user-select: none; }
.tile { min-width: 0; color: var(--brown); font-family: ui-serif, Georgia, serif; font-size: clamp(1.8rem, 5vw, 4.5rem); font-variant-numeric: tabular-nums; line-height: 1; text-align: center; transition: opacity 240ms ease, transform 240ms ease; }
.tile[data-value="0"] { color: var(--mocha); opacity: .52; }
.tile--arriving { animation: arrive 260ms ease both, breathe 7s ease-in-out 280ms infinite; }
.tile--steady { animation: breathe 7s ease-in-out infinite; }
.tile--leaving { animation: leave 180ms ease both; }
.puzzle-grid--small { width: min(170px, 34vw); gap: 8px 16px; }
.puzzle-grid--small .tile { font-size: clamp(1rem, 2vw, 1.45rem); }
.counter { margin: 24px 0 0; color: var(--mocha); font-size: .8rem; font-variant-numeric: tabular-nums; }
.inline-message { min-height: 1.35em; margin: 9px 0 0; color: var(--brown); font-size: .86rem; line-height: 1.45; }
.inline-message:empty { visibility: hidden; }
.text-button { padding: 0; border: 0; border-bottom: 1px solid transparent; background: transparent; cursor: pointer; font-size: .9rem; letter-spacing: .025em; transition: color 180ms ease, border-color 180ms ease, transform 180ms ease; }
.text-button:hover { color: var(--deep-coffee); border-color: var(--deep-coffee); transform: translateX(3px); }
.primary-action { margin-top: 26px; color: var(--deep-coffee); font-size: 1.05rem; }
.visually-hidden-input { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; opacity: 0; }
.solving-layout { display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; }
.banana { width: clamp(90px, 15vw, 148px); margin-bottom: 25px; transform-origin: 55% 85%; animation: banana-wobble 2.8s ease-in-out infinite; }
.timer { margin: 24px 0 5px; color: var(--brown); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9rem; letter-spacing: .06em; }
.progress-copy { min-height: 1.5em; margin: 0 0 24px; color: var(--mocha); font-size: .82rem; font-variant-numeric: tabular-nums; }
.solve-error { max-width: 440px; margin: -4px 0 20px; }
.result-layout { display: grid; min-height: 0; grid-template-rows: minmax(0, 1fr) auto auto auto; gap: clamp(10px, 1.8vh, 20px); }
.result-main { display: flex; min-height: 0; flex-direction: column; }
.result-main h2 { flex: 0 0 auto; font-size: clamp(3.2rem, 7vw, 6.8rem); }
.route-caption { margin: clamp(10px, 1.8vh, 20px) 0 10px; color: var(--mocha); font-size: .82rem; letter-spacing: .04em; }
.route-wrap { min-height: 0; flex: 1 1 auto; width: 100%; }
.route-grid { display: grid; width: 100%; height: 100%; align-content: center; justify-content: center; grid-auto-rows: minmax(0, 1fr); column-gap: clamp(8px, 1.4vw, 20px); row-gap: clamp(8px, 1.6vh, 18px); }
.route-grid--empty { align-content: center; }
.route-grid--empty .progress-copy { margin: 0; color: var(--mocha); font-size: clamp(.9rem, 1.4vw, 1.1rem); }
.route-step { display: flex; min-width: 0; min-height: 0; flex-direction: column; align-items: center; justify-content: center; color: var(--step-color); font-family: ui-serif, Georgia, serif; line-height: .78; }
.route-step--group-start { margin-inline-start: clamp(10px, 2vw, 30px); }
.route-step--group-start.route-step--row-start { margin-inline-start: 0; margin-block-start: clamp(8px, 1.6vh, 18px); }
.route-index { margin-bottom: 5px; color: var(--step-color); opacity: .58; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: max(.5rem, calc(var(--route-size, 2rem) * .15)); line-height: 1; }
.route-arrow { font-size: var(--route-size, 2rem); line-height: .82; }
.route-letter { margin-top: 8px; color: var(--step-color); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: max(.58rem, calc(var(--route-size, 2rem) * .2)); letter-spacing: .04em; }
.result-meta { display: flex; flex-wrap: wrap; gap: 5px 24px; min-height: 1.5em; margin-top: 16px; color: var(--mocha); font-size: .76rem; font-variant-numeric: tabular-nums; }
.result-meta span + span::before { content: "·"; margin-right: 24px; color: var(--line); }
.result-reference { display: flex; align-items: flex-start; gap: 14px 24px; }
.result-reference .eyebrow { margin: 3px 0 0; min-width: 132px; }
.result-layout > .text-button { align-self: flex-start; margin-top: 22px; }
@keyframes arrive { from { opacity: 0; transform: translateY(8px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes leave { to { opacity: 0; transform: translateY(-7px) scale(.96); } }
@keyframes breathe { 0%, 100% { opacity: .86; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-1px); } }
@keyframes banana-wobble { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg) translateY(-3px); } }
@media (max-width: 560px) {
  .view { padding: 26px 22px; }
  .input-layout { padding-top: 0; }
  .eyebrow { margin-bottom: 22px; font-size: .7rem; }
  .puzzle-grid { width: 100%; gap: 18px 11px; }
  .tile { font-size: clamp(1.65rem, 12vw, 3.1rem); }
  .result-layout { padding-bottom: 4px; gap: 8px; }
  .result-main h2 { font-size: clamp(2.8rem, 12vw, 4.5rem); }
  .route-caption { margin-top: 12px; }
  .route-step--group-start { margin-inline-start: clamp(6px, 2vw, 14px); }
  .route-step--group-start.route-step--row-start { margin-block-start: 8px; }
  .result-reference { gap: 8px 14px; }
  .result-reference .eyebrow { min-width: 0; margin-top: 2px; }
  .puzzle-grid--small { width: min(148px, 37vw); gap: 7px 12px; }
  .result-meta { gap: 4px 12px; }
  .result-meta span + span::before { margin-right: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .001ms !important; }
}
