:root {
  --paper: #f7f2e8;
  --surface: #fffdf8;
  --surface-soft: #f0eadc;
  --ink: #1b1711;
  --muted: #686155;
  --line: rgba(61, 50, 35, 0.18);
  --soil: #130f0d;
  --soil-deep: #090806;
  --moss: #326a46;
  --lichen: #97a889;
  --amber: #e2a83d;
  --rust: #b94c38;
  --cream: #f8e9c9;
  --violet: #8469b3;
  --bluecap: #6fb7c9;
  --brand: #b7833a;
  --brand-dark: #7a5423;
  --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: 8px;
  --shadow: 0 14px 38px rgba(27, 20, 12, 0.16);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: var(--font-sans);
  background:
    linear-gradient(rgba(255,255,255,.62), rgba(255,255,255,.46)),
    radial-gradient(circle at 16% 8%, rgba(151, 168, 137, .42), transparent 22rem),
    radial-gradient(circle at 86% 12%, rgba(132, 105, 179, .18), transparent 20rem),
    linear-gradient(180deg, #fbf7ee, #e7deca 58%, #d8cbb3);
}

button, a { -webkit-tap-highlight-color: transparent; }
button {
  min-height: 44px;
  border: 1px solid rgba(75, 57, 31, .28);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fffaf0, #eadcc1);
  color: var(--ink);
  cursor: pointer;
  font: 800 .9rem/1 var(--font-sans);
  text-transform: lowercase;
  box-shadow: 0 6px 16px rgba(40, 30, 16, .12), inset 0 1px 0 rgba(255,255,255,.75);
}
button:hover { transform: translateY(-1px); border-color: var(--brand); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }

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

.brandbar, .panel, .game-guide, .related-games, .game-footer, .ad-slot {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, .92);
  box-shadow: var(--shadow);
}

.brandbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  min-height: 56px;
  padding: 10px 12px;
}
.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(--muted);
  font-family: var(--font-mono);
  font-size: .8125rem;
}
.chip {
  width: 13px;
  height: 13px;
  border-radius: 4px;
  background:
    radial-gradient(circle at 32% 28%, #fff4d0 0 12%, transparent 13%),
    radial-gradient(circle at 62% 62%, #6fb7c9 0 13%, transparent 14%),
    linear-gradient(135deg, var(--rust), var(--amber) 52%, var(--moss));
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.18);
}
.brandbar p { margin: 0; color: var(--muted); font-size: .875rem; white-space: nowrap; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(132px, 180px) minmax(320px, 1fr) minmax(132px, 180px);
  gap: 12px;
  align-items: start;
}
.panel {
  display: grid;
  gap: 8px;
  padding: 10px;
}
.panel div {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid rgba(54, 42, 25, .16);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fffaf1, #f1e8d7);
}
.label {
  display: block;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: .72rem;
  font-weight: 700;
  line-height: 1.1;
  text-transform: lowercase;
}
.panel strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--ink);
  font-size: clamp(1rem, 1.5vw, 1.35rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-overflow: ellipsis;
}
.panel canvas {
  width: 100%;
  height: auto;
  min-height: 0;
  border-radius: 6px;
  background: #17100d;
}
.panel-button { width: 100%; }

