:root {
  --paper: #FBF9F5;
  --surface: #FFFFFF;
  --surface-sunken: #F3EFE7;
  --ink: #1A1712;
  --ink-muted: #6B6459;
  --line: #E7E0D4;
  --line-strong: #D8CFBE;
  --brand: #B7833A;
  --brand-strong: #8E6326;
  --brand-soft: #F0E4CE;
  --tile-jade: #33B06F;
  --tile-coral: #F05A5A;
  --tile-orchid: #8D62D9;
  --font-serif: Fraunces, Georgia, "Times New Roman", serif;
  --font-sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(26, 23, 18, .05), 0 1px 1px rgba(26, 23, 18, .04);
  --shadow-md: 0 14px 38px rgba(26, 23, 18, .13), 0 3px 8px rgba(26, 23, 18, .07);
  --ease: cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 16% 0%, rgba(240, 228, 206, .8), transparent 28rem),
    linear-gradient(180deg, var(--paper), #F7F1E8 100%);
  color: var(--ink);
  font-family: var(--font-sans);
}

a, button { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
button {
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font: 800 .94rem/1 var(--font-sans);
  transition: transform 160ms var(--ease), border-color 160ms var(--ease), box-shadow 160ms var(--ease), background 160ms var(--ease);
}
button:hover { transform: translateY(-1px); border-color: var(--brand); box-shadow: var(--shadow-sm); }
button:active, button.is-held { transform: translateY(0); background: var(--brand-soft); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }

.shell {
  width: min(1160px, calc(100vw - clamp(14px, 4vw, 48px)));
  min-height: 100svh;
  margin: 0 auto;
  padding: 16px 0 calc(18px + env(safe-area-inset-bottom));
  display: grid;
  gap: 12px;
}

.brandbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  box-shadow: var(--shadow-sm);
}
.wordmark {
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: clamp(1.35rem, 3vw, 1.85rem);
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}
.wordmark span { color: var(--brand); }
.product-lockup {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: .8125rem;
  line-height: 1;
}
.product-lockup span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border-radius: 4px;
  background: linear-gradient(135deg, var(--tile-jade), var(--tile-coral) 48%, var(--tile-orchid));
  box-shadow: inset 0 0 0 1px rgba(26, 23, 18, .16);
}
.brandbar p { margin: 0; color: var(--ink-muted); font-size: .875rem; line-height: 1.2; white-space: nowrap; }

.hud {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}
.hud div {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.label {
  display: block;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: lowercase;
}
.hud strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: clamp(1rem, 1.8vw, 1.45rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-wrap {
  position: relative;
  width: min(100%, calc((100svh - 250px) * 15 / 16));
  max-width: 860px;
  justify-self: center;
  overflow: hidden;
  aspect-ratio: 15 / 16;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: #08110f;
  box-shadow: var(--shadow-md), inset 0 0 0 1px rgba(255,255,255,.05);
}
.stage-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(66, 217, 245, .18), inset 0 -60px 120px rgba(51,176,111,.10);
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #08110f;
  touch-action: none;
  user-select: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 13px;
  padding: 24px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(251,249,245,.92), rgba(251,249,245,.72)),
    radial-gradient(circle at 50% 34%, rgba(247,201,72,.22), transparent 20rem),
    radial-gradient(circle at 42% 70%, rgba(51,176,111,.20), transparent 18rem);
}
.overlay.hidden { display: none; }
.overlay-tile {
  width: 68px;
  height: 68px;
  border: 1px solid rgba(26,23,18,.12);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 44% 34%, #fff1c7 0 9%, transparent 10%),
    radial-gradient(circle at 42% 45%, #f05a5a 0 34%, transparent 35%),
    radial-gradient(ellipse at 50% 80%, #33b06f 0 25%, transparent 26%),
    #08110f;
  box-shadow: var(--shadow-md);
}
.overlay h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(2.4rem, 8vw, 5rem);
  font-weight: 520;
  line-height: .92;
}
.overlay p { max-width: 540px; margin: 0; color: var(--ink-muted); font-size: 1rem; line-height: 1.45; }
.overlay button {
  min-width: 132px;
  border-color: var(--brand-strong);
  background: var(--brand-strong);
  color: #fff;
}
.keys {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  max-width: 560px;
}
.keys span {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.65);
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: .72rem;
}

