/* ==========================================================================
   Timber Squirrel — style.css
   Direction: "Norse twilight forest, lantern-lit". Organic and grounded, with
   one amber accent doing all the work. Display type is an old-style serif
   (Iowan / Palatino) so the saga reads like a saga; body and HUD are a humanist
   sans; every number is monospaced so the par counter never jitters.
   ========================================================================== */

:root {
  --ink:        #08120f;
  --ink-2:      #0e1c18;
  --ink-3:      #142723;
  --water:      #1d4a58;
  --moss:       #7b9a55;
  --bark:       #6a4a24;
  --gold:       #f0b64a;
  --gold-soft:  #ffd88a;
  --gold-dim:   #a8791f;
  --paper:      #f3efe4;
  --muted:      rgba(243, 239, 228, .62);
  --line:       rgba(243, 239, 228, .13);

  --display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --body:    "Avenir Next", "Segoe UI", "Gill Sans", "Trebuchet MS", sans-serif;
  --mono:    ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;
  --sh-1: 0 2px 6px rgba(0,0,0,.28);
  --sh-2: 0 10px 28px rgba(0,0,0,.42);
  --sh-3: 0 26px 70px rgba(0,0,0,.58);
  --ease: cubic-bezier(.16, 1, .3, 1);
  --t-fast: 150ms;
  --t-mid: 300ms;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  background:
    radial-gradient(1100px 620px at 50% -12%, #1b3a3a 0%, rgba(27,58,58,0) 62%),
    linear-gradient(180deg, #08120f 0%, #0b1a17 46%, #060d0b 100%);
  color: var(--paper);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }
/* flex children must be allowed to shrink below their min-content width,
   otherwise a wide table forces the whole page sideways on a 320px phone */
.shell > * { min-width: 0; }

.shell {
  max-width: 1160px;
  margin: 0 auto;
  padding: 14px 16px 56px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ------------------------------------------------------------------ topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px 2px;
  flex-wrap: wrap;
}
.brand { display: flex; flex-direction: column; line-height: 1.15; }
.brand b {
  font-family: var(--display);
  font-size: 21px;
  letter-spacing: -.01em;
  color: var(--paper);
}
.brand span { font-size: 11.5px; color: var(--gold); letter-spacing: .12em; text-transform: uppercase; }
.spacer { flex: 1 1 auto; }
.chip {
  font-size: 11px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 11px;
  white-space: nowrap;
}

/* ------------------------------------------------------------------- stage */
.stage {
  position: relative;
  width: 100%;
  height: min(78vh, 700px);
  min-height: 400px;
  flex: 1 1 auto;
  border-radius: var(--r-lg);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--sh-3);
  background: #08120f;
  isolation: isolate;
}
#board { display: block; width: 100%; height: 100%; touch-action: none; }

/* --------------------------------------------------------------------- hud */
.hud {
  position: absolute;
  inset: 10px 12px auto 12px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  pointer-events: none;
  z-index: 4;
}
.panel {
  background: rgba(8, 20, 18, .74);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 7px 12px;
  backdrop-filter: blur(9px);
  box-shadow: var(--sh-1);
}
.panel.left { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.panel.left .act {
  font-family: var(--display);
  font-size: 15px;
  color: var(--gold-soft);
  letter-spacing: .01em;
}
.panel.left .ch { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel.mid { display: flex; gap: 16px; }
.panel.mid .stat { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.panel.mid b { font-family: var(--mono); font-size: 17px; color: var(--paper); font-weight: 600; }
.panel.mid i { font-style: normal; font-size: 10px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.panel.mid .par b { color: var(--gold); }
.hud .right { margin-left: auto; display: flex; align-items: center; gap: 7px; pointer-events: auto; }
.stars { display: flex; gap: 3px; background: rgba(8,20,18,.74); border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; }
.stars i {
  width: 12px; height: 12px; display: block;
  background: rgba(243,239,228,.2);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  transition: background var(--t-mid) var(--ease), transform var(--t-mid) var(--ease);
}
.stars i.on { background: var(--gold); transform: scale(1.12); box-shadow: 0 0 10px rgba(240,182,74,.6); }
.iconbtn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(8,20,18,.74);
  color: var(--paper);
  font-size: 14px;
  cursor: pointer;
  backdrop-filter: blur(9px);
  transition: transform var(--t-fast) var(--ease), border-color var(--t-fast);
}
.iconbtn:hover { transform: translateY(-1px); border-color: rgba(240,182,74,.5); }
.iconbtn:active { transform: translateY(0) scale(.96); }

/* ------------------------------------------------------------------ toasts */
.toasts {
  position: absolute;
  left: 50%; top: 66px;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px;
  align-items: center;
  z-index: 6;
  pointer-events: none;
  width: max-content;
  max-width: 92%;
}
.toast {
  background: rgba(10, 24, 21, .93);
  border: 1px solid rgba(240,182,74,.32);
  color: var(--paper);
  font-size: 13px;
  border-radius: 999px;
  padding: 7px 16px;
  box-shadow: var(--sh-2);
  animation: toastIn 320ms var(--ease);
}
.toast.bad { border-color: rgba(214,106,74,.6); }
.toast.good { border-color: rgba(240,182,74,.7); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px) } to { opacity: 1; transform: none } }

.hint {
  position: absolute;
  left: 50%; bottom: 10px;
  transform: translateX(-50%);
  font-size: 11.5px;
  color: rgba(243,239,228,.5);
  background: rgba(8,20,18,.55);
  border-radius: 999px;
  padding: 4px 14px;
  white-space: nowrap;
  z-index: 3;
  pointer-events: none;
  transition: opacity var(--t-mid);
}

/* -------------------------------------------------------------------- dpad */
.dpad {
  position: absolute;
  left: 12px; bottom: 12px;
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(2, 46px);
  gap: 6px;
  z-index: 4;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-mid);
}
.dpad.on { opacity: 1; pointer-events: auto; }
.dbtn {
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: rgba(8,20,18,.72);
  color: var(--paper);
  font-size: 15px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background var(--t-fast), transform var(--t-fast);
  touch-action: manipulation;
}
.dbtn:active { background: rgba(240,182,74,.24); transform: scale(.95); }
.dbtn.up { grid-column: 2; grid-row: 1; }
.dbtn.lf { grid-column: 1; grid-row: 2; }
.dbtn.dn { grid-column: 2; grid-row: 2; }
.dbtn.rt { grid-column: 3; grid-row: 2; }

/* ----------------------------------------------------------------- actions */
.actions {
  position: absolute;
  right: 12px; bottom: 12px;
  display: flex;
  gap: 7px;
  z-index: 4;
}
.abtn {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(8,20,18,.74);
  color: var(--paper);
  font-size: 12.5px;
  font-family: var(--body);
  padding: 9px 15px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: transform var(--t-fast) var(--ease), border-color var(--t-fast), background var(--t-fast);
}
.abtn:hover { transform: translateY(-1px); border-color: rgba(240,182,74,.55); }
.abtn:active { transform: translateY(0) scale(.97); }
.abtn:disabled { opacity: .38; cursor: default; transform: none; }
.abtn.warn { border-color: rgba(214,106,74,.6); }

/* ---------------------------------------------------------------- overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: radial-gradient(700px 460px at 50% 40%, rgba(6,16,14,.72), rgba(4,10,9,.94));
  backdrop-filter: blur(4px);
  z-index: 8;
  animation: fadeIn 260ms var(--ease);
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.card-wrap {
  width: 100%;
  max-width: 480px;
  max-height: 100%;
  overflow: auto;
  background: linear-gradient(180deg, rgba(18,36,32,.97), rgba(10,22,19,.98));
  border: 1px solid rgba(240,182,74,.22);
  border-radius: var(--r-lg);
  padding: 24px 22px 20px;
  box-shadow: var(--sh-3);
  animation: cardIn 420ms var(--ease);
}
.card-wrap.wide { max-width: 720px; }
@keyframes cardIn { from { opacity: 0; transform: translateY(14px) scale(.97) } to { opacity: 1; transform: none } }

.kicker {
  display: block;
  font-size: 10.5px;
  letter-spacing: .17em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 8px;
}
.card-wrap h2 {
  font-family: var(--display);
  font-size: 30px;
  line-height: 1.08;
  letter-spacing: -.02em;
  margin: 0 0 10px;
}
.card-wrap h2 + .sub { margin-top: -6px; }
.card-wrap p { font-size: 14px; color: rgba(243,239,228,.82); margin: 0 0 10px; }
.card-wrap p.muted { color: var(--muted); font-size: 12.5px; }
.card-wrap strong { color: var(--gold-soft); font-weight: 600; }
.card-wrap em { color: var(--paper); font-style: italic; }

.row { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 16px; }
.row.single { justify-content: center; }

.btn {
  font-family: var(--body);
  font-size: 14px;
  padding: 11px 20px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.05);
  color: var(--paper);
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease), background var(--t-fast), border-color var(--t-fast);
}
.btn:hover { transform: translateY(-1px); border-color: rgba(240,182,74,.5); }
.btn:active { transform: translateY(0) scale(.98); }
.btn.primary {
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  border-color: transparent;
  color: #2a1c04;
  font-weight: 600;
  box-shadow: 0 8px 22px rgba(240,182,74,.28);
}
.btn.ghost { background: transparent; color: var(--muted); }

/* ------------------------------------------------------------- act / level */
.acts { display: flex; flex-direction: column; gap: 16px; margin-top: 6px; }
.actblk h3 {
  font-family: var(--display);
  font-size: 17px;
  margin: 0 0 2px;
  color: var(--gold-soft);
}
.actblk h3 small { font-family: var(--body); font-size: 11px; color: var(--muted); letter-spacing: .1em; text-transform: uppercase; margin-left: 8px; }
.actblk .acthint { font-size: 12px; color: var(--muted); margin: 0 0 9px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 7px; }
.lvbtn {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: rgba(255,255,255,.045);
  color: var(--paper);
  font-family: var(--mono);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: transform var(--t-fast) var(--ease), border-color var(--t-fast), background var(--t-fast);
}
.lvbtn:hover { transform: translateY(-2px); border-color: rgba(240,182,74,.5); }
.lvbtn.locked { opacity: .34; cursor: not-allowed; transform: none; }
.lvbtn.done { background: rgba(240,182,74,.12); border-color: rgba(240,182,74,.4); }
.lvbtn .mini { display: flex; gap: 2px; }
.lvbtn .mini i {
  width: 7px; height: 7px; background: rgba(243,239,228,.22);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.lvbtn .mini i.on { background: var(--gold); }

/* -------------------------------------------------------------- story card */
.card-wrap.story { max-width: 560px; }
.story-body p { font-size: 14.5px; line-height: 1.72; color: rgba(243,239,228,.86); }
.story-body p:first-child::first-letter {
  font-family: var(--display);
  font-size: 44px;
  line-height: .82;
  float: left;
  padding: 4px 8px 0 0;
  color: var(--gold);
}
.story-body .verse {
  font-family: var(--display);
  font-style: italic;
  color: var(--gold-soft);
  border-left: 2px solid rgba(240,182,74,.4);
  padding-left: 14px;
  margin: 14px 0;
}

/* ---------------------------------------------------------------- win card */
.bigstars { display: flex; gap: 9px; justify-content: center; margin: 14px 0 10px; }
.bigstars i {
  width: 38px; height: 38px;
  background: rgba(243,239,228,.16);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  transform: scale(.6);
  opacity: 0;
}
.bigstars i.on { background: var(--gold); animation: starPop 520ms var(--ease) forwards; }
.bigstars i.off { animation: starPop 520ms var(--ease) forwards; animation-delay: .18s; }
@keyframes starPop {
  0% { transform: scale(.4) rotate(-25deg); opacity: 0; }
  60% { transform: scale(1.22) rotate(6deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
.card-wrap.win p#winLine { text-align: center; color: var(--muted); font-size: 13.5px; }

/* ------------------------------------------------------------- endless hud */
.endstats { display: flex; gap: 22px; justify-content: center; margin: 14px 0 4px; }
.endstats span { display: flex; flex-direction: column; align-items: center; }
.endstats b { font-family: var(--mono); font-size: 22px; color: var(--gold); }
.endstats i { font-style: normal; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }

/* -------------------------------------------------------------- how to play */
.howgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-top: 6px; }
.howcard { border: 1px solid var(--line); border-radius: var(--r-md); padding: 13px 14px; background: rgba(255,255,255,.035); }
.howcard h4 { margin: 0 0 5px; font-family: var(--display); font-size: 16px; color: var(--gold-soft); }
.howcard p { font-size: 12.8px; color: rgba(243,239,228,.78); margin: 0; line-height: 1.55; }
.howcard .glyph { font-size: 19px; display: block; margin-bottom: 6px; }

/* ------------------------------------------------------------------- about */
.about {
  max-width: 780px;
  min-width: 0;
  margin: 34px auto 0;
  padding: 0 4px;
  overflow-wrap: break-word;
}
.about h1 {
  font-family: var(--display);
  font-size: clamp(26px, 4vw, 38px);
  line-height: 1.1;
  letter-spacing: -.025em;
  margin: 0 0 16px;
}
.about h2 {
  font-family: var(--display);
  font-size: 22px;
  letter-spacing: -.01em;
  margin: 30px 0 8px;
  color: var(--gold-soft);
}
.about p { color: rgba(243,239,228,.8); font-size: 15px; line-height: 1.75; }
.about strong { color: var(--paper); font-weight: 600; }
.about ol.howto { padding-left: 20px; color: rgba(243,239,228,.8); font-size: 15px; }
.about ol.howto li { margin: 6px 0; line-height: 1.7; }
.about table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin: 14px 0 6px;
  font-size: 13.6px;
}
.about table th, .about table td { overflow-wrap: anywhere; }
.about th, .about td { text-align: left; padding: 9px 11px; border-bottom: 1px solid var(--line); vertical-align: top; }
.about th { font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--gold); font-weight: 600; }
.about td { color: rgba(243,239,228,.78); }
.about .faq h3 { font-family: var(--display); font-size: 17px; color: var(--gold-soft); margin: 20px 0 4px; }
.about .faq p { margin: 0; font-size: 14.5px; }
.tags { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 22px; }
.tags span {
  font-size: 11px; letter-spacing: .07em; text-transform: uppercase;
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; color: var(--muted);
}

/* --------------------------------------------------------------- responsive */
@media (max-width: 860px) {
  .shell { padding: 10px 10px 40px; gap: 10px; }
  .stage { height: 62vh; min-height: 340px; border-radius: var(--r-md); }
  .hud { inset: 8px 8px auto 8px; }
  .panel.left .act { font-size: 13.5px; }
  .panel.left .ch { font-size: 10.5px; }
  .panel.mid { gap: 11px; padding: 6px 9px; }
  .panel.mid b { font-size: 15px; }
  .chip { display: none; }
  .actions { right: 8px; bottom: 8px; }
  .abtn { padding: 8px 12px; font-size: 11.5px; }
  .hint { display: none; }
  .card-wrap { padding: 20px 16px 16px; border-radius: var(--r-md); }
  .card-wrap h2 { font-size: 25px; }
}
@media (max-width: 520px) {
  .stage { height: 56vh; min-height: 300px; }
  .stars { padding: 5px 8px; }
  .iconbtn { width: 34px; height: 34px; }
  .dpad { grid-template-columns: repeat(3, 42px); grid-template-rows: repeat(2, 42px); left: 8px; bottom: 8px; }
  .actions { flex-direction: column; align-items: flex-end; }
  .dpad.on ~ .actions { bottom: 8px; }
  .about { margin-top: 24px; }
}
@media (hover: none) and (pointer: coarse) {
  .dpad { opacity: 1; pointer-events: auto; }
  .actions { bottom: 8px; }
}
@media (pointer: coarse) {
  .dpad { opacity: 1; pointer-events: auto; }
}

/* ---------------------------------------------------- focus & a11y states */
button:focus-visible, .lvbtn:focus-visible, a:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
