/* pumpkinsquash.space — shared foundation
 * Design tokens (the fall-harvest palette + type scale) plus the reset and
 * the play-screen chrome: topbar, icon buttons, tally, footer bar and the
 * settings sheet. The reading pages build on these tokens in pages.css.
 */

:root {
  /* ---- harvest palette ---- */
  --ink:        #20132a;   /* dusk, near-black plum */
  --ink-soft:   #3a2340;
  --parchment:  #f6ecd9;   /* warm cream, used on dark grounds */
  --paper:      #faf3e2;   /* page background */
  --gourd:      #f2792a;   /* pumpkin skin — primary accent */
  --gourd-dark: #c9541a;
  --squash:     #f4b731;   /* squash skin — secondary accent */
  --ember:      #c9541a;   /* rules, underlines */
  --rind:       #6b3a1c;   /* quiet brown, stamps and captions */
  --apple:      #c8324b;   /* hover / alert accent */
  --leaf:       #5f7c36;

  /* ---- type ---- */
  --face-display: 'Georgia', 'Iowan Old Style', 'Palatino Linotype', serif;
  --face-text:    'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --step--1: clamp(0.8rem, 0.77rem + 0.16vw, 0.9rem);
  --step-0:  clamp(1rem, 0.96rem + 0.2vw, 1.125rem);
  --step-1:  clamp(1.25rem, 1.16rem + 0.45vw, 1.6rem);
  --step-2:  clamp(1.7rem, 1.5rem + 1vw, 2.4rem);

  /* ---- layout ---- */
  --edge: clamp(1rem, 4vw, 2rem);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
  color-scheme: dark light;
}

/* ---------- reset ---------- */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--face-text);
  background: var(--ink);
  color: var(--parchment);
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
[hidden] { display: none !important; }

a { color: inherit; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

.sr {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* #btn-smash is visually hidden (.sr) so it doesn't clutter the play
   screen, but a sighted keyboard user tabbing to it needs to actually see
   it — so, like .skip below, it pops into view on focus instead of staying
   invisible. Screen reader users get it regardless of this rule. */
#btn-smash:focus-visible {
  position: fixed;
  width: auto;
  height: auto;
  margin: 0;
  padding: 0.75rem 1.4rem;
  clip: auto;
  overflow: visible;
  white-space: normal;
  left: 50%;
  bottom: calc(var(--safe-b) + 1rem);
  transform: translateX(-50%);
  background: var(--gourd);
  color: var(--ink);
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.95rem;
  z-index: 50;
  outline: 3px solid var(--squash);
  outline-offset: 3px;
}

/* the hidden <svg> holding shared clip-path/gradient defs — zero-sized via
   its own width/height attributes already, this just keeps it out of flow */
.visually-nil { position: absolute; }

.skip {
  position: absolute;
  top: calc(var(--safe-t) + 0.5rem);
  left: 0.5rem;
  transform: translateY(-140%);
  background: var(--parchment);
  color: var(--ink);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
  z-index: 100;
  transition: transform 0.15s ease;
}
.skip:focus { transform: translateY(0); }

/* ---------- play screen ---------- */

body.play {
  min-height: 100dvh;
}

/* The canvas stays pinned as a fixed backdrop, so the document can still
   scroll past it — used to reveal the beta banner below the game. */
.betabar {
  position: relative;
  z-index: 1;
  padding: 1.6rem max(var(--edge), var(--safe-r)) calc(1.6rem + var(--safe-b)) max(var(--edge), var(--safe-l));
  background: var(--ink-soft);
  color: var(--parchment);
  border-top: 3px solid var(--ember);
  text-align: center;
}
.betabar__title {
  margin: 0 0 0.4rem;
  font-family: var(--face-display);
  font-weight: 700;
  color: var(--squash);
  font-size: 1.1rem;
}
.betabar p {
  margin: 0 auto;
  max-width: 40rem;
  font-size: 0.9rem;
  opacity: 0.85;
  line-height: 1.5;
}
.betabar__hint {
  margin-top: 0.6rem !important;
  font-size: 0.78rem !important;
  opacity: 0.6 !important;
}

#stage {
  position: fixed;
  inset: 0;
  /* pan-y (not none): still blocks pinch-zoom and double-tap-zoom while
     tapping pieces, but lets a real vertical swipe reach the browser's own
     scroll gesture — needed since this fixed, full-viewport canvas sits
     over the "empty" space below the game too, and touch-action: none there
     was silently swallowing the swipe before it ever became a page scroll.
     The game itself only ever listens for pointerdown (a tap), never a
     drag, so allowing vertical panning here costs it nothing. */
  touch-action: pan-y;
  display: block;
}

