/* ============================================================
 * Block Classic — Tetris-style game styling
 * Uses --color-primary + --primary-rgb so the user's accent color
 * applies. Piece colors are local; everything else is themed.
 * ============================================================ */

.tt-tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 16px 14px;
  gap: 12px;
  min-height: 100%;
  /* Subtle accent-tinted radial that reads in both light and dark. */
  background: radial-gradient(ellipse at top,
    rgba(var(--primary-rgb, 127,13,242), 0.05) 0%,
    transparent 60%);
}

/* Height-driven stage: the board fills the available vertical space
   (capped) and its width is derived from the 10:20 aspect ratio.
   This makes the playfield big on desktops without scrolling. */
.tt-stage {
  display: grid;
  grid-template-columns: auto minmax(260px, 300px);
  grid-template-areas: "board hud";
  gap: 24px;
  align-items: stretch;
  height: min(82vh, 860px);
}

/* On narrower screens, stack the HUD over the board and let the board
   be width-driven instead so it doesn't overflow. */
@media (max-width: 760px) {
  .tt-tool { padding: 12px; }
  .tt-stage {
    grid-template-columns: 1fr;
    grid-template-areas: "hud" "board";
    height: auto;
    width: 100%;
    max-width: 420px;
    gap: 12px;
  }
}

/* ============================================================
 * Board
 * ============================================================ */

.tt-board-wrap {
  position: relative;
  grid-area: board;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  padding: 8px;
  box-shadow:
    0 0 0 1px rgba(var(--primary-rgb, 127,13,242), 0.05) inset,
    0 20px 60px -20px rgba(0,0,0,0.25),
    0 0 40px -10px rgba(var(--primary-rgb, 127,13,242), 0.12);
  aspect-ratio: 10 / 20;
  height: 100%;
  width: auto;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 760px) {
  .tt-board-wrap {
    height: auto;
    width: 100%;
  }
}

.tt-board {
  display: grid;
  width: 100%;
  height: 100%;
  gap: 1px;
  /* Theme-aware playfield. In dark mode this is near-black; in light
     mode it's a soft off-white that doesn't compete with the pieces. */
  background: var(--color-bg);
  border-radius: 10px;
  overflow: hidden;
  /* Stronger gridlines so the empty cells read on both light and dark.
     A neutral mid-gray tint with enough alpha to show on white. */
  background-image:
    linear-gradient(to right, rgba(128,128,128,0.14) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(128,128,128,0.14) 1px, transparent 1px);
  background-size: 10% 5%;
}

/* ============================================================
 * Cell
 * ============================================================ */

.tt-cell {
  position: relative;
  background: transparent;
  transition: background 60ms linear;
}

.tt-cell.is-empty {
  /* Mode-independent neutral tint — enough contrast to read on white. */
  background: rgba(128,128,128,0.08);
}

.tt-cell.is-filled {
  background: var(--fill);
  background: linear-gradient(140deg,
    color-mix(in oklab, var(--fill) 100%, white 8%) 0%,
    var(--fill) 55%,
    color-mix(in oklab, var(--fill) 100%, black 18%) 100%);
  box-shadow:
    inset 0 1px 0 0 color-mix(in oklab, var(--edge) 100%, white 10%),
    inset 0 0 0 1px color-mix(in oklab, var(--fill) 100%, black 24%);
  border-radius: 2px;
}

.tt-cell.is-ghost {
  /* Ghost outline shows where the piece will land. Use the piece's
     own fill color (not the lighter edge) so it stays readable on white. */
  background: color-mix(in srgb, var(--fill) 14%, transparent);
  border: 1.5px dashed color-mix(in srgb, var(--fill) 70%, transparent);
  border-radius: 2px;
}

@keyframes tt-clear-flash {
  0%   { background: var(--fill); filter: brightness(1) saturate(1); transform: scale(1); }
  40%  { background: #fff; filter: brightness(2.4) saturate(0); transform: scale(1.06); }
  100% { background: transparent; filter: brightness(1); transform: scale(0.7); opacity: 0; }
}
.tt-cell.is-clearing {
  animation: tt-clear-flash 180ms ease-out forwards;
}

/* ============================================================
 * Mini piece preview (used in Hold + Next)
 * ============================================================ */

.tt-mini {
  display: grid;
  gap: 2px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 4px;
  aspect-ratio: 4 / 3;
  width: 100%;
}
.tt-mini.is-dim {
  /* When canHold is false the slot is locked until next spawn. Keep the
     piece clearly visible — just hint at the disabled state with a softer
     border and a small lock indicator. */
  opacity: 0.85;
  position: relative;
}
.tt-mini.is-dim::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}
.tt-mini-empty {
  aspect-ratio: 4 / 3;
  width: 100%;
  background: var(--color-bg);
  border: 1px dashed var(--color-border);
  border-radius: 6px;
}

