/* ===========================================================================
   COMPONENTS — the shared furniture every game is built from.
   One button set, one panel, one HUD, one overlay, one arena. A game that
   needs something new adds a modifier here rather than inventing its own.
   =========================================================================== */

/* ===========================
   BUTTONS
   =========================== */
button {
  font-family: var(--font-sans);
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 28px;
  font-size: 0.98rem;
  font-weight: 600;
  font-family: var(--font-sans);
  line-height: 1.2;
  color: var(--accent-contrast);
  background: var(--game-accent);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast),
              box-shadow var(--transition-fast), border-color var(--transition-fast),
              color var(--transition-fast);
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--game-accent-soft);
  filter: brightness(1.06);
}

.btn:active {
  transform: translateY(0) scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn--secondary {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--card-border);
}

.btn--secondary:hover {
  border-color: var(--game-accent);
  color: var(--game-accent);
  filter: none;
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
  padding: 8px 14px;
}

.btn--ghost:hover {
  color: var(--game-accent);
  background: var(--accent-subtle);
  box-shadow: none;
  filter: none;
}

.btn--sm {
  padding: 8px 18px;
  font-size: 0.85rem;
}

.btn--block {
  width: 100%;
}

/* Pill selectors — difficulty pickers, mode switches */
.choice-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.choice {
  padding: 9px 20px;
  font-size: 0.86rem;
  font-weight: 600;
  font-family: var(--font-sans);
  background: transparent;
  border: 1px solid var(--card-border);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast),
              border-color var(--transition-fast), transform var(--transition-fast);
}

.choice:hover {
  border-color: var(--game-accent);
  color: var(--game-accent);
  transform: translateY(-1px);
}

.choice[aria-pressed="true"] {
  background: var(--game-accent);
  border-color: var(--game-accent);
  color: #fff;
}

/* ===========================
   INPUTS
   =========================== */
.field {
  padding: 11px 16px;
  font-size: 0.95rem;
  font-family: var(--font-sans);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  outline: none;
  width: 100%;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.field:focus {
  border-color: var(--game-accent);
  box-shadow: 0 0 0 3px var(--game-accent-soft);
}

.field::placeholder {
  color: var(--text-tertiary);
  opacity: 0.9;
}

.field--mono {
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

/* ===========================
   GAME CARD GRID
   =========================== */
.games-section {
  padding: 8px 24px 120px;
  width: 100%;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(248px, 1fr));
  gap: 24px;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 24px;
}

.game-card {
  position: relative;
  display: flex;
  flex-direction: column;
  text-align: left;
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--card-shadow);
  cursor: pointer;
  padding: 0;
  font-family: var(--font-sans);
  color: inherit;
  transition: transform var(--transition-base), box-shadow var(--transition-base),
              border-color var(--transition-base);
}

.game-card:hover,
.game-card:focus-visible {
  transform: translateY(-6px);
  border-color: var(--game-accent);
  box-shadow: 0 8px 40px var(--game-accent-soft);
}

