/* Pattern Breaker — mobile-first styles.
 * System theme via prefers-color-scheme (no JS toggle), plus
 * color-scheme so form controls follow the OS theme too.
 * Banner reserve: anchored adaptive banners are up to 90dp tall on
 * phones — body padding-bottom reserves it and fixed overlays
 * (toast, sheet) carry their own --banner-h offset.
 * The whole game view fits above the banner with no scrolling:
 * topbar + HUD + status + history + lock + controls = 100dvh minus
 * the banner reserve (the lock is flex-centred in the stage, so the
 * controls row always lands exactly on the banner zone).
 */
:root {
  color-scheme: light dark;
  --banner-h: 0px;
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #e2e9f1;
  --ink: #101820;
  --ink-2: #46525e;
  --ink-3: #76828e;
  --line: #c9d3dd;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #dbeafe;
  --danger: #b3261e;
  --warn: #8a5a00;
  --good: #15803d;
  --radius: 16px;
  --lock-bg: #dbe4ef;
  --dot: #ffffff;
  --dot-ring: #94a3b8;
  --dot-active: #2563eb;
  --dot-win: #dc2626;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f16;
    --surface: #141b28;
    --surface-2: #1d2739;
    --ink: #eef2f8;
    --ink-2: #b9c4d4;
    --ink-3: #7e8ba0;
    --line: #2a3448;
    --accent: #60a5fa;
    --accent-ink: #0b1526;
    --accent-soft: #1e3a5f;
    --danger: #ff8a80;
    --warn: #ffcf7d;
    --good: #4ade80;
    --lock-bg: #1d2739;
    --dot: #e8eef7;
    --dot-ring: #5b6b82;
    --dot-active: #60a5fa;
    --dot-win: #f87171;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--banner-h);
  overflow: hidden;
}
body, button, input { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
button { touch-action: manipulation; }
button, a { -webkit-touch-callout: none; user-select: none; }

.app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  padding: 0 12px;
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 52px; padding-top: 6px; flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 30px; height: 30px; display: block; }
.brand-mark svg { width: 100%; height: 100%; display: block; }
.brand-word { font-size: 21px; font-weight: 800; letter-spacing: -0.02em; }
.brand-word span { color: var(--accent); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.about-button {
  min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  font-weight: 600; cursor: pointer;
}
.icon-button {
  flex-shrink: 0; width: 44px; height: 44px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 20px;
}

/* ---- HUD + status ---- */
.hud {
  display: flex; align-items: center; gap: 14px;
  min-height: 34px; flex-shrink: 0;
  font-size: 12px; font-weight: 700; letter-spacing: 0.08em; color: var(--ink-3);
}
.hud strong { color: var(--ink); font-size: 14px; }
.hud-time strong { color: var(--danger); }
.countdown-bar {
  height: 6px; border-radius: 3px; background: var(--surface-2);
  overflow: hidden; flex-shrink: 0; margin: 2px 0 4px;
}
.countdown-bar span {
  display: block; height: 100%; width: 100%;
  background: var(--accent); border-radius: 3px;
  transition: width 0.25s linear;
}
.countdown-bar.alert span { background: var(--danger); }
.status {
  min-height: 26px; flex-shrink: 0;
  font-size: 14px; color: var(--ink-2); text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---- history ---- */
.history {
  flex-shrink: 0;
  height: 92px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
  padding: 2px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.history-empty {
  color: var(--ink-3); font-size: 13px; text-align: center;
  padding-top: 30px;
}
.hist-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; min-height: 26px;
}
.hist-row .hist-num { width: 20px; color: var(--ink-3); font-weight: 700; flex-shrink: 0; }
.hist-row svg { flex-shrink: 0; }
.hist-pegs { display: flex; gap: 3px; margin-left: auto; flex-shrink: 0; }
.hist-pegs i {
  width: 11px; height: 11px; border-radius: 50%; display: block;
}
.peg-good { background: var(--good); }
.peg-mid { background: #d97706; }
.peg-bad { background: var(--line); }
.peg-good { color: var(--good); }
.peg-mid { color: #d97706; }
.peg-bad { color: var(--ink-3); }

/* ---- lock stage ---- */
.stage {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 4px 0;
}
.lock {
  position: relative;
  width: min(308px, 80vw, calc(100dvh - 462px));
  min-width: 220px;
  aspect-ratio: 1 / 1;
  background: var(--lock-bg);
  border-radius: 24px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.lock.shake { animation: shake 0.25s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
#lockSvg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
}
#liveLine { stroke: var(--accent); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; opacity: 0.9; }
#liveTip { stroke: var(--accent); stroke-width: 3; }
.dots {
  position: absolute; inset: 0;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
}
.dot-cell { display: flex; align-items: center; justify-content: center; }
.dot {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--dot);
  border: 3px solid var(--dot-ring);
  transition: background 0.08s, border-color 0.08s, transform 0.08s;
}
.dot.active { background: var(--accent); border-color: var(--accent); transform: scale(1.15); }
.dot.win { background: var(--dot-win); border-color: var(--dot-win); }
.lock-hint {
  margin-top: 8px; font-size: 13px; color: var(--ink-3); flex-shrink: 0;
}
.lock-hint strong { color: var(--ink-2); }

/* ---- controls ---- */
.controls {
  display: flex; gap: 8px; flex-shrink: 0;
  padding: 8px 0 4px;
}
.ctl-btn {
  min-height: 48px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
  font-weight: 700; cursor: pointer; padding: 0 12px;
}
.ctl-btn.ctl-wide { flex: 1; }
.ctl-btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---- sheets ---- */
.sheet {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: var(--banner-h);
}
.sheet-center { align-items: center; padding-bottom: var(--banner-h); }
.sheet-card {
  background: var(--surface); color: var(--ink);
  width: 100%; max-width: 560px;
  max-height: calc(100dvh - var(--banner-h) - 24px);
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.25);
}
.sheet-center .sheet-card { border-radius: 20px; }
.sheet-card h1 { margin: 0 0 6px; font-size: 26px; line-height: 1.2; }
.sheet-card h2 { margin: 0; font-size: 20px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.menu-sub { margin: 0 0 8px; color: var(--ink-2); font-size: 14px; }
.menu-best { margin: 0 0 14px; font-size: 13px; font-weight: 700; color: var(--ink-2); }
.menu-first { margin: 12px 0 4px; font-size: 14px; }
.menu-help { margin: 0 0 10px; font-size: 13px; color: var(--ink-2); }
.about-body { margin: 0 0 10px; font-size: 14px; color: var(--ink-2); }
.about-meta { margin: 12px 0 0; font-size: 12px; color: var(--ink-3); }
.seg-label { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; color: var(--ink-3); margin: 12px 0 6px; text-transform: uppercase; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg-btn {
  flex: 1 1 auto; min-height: 48px; padding: 0 10px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); font-weight: 700; cursor: pointer;
  font-size: 14px; white-space: nowrap;
}
.seg-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.button {
  display: block; width: 100%; min-height: 52px;
  border-radius: 14px; border: none; cursor: pointer;
  font-weight: 800; font-size: 16px; margin: 6px 0;
}
.button-primary { background: var(--accent); color: var(--accent-ink); }
.button-secondary { background: var(--surface-2); color: var(--ink); }
.footer-link {
  display: block; margin: 10px auto 0; padding: 8px 12px;
  background: none; border: none; cursor: pointer;
  color: var(--accent); font-weight: 700; font-size: 14px;
  min-height: 44px;
}

/* ---- toast ---- */
.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--banner-h));
  z-index: 50;
  background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  pointer-events: none;
  max-width: calc(100vw - 32px);
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
