:root {
  color-scheme: light;
  --ink: #3b1a0a;
  --cream: #fff1d6;
  --barn: #9a3412;
  --cranberry: #b3261e;
  --crust: #e7a442;
  --meadow: #7e9a3a;
  --meadow-light: #a7b957;
  --sky: #9fe3d6;
  --haze: #cdefe8;
  --pumpkin: #f07812;
  --apple: #e0312b;
  --pecan: #4a2c16;
  --teal: #1f5f5b;
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  overflow-x: hidden;
  max-width: 100%;
}

body {
  min-height: 100dvh;
  color: var(--ink);
  background: linear-gradient(180deg, var(--haze) 0%, var(--sky) 24%, #b7d48a 58%, var(--meadow) 100%);
}

button, a, summary { -webkit-tap-highlight-color: transparent; }

button {
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  border: 2px solid var(--ink);
  background: var(--cream);
  border-radius: 999px;
  font-weight: 800;
}

button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 2px;
}

.page {
  width: min(1240px, 100%);
  margin: 0 auto;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  overflow: hidden;
}

.site-header {
  background: var(--cream);
  border: 3px solid var(--barn);
  border-radius: 18px;
  padding: 8px 10px 6px;
}

.header-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}

.logo-plate {
  display: grid;
  place-items: center;
  padding: 4px;
  border-radius: 12px;
  background: #3b1a0a;
  border: 2px solid #9a3412;
  box-shadow: 0 0 0 2px #e7a442;
}

.brand img, .logo-fallback {
  width: 36px;
  height: 36px;
  display: block;
  border-radius: 8px;
}

.logo-fallback {
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--barn);
  color: var(--cream);
  font-size: 0.55rem;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  padding: 2px;
}

h1 {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 1.25rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.back {
  flex: 0 0 auto;
  color: var(--barn);
  font-weight: 800;
  font-size: 0.86rem;
  text-decoration: none;
  white-space: nowrap;
}

.tagline {
  margin: 4px 0 0;
  font-size: 0.92rem;
  line-height: 1.25;
}

.hud {
  background-color: #f6d3c6;
  background-image:
    linear-gradient(90deg, rgba(179, 38, 30, 0.16) 50%, transparent 50%),
    linear-gradient(rgba(179, 38, 30, 0.16) 50%, transparent 50%);
  background-size: 14px 14px;
  background-position: 0 0, 0 0;
  border-radius: 22px;
  padding: 7px;
}

.hud-inner {
  background: var(--cream);
  border-radius: 16px;
  padding: 8px 10px 6px;
}

.play {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hud-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 12px;
  margin: 0;
}

.hud-helpings { grid-column: 1 / -1; }

.hud-grid p {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  min-width: 0;
}

.hud-grid span {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.hud-grid strong {
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

.hud-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.hud-actions button {
  flex: 1;
  min-height: 36px;
  background: #fff;
  font-size: 0.85rem;
}

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(64px, 72px) minmax(64px, 78px);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 4px;
}

.field-frame { grid-column: 1 / -1; grid-row: 1; }

.lane-col, .action-col { display: contents; }

.lane-col button {
  min-height: 52px;
  min-width: 0;
  border-radius: 14px;
  padding: 2px;
  font-size: 1rem;
  line-height: 1;
  background: rgba(255, 241, 214, 0.92);
}

.lane-col button.is-on {
  background: var(--crust);
}

.action-col { justify-content: flex-end; }

#flavor, #launch {
  width: 100%;
  min-height: 64px;
  min-width: 0;
  padding: 4px 2px;
}

#flavor {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  border-radius: 18px;
  padding: 3px 7px 4px;
  overflow: hidden;
  background: var(--cream);
  font-size: 0.72rem;
  line-height: 1.05;
}

.flavor-kicker {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

#flavor-name {
  display: block;
  max-width: 100%;
  font-size: 0.68rem;
  line-height: 1.05;
  letter-spacing: -0.04em;
  text-align: center;
}

.pie-icon {
  width: 22px;
  height: 22px;
  display: block;
  flex: 0 0 auto;
}

.pie-icon-fill {
  fill: var(--pumpkin);
  stroke: #3b1a0a;
  stroke-width: 2.4;
  stroke-linejoin: round;
}

.pie-icon-crust {
  fill: none;
  stroke: #e7a442;
  stroke-width: 3.4;
  stroke-linecap: round;
}

.pie-icon-lattice {
  fill: none;
  stroke: #fff6dc;
  stroke-width: 1.7;
  stroke-linecap: round;
}

#flavor[data-flavor="pumpkin"] { box-shadow: inset 0 0 0 3px var(--pumpkin); }
#flavor[data-flavor="pumpkin"] .pie-icon-fill { fill: var(--pumpkin); }
#flavor[data-flavor="apple"] { box-shadow: inset 0 0 0 3px var(--apple); }
#flavor[data-flavor="apple"] .pie-icon-fill { fill: var(--apple); }
#flavor[data-flavor="apple"] .pie-icon-lattice { stroke: #ffe08a; stroke-width: 2.2; }
#flavor[data-flavor="pecan"] { box-shadow: inset 0 0 0 3px var(--pecan); }
#flavor[data-flavor="pecan"] .pie-icon-fill { fill: var(--pecan); }
#flavor[data-flavor="pecan"] .pie-icon-lattice { stroke: #e8c27a; stroke-width: 2; }

