:root {
  color-scheme: dark;
  --bg: #101426;
  --panel: #191f35;
  --panel-soft: #1d2540;
  --paper: #f4f5fa;
  --muted: #a6adc4;
  --mint: #baf279;
  --violet: #b8a0ff;
  --line: #ffffff18;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--paper);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(ellipse at 13% 8%, #5f4d9b50, transparent 34rem),
    radial-gradient(ellipse at 88% 45%, #196a7850, transparent 35rem),
    linear-gradient(145deg, #101426, #111a2b 64%, #101426);
}

.site-shell { width: min(1040px, calc(100% - 36px)); margin: 0 auto; padding: 22px 0 28px; }
.topbar { height: 52px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-size: 13px; font-weight: 800; letter-spacing: .15em; }
.brand-mark { width: 29px; height: 29px; display: grid; place-items: center; border-radius: 9px; background: var(--mint); color: #20251a; font-family: Georgia, serif; font-size: 18px; letter-spacing: 0; }
.brand-dot { color: var(--mint); }
.back-link { color: #c2c8d8; text-decoration: none; font-size: 12px; transition: color .2s ease; }
.back-link:hover { color: var(--mint); }
.intro { padding: 33px 0 23px; }
.eyebrow, .panel-kicker, .screen-kicker { color: #abb2c9; font-size: 10px; letter-spacing: .17em; font-weight: 700; }
.eyebrow { display: flex; align-items: center; gap: 10px; }
.eyebrow i { width: 5px; height: 5px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 10px var(--mint); }
.intro h1 { margin: 9px 0 5px; font-size: clamp(28px, 5vw, 39px); line-height: 1.16; letter-spacing: -.055em; }
.intro p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }

#game-container {
  display: grid;
  grid-template-columns: minmax(250px, 390px) minmax(280px, 1fr);
  align-items: start;
  gap: 25px;
  padding: 22px;
  border: 1px solid #ffffff1b;
  border-radius: 24px;
  background: linear-gradient(135deg, #1a2037e8, #171d31e8);
  box-shadow: 0 28px 90px #04071270, inset 0 1px #ffffff0c;
  backdrop-filter: blur(16px);
}
#game-area { min-width: 0; width: 100%; }
.canvas-shell { position: relative; width: min(100%, 390px); margin: 0 auto; overflow: hidden; border: 1px solid #7c88aa54; border-radius: 15px; background: #080d18; box-shadow: 0 18px 48px #06091588; }
#game-canvas { display: block; width: 100%; height: auto; aspect-ratio: 1 / 2; background: #080d18; }
#game-overlay { position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; padding: 16px; background: #080d18c7; backdrop-filter: blur(7px); }
#game-overlay.hidden { display: none; }
.screen { width: min(100%, 300px); padding: 25px 21px; text-align: center; border: 1px solid #ffffff22; border-radius: 20px; background: linear-gradient(155deg, #252d4bfa, #191f35f7); box-shadow: 0 20px 55px #050814a8; }
.screen-kicker { color: var(--mint); }
.screen h2 { margin: 10px 0 8px; font-size: clamp(21px, 4vw, 29px); letter-spacing: -.04em; }
.screen p { margin: 0 0 19px; color: #b8bfd1; font-size: 12px; line-height: 1.7; }
.screen p strong { color: #fff; font-size: 19px; }
.screen button { width: 100%; min-height: 48px; padding: 11px 16px; border: 0; border-radius: 13px; color: #202a1c; background: linear-gradient(110deg, #c8f58b, #a6e86f); font: inherit; font-size: 13px; font-weight: 800; cursor: pointer; transition: transform .18s, filter .18s; }
.screen button:hover { transform: translateY(-2px); filter: brightness(1.04); }
.screen button span { margin-left: 7px; font-size: 16px; }
#high-score { margin-top: 16px; color: #aeb6cc; font-size: 11px; }
#high-score strong { margin-left: 5px; color: #fff; font-size: 15px; }
.hidden { display: none !important; }

#touch-controls { display: none; }
#game-info { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; min-width: 0; }
.info-panel { min-width: 0; padding: 17px; border: 1px solid #ffffff13; border-radius: 17px; background: linear-gradient(145deg, #242b46, #1d243d); box-shadow: inset 0 1px #ffffff08; }
.next-panel { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; padding: 16px 19px; }
.info-panel h2 { margin: 5px 0 0; font-size: 15px; letter-spacing: -.02em; }
#next-canvas { display: block; width: 94px; height: 94px; border: 1px solid #ffffff13; border-radius: 13px; background: #0b1020; }
.stats-panel { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 15px 10px; }
.stat { min-width: 0; display: grid; gap: 8px; justify-items: center; padding: 2px 4px; }
.stat + .stat { border-left: 1px solid var(--line); }
.label { color: #aab2ca; font-size: 10px; }
.stat strong { color: #fff; font-variant-numeric: tabular-nums; font-size: clamp(17px, 2.8vw, 24px); }
#controls { grid-column: 1 / -1; }
#controls h2 { margin-bottom: 15px; }
.control-list { display: grid; gap: 7px; }
.control-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: #ccd1df; font-size: 11px; }
.control-item span:first-child { min-width: 66px; padding: 6px 8px; border: 1px solid #ffffff16; border-radius: 7px; color: #f1f2fa; background: #11172a; text-align: center; font-weight: 700; }
.record-note { grid-column: 1 / -1; margin: 1px 0 0; color: #929bb5; font-size: 10px; text-align: center; }
.mobile-hint { display: none; }
.footer { min-height: 57px; display: flex; align-items: end; justify-content: space-between; gap: 12px; color: #9299ad; font-size: 10px; letter-spacing: .05em; }
.footer b { margin-left: 7px; color: var(--mint); font-size: 14px; }

@media (max-width: 760px), (pointer: coarse) {
  .site-shell { width: min(560px, calc(100% - 28px)); padding-top: 14px; }
  #game-container { grid-template-columns: minmax(0, 1fr); gap: 17px; padding: 14px; border-radius: 20px; }
  .canvas-shell { width: min(100%, 370px); }
  #touch-controls { display: grid; gap: 8px; width: min(100%, 370px); margin: 11px auto 0; user-select: none; -webkit-user-select: none; }
  .touch-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .touch-row button { min-width: 0; min-height: 52px; border: 1px solid #ffffff1c; border-radius: 13px; color: #f4f5fa; background: linear-gradient(145deg, #2a3352, #202741); font: inherit; font-size: 16px; font-weight: 750; box-shadow: inset 0 1px #ffffff0a, 0 5px 12px #05081445; touch-action: none; }
  .touch-row button:active { color: #1b2518; background: var(--mint); transform: translateY(1px); }
  .touch-row-secondary button { min-height: 44px; font-size: 11px; }
  .touch-row-secondary button:nth-child(2) { color: #242039; background: linear-gradient(120deg, #c5b0ff, #a48af0); }
  .mobile-hint { display: block; margin: 9px 0 0; color: #98a1ba; font-size: 10px; text-align: center; }
  #game-info { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .next-panel { grid-column: 1 / -1; }
  #controls { grid-column: 1 / -1; }
  .footer { align-items: center; margin-top: 6px; }
}

@media (max-width: 360px) {
  .site-shell { width: calc(100% - 20px); }
  #game-container { padding: 10px; }
  .screen { padding: 19px 15px; }
  .screen p { font-size: 11px; }
  #game-info { gap: 8px; }
  .info-panel { padding: 13px; }
  .stats-panel { padding: 13px 6px; }
  .label { font-size: 9px; }
}

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

/* Reserve room for the header, score strip and both touch rows before sizing
   the 1:2 board. svh also leaves room for a mobile browser's visible toolbar. */
@media (max-width: 760px), (pointer: coarse) {
  .site-shell { width: min(560px, calc(100% - 16px)); padding: 4px 0 max(6px, env(safe-area-inset-bottom)); }
  .topbar { height: 38px; }
  .intro { padding: 7px 0; }
  .intro h1 { margin: 0; font-size: 22px; line-height: 26px; }
  .intro .eyebrow, .intro p, .footer, .mobile-hint, #controls, .record-note { display: none; }
  #game-container { padding: 8px; gap: 7px; border-radius: 15px; }
  #game-info { order: -1; grid-template-columns: minmax(80px, .7fr) minmax(0, 1.5fr); gap: 6px; }
  .next-panel, .stats-panel { grid-column: auto; padding: 4px 6px; border-radius: 10px; }
  .next-panel { gap: 3px; }
  .next-panel .panel-kicker { display: none; }
  .next-panel h2 { margin: 0; font-size: 11px; white-space: nowrap; }
  #next-canvas { width: 38px; height: 38px; border-radius: 6px; }
  .stats-panel { gap: 0; }
  .stat { gap: 2px; padding: 0 2px; align-content: center; }
  .stat strong { font-size: 16px; overflow-wrap: anywhere; }
  .label { font-size: 9px; white-space: nowrap; }
  .canvas-shell { width: min(100%, 300px, calc((100vh - 258px - env(safe-area-inset-bottom)) / 2)); width: min(100%, 300px, calc((100svh - 258px - env(safe-area-inset-bottom)) / 2)); border-radius: 9px; }
  #touch-controls { margin-top: 6px; gap: 6px; width: min(100%, 370px); }
  .touch-row { gap: 6px; }
  .touch-row button { min-height: 44px; border-radius: 10px; }
  #game-overlay { padding: 6px; }
  .screen { padding: 12px 7px; border-radius: 12px; }
  .screen-kicker { font-size: 9px; letter-spacing: .05em; }
  .screen h2 { font-size: 18px; margin: 6px 0; }
  .screen p { font-size: 11px; margin-bottom: 10px; }
  .screen button { min-height: 44px; padding: 8px 4px; }
  #high-score { margin-top: 8px; }
}

/* Short landscape screens place controls beside the board. */
@media (orientation: landscape) and (max-height: 540px) and (pointer: coarse) {
  .site-shell { width: min(900px, calc(100% - 16px)); }
  .intro { display: none; }
  #game-container { grid-template-columns: minmax(0, 1fr) 140px; gap: 10px; }
  #game-info { order: 0; grid-template-columns: 1fr; }
  #game-area { display: grid; grid-template-columns: auto minmax(150px, 1fr); align-items: center; gap: 12px; }
  .canvas-shell { width: min(230px, calc((100vh - 76px - env(safe-area-inset-bottom)) / 2)); width: min(230px, calc((100svh - 76px - env(safe-area-inset-bottom)) / 2)); }
  #touch-controls { margin: 0; }
  .screen p, .screen-kicker { display: none; }
}