.controls {
  display: grid;
  grid-template-columns: auto repeat(3, minmax(88px, 1fr));
  align-items: center;
  gap: 10px;
  width: min(860px, 100%);
  justify-self: center;
  touch-action: none;
}
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(2, 48px);
  gap: 8px;
}
.pad { min-width: 48px; min-height: 48px; padding: 0; font-size: 1.2rem; }
.pad.up { grid-column: 2; grid-row: 1; }
.pad.left { grid-column: 1; grid-row: 2; }
.pad.down { grid-column: 2; grid-row: 2; }
.pad.right { grid-column: 3; grid-row: 2; }
.action { min-height: 56px; text-transform: lowercase; }
.action.fire { background: #12352e; color: #fff1c7; border-color: #2c6d5d; }
.action.auto-fire { background: #ffffff; color: #12352e; border-color: #33b06f; }
.action.auto-fire[aria-pressed="true"] { background: #33b06f; color: #08110f; border-color: #207d4d; box-shadow: 0 0 0 2px rgba(51, 176, 111, 0.18), 0 10px 26px rgba(51, 176, 111, 0.22); }
.action.focus { background: #f7c948; border-color: #c59722; color: #1a1712; }

.ad-slot {
  min-height: 92px;
  display: grid;
  align-items: center;
  padding: 8px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface-sunken) 72%, transparent);
}
.ad-slot p { margin: 0 0 6px; color: var(--ink-muted); font-size: .72rem; font-family: var(--font-mono); text-transform: uppercase; }

.game-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--ink-muted);
  font-size: .84rem;
  padding: 4px 2px;
}
.game-footer nav { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.game-footer a { text-decoration: none; }
.game-footer button { min-height: 34px; padding: 0 10px; border-radius: var(--radius-sm); font-size: .78rem; color: var(--ink-muted); }

.cookie-banner {
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 10;
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}
.cookie-banner[hidden] { display: none; }
.cookie-banner p { margin: 0; color: var(--ink-muted); font-size: .9rem; line-height: 1.4; }
.cookie-banner div { display: flex; gap: 8px; }
.cookie-banner button { padding: 0 14px; }
.cookie-banner button:last-child { border-color: var(--brand-strong); background: var(--brand-strong); color: #fff; }

@media (max-width: 720px) {
  .shell { width: min(100% - 20px, 540px); padding-top: 10px; gap: 9px; }
  .brandbar { grid-template-columns: 1fr; gap: 5px; min-height: 0; border-radius: var(--radius-md); }
  .brandbar p { display: none; }
  .hud { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .hud div { padding: 8px 9px; }
  .hud div:nth-child(5) { grid-column: span 2; }
  .stage-wrap {
    width: min(100%, calc((70svh) * 15 / 16));
    max-height: min(70svh, 760px);
    border-radius: var(--radius-md);
  }
  .controls { grid-template-columns: repeat(3, 1fr); gap: 8px; padding-bottom: env(safe-area-inset-bottom); }
  .dpad { grid-column: 1 / -1; justify-self: center; }
  .action { min-height: 52px; }
  .ad-slot { min-height: 72px; }
  .game-footer { align-items: flex-start; flex-direction: column; }
  .cookie-banner { flex-direction: column; align-items: stretch; }
  .cookie-banner div { justify-content: flex-end; }
}

@media (max-width: 360px) {
  .shell { width: calc(100% - 12px); }
  .hud { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hud div:nth-child(5) { grid-column: span 2; }
  .overlay { padding: 14px; }
  .overlay p { font-size: .9rem; }
  .keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; scroll-behavior: auto !important; }
}

.game-guide {
  display: grid;
  gap: 12px;
  margin-top: 22px;
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  box-shadow: var(--shadow-sm);
  color: var(--ink-muted);
  line-height: 1.65;
}

.game-guide h2 {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: clamp(1.35rem, 3vw, 2rem);
  font-weight: 500;
  letter-spacing: 0;
}

.game-guide p {
  margin: 0;
}

.game-guide table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
}

.game-guide th,
.game-guide td {
  padding: 10px 12px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.game-guide th {
  color: var(--ink);
  background: color-mix(in srgb, var(--surface-sunken) 78%, transparent);
}

.game-guide details {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-sunken) 70%, transparent);
}

.game-guide summary {
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
}

.game-guide details p {
  margin-top: 8px;
}

.ad-slot-bottom {
  margin-top: 22px;
}

@media (max-width: 720px) {
  .game-guide {
    margin-top: 18px;
    padding: 16px;
  }

  .game-guide table,
  .game-guide thead,
  .game-guide tbody,
  .game-guide tr,
  .game-guide th,
  .game-guide td {
    display: block;
  }

  .game-guide th {
    display: none;
  }

  .game-guide td {
    border-top: 0;
  }

  .game-guide td:first-child {
    border-top: 1px solid var(--line);
    color: var(--ink);
    font-weight: 700;
  }
}

/* Responsive fit pass: mushrooms has a tall playfield, so cap it by remaining viewport. */
.game-footer button {
  min-height: 34px;
  padding: 0 8px;
}

@media (min-width: 721px) and (max-width: 900px) {
  .stage-wrap {
    width: min(100%, calc((100svh - 360px) * 15 / 16));
    max-height: calc(100svh - 360px);
  }
}

@media (max-width: 720px) and (orientation: portrait) {
  .shell {
    width: min(100% - 12px, 540px);
    min-height: 100svh;
    gap: 6px;
  }

  .stage-wrap {
    width: min(100%, calc((100svh - 355px) * 15 / 16));
    max-height: calc(100svh - 355px);
  }

  .controls {
    gap: 6px;
  }

  .action {
    min-height: 44px;
    font-size: 0.82rem;
  }

  .dpad {
    grid-template-columns: repeat(3, 42px);
    grid-template-rows: repeat(2, 42px);
    gap: 6px;
  }

  .pad {
    min-width: 42px;
    min-height: 42px;
  }
}

@media (max-height: 480px) and (orientation: landscape) {
  .shell {
    width: min(100vw - 10px, 980px);
    min-height: 100svh;
    padding: 4px 0 calc(4px + env(safe-area-inset-bottom));
    gap: 4px;
  }

  .brandbar {
    min-height: 34px;
    padding: 5px 8px;
    border-radius: var(--radius-md);
  }

  .brandbar p {
    display: none;
  }

  .hud {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
  }

  .hud div,
  .hud div:nth-child(5) {
    grid-column: auto;
    padding: 5px 7px;
  }

  .stage-wrap {
    width: min(100%, calc((100svh - 150px) * 15 / 16));
    max-height: calc(100svh - 150px);
  }

  .controls {
    grid-template-columns: auto repeat(3, minmax(72px, 1fr));
    gap: 5px;
  }

  .dpad {
    grid-template-columns: repeat(3, 36px);
    grid-template-rows: repeat(2, 36px);
    gap: 4px;
  }

  .pad {
    min-width: 36px;
    min-height: 36px;
  }

  .action {
    min-height: 38px;
    font-size: 0.78rem;
  }
}

/* Responsive fit pass follow-up: remove narrow overflow and shrink very short portrait screens. */
@media (max-width: 720px) {
  .shell {
    width: calc(100vw - 12px);
  }
}

@media (max-width: 420px) and (max-height: 700px) and (orientation: portrait) {
  .stage-wrap {
    width: min(100%, calc((100svh - 410px) * 15 / 16));
    max-height: calc(100svh - 410px);
  }
}

@media (max-height: 480px) and (orientation: landscape) {
  .stage-wrap {
    width: min(100%, calc((100svh - 180px) * 15 / 16));
    max-height: calc(100svh - 180px);
  }
}

/* Responsive fit pass follow-up: allow grid children to shrink inside narrow shells. */
.shell > * {
  min-width: 0;
  max-width: 100%;
}

.brandbar,
.hud,
.controls,
.game-guide,
.ad-slot,
.game-footer {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.related-games {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding: clamp(16px, 3vw, 24px);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface-sunken) 72%, transparent);
  box-shadow: var(--shadow-sm);
}

.related-games h2 {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: clamp(1.2rem, 2.6vw, 1.7rem);
  font-weight: 500;
  letter-spacing: 0;
}

.related-games nav {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.related-games a {
  display: grid;
  gap: 5px;
  min-width: 0;
  min-height: 72px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  color: var(--ink-muted);
  text-decoration: none;
}

.related-games a:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.related-games strong,
.related-games span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.related-games strong {
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.15;
}

.related-games span {
  font-size: 0.78rem;
  line-height: 1.35;
}

@media (max-width: 820px) {
  .related-games nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  .related-games {
    padding: 14px;
  }

  .related-games nav {
    grid-template-columns: 1fr;
  }

  .related-games a {
    min-height: 0;
  }
}
