:root {
  color-scheme: dark;
  --bg: #08131b;
  --panel: rgba(7, 25, 34, 0.88);
  --panel-strong: rgba(10, 34, 46, 0.96);
  --edge: rgba(141, 220, 255, 0.22);
  --text: #eef7fb;
  --muted: #94b7c7;
  --accent: #ff8a3d;
  --accent-soft: #ffd9c2;
  --mint: #73ffd1;
  --danger: #ff6b6b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow: hidden;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background:
    radial-gradient(
      circle at top left,
      rgba(255, 138, 61, 0.16),
      transparent 28%
    ),
    radial-gradient(
      circle at top right,
      rgba(115, 255, 209, 0.16),
      transparent 22%
    ),
    linear-gradient(160deg, #040a0e 0%, #0b1e29 55%, #06111a 100%);
}

/* ── App shell: anchored to the full viewport, flex row ── */
.app-shell {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: row;
  gap: 12px;
  padding: 12px;
}

body.mobile-blocked .app-shell {
  filter: blur(14px);
  opacity: 0.18;
  pointer-events: none;
  user-select: none;
}

.platform-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(4, 10, 14, 0.8);
  backdrop-filter: blur(14px);
}

.platform-overlay[hidden] {
  display: none;
}

.platform-card {
  width: min(100%, 420px);
  padding: 28px 24px;
  border-radius: 24px;
  border: 1px solid var(--edge);
  background:
    radial-gradient(circle at top, rgba(255, 138, 61, 0.14), transparent 48%),
    var(--panel-strong);
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.32);
  text-align: center;
}

.platform-eyebrow {
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
}

.platform-card h2 {
  font-family: "Syne", sans-serif;
  font-size: 1.9rem;
  line-height: 1.05;
  margin-bottom: 12px;
}

.platform-copy {
  font-size: 0.98rem;
  line-height: 1.55;
  color: var(--accent-soft);
}

.platform-copy.muted {
  margin-top: 10px;
  color: var(--muted);
}

/* ── Panel base ── */
.sidebar-panel,
.board-panel,
.camera-panel {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 24px;
  backdrop-filter: blur(18px);
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

/* ── LEFT SIDEBAR: fixed narrow width ── */
.sidebar-panel {
  flex: 0 0 230px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 12px;
  overflow-y: auto;
}

.sidebar-title {
  flex-shrink: 0;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.65rem;
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

h1 {
  font-family: "Syne", sans-serif;
  font-size: 1.6rem;
  line-height: 1;
}

/* ── Shared card ── */
.queue-card {
  background: var(--panel-strong);
  border: 1px solid var(--edge);
  border-radius: 16px;
  padding: 10px;
  flex-shrink: 0;
}

.label {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.65rem;
  color: var(--muted);
  display: block;
  margin-bottom: 6px;
}

/* Next piece */
.next-card {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#next-piece {
  display: block;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  background: linear-gradient(
    180deg,
    rgba(10, 27, 38, 0.96),
    rgba(5, 12, 18, 0.96)
  );
  border: 1px solid var(--edge);
}

/* Stats */
.stats-card .stat-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 7px;
  border: 1px solid var(--edge);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.8rem;
}

.stat-row span {
  color: var(--muted);
}

.stat-row strong {
  color: var(--mint);
}

/* Controls hint */
.hint-list {
  padding-left: 12px;
  font-size: 0.75rem;
  color: var(--accent-soft);
  line-height: 1.65;
}

/* ── CENTER: Game board — takes all remaining space ── */
.board-panel {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background:
    radial-gradient(circle at top, rgba(115, 255, 209, 0.06), transparent 40%),
    var(--panel);
}

#game {
  display: block;
  /* Fill height, let aspect-ratio determine width */
  height: 100%;
  max-height: calc(100vh - 48px);
  width: auto;
  max-width: 100%;
  aspect-ratio: 1 / 2;
  border-radius: 14px;
  background: linear-gradient(
    180deg,
    rgba(10, 27, 38, 0.96),
    rgba(5, 12, 18, 0.96)
  );
  border: 1px solid var(--edge);
}

