:root {
  --bg: #080b16;
  --surface: #101525;
  --surface-raised: #151c30;
  --line: rgba(167, 184, 219, 0.14);
  --line-bright: rgba(167, 184, 219, 0.27);
  --text: #f3f6ff;
  --muted: #8c98b2;
  --muted-deep: #5d6881;
  --lime: #d8f47a;
  --cyan: #64d9e8;
  --violet: #9c81ff;
  --danger: #ff8f91;
  --font-display: "Space Grotesk", sans-serif;
  --font-mono: "DM Mono", monospace;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 16% 4%, rgba(100, 217, 232, 0.1), transparent 25rem),
    radial-gradient(circle at 86% 74%, rgba(156, 129, 255, 0.09), transparent 28rem),
    var(--bg);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; }
button:focus-visible { outline: 2px solid var(--lime); outline-offset: 4px; }

.page-shell {
  width: min(1180px, calc(100% - 64px));
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  text-decoration: none;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.22em;
}

.brand-mark {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  color: var(--bg);
  background: var(--lime);
  border-radius: 7px;
  font-size: 19px;
  letter-spacing: 0;
}

.topbar-caption, .footer-note, .panel-label, .stat-label, .stat-accent, .panel-index, .key-row, .live-indicator, .modal-kicker, .best-score-row span, .result-grid span, .start-meta span {
  font-family: var(--font-mono);
  letter-spacing: 0.1em;
}

.topbar-caption { color: var(--muted-deep); font-size: 10px; letter-spacing: 0.24em; }

.icon-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0 8px 12px;
  color: var(--muted);
  border: 0;
  background: transparent;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  transition: color 160ms ease;
}
.icon-button:hover { color: var(--text); }
.sound-icon { color: var(--lime); font-size: 17px; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 64px;
  align-items: start;
  padding: 68px 52px 48px;
  flex: 1;
}

.board-column { min-width: 0; }
.game-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 23px; }
.eyebrow { margin: 0 0 11px; color: var(--lime); font: 500 10px var(--font-mono); letter-spacing: 0.18em; }
h1 { margin: 0; font-size: clamp(28px, 4vw, 43px); line-height: 1; letter-spacing: -0.06em; font-weight: 600; }
.live-indicator { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 12px rgba(216, 244, 122, 0.8); }
.alert-dot { background: var(--danger); box-shadow: 0 0 12px rgba(255, 143, 145, 0.8); }