.game-card__strip {
  height: 6px;
  width: 100%;
  background: linear-gradient(135deg, var(--game-accent), color-mix(in srgb, var(--game-accent) 45%, #fff));
  flex-shrink: 0;
}

.game-card__body {
  padding: 26px 24px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  flex: 1;
}

.game-card__icon {
  width: 76px;
  height: 76px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.game-card__title {
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.game-card__tagline {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 0;
}

/* Your best for this game, in the card and again in the arena toolbar. There
   is no global board any more, so this is the only number you're chasing. */
.game-card__best {
  margin-top: auto;
  padding: 4px 12px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-family: var(--font-mono);
  color: var(--game-accent);
  background: var(--game-accent-soft);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

/* ===========================
   GAME SHELL
   The skeleton every game view shares.
   =========================== */
.game-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 100%;
  max-width: 900px;
  padding: 24px 24px 60px;
}

.game-shell--wide { max-width: 1040px; }
.game-shell--narrow { max-width: 700px; }

.game-shell__head {
  text-align: center;
}

.game-shell__head h1 {
  font-size: clamp(1.7rem, 3vw, 2.3rem);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.game-shell__tagline {
  color: var(--text-secondary);
  font-size: 0.98rem;
  margin-top: 4px;
}

/* One toolbar under every arena, in the same place, with the same controls. */
.game-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  flex-wrap: wrap;
}

.game-tools__best {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-align: center;
  flex: 1;
}

.game-tools__best:empty { display: none; }

/* ===========================
   ARENA — the one game surface
   =========================== */
/* The arena is a panel on the page, built from the same glass-card language as
   the menu cards — not a separate screen dropped on top of the site. */
.arena {
  position: relative;
  width: 100%;
  min-height: min(540px, 68vh);
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(130% 100% at 50% 0%, var(--arena-bg-alt), var(--arena-bg));
  border: 1px solid var(--arena-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--arena-shadow);
  overflow: hidden;
  color: var(--arena-ink);
  isolation: isolate;
}

/* A quiet dot grid marks it as a play surface in both themes, where the old
   white starfield only worked on black. */
.arena::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: radial-gradient(circle at center, var(--arena-grid) 1px, transparent 1px);
  background-size: 26px 26px;
  mask-image: radial-gradient(120% 100% at 50% 0%, #000 35%, transparent 85%);
  -webkit-mask-image: radial-gradient(120% 100% at 50% 0%, #000 35%, transparent 85%);
}

.arena__stage {
  position: relative;
  flex: 1;
  min-height: 0;
  z-index: var(--z-arena);
}

.arena--plain::before { display: none; }

.arena.shake {
  animation: arena-shake 0.4s ease-out;
}

@keyframes arena-shake {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(-5px, 2px); }
  30% { transform: translate(4px, -3px); }
  45% { transform: translate(-3px, 3px); }
  60% { transform: translate(3px, -2px); }
  80% { transform: translate(-2px, 1px); }
}

/* ===========================
   HUD
   =========================== */
.hud {
  position: relative;
  z-index: var(--z-arena-ui);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 18px;
  background: var(--hud-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--arena-line);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--hud-ink);
  flex-shrink: 0;
}

.hud__group {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.hud__item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}

.hud__label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.66rem;
  color: var(--arena-ink-dim);
}

.hud__value {
  font-family: var(--font-mono);
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--arena-ink);
  font-variant-numeric: tabular-nums;
}

.hud__value--accent { color: var(--game-accent); }
.hud__value--good { color: var(--success); }
.hud__value--bad { color: var(--danger); }

/* Hearts / lives */
.hud__lives {
  display: flex;
  gap: 4px;
}

.life {
  font-size: 1rem;
  color: var(--danger);
  transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.life.lost {
  opacity: 0.22;
  transform: scale(0.8);
}

/* Meter (health, progress, timer) */
.meter {
  width: 96px;
  height: 7px;
  background: var(--arena-line);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.meter__fill {
  height: 100%;
  width: 100%;
  border-radius: var(--radius-full);
  background: var(--success);
  transition: width 0.25s var(--ease-out), background var(--transition-fast);
}

.meter__fill.low { background: var(--danger); }

/* ===========================
   OVERLAY + PANEL
   Setup screens and results screens are the same component in the same slot.
   =========================== */
.overlay {
  position: absolute;
  inset: 0;
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--scrim);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: fadeIn 0.3s var(--ease-out);
  overflow-y: auto;
}

.overlay[hidden] { display: none; }

.panel {
  /* Glass over an opaque base so it stays legible on top of a dark arena in
     both themes. */
  background-color: var(--bg-primary);
  background-image: linear-gradient(var(--glass-bg), var(--glass-bg));
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 18px 50px rgba(26, 29, 46, 0.14);
  color: var(--text-primary);
  padding: 30px 34px;
  width: 100%;
  max-width: 440px;
  max-height: 100%;
  overflow-y: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.panel--wide { max-width: 560px; }

.panel__eyebrow {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--game-accent);
}

.panel h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
  color: var(--text-primary);
}

.panel h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--game-accent);
}

.panel p {
  color: var(--text-secondary);
  font-size: 0.94rem;
  line-height: 1.6;
  margin: 0;
}

.panel__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 4px;
}

.panel__hint {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  line-height: 1.6;
}