#launch {
  background:
    linear-gradient(#fff1d6, #fff1d6) top / 100% calc((1 - var(--p, 1)) * 100%) no-repeat,
    var(--crust);
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.field-frame {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 6px;
  border-radius: 22px;
  background-color: #f6d3c6;
  background-image:
    linear-gradient(90deg, rgba(179, 38, 30, 0.16) 50%, transparent 50%),
    linear-gradient(rgba(179, 38, 30, 0.16) 50%, transparent 50%);
  background-size: 14px 14px;
}

.field-slot {
  position: absolute;
  inset: 6px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-radius: 16px;
}

#field {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
  border-radius: 16px;
  background: var(--sky);
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border-radius: 16px;
  background: rgba(59, 26, 10, 0.16);
}

.end-cover {
  inset: 0;
  z-index: 4;
  padding: 6px;
  border-radius: 18px;
  background: rgba(59, 26, 10, 0.28);
  align-items: stretch;
}

.overlay[hidden] { display: none !important; }

.sheet {
  width: min(100%, 420px);
  max-height: 100%;
  overflow: auto;
  background: var(--cream);
  color: var(--ink);
  border: 3px solid var(--barn);
  border-radius: 20px;
  padding: 14px;
}

.sheet p { margin: 0 0 10px; line-height: 1.35; }

.overlay-title, h2, h3 {
  margin: 0 0 8px;
  line-height: 1.15;
}

h2 { font-size: 1.45rem; }
h3 { margin-top: 14px; font-size: 1rem; }

.big-score {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 800;
}

.big-score strong {
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
}

.best { font-weight: 700; }

#start, #resume, #again {
  width: 100%;
  min-height: 64px;
  background: var(--crust);
  font-size: 1.15rem;
}

#ended .sheet {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 8px 10px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

#ended h2 { font-size: 1.15rem; margin-bottom: 2px; }
#ended .sheet p { margin: 0 0 3px; font-size: 0.8rem; line-height: 1.2; }
#ended .big-score strong { font-size: 1.45rem; }
#ended h3 { margin: 4px 0 3px; font-size: 0.88rem; }
#ended #again {
  min-height: 48px;
  font-size: 1rem;
  margin: 2px 0 2px;
}

#merch {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

#merch a {
  display: block;
  padding: 4px 8px;
  border-radius: 10px;
  border: 2px solid var(--barn);
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  font-size: 0.75rem;
  line-height: 1.2;
  text-decoration: none;
  overflow-wrap: anywhere;
}

#merch a.feature { border-width: 3px; }

.howto {
  background: var(--cream);
  border-radius: 16px;
  border: 2px solid var(--barn);
  padding: 0 12px;
  max-height: 28vh;
  overflow: auto;
  flex: 0 0 auto;
}

.howto summary {
  cursor: pointer;
  font-weight: 800;
  padding: 8px 0;
}

.howto-body { padding-bottom: 8px; }
.howto-body p { margin: 0 0 8px; font-size: 0.92rem; line-height: 1.4; }

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 12px;
  align-items: center;
  padding: 2px 4px 0;
  font-size: 0.85rem;
}

.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}

.site-footer a {
  color: var(--barn);
  font-weight: 800;
  text-decoration: none;
}

.site-footer p { margin: 0; }

.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;
}

.noscript {
  margin: 12px;
  padding: 12px;
  background: var(--cream);
  border-radius: 12px;
}

#score.pop { animation: score-pop 180ms ease; }

@keyframes score-pop {
  from { transform: scale(1.12); }
  to { transform: scale(1); }
}

@media (min-width: 960px) {
  .page { padding: 10px 12px 8px; gap: 8px; }
  h1 { font-size: 1.7rem; }
  .tagline { font-size: 1rem; }
  .play {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 168px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 6px 10px;
  }
  .stage { display: contents; }
  .hud {
    grid-column: 2;
    grid-row: 1;
    align-self: start;
    padding: 4px;
    border-radius: 16px;
  }
  .hud-inner { padding: 6px 8px 6px; }
  .hud-grid {
    grid-template-columns: 1fr;
    gap: 1px;
  }
  .hud-grid span { font-size: 0.72rem; }
  .hud-grid strong { font-size: 1.05rem; }
  .hud-actions { margin-top: 4px; gap: 4px; }
  .hud-actions button { min-height: 32px; font-size: 0.78rem; }
  .field-frame { grid-column: 1; grid-row: 1 / -1; }
  .lane-col {
    display: flex;
    flex-direction: column;
    grid-column: 2;
    grid-row: 2;
    gap: 6px;
    min-height: 0;
  }
  .action-col {
    display: flex;
    flex-direction: column;
    grid-column: 2;
    grid-row: 3;
    gap: 6px;
  }
  .lane-col button { flex: 1; min-height: 44px; font-size: 1.05rem; }
  #flavor { min-height: 64px; font-size: 0.92rem; }
  #flavor-name { font-size: 0.95rem; letter-spacing: 0; }
  .pie-icon { width: 30px; height: 30px; }
  #launch { min-height: 72px; font-size: 1.15rem; }
  .brand img, .logo-fallback { width: 44px; height: 44px; }
  #ended .sheet { padding: 14px 16px; }
  #ended h2 { font-size: 1.45rem; }
  #ended .big-score strong { font-size: 2rem; }
  #ended #again { min-height: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  #score.pop { animation: none; }
}