.play-area { position: relative; display: flex; justify-content: center; }
.board-frame {
  position: relative;
  width: min(100%, 380px);
  aspect-ratio: 1 / 2;
  padding: 9px;
  background: linear-gradient(145deg, #202b45, #0b1020 55%, #1b2540);
  border: 1px solid var(--line-bright);
  border-radius: 11px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}
.board-frame::before { content: ""; position: absolute; inset: 3px; border: 1px solid rgba(216, 244, 122, 0.1); border-radius: 8px; pointer-events: none; }
#game-board { display: block; width: 100%; height: 100%; border-radius: 5px; background: #0a1020; }
.board-scanline { position: absolute; inset: 10px; border-radius: 5px; pointer-events: none; background: linear-gradient(transparent 49%, rgba(255, 255, 255, 0.02) 50%, transparent 51%); background-size: 100% 8px; opacity: 0.25; }

.sidebar { display: flex; flex-direction: column; gap: 15px; padding-top: 49px; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-card, .panel-card, .best-score-row {
  background: linear-gradient(145deg, rgba(25, 33, 55, 0.9), rgba(14, 20, 36, 0.9));
  border: 1px solid var(--line);
  border-radius: 10px;
}
.stat-card { min-height: 91px; padding: 16px 15px; }
.stat-card-wide { grid-column: 1 / -1; min-height: 112px; padding: 18px 20px; position: relative; overflow: hidden; }
.stat-card-wide::after { content: ""; position: absolute; width: 110px; height: 110px; right: -40px; bottom: -50px; border-radius: 50%; border: 1px solid rgba(216, 244, 122, 0.2); box-shadow: 0 0 0 16px rgba(216, 244, 122, 0.03), 0 0 0 33px rgba(216, 244, 122, 0.02); }
.stat-label, .panel-label { display: block; color: var(--muted); font-size: 9px; }
.stat-card strong { display: block; margin-top: 10px; color: var(--text); font: 500 24px var(--font-mono); letter-spacing: 0.03em; }
.stat-card-wide strong { font-size: 34px; }
.stat-accent { display: block; margin-top: 6px; color: var(--lime); font-size: 8px; }

.panel-card { padding: 17px 19px; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; }
.mini-button { padding: 4px 7px; color: var(--lime); border: 1px solid rgba(216, 244, 122, 0.25); border-radius: 3px; background: transparent; cursor: pointer; font: 9px var(--font-mono); letter-spacing: 0.08em; transition: background 160ms ease, color 160ms ease; }
.mini-button:hover { color: var(--bg); background: var(--lime); }
.panel-index { color: var(--muted-deep); font-size: 9px; }
#next-piece, #next-piece-mobile { display: block; margin: 13px auto 0; max-width: 100%; }
.next-card { min-height: 190px; }
.mobile-next-card { display: none; }
.controls-card { padding-bottom: 15px; }
.key-list { margin-top: 16px; display: grid; gap: 9px; }
.key-row { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 9px; }
.key-row span:nth-child(2) { flex: 1; }
.key-cap { display: inline-grid; min-width: 24px; height: 23px; padding: 0 5px; place-items: center; color: var(--text); border: 1px solid var(--line-bright); border-radius: 4px; background: rgba(255, 255, 255, 0.03); font-size: 11px; }
.key-space { min-width: 48px; font-size: 8px; }
.key-letter { color: var(--lime); border-color: rgba(216, 244, 122, 0.3); }
.best-score-row { display: flex; align-items: center; justify-content: space-between; padding: 16px 19px; }
.best-score-row strong { display: block; margin-top: 7px; font: 500 20px var(--font-mono); }
.trophy { color: var(--lime); font-size: 22px; }

.mobile-controls { display: none; }

.footer-note { display: flex; justify-content: space-between; gap: 20px; padding: 18px 52px 28px; color: var(--muted-deep); font-size: 9px; }

.modal-layer { position: fixed; z-index: 10; inset: 0; display: grid; place-items: center; padding: 28px; background: rgba(5, 7, 15, 0.82); backdrop-filter: blur(10px); animation: fade-in 180ms ease both; }
.modal-layer.is-hidden { display: none; }
.modal-card { width: min(100%, 530px); padding: 43px 48px; border: 1px solid var(--line-bright); border-radius: 14px; background: linear-gradient(145deg, #1a2238, #101626); box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5); }
.start-card { min-height: 455px; display: flex; flex-direction: column; justify-content: center; }
.compact-card { width: min(100%, 430px); }
.modal-kicker { display: flex; align-items: center; gap: 9px; color: var(--lime); font-size: 9px; }
.modal-card h2 { margin: 28px 0 19px; font-size: clamp(38px, 7vw, 58px); line-height: 0.96; letter-spacing: -0.07em; font-weight: 600; }
.modal-card h2 em { color: var(--lime); font-style: normal; }
.modal-card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.75; }
.primary-button { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 53px; margin-top: 31px; padding: 0 17px 0 20px; color: var(--bg); border: 0; border-radius: 6px; background: var(--lime); cursor: pointer; font-size: 14px; font-weight: 700; transition: transform 160ms ease, background 160ms ease; }
.primary-button:hover { background: #e8ff9a; transform: translateY(-2px); }
.primary-button span:last-child { font-size: 20px; }
.start-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 27px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 9px; }
.start-meta strong { color: var(--text); font: 500 14px var(--font-mono); }
.modal-actions { display: grid; gap: 3px; }
.text-button { min-height: 37px; color: var(--muted); border: 0; background: transparent; cursor: pointer; font-size: 12px; transition: color 160ms ease; }
.text-button:hover { color: var(--text); }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 28px; }
.result-grid div { padding: 14px 11px; border: 1px solid var(--line); border-radius: 6px; }
.result-grid span { display: block; color: var(--muted); font-size: 8px; }
.result-grid strong { display: block; margin-top: 9px; color: var(--text); font: 500 19px var(--font-mono); }
.new-best { margin-top: 18px !important; color: var(--lime) !important; font-family: var(--font-mono); font-size: 11px !important; }
.new-best.is-hidden { display: none; }

.toast { position: fixed; z-index: 20; left: 50%; bottom: 27px; transform: translate(-50%, 15px); padding: 10px 16px; color: var(--bg); border-radius: 5px; background: var(--lime); font: 500 11px var(--font-mono); opacity: 0; pointer-events: none; transition: opacity 180ms ease, transform 180ms ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }

@media (max-width: 900px) {
  .page-shell { width: min(680px, calc(100% - 36px)); }
  .game-layout { grid-template-columns: 1fr; gap: 28px; padding: 46px 0 30px; }
  .sidebar { padding-top: 0; display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
  .stats-grid { grid-column: 1 / -1; }
  .next-card { display: none; }
  .controls-card { grid-column: 1 / 2; }
  .best-score-row { grid-column: 2 / 3; }
  .mobile-next-card { display: flex; align-items: center; justify-content: space-between; width: min(100%, 380px); margin: 12px auto 0; padding: 10px 18px; }
  .mobile-next-card canvas { margin: 0; width: 100px; height: 74px; }
  .mobile-controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: min(100%, 380px); margin: 12px auto 0; }
  .control-button { min-height: 50px; color: var(--text); border: 1px solid var(--line-bright); border-radius: 6px; background: var(--surface-raised); cursor: pointer; font-size: 23px; touch-action: manipulation; }
  .control-button:active { transform: translateY(1px); background: var(--line-bright); }
  .control-primary { color: var(--bg); border-color: var(--lime); background: var(--lime); }
  .control-drop { grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; gap: 9px; min-height: 43px; font-size: 11px; letter-spacing: 0.08em; }
  .control-drop strong { color: var(--muted); font: 9px var(--font-mono); }
  .footer-note { padding: 0 0 25px; }
}

@media (max-width: 500px) {
  .page-shell { width: calc(100% - 28px); }
  .topbar { height: 74px; }
  .topbar-caption { display: none; }
  .sound-label { display: none; }
  .game-layout { padding-top: 33px; }
  .game-heading { margin-bottom: 18px; }
  h1 { font-size: 28px; }
  .eyebrow { font-size: 8px; }
  .sidebar { gap: 9px; }
  .stat-card { min-height: 81px; padding: 13px 11px; }
  .stat-card-wide { min-height: 95px; padding: 15px; }
  .stat-card strong { margin-top: 8px; font-size: 19px; }
  .stat-card-wide strong { font-size: 27px; }
  .stat-accent { font-size: 7px; }
  .controls-card, .best-score-row { grid-column: 1 / -1; }
  .best-score-row { order: -1; }
  .controls-card { padding: 14px; }
  .key-list { grid-template-columns: 1fr 1fr; gap: 8px; }
  .key-row { gap: 6px; font-size: 8px; }
  .key-row span:nth-child(2) { display: none; }
  .key-cap { min-width: 30px; }
  .key-space { min-width: 47px; }
  .footer-note { font-size: 7px; }
  .modal-layer { padding: 16px; }
  .modal-card { padding: 32px 25px; }
  .start-card { min-height: 410px; }
  .modal-card h2 { margin-top: 22px; font-size: 43px; }
  .modal-card p { font-size: 12px; }
}
