:root {
  color-scheme: dark;
  --ink: #f4f7ff;
  --muted: #7f89a9;
  --line: rgba(174, 196, 255, 0.16);
  --panel: rgba(12, 16, 36, 0.72);
  --cyan: #2de2e6;
  --violet: #8b5cf6;
  --pink: #ff4d9d;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: #050611; }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(rgba(7, 9, 24, .76), rgba(7, 9, 24, .96)),
    repeating-linear-gradient(90deg, transparent 0 59px, rgba(68, 94, 160, .08) 60px),
    repeating-linear-gradient(0deg, transparent 0 59px, rgba(68, 94, 160, .08) 60px),
    #070918;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 35%, transparent 0, rgba(2, 3, 12, .05) 45%, rgba(2, 3, 12, .78) 100%);
  z-index: -1;
}

button, kbd { font: inherit; }
button { color: inherit; }

.ambient {
  position: fixed;
  width: 34rem;
  height: 34rem;
  border-radius: 50%;
  filter: blur(100px);
  opacity: .12;
  pointer-events: none;
  z-index: -1;
}
.ambient-one { top: -15rem; left: -10rem; background: var(--violet); }
.ambient-two { right: -14rem; bottom: -16rem; background: var(--cyan); }

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

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

.brand {
  display: inline-flex;
  gap: 13px;
  align-items: center;
  color: var(--ink);
  text-decoration: none;
  font-weight: 900;
  letter-spacing: .18em;
  font-size: .9rem;
}

