/* Snake Classic — system theme + layout. Follows prefers-color-scheme live. */
:root {
  color-scheme: light dark;
  --banner-h: 0px;
  --bg: #f4fbf0;
  --surface: #ffffff;
  --ink: #1c2b1a;
  --ink-dim: #5f735c;
  --accent: #16a34a;
  --accent-ink: #ffffff;
  --line: #d8e8d2;
  --good: #16a34a;
  --board-bg: #eaf7e4;
  --shadow: 0 8px 32px rgba(28, 43, 26, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1a12;
    --surface: #1a2b1e;
    --ink: #eef7ea;
    --ink-dim: #a8bfa4;
    --accent: #4ade80;
    --accent-ink: #0f1a12;
    --line: #2c4232;
    --good: #4ade80;
    --board-bg: #16241a;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--banner-h);
  -webkit-touch-callout: none; /* no long-press callout anywhere in the app */
}
button { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
body.sc_banner { padding-bottom: var(--banner-h); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px 2px;
  max-width: 480px; width: 100%; margin: 0 auto;
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #16a34a, #4ade80);
  font-size: 20px;
}
.icon-btn {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  width: 40px; height: 40px; font-size: 18px; cursor: pointer;
}
.top-actions { display: flex; gap: 8px; }

main {
  max-width: 480px; width: 100%; margin: 0 auto;
  padding: 6px 16px 6px; /* 6px bottom = tight 6px gap above the banner zone */
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column;
}

/* ---- HUD ---- */
.hud {
  display: flex; gap: 8px; margin-top: 4px;
  flex: 0 0 auto;
}
.hud-item {
  flex: 1; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px 4px 5px; text-align: center;
}
.hud-label { display: block; font-size: 11px; color: var(--ink-dim); font-weight: 600; }
.hud-value { display: block; font-size: 17px; font-weight: 800; }

/* ---- board: flexes to fill the remaining viewport height, so the
 * whole game always fits above the banner with no scrolling
 * (checklist 2026-11-12). */
.board-wrap {
  position: relative;
  flex: 1 1 auto; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  margin-top: 8px;
}
#board {
  display: block;
  border-radius: 12px;
  border: 1px solid var(--line);
  touch-action: none; /* swipe steering owns the gesture */
}

/* ---- menu / pause overlays sit on top of the board ---- */
.overlay {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 12px;
}
.overlay-card {
  background: var(--surface); color: var(--ink);
  width: calc(100% - 32px); max-width: 340px;
  border-radius: 16px; padding: 18px;
  box-shadow: var(--shadow);
  text-align: center;
}
.overlay-card h2 { margin: 0 0 4px; font-size: 22px; }
.menu-snake { font-size: 44px; line-height: 1; }
.menu-sub { margin: 6px 0; font-size: 15px; font-weight: 600; }
.overlay-card p { line-height: 1.55; font-size: 15px; }

/* ---- D-pad ---- */
.controls {
  flex: 0 0 auto;
  display: flex; justify-content: center;
  margin-top: 8px;
}
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 44px);
  gap: 4px;
}
.dpad-btn {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.dpad-btn:active { background: var(--accent); color: var(--accent-ink); }
.dpad-center { font-size: 14px; }

.primary-btn, .ghost-btn {
  display: block; width: 100%; border-radius: 12px; font-size: 17px;
  font-weight: 700; padding: 13px; margin-top: 10px; cursor: pointer;
  flex: 0 0 auto;
}
.primary-btn { background: var(--accent); color: var(--accent-ink); border: none; }
.ghost-btn { background: transparent; color: var(--ink); border: 1px solid var(--line); }

/* ---- sheets / toast ---- */
.sheet {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}
.sheet-card {
  background: var(--surface); color: var(--ink);
  width: 100%; max-width: 480px; max-height: calc(100dvh - var(--banner-h) - 16px);
  overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 18px 18px calc(18px + var(--banner-h));
  box-shadow: var(--shadow);
}
body.sc_banner .sheet-card { padding-bottom: calc(18px + var(--banner-h)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-card p { line-height: 1.55; font-size: 15px; }
.sheet-note { color: var(--ink-dim); font-size: 13px; }
.result-line { font-size: 18px; font-weight: 700; text-align: center; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(24px + var(--banner-h));
  z-index: 50; pointer-events: none;
  background: var(--ink); color: var(--bg);
  border-radius: 10px; padding: 12px 14px; text-align: center;
  font-size: 14px; font-weight: 600;
}
