:root {
  --paper: #FBF9F5;
  --surface: #FFFFFF;
  --surface-sunken: #F3EFE7;
  --ink: #1A1712;
  --ink-muted: #6B6459;
  --ink-faint: #9A9186;
  --line: #E7E0D4;
  --line-strong: #D8CFBE;
  --brand: #B7833A;
  --brand-strong: #8E6326;
  --brand-soft: #F0E4CE;
  --brand-contrast: #FFFFFF;
  --tile-teal: #2F8F83;
  --tile-teal-soft: #D9EDEA;
  --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: 22px;
  --shadow-sm: 0 1px 2px rgba(26, 23, 18, .05), 0 1px 1px rgba(26, 23, 18, .04);
  --shadow-md: 0 4px 16px rgba(26, 23, 18, .07), 0 2px 4px rgba(26, 23, 18, .04);
  --ease: cubic-bezier(.2, .7, .2, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 82% 0%, rgba(217, 237, 234, 0.6), transparent 26rem),
    linear-gradient(180deg, var(--paper), #F7F1E8 100%);
  color: var(--ink);
  font-family: var(--font-sans);
}

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

button {
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font: 700 0.95rem/1 var(--font-sans);
  transition: transform 160ms var(--ease), box-shadow 160ms var(--ease), border-color 160ms var(--ease), background 160ms var(--ease);
}

button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  border-color: var(--brand);
}

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

.shell {
  width: min(760px, calc(100vw - clamp(12px, 3vw, 32px)));
  min-height: 100vh;
  margin: 0 auto;
  padding: 10px 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 8px;
}

.brandbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  min-height: 46px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  box-shadow: var(--shadow-sm);
}

.wordmark {
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: clamp(1.1rem, 2vw, 1.45rem);
  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: 0.74rem;
  line-height: 1;
}

.chip {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border-radius: 4px;
  background: var(--tile-teal);
  box-shadow: inset 0 0 0 1px rgba(26, 23, 18, 0.16);
}

.brandbar p {
  margin: 0;
  max-width: 400px;
  color: var(--ink-muted);
  font-size: 0.78rem;
  line-height: 1.35;
  white-space: nowrap;
}

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

.hud div {
  min-width: 0;
  padding: 8px 10px;
  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: 0.68rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: lowercase;
}

.hud strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: clamp(1rem, 1.5vw, 1.25rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.stage-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: #050506;
  box-shadow: 0 18px 48px rgba(26, 23, 18, 0.16), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.stage-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(90, 200, 220, 0.2), inset 0 0 60px rgba(40, 140, 200, 0.1);
  z-index: 1;
}

canvas {
  display: block;
  width: 100%;
  height: min(62vh, 620px);
  min-height: 340px;
  background: #050506;
  touch-action: none;
  aspect-ratio: 1008 / 1116;
  margin: 0 auto;
  object-fit: contain;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 16px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(251, 249, 245, 0.94), rgba(251, 249, 245, 0.78)),
    radial-gradient(circle at 50% 28%, rgba(47, 143, 131, 0.18), transparent 22rem);
}

.overlay.hidden {
  display: none;
}

.overlay-tile {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(38, 99, 91, 0.28);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 30% 24%, rgba(255, 214, 92, 0.95), transparent 30%),
    radial-gradient(circle at 72% 34%, rgba(90, 200, 150, 0.9), transparent 32%),
    radial-gradient(circle at 42% 76%, rgba(45, 110, 100, 0.85), transparent 32%),
    #10231f;
  box-shadow: var(--shadow-md);
}

.overlay h1 {
  max-width: 900px;
  margin: 0;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: clamp(2.2rem, 7vw, 4rem);
  font-weight: 500;
  line-height: 0.94;
  letter-spacing: 0;
}

.overlay p {
  max-width: 640px;
  margin: 0;
  color: var(--ink-muted);
  font-size: clamp(0.9rem, 1.7vw, 1.02rem);
  line-height: 1.55;
}

.overlay button {
  min-width: 150px;
  padding: 0 24px;
  border: 0;
  background: var(--brand-strong);
  color: var(--brand-contrast);
  box-shadow: var(--shadow-sm);
  text-transform: lowercase;
}

.keys {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 760px;
}