/* ── Game frame: relative so overlay can be positioned over canvas ── */
.game-frame {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Tutorial overlay ── */
.tutorial-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(to top, rgba(4,10,14,0.92) 0%, rgba(4,10,14,0.3) 55%, transparent 100%);
  border-radius: 14px;
  pointer-events: none;
}

.tutorial-overlay[hidden] { display: none; }

.tutorial-card {
  pointer-events: all;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tutorial-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tutorial-progress {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mint);
}

.tutorial-instruction {
  font-family: "Syne", sans-serif;
  font-size: 1.25rem;
  line-height: 1.3;
  color: #fff;
  margin: 0;
}

.tutorial-hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0;
}

#tutorial-skip {
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  padding: 4px 10px;
  border: 1px solid var(--edge);
}

#tutorial-replay-button {
  background: transparent;
  color: var(--mint);
  border: 1px solid var(--mint);
  font-size: 0.75rem;
  padding: 7px 10px;
  width: 100%;
}

.gameover-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(4, 10, 14, 0.82);
  backdrop-filter: blur(6px);
  border-radius: 14px;
}

.gameover-overlay[hidden] {
  display: none;
}

.gameover-title {
  font-family: "Syne", sans-serif;
  font-size: 3rem;
  color: var(--danger);
  letter-spacing: 0.04em;
}

.gameover-score {
  font-size: 1.1rem;
  color: var(--muted);
}

.gameover-overlay button {
  margin-top: 8px;
  padding: 12px 32px;
  font-size: 1rem;
}

/* ── RIGHT: Camera panel — fixed width ── */
.camera-panel {
  flex: 0 0 640px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  overflow: hidden;
}

/* Buttons row */
.camera-controls {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 9px 6px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  color: #041017;
  background: linear-gradient(135deg, var(--mint), #9ce8ff);
  transition:
    transform 120ms ease,
    opacity 120ms ease;
  white-space: nowrap;
}

button:nth-child(2) {
  background: linear-gradient(135deg, var(--accent), #ffcf6b);
}

#recalibrate-button {
  background: linear-gradient(135deg, #b7c9d6, #e0edf5);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button:not(:disabled):hover {
  transform: translateY(-1px);
}

/* Camera feed — 16:9 landscape so user sees themselves with room above head */
.camera-frame {
  flex: 1 1 0;
  position: relative;
  min-height: 0;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--edge);
  background: #020608;
  aspect-ratio: 16 / 9;
  width: 100%;
  max-height: 100%;
}

#webcam,
#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#webcam {
  transform: scaleX(-1);
  z-index: 1;
  background: #020608;
}

#overlay {
  pointer-events: none;
  z-index: 2;
}

.camera-hud {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  padding: 7px 11px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.75rem;
  background: var(--panel-strong);
  border: 1px solid var(--edge);
  border-radius: 11px;
  z-index: 3;
}

.countdown-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: "Syne", sans-serif;
  font-size: clamp(3rem, 6vw, 6rem);
  color: white;
  text-shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 160ms ease;
  pointer-events: none;
  z-index: 4;
}

.countdown-overlay.active {
  opacity: 1;
}

/* Status bar */
.status-bar {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.status-item {
  padding: 6px 7px;
  background: var(--panel-strong);
  border: 1px solid var(--edge);
  border-radius: 11px;
  font-size: 0.72rem;
  min-width: 0;
}

.status-item .label {
  margin-bottom: 2px;
}

.status-item strong {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--mint);
  font-size: 0.75rem;
}

/* Debug card */
.debug-card {
  flex-shrink: 0;
}

.debug-card strong {
  font-size: 0.78rem;
  color: var(--muted);
  display: block;
  margin-bottom: 3px;
}

.debug-card pre {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.68rem;
  line-height: 1.45;
  color: var(--accent-soft);
  max-height: 72px;
  overflow-y: auto;
}
