/* Blockfall — matches the games hub palette. Dark by default, light via prefers-color-scheme. */

:root {
  color-scheme: dark;
  --font-display: 'Bricolage Grotesque', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-body: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  --bg: #0d0d10;
  --surface: #17171c;
  --surface-2: #222229;
  --text: #f5f5f7;
  --muted: #a1a1aa;
  --line: #2a2a31;
  --accent: #b18cff;
  --on-accent: #150d24;
  --warn: #ffd23f;
  --danger: #ff5d5d;
  --focus: #ffd23f;

  /* Well (read by game.js, so the canvas follows light/dark) */
  --well: #111115;
  --well-cell: #1a1a20;
  --flash: #ffffff;

  /* Piece colors (game.js reads these names from PIECES in logic.js) */
  --p-i: #2fbf71;
  --p-o: #5aa9ff;
  --p-t: #ffd23f;
  --p-s: #ff6b6b;
  --p-z: #3dd6d0;
  --p-j: #ffa94d;
  --p-l: #b18cff;

  /* Sizes, set by game.js from the screen */
  --side: 112px;
  --play-gap: 16px;
  --well-pad: 8px;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f6f6f3;
    --surface: #ffffff;
    --surface-2: #ececea;
    --text: #141416;
    --muted: #55555e;
    --line: #dcdcd6;
    --accent: #8a63e8;
    --on-accent: #ffffff;
    --focus: #141416;
    --well: #e6e6e0;
    --well-cell: #f0f0ec;
    --flash: #8a63e8;
    --p-i: #1d9a58;
    --p-o: #2f7fe0;
    --p-t: #e8aa00;
    --p-s: #e04848;
    --p-z: #10a29c;
    --p-j: #e5791a;
    --p-l: #8a63e8;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background:
    radial-gradient(60rem 30rem at 15% -10%, rgba(177, 140, 255, 0.14), transparent 60%),
    radial-gradient(50rem 28rem at 110% 0%, rgba(61, 214, 208, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.topbar {
  width: 100%;
  max-width: 560px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}
.back {
  justify-self: start;
  display: inline-flex; align-items: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.95rem;
  padding: 6px 8px 6px 2px; border-radius: 10px;
}
.back:hover { color: var(--text); }
.back svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.5rem, 6vw, 2rem);
  letter-spacing: -0.03em;
  margin: 0;
}

/* ---- HUD ---- */

.hud {
  display: flex; align-items: stretch; gap: 8px;
  width: min(100%, 520px);
}
.stat {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; justify-content: center;
  padding: 5px 12px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line);
  font: 800 clamp(1rem, 4.2vw, 1.15rem) / 1.2 var(--font-display);
  font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stat-score { flex-grow: 1.6; }
.stat-label {
  font: 600 0.68rem / 1.3 var(--font-body);
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
}
.icon-btn {
  flex: none; width: 48px; border-radius: 14px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  display: grid; place-items: center; padding: 0;
  transition: transform 120ms ease;
}
.icon-btn:hover { border-color: var(--muted); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Play area: hold | well | next ---- */

.play {
  width: 100%;
  display: grid;
  grid-template-columns: var(--side) auto var(--side);
  justify-content: center;
  align-items: start;
  gap: var(--play-gap);
}
.side { display: flex; flex-direction: column; min-width: 0; }
.panel {
  width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 8px 4px 10px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line);
}
button.panel { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button.panel:hover { border-color: var(--muted); }
.panel-label {
  font: 600 0.68rem / 1.3 var(--font-body);
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
}
.panel canvas { display: block; }

.well-wrap {
  position: relative;
  padding: var(--well-pad);
  border-radius: 14px;
  background: var(--well);
  border: 1px solid var(--line);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#well { display: block; }

.overlay {
  position: absolute; inset: 0;
  border-radius: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 16px; text-align: center;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.overlay[hidden] { display: none; }
.overlay-title {
  margin: 0;
  font: 800 clamp(1.4rem, 6vw, 2rem) / 1.1 var(--font-display);
  letter-spacing: -0.03em;
}
.overlay-text { margin: 0 0 8px; color: var(--muted); font-size: 0.95rem; }
.primary {
  border: 0; cursor: pointer;
  padding: 10px 24px; border-radius: 999px;
  background: var(--accent); color: var(--on-accent);
  font-weight: 800;
  transition: transform 120ms ease;
}
.primary:active { transform: scale(0.96); }

/* ---- Touch buttons (shown for coarse pointers) ---- */

.touch {
  display: none;
  width: min(100%, 520px);
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.touch button {
  height: 58px; padding: 0; cursor: pointer;
  border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line);
  display: grid; place-items: center;
  -webkit-tap-highlight-color: transparent;
}
.touch button.down { background: var(--surface-2); border-color: var(--accent); }
.touch svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.touch-text { font: 800 0.85rem var(--font-display); }

.hint { margin: 0; max-width: 520px; text-align: center; color: var(--muted); font-size: 0.88rem; }
.hint-touch { display: none; }

@media (pointer: coarse) {
  .touch { display: grid; }
  .hint-keys { display: none; }
  .hint-touch { display: inline; }
}

.status {
  margin: 0; min-height: 1.6em; text-align: center;
  font: 800 1.25rem var(--font-display); letter-spacing: -0.01em;
}
.status.win { color: var(--accent); }
.status.lose { color: var(--danger); }
.best { margin: -10px 0 0; color: var(--muted); font-size: 0.9rem; min-height: 1.4em; }

@media (max-width: 519px) {
  .app { gap: 10px; }
  .best { margin-top: -6px; }
  .panel { padding: 6px 2px 8px; gap: 4px; }
}

@media (hover: none) { .icon-btn:hover, button.panel:hover { border-color: var(--line); } }
@media (prefers-reduced-motion: reduce) { .icon-btn, .primary { transition: none; } }