.panel__hint kbd {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  padding: 2px 7px;
  margin: 0 1px;
  border-radius: 5px;
  background: var(--bg-tertiary);
  border: 1px solid var(--card-border);
  color: var(--text-primary);
  box-shadow: 0 1.5px 0 var(--divider);
}

/* Big result figure — score, time, grade */
.result-figure {
  font-size: 2.9rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--game-accent);
  font-variant-numeric: tabular-nums;
}

.result-grade {
  width: 78px;
  height: 78px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--game-accent);
  background: var(--game-accent-soft);
  border: 2px solid var(--game-accent);
}

/* ===========================
   STATS GRID
   =========================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
  width: 100%;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
}

.stat__label {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.stat__value {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.stat__value--good { color: var(--success); }
.stat__value--warn { color: var(--warning); }
.stat__value--bad  { color: var(--danger); }

/* Scrollable learn-list (keyboard recap, bug hunt recap) */
.recap {
  width: 100%;
  max-height: 190px;
  overflow-y: auto;
  text-align: left;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  background: var(--accent-subtle);
  padding: 10px 12px;
}

.recap__item {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid var(--divider);
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.recap__item:last-child { border-bottom: none; }

.recap__item strong {
  color: var(--game-accent);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  flex-shrink: 0;
}

/* ===========================
   COUNTDOWN
   =========================== */
.countdown {
  position: absolute;
  inset: 0;
  z-index: calc(var(--z-overlay) + 1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(4rem, 16vw, 8rem);
  font-weight: 800;
  color: var(--arena-ink);
  text-shadow: 0 0 40px var(--game-accent);
  pointer-events: none;
}

.countdown.pop {
  animation: countdown-pop 0.6s var(--ease-out);
}

@keyframes countdown-pop {
  0%   { transform: scale(0.4); opacity: 0; }
  35%  { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 0.85; }
}

/* ===========================
   FLOATING FEEDBACK (hit/miss judgements)
   =========================== */
.judgement {
  position: absolute;
  z-index: calc(var(--z-arena-ui) + 1);
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  pointer-events: none;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  animation: judgement-float 0.55s var(--ease-out) forwards;
}

.judgement--perfect { color: var(--success); text-shadow: 0 0 14px var(--success-soft); }
.judgement--good    { color: var(--warning); text-shadow: 0 0 14px var(--warning-soft); }
.judgement--miss    { color: var(--danger);  text-shadow: 0 0 14px var(--danger-soft); }

@keyframes judgement-float {
  0%   { opacity: 1; transform: translate(-50%, -50%) scale(0.8); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1.15); }
}

/* ===========================
   TOAST — replaces alert()
   =========================== */
.toast-stack {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: min(420px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  border-radius: var(--radius-full);
  background-color: var(--bg-primary);
  background-image: linear-gradient(var(--glass-bg), var(--glass-bg));
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.22);
  color: var(--text-primary);
  font-size: 0.88rem;
  font-weight: 600;
  animation: toast-in 0.28s var(--ease-out);
  max-width: 100%;
}

.toast--error { border-color: var(--danger); color: var(--danger); }
.toast--success { border-color: var(--success); color: var(--success); }

.toast.leaving { animation: toast-out 0.24s var(--ease-out) forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(10px) scale(0.97); }
}

/* ===========================
   TOUCH CONTROLS
   Rendered by core/input.js from each game's `controls` descriptor.
   Only ever visible on coarse pointers.
   =========================== */
.touch-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: calc(var(--z-arena-ui) + 2);
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 16px 18px calc(16px + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}

@media (pointer: coarse) {
  .touch-controls { display: flex; }
}

body.force-touch-controls .touch-controls { display: flex; }

.touch-cluster {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.touch-btn {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--arena-chip);
  border: 1px solid var(--arena-line);
  color: var(--arena-ink);
  font-size: 1.3rem;
  font-weight: 700;
  font-family: var(--font-sans);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.touch-btn.pressed {
  background: var(--game-accent);
  border-color: var(--game-accent);
  color: #fff;
  transform: scale(0.94);
}

.touch-btn--wide {
  width: 84px;
}