.brand-mark {
  width: 28px;
  height: 28px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2px;
  transform: rotate(-8deg) skew(-5deg);
}
.brand-mark i { background: linear-gradient(135deg, #fff, var(--cyan)); box-shadow: 0 0 14px rgba(45, 226, 230, .45); }
.brand-mark i:nth-child(1) { opacity: .42; }
.brand-mark i:nth-child(4) { opacity: .7; }

.top-actions { display: flex; align-items: center; gap: 22px; }
.status, .icon-button {
  font-size: .67rem;
  letter-spacing: .14em;
  font-weight: 800;
}
.status { color: #9aa5c4; display: flex; align-items: center; gap: 8px; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: #55f58d; box-shadow: 0 0 12px #55f58d; }
.icon-button { border: 1px solid var(--line); background: rgba(255,255,255,.025); padding: 9px 12px; cursor: pointer; }
.icon-button:hover { border-color: rgba(45, 226, 230, .55); }
.icon-button:disabled { opacity: .38; cursor: not-allowed; }

.game-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(185px, 1fr) 360px minmax(185px, 1fr);
  gap: clamp(24px, 5vw, 76px);
  align-items: center;
  padding: 34px 0 24px;
}

.side-panel { width: 100%; max-width: 230px; }
.stats-panel { justify-self: end; }
.next-panel { justify-self: start; }

.eyebrow, .card-title, .metric span, .mobile-stats small {
  color: var(--muted);
  font-size: .64rem;
  letter-spacing: .18em;
  font-weight: 800;
}
.eyebrow { margin-bottom: 15px; }

.metric { padding: 15px 0; border-bottom: 1px solid var(--line); }
.metric span, .metric strong { display: block; }
.metric strong { margin-top: 6px; font: 700 1.7rem/1 "SFMono-Regular", Consolas, monospace; letter-spacing: .04em; }
.metric.featured strong { font-size: clamp(2rem, 3vw, 2.7rem); color: var(--cyan); text-shadow: 0 0 24px rgba(45,226,230,.28); }
.metric-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.high-score { margin-bottom: 34px; }

.piece-card, .controls-card {
  border: 1px solid var(--line);
  background: linear-gradient(145deg, rgba(19, 25, 54, .8), rgba(8, 11, 28, .7));
  box-shadow: inset 0 1px rgba(255,255,255,.03), 0 18px 50px rgba(0,0,0,.18);
}
.card-title { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; }
.card-title small { font-size: .58rem; color: #596382; }
.piece-card canvas { display: block; width: 100%; }
.hold-card canvas { height: 100px; }
.next-card canvas { height: 270px; }

.controls-card { margin-top: 18px; padding-bottom: 5px; }
.controls-card dl { margin: 8px 14px; }
.controls-card dl div { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; color: var(--muted); font-size: .7rem; }
.controls-card dt { display: flex; gap: 4px; }
.controls-card dd { margin: 0; }
kbd { min-width: 25px; padding: 4px 6px; color: #cbd4ee; text-align: center; font-size: .57rem; border: 1px solid #333c5d; border-bottom-width: 2px; background: #12162a; }

.board-column { width: 100%; }
.board-stage { position: relative; perspective: 1100px; padding: 10px 18px 25px; }
.board-frame {
  position: relative;
  width: 100%;
  padding: 9px;
  border: 1px solid rgba(140, 161, 233, .34);
  background: linear-gradient(145deg, #252c4b 0, #090c20 10%, #050713 85%, #1a2040 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.04),
    inset 10px 0 18px rgba(255,255,255,.025),
    0 0 55px rgba(83, 80, 255, .13),
    28px 36px 65px rgba(0, 0, 0, .52);
  transform: rotateX(1.5deg) rotateY(-1.5deg);
  transform-style: preserve-3d;
}
.board-frame::before, .board-frame::after {
  content: "";
  position: absolute;
  z-index: -1;
}
.board-frame::before { top: 9px; right: -13px; width: 13px; height: calc(100% - 3px); background: linear-gradient(90deg, #171d38, #070916); transform: skewY(42deg); transform-origin: left top; }
.board-frame::after { left: 9px; bottom: -13px; width: calc(100% - 3px); height: 13px; background: linear-gradient(#131933, #050611); transform: skewX(48deg); transform-origin: left top; }
#gameCanvas { display: block; width: 100%; aspect-ratio: 1 / 2; background: #050714; touch-action: none; }
.board-shadow { position: absolute; z-index: -1; left: 11%; right: 4%; bottom: 2px; height: 12%; background: rgba(53, 68, 150, .28); filter: blur(24px); transform: rotate(-4deg); }
.scanlines { position: absolute; inset: 9px; pointer-events: none; opacity: .12; background: repeating-linear-gradient(0deg, rgba(255,255,255,.08) 0 1px, transparent 1px 4px); }

.game-overlay {
  position: absolute;
  inset: 9px;
  display: grid;
  place-items: center;
  text-align: center;
  background: radial-gradient(circle at 50% 46%, rgba(25, 31, 70, .83), rgba(4, 6, 18, .96));
  transition: opacity .22s ease, visibility .22s ease;
}
.game-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.overlay-copy { padding: 28px; }
.overlay-copy h1 { margin: 0; font-size: clamp(2.7rem, 7vw, 4.4rem); line-height: .85; letter-spacing: -.07em; font-weight: 950; }
.overlay-copy h1 em { font-style: normal; color: transparent; -webkit-text-stroke: 1px var(--cyan); text-shadow: 0 0 25px rgba(45,226,230,.3); }
.overlay-copy p { max-width: 245px; margin: 22px auto; color: #9aa5c4; font-size: .82rem; line-height: 1.6; }
.primary-button {
  min-width: 175px;
  padding: 13px 18px;
  border: 0;
  color: #031013;
  background: linear-gradient(135deg, #8ffcff, var(--cyan));
  box-shadow: 0 9px 30px rgba(45,226,230,.22), inset 0 -3px rgba(0,0,0,.15);
  font-weight: 950;
  letter-spacing: .12em;
  font-size: .7rem;
  cursor: pointer;
}
.primary-button:hover { transform: translateY(-1px); filter: brightness(1.08); }

.mobile-stats { display: none; }

footer { min-height: 46px; border-top: 1px solid var(--line); border-bottom: 0; color: #57617f; font-size: .56rem; letter-spacing: .13em; font-weight: 700; }
#liveStatus { color: #8996b9; }

@media (max-width: 850px) {
  .app-shell { width: min(100% - 24px, 470px); }
  .topbar { min-height: 58px; }
  .top-actions { gap: 8px; }
  .top-actions .status { display: none; }
  .game-layout { display: block; padding: 16px 0 8px; }
  .side-panel { display: none; }
  .board-column {
    width: min(350px, calc((100dvh - 155px) / 2));
    min-width: 215px;
    margin: auto;
  }
  .board-stage { padding: 5px 12px 18px; }
  .board-frame { transform: none; }
  .board-frame::before, .board-frame::after { display: none; }
  .mobile-stats { display: grid; grid-template-columns: 2fr 1fr 1fr; margin-bottom: 10px; border: 1px solid var(--line); background: var(--panel); }
  .mobile-stats span { display: grid; gap: 3px; padding: 9px 11px; border-right: 1px solid var(--line); }
  .mobile-stats span:last-child { border: 0; }
  .mobile-stats strong { font-family: "SFMono-Regular", Consolas, monospace; font-size: .95rem; }
  footer { display: none; }
}

@media (max-width: 420px) {
  .brand { gap: 8px; font-size: .76rem; letter-spacing: .13em; }
  .brand-mark { width: 24px; height: 24px; }
  .icon-button { padding: 8px 9px; font-size: .58rem; letter-spacing: .08em; }
}

@media (max-height: 760px) and (min-width: 851px) {
  .game-layout { padding-top: 15px; }
  .board-column { max-width: 315px; justify-self: center; }
  .topbar { min-height: 56px; }
  footer { min-height: 38px; }
}

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