.stage-wrap {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(46, 35, 19, .48);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 50% 16%, rgba(235, 214, 168, .16), transparent 16rem),
    radial-gradient(circle at 25% 86%, rgba(50, 106, 70, .22), transparent 18rem),
    linear-gradient(180deg, #201712, #0e0b09 62%, #070605);
  box-shadow: 0 22px 70px rgba(18, 12, 6, .45), inset 0 0 0 1px rgba(255,255,255,.06);
}
.stage-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  box-shadow: inset 0 0 0 10px rgba(21, 15, 10, .7), inset 0 0 70px rgba(248, 233, 201, .08);
}
#game {
  display: block;
  width: min(100%, 540px, 37.4svh);
  height: auto;
  aspect-ratio: 540 / 1040;
  margin: 0 auto;
  background: #0d0907;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 10px;
  z-index: 3;
  display: grid;
  place-content: center;
  gap: 12px;
  padding: 18px;
  text-align: center;
  background: radial-gradient(circle at 50% 38%, rgba(9, 7, 5, .66), rgba(9, 7, 5, .9));
  color: #fff8e8;
}
.overlay[hidden] { display: none; }
.overlay h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(2.2rem, 8vw, 5rem);
  font-weight: 650;
  line-height: .92;
}
.overlay p { max-width: 38rem; margin: 0 auto; color: #eadfc8; line-height: 1.45; }
.keys { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; max-width: 38rem; }
.keys span {
  padding: 6px 8px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  color: #f5e9cf;
  font-family: var(--font-mono);
  font-size: .72rem;
}
#startButton { justify-self: center; min-width: 132px; }

.controls {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
}
.controls button { min-width: 0; padding-inline: 6px; }

.game-guide, .related-games, .game-footer, .ad-slot { padding: 14px; }
.game-guide h2, .related-games h2 { margin: 0 0 8px; font-size: 1rem; }
.game-guide p { margin: 0 0 8px; color: var(--muted); line-height: 1.5; }
.related-games nav { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.related-games a {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
  background: #fffaf1;
}
.related-games span { color: var(--muted); font-size: .82rem; line-height: 1.3; }
.game-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: .86rem;
}
.game-footer nav { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.game-footer a { color: var(--brand-dark); }
.game-footer button { min-height: 34px; padding: 0 10px; font-size: .78rem; }
@media (max-width: 880px) {
  .brandbar { grid-template-columns: 1fr; gap: 6px; }
  .brandbar p { white-space: normal; }
  .game-layout { grid-template-columns: 1fr; }
  .panel { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .panel-right { display: none; }
  #game { width: min(100%, 33.2svh); height: auto; }
  .controls { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .related-games nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 430px) {
  .shell { width: calc(100vw - 14px); padding-top: 7px; gap: 8px; }
  .panel { grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 6px; }
  .panel-left .panel-button { display: none; }
  .panel strong { font-size: 1rem; }
  #game { width: min(100%, 28svh); height: auto; }
  .controls { gap: 6px; }
  .controls button { min-height: 48px; font-size: .8rem; }
  .game-guide, .related-games { display: none; }
  .game-footer { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .shell { width: calc(100vw - 12px); padding: 6px 0; gap: 6px; }
  .brandbar, .game-guide, .related-games, .game-footer, .ad-slot { display: none; }
  .game-layout { grid-template-columns: 118px minmax(280px, 1fr); gap: 6px; }
  .panel { grid-template-columns: 1fr; gap: 4px; padding: 6px; }
  .panel div { padding: 5px 7px; }
  .panel strong { margin-top: 2px; font-size: .86rem; }
  .panel-left .panel-button, .panel-right { display: none; }
  #game { width: min(100%, 32.2svh); height: auto; }
  .controls { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
  .controls button { min-height: 40px; font-size: .72rem; }
}

.next-preview canvas {
  aspect-ratio: 1 / 1;
}

@media (max-width: 880px) {
  .panel-right {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .panel-right div:not(.next-preview) {
    display: none;
  }
  .panel-right .next-preview {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: auto 96px;
    align-items: center;
    gap: 10px;
  }
  .panel-right .next-preview canvas {
    width: 96px;
    justify-self: end;
  }
}

@media (max-width: 430px) {
  .panel-right .next-preview {
    grid-template-columns: auto 72px;
  }
  .panel-right .next-preview canvas {
    width: 72px;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .panel-right {
    display: none;
  }
}

@media (max-width: 880px) {
  .game-layout {
    position: relative;
  }
  .panel-right {
    position: absolute;
    top: 86px;
    right: 8px;
    z-index: 4;
    display: block;
    width: 104px;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    pointer-events: none;
  }
  .panel-right div:not(.next-preview) {
    display: none;
  }
  .panel-right .next-preview {
    display: grid;
    grid-template-columns: 1fr;
    gap: 3px;
    padding: 6px;
    border: 1px solid rgba(255, 246, 214, .35);
    background: rgba(13, 9, 7, .78);
    backdrop-filter: blur(8px);
  }
  .panel-right .next-preview .label {
    color: #f8e7bf;
  }
  .panel-right .next-preview canvas {
    width: 88px;
    justify-self: center;
  }
}

@media (max-width: 430px) {
  .panel-right {
    top: 78px;
    right: 6px;
    width: 78px;
  }
  .panel-right .next-preview {
    padding: 4px;
  }
  .panel-right .next-preview canvas {
    width: 68px;
  }
}
