/* ============================================================================
   BPSO Blog — tetris/game.css
   Self-contained styles for the playable Tetris embedded in the Tetris post.
   Scoped under .bpso-tetris so it never leaks into the article. Uses the blog's
   BPSO Lab 2026 design tokens (with local fallbacks if loaded standalone).
   ========================================================================== */

.bpso-tetris {
  /* local fallbacks mirror blog.css :root so the widget is robust on its own */
  --t-brand-blue: var(--brand-blue, #2563eb);
  --t-brand-light: var(--brand-light, #60a5fa);
  --t-brand-glow: var(--brand-glow, rgba(37, 99, 235, .35));
  --t-bg: var(--bg-dark, #0f172a);
  --t-surface: var(--bg-card, #1e293b);
  --t-surface-2: #243349;
  --t-text: var(--text-main, #f8fafc);
  --t-muted: var(--text-muted, #94a3b8);
  --t-border: var(--border, rgba(255, 255, 255, .08));
  --t-tools: var(--cat-tools, #8b5cf6);

  /* tetromino palette (on-brand, distinct, WCAG-friendly on dark playfield) */
  --t-I: #38bdf8; /* sky   */
  --t-O: #facc15; /* amber */
  --t-T: #8b5cf6; /* violet (brand tools) */
  --t-S: #22c55e; /* green */
  --t-Z: #ef4444; /* red (brand security) */
  --t-J: #2563eb; /* brand blue */
  --t-L: #fb923c; /* orange */

  font-family: var(--font-body, 'Inter', system-ui, sans-serif);
  color: var(--t-text);
  display: grid;
  /* Board column capped at the playfield's max width (cell cap 34 × 10 cols = 340px) so
     the track never gets wider than the board -> no empty strip on the right. The whole
     board+panel group is centered, so any slack sits symmetrically outside, not between them. */
  grid-template-columns: minmax(0, 340px) clamp(150px, 26%, 200px);
  gap: clamp(.7rem, 2.5vw, 1.4rem);
  align-items: start;
  justify-content: center;
  width: 100%;
}

/* Light theme: keep the playfield dark (pieces pop) but make side panels + text readable */
[data-theme="light"] .bpso-tetris {
  --t-surface: #ffffff;
  --t-surface-2: #eef2f7;
  --t-text: #0f172a;
  --t-muted: #475569;
  --t-border: rgba(15, 23, 42, .12);
  --t-bg: #0f172a;
}

/* ---------------------------------------------------------- Playfield */
.bpso-tetris__stage {
  position: relative;
  min-width: 0;
}

.bpso-tetris__canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .03), transparent 30%),
    var(--t-bg);
  border: 1px solid var(--t-border);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .25), 0 10px 30px -12px rgba(0, 0, 0, .6);
  touch-action: none; /* we manage gestures/buttons ourselves */
}

/* Overlay for pause / game-over / start */
.bpso-tetris__overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1rem;
  border-radius: 12px;
  background: color-mix(in srgb, var(--t-bg) 78%, transparent);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.bpso-tetris__overlay[hidden] { display: none; }

.bpso-tetris__overlay-card {
  max-width: 88%;
}
.bpso-tetris__overlay-title {
  font-family: var(--font-head, 'Poppins', sans-serif);
  font-weight: 800;
  font-size: clamp(1.4rem, 5vw, 2rem);
  margin: 0 0 .4rem;
  letter-spacing: -.01em;
  color: var(--t-text);
}
.bpso-tetris__overlay-sub {
  margin: 0 0 1.1rem;
  color: var(--t-muted);
  font-size: .95rem;
  line-height: 1.5;
}

/* ---------------------------------------------------------- Sidebar */
.bpso-tetris__side {
  display: flex;
  flex-direction: column;
  gap: clamp(.6rem, 2vw, 1rem);
  min-width: 0;
}

.bpso-tetris__panel {
  background: var(--t-surface);
  border: 1px solid var(--t-border);
  border-radius: 12px;
  padding: .75rem .85rem;
}
.bpso-tetris__panel-label {
  font-family: var(--font-head, 'Poppins', sans-serif);
  font-weight: 700;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--t-muted);
  margin: 0 0 .45rem;
}
.bpso-tetris__panel-value {
  font-family: var(--font-head, 'Poppins', sans-serif);
  font-weight: 800;
  font-size: 1.35rem;
  line-height: 1;
  color: var(--t-text);
  font-variant-numeric: tabular-nums;
}

.bpso-tetris__previews {
  display: flex;
  gap: .9rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.bpso-tetris__preview {
  display: grid;
  gap: .35rem;
  justify-items: center;
}
.bpso-tetris__preview canvas {
  display: block;
  width: 72px;
  height: 72px;
  background: var(--t-bg);
  border: 1px solid var(--t-border);
  border-radius: 8px;
}
/* Tiny caption under each preview so NEXT vs HOLD is unambiguous and the empty
   hold slot reads as intentional (not a broken render). */
.bpso-tetris__preview-cap {
  font-family: var(--font-head, 'Poppins', sans-serif);
  font-weight: 700;
  font-size: .58rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--t-muted);
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  line-height: 1;
}
.bpso-tetris__preview-cap kbd {
  font-family: ui-monospace, monospace;
  font-size: .56rem;
  background: var(--t-surface-2);
  border: 1px solid var(--t-border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: .1em .35em;
  color: var(--t-text);
}

/* ---------------------------------------------------------- Touch controls */
.bpso-tetris__touch {
  grid-column: 1 / -1;
  display: none; /* shown only on coarse pointers / small screens */
  gap: .5rem;
  margin-top: .2rem;
}
.bpso-tetris__touch-row {
  display: flex;
  gap: .5rem;
  justify-content: center;
}
.bpso-tetris__btn {
  appearance: none;
  flex: 1 1 0;
  min-width: 48px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  font-family: var(--font-head, 'Poppins', sans-serif);
  font-weight: 600;
  font-size: 1.2rem;
  color: var(--t-text);
  background: var(--t-surface);
  border: 1px solid var(--t-border);
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .1s ease, background .15s ease, border-color .15s ease;
}
.bpso-tetris__btn:hover { border-color: color-mix(in srgb, var(--t-brand-blue) 60%, var(--t-border)); }
.bpso-tetris__btn:active { transform: translateY(1px) scale(.97); background: var(--t-surface-2); }
.bpso-tetris__btn .label {
  font-family: var(--font-body, 'Inter', sans-serif);
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .04em;
}
.bpso-tetris__btn--wide { flex: 2 1 0; }

/* primary action buttons inside overlays */
.bpso-tetris__action {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font-family: var(--font-head, 'Poppins', sans-serif);
  font-weight: 600;
  font-size: 1rem;
  color: #fff;
  background: var(--t-brand-blue);
  border: 0;
  padding: .75rem 1.5rem;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 10px 28px -8px var(--t-brand-glow);
  transition: transform .18s ease, background .18s ease, box-shadow .18s ease;
}
.bpso-tetris__action:hover { background: var(--brand-dark, #1e40af); transform: translateY(-2px); }
.bpso-tetris__action:active { transform: translateY(0); }

/* small ghost buttons in the side panel (pause / restart) */
.bpso-tetris__controls {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
.bpso-tetris__ghost {
  appearance: none;
  flex: 1 1 78px;
  min-width: 0;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  min-height: 40px;
  font-family: var(--font-body, 'Inter', sans-serif);
  font-weight: 600;
  font-size: .82rem;
  color: var(--t-muted);
  background: transparent;
  border: 1px solid var(--t-border);
  border-radius: 10px;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.bpso-tetris__ghost:hover { color: var(--t-text); border-color: var(--t-brand-blue); }
.bpso-tetris__ghost i { font-size: 1.05rem; }

/* keyboard hint (hidden on touch) */
.bpso-tetris__keys {
  font-size: .72rem;
  color: var(--t-muted);
  line-height: 1.7;
  margin: 0;
}
.bpso-tetris__keys kbd {
  font-family: ui-monospace, monospace;
  font-size: .72rem;
  background: var(--t-surface-2);
  border: 1px solid var(--t-border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: .05em .4em;
  color: var(--t-text);
}

/* line-clear flash on the score readout */
.bpso-tetris__panel-value.is-pop {
  animation: bpso-tetris-pop .4s ease;
}
@keyframes bpso-tetris-pop {
  0% { transform: scale(1); color: var(--t-text); }
  35% { transform: scale(1.18); color: var(--t-brand-light); }
  100% { transform: scale(1); color: var(--t-text); }
}

/* ---------------------------------------------------------- Responsive */
/* Touch controls appear on coarse pointers OR narrow viewports */
@media (pointer: coarse) {
  .bpso-tetris__touch { display: grid; }
  .bpso-tetris__keys { display: none; }
}
@media (max-width: 560px) {
  .bpso-tetris {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  /* Order so the board and the touch controls sit together (controls visible
     while playing); the score/previews go below. Board height is capped in JS. */
  .bpso-tetris__stage { width: max-content; max-width: 100%; order: 0; }
  .bpso-tetris__touch { display: grid; order: 1; width: 100%; margin-top: .6rem; }
  .bpso-tetris__side {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
    order: 2;
    width: 100%;
  }
  .bpso-tetris__panel { flex: 1 1 90px; }
  .bpso-tetris__previews { flex: 1 1 100%; justify-content: space-around; }
  .bpso-tetris__controls { flex: 1 1 100%; }
  .bpso-tetris__keys { display: none; }
}

/* Respect reduced motion: drop the flourish animations, keep gameplay. */
@media (prefers-reduced-motion: reduce) {
  .bpso-tetris__panel-value.is-pop { animation: none; }
  .bpso-tetris__action,
  .bpso-tetris__btn { transition: none; }
}
