:root {
  color-scheme: dark;
  --night: #121815;
  --panel: #1a221d;
  --panel-raised: #202a24;
  --edge: #354139;
  --text: #e8eee8;
  --muted: #9aa79d;
  --quiet: #67756b;
  --snake: #8fe36a;
  --snake-head: #d1fa74;
  --fruit: #ffb84d;
  --focus: #f2d393;
  font-family: -apple-system, BlinkMacSystemFont, "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--night); color: var(--text); }
button, select { font: inherit; color: inherit; }
button { border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
button:disabled { cursor: not-allowed; opacity: .45; }
[hidden] { display: none !important; }

.game-app { width: min(1120px, calc(100% - 56px)); margin: 0 auto; }
.game-topbar { min-height: 72px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #29332c; }
.back-link { display: inline-flex; align-items: center; gap: 9px; color: #c0cbc1; text-decoration: none; font-size: 13px; }
.back-link:hover { color: var(--snake-head); }
.back-link span { font-size: 20px; line-height: 1; }
.topbar-mark { display: flex; align-items: center; gap: 4px; color: #78857a; font-size: 11px; }
.topbar-mark i { display: block; width: 5px; height: 12px; border-radius: 3px; background: #53634e; }
.topbar-mark i:nth-child(2) { height: 18px; background: var(--snake); }
.topbar-mark i:nth-child(3) { margin-right: 7px; height: 9px; background: #778574; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(285px, .7fr); gap: clamp(32px, 7vw, 92px); align-items: center; padding: 48px 0 34px; }
.arena { min-width: 0; }
.arena-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 19px; }
.eyebrow { color: var(--snake); font-size: 10px; font-weight: 650; letter-spacing: .12em; }
h1 { margin: 5px 0 0; font-size: clamp(27px, 4vw, 39px); line-height: 1.15; letter-spacing: -.045em; font-weight: 670; }
.play-mode { display: inline-flex; align-items: center; gap: 7px; color: #a3b0a5; font-size: 11px; white-space: nowrap; padding-bottom: 4px; }
.play-mode i { width: 7px; height: 7px; border-radius: 50%; background: var(--snake); box-shadow: 0 0 10px #8fe36a88; }
.mode-stack { display: grid; justify-items: end; gap: 7px; }
.session-mode { padding: 4px 8px; border: 1px solid #43523e; border-radius: 5px; color: var(--snake-head); font-size: 10px; white-space: nowrap; }
.session-mode.ended { border-color: #6b5133; color: var(--fruit); }

.board-frame { width: min(100%, 530px); padding: clamp(12px, 2.7vw, 20px); border: 1px solid #354139; border-radius: 21px; background: linear-gradient(145deg, #1c251f, #161e19); box-shadow: 0 22px 70px #0004, inset 0 1px #ffffff08; }
.board { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: clamp(5px, 1vw, 9px); aspect-ratio: 1; padding: clamp(7px, 1.6vw, 12px); border-radius: 13px; background: #0d130f; box-shadow: inset 0 2px 14px #0008; }
.pixel { position: relative; display: grid; place-items: center; min-width: 0; aspect-ratio: 1; border-radius: 8px; background: #19221c; }
.pixel::before { content: ""; display: block; width: 57%; aspect-ratio: 1; border-radius: 50%; background: #29352d; box-shadow: inset 0 1px 3px #0006; transition: background-color .1s ease, box-shadow .1s ease, transform .1s ease; }
.pixel.snake-body::before { background: var(--snake); box-shadow: 0 0 11px #8fe36a55, inset 0 1px 2px #ffffff62; }
.pixel.snake-head::before { width: 68%; background: var(--snake-head); box-shadow: 0 0 17px #d1fa7499, inset 0 1px 2px #ffffff9c; }
.pixel.fruit::before { width: 53%; background: var(--fruit); box-shadow: 0 0 18px #ffb84daa, inset 0 1px 2px #fff8; }
.pixel.fruit { animation: fruit-pulse 1.5s ease-in-out infinite; }
@keyframes fruit-pulse { 50% { filter: brightness(1.18); } }
.pixel.end-pixel::before { width: 65%; background: var(--fruit); box-shadow: 0 0 17px #ffb84d88, inset 0 1px 2px #fff8; animation: letter-pop .16s ease-out; }
@keyframes letter-pop { from { opacity: .35; transform: scale(.65); } to { opacity: 1; transform: scale(1); } }
.round-status { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 5px 12px; min-height: 29px; padding: 10px 2px 0; color: #9cae98; font-size: 10px; line-height: 1.7; }
.round-status #idle-countdown { color: var(--fruit); font-variant-numeric: tabular-nums; }
.board-frame:has(.board[data-state="over"], .board[data-state="won"]) + .round-status { color: var(--fruit); }

.address-note { display: flex; align-items: center; gap: 9px; margin: 13px 2px 0; color: #718076; font-size: 10px; line-height: 1.6; }
.address-mark { width: 9px; height: 9px; border: 1px solid #68766a; border-radius: 2px; flex: none; }

.console { padding: 20px 0 9px; }
.scoreline { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.score-box { padding: 13px 16px 14px; border: 1px solid #344037; border-radius: 11px; background: #19211c; }
.score-box span { display: block; color: var(--muted); font-size: 10px; }
.score-box strong { display: block; margin-top: 5px; color: var(--snake-head); font-size: 28px; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -.05em; }
.best-score strong { color: #c7d0c5; }
.game-state { min-height: 92px; padding: 23px 1px 13px; }
.state-label { font-size: 18px; font-weight: 620; }
.game-message { min-height: 38px; margin-top: 7px; color: var(--muted); font-size: 12px; line-height: 1.65; }
.game-actions { display: grid; gap: 9px; }
.action-primary, .action-secondary { min-height: 45px; border-radius: 8px; padding: 11px 14px; font-size: 12px; font-weight: 620; transition: background-color .15s ease, border-color .15s ease, color .15s ease; }
.action-primary { background: var(--snake-head); color: #172013; box-shadow: 0 5px 19px #8fe36a1c; }
.action-primary:hover { background: #e0ff9a; }
.secondary-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.action-secondary { border: 1px solid #3a473d; background: #1d2721; color: #d3ddd3; }
.action-secondary:hover:not(:disabled) { border-color: #71816e; background: #242f27; }
.speed-control, .channel-select { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 42px; color: #aab6aa; font-size: 11px; }
.speed-control { margin-top: 7px; }
.speed-control select, .channel-select select { min-width: 112px; border: 1px solid #354139; border-radius: 7px; padding: 7px 10px; background: #18211b; color: #dce5da; font-size: 11px; }

.dali-section { margin-top: 22px; }
.section-rule { height: 1px; margin-bottom: 20px; background: #2a352d; }
.dali-heading-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dali-heading-row .eyebrow { color: #99a991; font-size: 9px; }
.dali-heading-row h2 { margin-top: 4px; font-size: 16px; font-weight: 620; letter-spacing: -.02em; }
.dali-indicator { display: inline-flex; align-items: center; gap: 7px; color: #78857b; font-size: 10px; white-space: nowrap; }
.dali-indicator i { width: 7px; height: 7px; border-radius: 50%; background: #626f66; }
.dali-indicator.connected { color: var(--snake); }
.dali-indicator.connected i { background: var(--snake); box-shadow: 0 0 10px #8fe36a88; }
.channel-select { margin-top: 12px; }
.dali-button { width: 100%; margin-top: 5px; }
.restore-button { width: 100%; margin-top: 8px; padding: 9px; border: 1px solid #775c35; border-radius: 7px; background: #2a2419; color: #ffce7f; font-size: 11px; }
.restore-button:hover:not(:disabled) { background: #352b1c; }
.dali-status { min-height: 37px; margin-top: 9px; color: #88958b; font-size: 10px; line-height: 1.65; }
.dali-status.error { color: #f0a59a; }
.dali-status.success { color: var(--snake); }
.keyboard-hint { margin-top: 15px; color: #738076; font-size: 10px; line-height: 1.8; }
kbd { display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-right: 3px; border: 1px solid #3a473d; border-radius: 4px; background: #1c251f; color: #c5d0c3; font-family: inherit; font-size: 9px; }
.keyboard-hint span { display: block; margin-top: 4px; }

.game-footer { display: flex; justify-content: space-between; gap: 12px; padding: 14px 0 22px; border-top: 1px solid #29332c; color: #66736a; font-size: 10px; }

body.embedded { min-width: 0; min-height: 0; }
body.embedded .game-app { width: min(1120px, calc(100% - 32px)); }
body.embedded .game-topbar, body.embedded .game-footer { display: none; }
body.embedded .game-layout { padding-top: 27px; padding-bottom: 28px; }

.touch-controls { display: none; }
.touch-controls:not([hidden]) { display: grid; grid-template-columns: repeat(3, 58px); grid-template-rows: repeat(2, 50px); justify-content: center; gap: 7px; margin: 18px auto 0; touch-action: manipulation; }
.touch-controls button { border: 1px solid #465448; border-radius: 12px; background: #202b23; color: #dce8d8; font-size: 23px; line-height: 1; }
.touch-controls button:active { background: #344631; color: var(--snake-head); transform: translateY(1px); }
.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; }
@media (max-width: 760px) {
  .game-app { width: min(560px, calc(100% - 32px)); }
  .game-topbar { min-height: 60px; }
  .topbar-mark { font-size: 9px; }
  .game-layout { grid-template-columns: minmax(0, 1fr); gap: 24px; padding: 24px 0 22px; }
  .arena-heading { margin-bottom: 13px; }
  h1 { font-size: 29px; }
  .board-frame { margin: 0 auto; }
  .console { padding: 4px 0 10px; }
  .scoreline { max-width: 400px; }
  .game-state { min-height: 76px; padding-top: 17px; }
  .dali-section { margin-top: 18px; }
  .game-footer { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  body.embedded .game-layout { padding-top: 22px; }
}
@media (max-width: 380px) {
  .game-app { width: calc(100% - 24px); }
  .board-frame { padding: 10px; border-radius: 16px; }
  .board { gap: 4px; padding: 6px; }
  .pixel { border-radius: 6px; }
  .score-box { padding: 11px 13px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