/* ============================================================
 * HUD
 * ============================================================ */

.tt-hud {
  grid-area: hud;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  min-width: 0;
  /* Allow the HUD to scroll internally if the board is very tall and
     there are many history rows — never push the layout. */
  overflow-y: auto;
  padding-right: 2px;
}

@media (max-width: 760px) {
  .tt-hud {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
    overflow: visible;
  }
  .tt-hud-section,
  .tt-hud-grid {
    flex: 1 1 calc(50% - 5px);
    min-width: 140px;
  }
  .tt-hud-history { flex-basis: 100%; }
}

.tt-hud-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

/* Hold + Next sit side-by-side on desktop to save vertical space. */
.tt-hud-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2.4fr);
  gap: 8px;
  flex-shrink: 0;
}
@media (max-width: 760px) {
  .tt-hud-pair {
    grid-template-columns: 1fr 2fr;
    flex-basis: 100%;
  }
}

.tt-hud-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tt-hud-stat {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tt-hud-stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-hi);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.tt-hud-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.tt-hud-score {
  font-size: 24px;
  font-weight: 800;
  color: var(--color-primary);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  text-shadow: 0 0 24px rgba(var(--primary-rgb, 127,13,242), 0.3);
}

.tt-hud-meta {
  font-size: 11px;
  color: var(--text-muted);
}
.tt-hud-meta strong {
  color: var(--text-md);
  font-variant-numeric: tabular-nums;
}

/* Horizontal next-queue — keeps the HUD short so it aligns with the
   board on desktop. Three mini pieces side by side. */
.tt-hud-queue {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.tt-hud-queue .tt-mini { aspect-ratio: 4 / 3; }

/* History list */
.tt-hud-history {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}
.tt-hud-history-list {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 2px;
  scrollbar-width: thin;
}
.tt-history-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  gap: 8px;
  padding: 6px 8px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.tt-history-score {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-hi);
}
.tt-history-meta {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tt-history-when {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}
.tt-history-empty {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  padding: 12px 8px;
}

/* Floating "Tetris ×B2B" flash that fades out near the score */
.tt-hud-clear-flash {
  position: absolute;
  top: 50px;
  right: -8px;
  background: var(--color-primary);
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  box-shadow: 0 8px 24px -6px rgba(var(--primary-rgb, 127,13,242), 0.6);
  animation: tt-flash 1100ms ease-out forwards;
  pointer-events: none;
  z-index: 4;
}
@keyframes tt-flash {
  0%   { opacity: 0; transform: translateY(-6px) scale(0.9); }
  20%  { opacity: 1; transform: translateY(0) scale(1.05); }
  60%  { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-12px) scale(0.95); }
}

/* ============================================================
 * Pause button (top-right of board)
 * ============================================================ */

.tt-pause-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--text-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  z-index: 3;
  transition: all 150ms;
}
.tt-pause-btn:hover {
  color: #fff;
  border-color: rgba(var(--primary-rgb, 127,13,242), 0.4);
  background: rgba(var(--primary-rgb, 127,13,242), 0.18);
}
.tt-pause-btn .material-symbols-outlined { font-size: 18px; }

/* ============================================================
 * Overlays (start, pause, game over)
 * ============================================================ */

.tt-overlay {
  position: absolute;
  inset: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Theme-aware scrim — mixes the app canvas color with transparency
     so light mode gets a light wash, dark mode gets a dark wash. */
  background: color-mix(in srgb, var(--color-bg) 80%, transparent);
  backdrop-filter: blur(8px);
  border-radius: 10px;
  z-index: 5;
  padding: 16px;
  animation: tt-fade-in 200ms ease-out;
}
@keyframes tt-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.tt-overlay-card {
  width: 100%;
  max-width: 360px;
  max-height: 100%;
  overflow: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  padding: 22px 20px;
  box-shadow:
    0 30px 60px -20px rgba(0,0,0,0.35),
    0 0 40px -8px rgba(var(--primary-rgb, 127,13,242), 0.2);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
  color: var(--text-hi);
}