.keys span {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1;
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-areas:
    ".    up    ."
    "left down right";
  gap: 6px;
}

.controls button {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-transform: lowercase;
  border-color: color-mix(in srgb, var(--tile-teal) 48%, var(--line-strong));
  background: var(--tile-teal-soft);
  color: var(--tile-teal);
}

#upButton { grid-area: up; }
#leftButton { grid-area: left; }
#downButton { grid-area: down; }
#rightButton { grid-area: right; }

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.001ms !important;
  }
}

.ad-slot {
  min-height: 82px;
  overflow: hidden;
  padding: 8px 10px;
  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);
}

.ad-slot p {
  margin: 0 0 4px;
  padding: 0;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 1;
  text-transform: uppercase;
}

.ad-slot .adsbygoogle {
  min-height: 64px;
}

.game-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 2px 2px;
  color: var(--ink-muted);
  font-size: 0.75rem;
}

.game-footer nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.game-footer a,
.game-footer button {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--ink-muted);
  font: inherit;
  text-decoration: none;
}

.game-footer a:hover,
.game-footer button:hover {
  color: var(--ink);
  transform: none;
  box-shadow: none;
}

.cookie-banner {
  position: fixed;
  inset: auto 16px 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 680px;
  margin: 0 auto;
  padding: 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: 0 12px 40px rgba(26, 23, 18, .16), 0 4px 10px rgba(26, 23, 18, .08);
}

.cookie-banner[hidden] {
  display: none;
}

.cookie-banner p {
  flex: 1;
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.cookie-banner a {
  color: var(--brand-strong);
}

.cookie-banner div {
  display: flex;
  gap: 8px;
}

.cookie-banner button {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.78rem;
}

.cookie-banner button:last-child {
  border-color: var(--brand-strong);
  background: var(--brand-strong);
  color: var(--brand-contrast);
}

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 10px, 760px);
    padding: 6px 0;
    gap: 5px;
  }

  .brandbar {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 6px;
    min-height: 42px;
  }

  .brandbar p {
    display: none;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hud div {
    padding: 7px 8px;
  }

  canvas {
    height: 58vh;
    min-height: 320px;
  }

  .overlay {
    padding: 16px;
  }

  .ad-slot {
    min-height: 76px;
    padding: 6px 8px;
  }

  .ad-slot .adsbygoogle {
    min-height: 58px;
  }

  .game-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .game-footer nav {
    justify-content: flex-start;
  }

  .cookie-banner {
    flex-direction: column;
    align-items: stretch;
  }

  .cookie-banner div {
    justify-content: flex-end;
  }
}

@media (max-height: 760px) {
  .shell {
    padding-top: 6px;
    padding-bottom: 6px;
    gap: 5px;
  }

  .brandbar {
    min-height: 40px;
  }

  .ad-slot {
    min-height: 70px;
  }

  .ad-slot .adsbygoogle {
    min-height: 52px;
  }

  canvas {
    height: min(54vh, 540px);
    min-height: 300px;
  }
}

.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: keep playable canvas and controls in the first viewport on phones/tablets. */
.game-footer button {
  min-height: 34px;
  padding: 0 8px;
}

@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 {
    gap: 4px;
  }

  .hud div {
    padding: 5px 7px;
  }

  .label {
    font-size: 0.62rem;
  }

  .hud strong {
    font-size: 0.95rem;
  }

  canvas {
    height: clamp(170px, calc(100svh - 150px), 270px);
    min-height: 0;
  }

  .controls,
  .move-slider {
    gap: 5px;
  }

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

  .slider-track {
    height: 38px;
  }

  .slider-thumb {
    width: 32px;
    height: 32px;
    margin: -16px 0 0 -16px;
  }
}

@media (max-width: 420px) and (orientation: portrait) {
  .shell {
    min-height: 100svh;
  }

  canvas {
    height: clamp(240px, calc(100svh - 285px), 430px);
    min-height: 0;
  }

  .controls button {
    min-height: 42px;
    font-size: 0.8rem;
  }
}

/* Responsive fit pass follow-up: tighter landscape cap for short phones. */
@media (max-height: 480px) and (orientation: landscape) {
  canvas {
    height: clamp(160px, calc(100svh - 180px), 250px);
  }
}

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