.frame {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  /* vh first as a fallback for browsers that don't know dvh (an unsupported
     unit makes the whole declaration invalid, so it's skipped, not just
     ignored) — dvh second so it wins in the cascade where it *is* supported,
     which is the one that actually accounts for a mobile browser's address
     bar showing and hiding. They were declared in the wrong order before
     (dvh first, vh second silently overrides it) so dvh was never used. */
  min-height: 100vh;
  min-height: 100dvh;
  pointer-events: none;
}
.frame > * { pointer-events: auto; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(var(--safe-t) + 0.9rem) max(var(--edge), var(--safe-r)) 0.9rem max(var(--edge), var(--safe-l));
}

.wordmark {
  margin: 0;
  font-family: var(--face-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}
.wordmark__p { color: var(--gourd); }
.wordmark__s { color: var(--squash); }

.topbar__tools {
  display: flex;
  gap: 0.5rem;
}

.icon-btn {
  width: 2.6rem;
  height: 2.6rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(32, 19, 42, 0.55);
  border: 1px solid rgba(246, 236, 217, 0.18);
  color: var(--parchment);
  backdrop-filter: blur(6px);
  transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}
.icon-btn svg { width: 1.35rem; height: 1.35rem; }
.icon-btn:active { transform: scale(0.92); }
.icon-btn:focus-visible { outline: 2px solid var(--squash); outline-offset: 2px; }

/* pumpkin-shaped badge instead of a plain circle, for the three topbar
   toggles specifically (not the settings sheet's own close button) */
.icon-btn--pumpkin { clip-path: url(#pumpkin-clip); }

/* music and sound-effects buttons keep the same glyph on or off — muted vs
   on is told by colour instead: greyed out and dim while silent (both
   start this way on arrival), pumpkin orange with a dark glyph once the
   visitor turns it on. Hover is declared after both so it always wins,
   giving a consistent "this is clickable" hint either way. */
.icon-btn[aria-pressed="false"] {
  background: rgba(120, 118, 128, 0.32);
  border-color: rgba(246, 236, 217, 0.14);
  color: rgba(246, 236, 217, 0.5);
}
.icon-btn[aria-pressed="true"] {
  background: var(--gourd);
  border-color: var(--gourd);
  color: var(--ink);
}
.icon-btn:hover { background: rgba(242, 121, 42, 0.35); border-color: var(--gourd); }

.icon-btn--plain {
  background: transparent;
  border: 0;
  backdrop-filter: none;
}
.icon-btn--plain:hover { background: rgba(246, 236, 217, 0.12); }

.tally {
  align-self: center;
  margin-top: 0.4rem;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  background: rgba(32, 19, 42, 0.55);
  border: 1px solid rgba(246, 236, 217, 0.16);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  font-family: var(--face-display);
}
.tally__num {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--squash);
  font-variant-numeric: tabular-nums;
}
.tally__word {
  font-size: 0.8rem;
  opacity: 0.75;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.tally.is-hit .tally__num { animation: tally-pop 0.32s ease-out; }

@keyframes tally-pop {
  0%   { transform: scale(1.35); color: var(--gourd); }
  100% { transform: scale(1); color: var(--squash); }
}

.nudge {
  align-self: center;
  margin: 0.5rem 0 0;
  padding: 0.3rem 0.8rem;
  font-size: 0.85rem;
  opacity: 0.7;
  text-align: center;
}

.footbar {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 0 max(var(--edge), var(--safe-r)) calc(var(--safe-b) + 1rem) max(var(--edge), var(--safe-l));
}

.pill {
  padding: 0.75rem 1.4rem;
  border-radius: 999px;
  background: var(--gourd);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 6px 20px rgba(242, 121, 42, 0.35);
  transition: transform 0.12s ease, background 0.15s ease;
}
.pill:hover { background: var(--squash); }
.pill:active { transform: scale(0.96); }
.pill--quiet {
  background: rgba(246, 236, 217, 0.12);
  color: var(--parchment);
  box-shadow: none;
  font-size: 0.85rem;
  padding: 0.55rem 1rem;
}
.pill--quiet:hover { background: rgba(246, 236, 217, 0.2); }

.pill kbd {
  font-family: var(--face-text);
  font-size: 0.72rem;
  padding: 0.1rem 0.4rem;
  border-radius: 5px;
  background: rgba(32, 19, 42, 0.25);
}

.minilinks {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.3rem 0.9rem;
}
.minilinks a {
  font-size: 0.78rem;
  opacity: 0.65;
  text-decoration: none;
}
.minilinks a:hover { opacity: 1; text-decoration: underline; }

/* ---------- settings sheet ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
@media (min-width: 640px) {
  .sheet { align-items: center; }
}

.sheet__scrim {
  position: absolute;
  inset: 0;
  background: rgba(15, 8, 20, 0.6);
  backdrop-filter: blur(2px);
}

.panel {
  position: relative;
  width: min(30rem, 100%);
  max-height: min(88vh, 44rem);
  overflow-y: auto;
  background: var(--ink-soft);
  color: var(--parchment);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  padding-bottom: var(--safe-b);
}
@media (min-width: 640px) {
  .panel { border-radius: 20px; }
}

.panel__head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.2rem;
  background: var(--ink-soft);
  border-bottom: 1px solid rgba(246, 236, 217, 0.12);
}
.panel__head h2 {
  margin: 0;
  font-family: var(--face-display);
  font-size: 1.1rem;
}

.panel__body {
  padding: 0.4rem 1.2rem 1.4rem;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid rgba(246, 236, 217, 0.1);
}
.row label, .row__label { font-size: 0.92rem; }

.row--stack {
  flex-direction: column;
  align-items: stretch;
  gap: 0.6rem;
}

.switch {
  appearance: none;
  width: 2.6rem;
  height: 1.5rem;
  border-radius: 999px;
  background: rgba(246, 236, 217, 0.18);
  position: relative;
  flex: none;
  transition: background 0.15s ease;
}
.switch::before {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 1.2rem; height: 1.2rem;
  border-radius: 50%;
  background: var(--parchment);
  transition: transform 0.15s ease;
}
.switch:checked { background: var(--gourd); }
.switch:checked::before { transform: translateX(1.1rem); }
.switch:focus-visible { outline: 2px solid var(--squash); outline-offset: 2px; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.chip {
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  background: rgba(246, 236, 217, 0.1);
  border: 1px solid transparent;
  font-size: 0.85rem;
}
.chip[aria-checked="true"] {
  background: rgba(242, 121, 42, 0.25);
  border-color: var(--gourd);
  color: var(--squash);
  font-weight: 600;
}
.chip:hover { background: rgba(246, 236, 217, 0.18); }

.panel__foot {
  margin-top: 0.6rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(246, 236, 217, 0.1);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.7rem;
}

.fineprint {
  font-size: 0.76rem;
  opacity: 0.6;
  margin: 0;
}

@media (prefers-reduced-motion: reduce) {
  .icon-btn, .pill, .switch, .switch::before, .skip { transition: none; }
  .tally.is-hit .tally__num { animation: none; }
}