.tt-overlay-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.tt-overlay-brand .material-symbols-outlined {
  font-size: 28px;
  color: var(--color-primary);
}
.tt-overlay-brand h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text-hi);
}

.tt-overlay-sub {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.tt-overlay-banner {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 auto;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(251,191,36,0.14);
  color: #fcd34d;
  border: 1px solid rgba(251,191,36,0.3);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.tt-overlay-banner .material-symbols-outlined { font-size: 14px; }

.tt-overlay-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  gap: 6px;
  padding: 10px 0;
  border-top: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
}
.tt-overlay-stats > div { display: flex; flex-direction: column; gap: 2px; }
.tt-overlay-bignum {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-hi);
  font-variant-numeric: tabular-nums;
}

.tt-overlay-meta-line {
  font-size: 12px;
  color: var(--text-muted);
}
.tt-overlay-meta-line strong {
  color: var(--text-hi);
  font-variant-numeric: tabular-nums;
}

/* Helper toggles on the start overlay */
.tt-helpers {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}
.tt-helpers-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.tt-helper-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text-md);
  transition: all 120ms;
}
.tt-helper-chip:hover {
  border-color: rgba(var(--primary-rgb, 127,13,242), 0.4);
}
.tt-helper-chip.is-on {
  border-color: rgba(var(--primary-rgb, 127,13,242), 0.4);
  background: rgba(var(--primary-rgb, 127,13,242), 0.08);
  color: var(--text-hi);
}
.tt-helper-chip.is-off {
  opacity: 0.7;
}
.tt-helper-chip .material-symbols-outlined {
  font-size: 18px;
  color: var(--color-primary);
}
.tt-helper-chip.is-off .material-symbols-outlined {
  color: var(--text-muted);
}
.tt-helper-chip span {
  font-size: 11px;
  font-weight: 600;
}
.tt-helper-state {
  font-size: 9px !important;
  font-weight: 700 !important;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted) !important;
}
.tt-helper-chip.is-on .tt-helper-state {
  color: var(--color-primary) !important;
}

.tt-overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tt-overlay-actions .lh-btn {
  justify-content: center;
  padding: 10px 14px;
}

/* Controls hint disclosure */
.tt-controls-hint {
  text-align: left;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 10px 12px;
}
.tt-controls-hint summary {
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tt-controls-hint summary::after {
  content: '+';
  font-size: 14px;
  color: var(--text-muted);
}
.tt-controls-hint[open] summary::after { content: '–'; }
.tt-controls-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-md);
}
.tt-controls-grid kbd {
  font-family: var(--font-mono, ui-monospace, monospace);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  color: var(--text-hi);
}

/* ============================================================
 * Touch controls (mobile)
 * ============================================================ */

.tt-touch-bar {
  display: none;
  gap: 8px;
  padding: 8px 0 4px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 720px;
}

/* Show touch controls on small viewports OR coarse pointers */
@media (max-width: 700px), (pointer: coarse) {
  .tt-touch-bar { display: flex; }
}

.tt-touch-btn {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--text-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  flex-direction: column;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: all 100ms;
}
.tt-touch-btn:active {
  background: rgba(var(--primary-rgb, 127,13,242), 0.22);
  color: #fff;
  transform: scale(0.95);
}
.tt-touch-btn-wide {
  width: auto;
  padding: 0 18px;
  flex-direction: row;
}
.tt-touch-btn .material-symbols-outlined { font-size: 22px; }
.tt-touch-btn-wide .material-symbols-outlined { font-size: 18px; }

/* ============================================================
 * Settings panel (inside Settings → Tools → Block Classic)
 * ============================================================ */

.tt-settings {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.tt-settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 10px;
}
.tt-settings-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-hi);
}
.tt-settings-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.tt-settings-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 14px 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  margin-top: 4px;
}
.tt-settings-stats > div {
  display: flex; flex-direction: column; gap: 2px;
}
.tt-settings-stat-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-hi);
  font-variant-numeric: tabular-nums;
}
