/**
 * Wabtec Jigsaw — shared design tokens & utilities
 * Used by player screens and Settings (light brand alignment).
 */
:root {
  /* Core palette (player UI) */
  --bg-primary: #FFFFFF;
  --surface-secondary: #F5F5F5;
  --text-primary: #111111;
  --text-muted: #555555;
  --accent-red: #E31B23;
  --accent-red-dark: #c5141b;
  --accent-red-soft: rgba(227, 27, 35, 0.14);
  --dark-ui: #171717;
  --border: #D9D9D9;
  --success: #2E7D32;
  --warning: #E65100;
  --on-dark: #FFFFFF;

  /* Typography */
  --font-display: "Orbitron", sans-serif;
  --font-body: "Exo 2", "Segoe UI", system-ui, sans-serif;

  /* Spacing & radii */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 36px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  /* Elevation */
  --shadow-sm: 0 4px 14px rgba(17, 17, 17, 0.08);
  --shadow-md: 0 8px 22px rgba(17, 17, 17, 0.12);
  --shadow-lg: 0 18px 42px rgba(17, 17, 17, 0.16);
  --shadow-accent: 0 8px 20px rgba(227, 27, 35, 0.28);

  /* Motion */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --dur-fast: 0.18s;
  --dur-med: 0.28s;

  /* Settings (aligned to player red / dark, less neon) */
  --settings-bg: #f4f4f5;
  --settings-panel: #FFFFFF;
  --settings-panel-2: #F8F8F9;
  --settings-line: #E2E2E4;
  --settings-text: #171717;
  --settings-muted: #5c5c5c;
  --settings-sidebar: #171717;
  --settings-sidebar-text: #FFFFFF;
}

/* ---------- Shared chrome ---------- */
.corner-accent {
  position: fixed;
  pointer-events: none;
  z-index: 0;
  width: min(26vw, 380px);
  height: min(22vh, 220px);
}

.corner-tl {
  top: 0;
  left: 0;
  background: linear-gradient(135deg, var(--accent-red) 0%, var(--accent-red) 42%, transparent 43%);
  opacity: 0.92;
}

.corner-br {
  bottom: 0;
  right: 0;
  background: linear-gradient(315deg, var(--accent-red) 0%, var(--accent-red) 42%, transparent 43%);
  opacity: 0.92;
}

/* Focus ring for keyboard / kiosk nav */
:focus-visible {
  outline: 3px solid var(--accent-red);
  outline-offset: 3px;
}

a:focus:not(:focus-visible),
button:focus:not(:focus-visible) {
  outline: none;
}

/* Image CTA with visible text fallback */
.cta-img-btn {
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  color: inherit;
  transition: transform var(--dur-fast) ease, filter var(--dur-fast) ease;
}

.cta-img-btn img {
  display: block;
  height: auto;
  object-fit: contain;
}

.cta-img-btn .cta-label {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-red);
}

.cta-img-btn:hover,
.cta-img-btn:focus-visible {
  transform: translateY(-2px) scale(1.03);
  filter: drop-shadow(0 8px 18px rgba(227, 27, 35, 0.3));
}

.cta-img-btn:active {
  transform: scale(0.97);
}

.cta-img-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

/* Panel title when frame art is off / for a11y */
.panel-title {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-primary);
  text-align: center;
}

.panel-title-bar {
  width: min(40vw, 280px);
  height: 3px;
  background: var(--accent-red);
  border-radius: 2px;
  margin: 0.4rem auto 0;
}

/* Frame art toggle: keep PNGs by default; hide when body.no-frame-art */
body.no-frame-art .frame-art {
  display: none !important;
}

body.no-frame-art .welcome-frame,
body.no-frame-art .sel-panel,
body.no-frame-art .lb-panel,
body.no-frame-art .finish-panel {
  background: var(--bg-primary);
  border: 2px solid var(--dark-ui);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), 0 0 0 3px var(--accent-red);
  aspect-ratio: auto;
  max-height: none;
  min-height: min(60vh, 520px);
  padding: var(--space-lg);
}

body.no-frame-art .welcome-inner,
body.no-frame-art .sel-content,
body.no-frame-art .lb-content {
  position: relative;
  left: auto;
  right: auto;
  top: auto;
  bottom: auto;
  inset: auto;
}

body.no-frame-art .panel-title-fallback {
  display: block;
}

.panel-title-fallback {
  display: none;
  margin-bottom: var(--space-md);
}

body.no-frame-art .finish-time-val,
body.no-frame-art .finish-score-val {
  position: static;
  width: auto;
  margin: 0.35rem 0;
}

body.no-frame-art .finish-puzzle-slot {
  position: relative;
  left: auto;
  top: auto;
  width: min(70%, 420px);
  height: auto;
  margin: 0 auto 1rem;
  aspect-ratio: 16 / 10;
}

body.no-frame-art .finish-stats {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

body.no-frame-art .finish-stats-label {
  display: inline;
  font-family: var(--font-display);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.finish-stats-label {
  /* Hidden when frame art supplies labels */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body.no-frame-art .finish-stats-label {
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* Visually hidden but available to AT / screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Puzzle reveal interstitial */
.puzzle-reveal {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(6px);
  opacity: 1;
  transition: opacity var(--dur-med) ease;
}

.puzzle-reveal.hidden {
  opacity: 0;
  pointer-events: none;
}

.puzzle-reveal-kicker {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.puzzle-reveal-title {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-primary);
  text-align: center;
  max-width: 90vw;
}

.puzzle-reveal-bar {
  width: min(40vw, 220px);
  height: 4px;
  background: var(--accent-red);
  border-radius: 2px;
}

/* Progress track (puzzle HUD) */
.progress-track {
  display: block;
  width: 100%;
  height: 5px;
  margin-top: 4px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.22);
  overflow: hidden;
}

.progress-track-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-red);
  border-radius: inherit;
  transition: width var(--dur-fast) ease;
}

.timer-pill.low-time {
  border-color: var(--warning);
  animation: timer-pulse 0.9s ease-in-out infinite;
  box-shadow: 0 0 0 3px rgba(230, 81, 0, 0.25);
}

.timer-pill.low-time #timer {
  color: #FFB74D;
}

@keyframes timer-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

/* Hint chip with label */
.hint-btn.has-label {
  width: auto;
  min-width: 52px;
  height: auto;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  flex-direction: column;
  gap: 2px;
}

.hint-btn .hint-btn-label {
  font-family: var(--font-display);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 1;
}

/* ---------- Responsive helpers ---------- */
@media (max-width: 1100px), (orientation: portrait) {
  .puzzle-main-stack {
    grid-template-columns: 1fr !important;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .puzzle-main-stack .puzzle-trays-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    min-height: 140px;
    max-height: 28vh;
  }
}

@media (max-width: 720px) {
  .actions {
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center !important;
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .timer-pill.low-time {
    animation: none !important;
  }
}
