/* ============================================================
   GeoMapes — style.css (v0.1.0)
   Tokens: assets/brand/tokens.css (paleta, tipografia, espaiat)
   Arquitectura: reset → layout global → header → screens →
                 components (cards, buttons, tray, modal)
============================================================ */

/* ── Reset mínim ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: var(--fs-md);
  line-height: var(--lh-base);
  color: var(--c-text);
  background: var(--c-bg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

img, svg { display: block; max-width: 100%; }
a { color: var(--c-brand); text-decoration: underline; }
a:hover { color: var(--c-brand-600); }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
ul, ol { list-style: none; }
dialog { border: none; }

/* ── Focus visible global ────────────────────────────────── */
:focus-visible {
  outline: 3px solid var(--c-brand-400);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* ═══════════════════════════════════════════════════════════
   LAYOUT GLOBAL
═══════════════════════════════════════════════════════════ */
#app {
  flex: 1;
  display: grid;
  grid-template-rows: 1fr;
  overflow: hidden;
  position: relative;
}

/* ── Pantalla (screen) ────────────────────────────────────── */
.screen {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease);
  padding: var(--sp-6) var(--sp-4);
}

.screen.screen--active {
  opacity: 1;
  pointer-events: auto;
}

/* ═══════════════════════════════════════════════════════════
   HEADER
═══════════════════════════════════════════════════════════ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-6);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: 60px;
}

.header-logo {
  display: flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
}
.header-logo img { height: 40px; width: auto; }

.header-nav {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* ── Selector idioma ────────────────────────────────────── */
.lang-toggle {
  display: flex;
  background: var(--c-surface-2);
  border-radius: var(--radius-pill);
  padding: 2px;
  gap: 2px;
}

.btn-lang {
  font-family: var(--font-head);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  letter-spacing: .04em;
  line-height: 1;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  color: var(--c-text-muted);
  transition: background var(--dur-fast), color var(--dur-fast);
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-lang[aria-pressed="true"],
.btn-lang.active {
  background: var(--c-brand);
  color: var(--c-text-on-brand);
}

.btn-lang:hover:not([aria-pressed="true"]):not(.active) {
  background: var(--c-border);
  color: var(--c-text);
}

/* ── Botó icona (header + controls) ─────────────────────── */
.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  border-radius: var(--radius-sm);
  color: var(--c-text-muted);
  transition: background var(--dur-fast), color var(--dur-fast);
}

.btn-icon:hover { background: var(--c-surface-2); color: var(--c-text); }
.btn-icon svg { width: 20px; height: 20px; flex-shrink: 0; }

/* ═══════════════════════════════════════════════════════════
   SCREEN: HOME — selector de mapes
═══════════════════════════════════════════════════════════ */
.home-hero {
  text-align: center;
  padding: var(--sp-8) var(--sp-4) var(--sp-6);
  max-width: 600px;
  margin: 0 auto;
}

.home-title {
  font-family: var(--font-head);
  font-size: var(--fs-3xl);
  font-weight: var(--fw-black);
  color: var(--c-brand-600);
  line-height: var(--lh-tight);
  margin-bottom: var(--sp-2);
}

.home-sub {
  font-size: var(--fs-lg);
  color: var(--c-text-muted);
}

/* Graella de mapes */
.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--sp-4);
  padding: var(--sp-2) 0 var(--sp-8);
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

/* Card de mapa (real) */
.map-card {
  background: var(--c-surface);
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--dur-base) var(--ease), box-shadow var(--dur-base);
  display: flex;
  flex-direction: column;
  min-height: 220px;
}

.map-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--c-brand-300);
}

.map-card:focus-within { box-shadow: var(--shadow-focus); }

.map-card__thumb {
  height: 140px;
  background: var(--c-map-land);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.map-card__thumb svg { width: 100%; height: 100%; }

.map-card__body {
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  flex: 1;
}

.map-card__name {
  font-family: var(--font-head);
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  color: var(--c-brand-600);
  line-height: var(--lh-snug);
}

.map-card__desc {
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
}

.map-card__cats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  margin-top: var(--sp-2);
}

.cat-chip {
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semi);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--c-brand-50);
  color: var(--c-brand-600);
  border: 1px solid var(--c-brand-100);
}

/* Card placeholder — animació skeleton */
.map-card--placeholder { cursor: default; pointer-events: none; }
.map-card--placeholder:hover { transform: none; box-shadow: none; }

.skel {
  display: block;
  background: linear-gradient(90deg, var(--c-surface-2) 25%, var(--c-border) 50%, var(--c-surface-2) 75%);
  background-size: 200% 100%;
  animation: skel-shine 1.4s ease-in-out infinite;
  border-radius: var(--radius-xs);
}

.skel--img  { height: 140px; border-radius: 0; }
.skel--line { height: 18px; margin: var(--sp-4) var(--sp-4) 0; }
.skel--short { width: 60%; margin-top: var(--sp-2); margin-bottom: var(--sp-4); }

@keyframes skel-shine {
  0%   { background-position: 200% center; }
  100% { background-position: -200% center; }
}

/* ═══════════════════════════════════════════════════════════
   SCREEN: CONFIGURADOR
═══════════════════════════════════════════════════════════ */
.config-wrap {
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
}

.config-header {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

.config-map-name {
  font-family: var(--font-head);
  font-size: var(--fs-2xl);
  font-weight: var(--fw-black);
  color: var(--c-brand-600);
}

.config-section { margin-bottom: var(--sp-6); }
.config-section-title {
  font-family: var(--font-head);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--c-text-muted);
  margin-bottom: var(--sp-3);
}

/* Llista categories */
.category-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

/* Cards de mode */
.mode-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-3);
}

.mode-card {
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  cursor: pointer;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}

.mode-card input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; }
.mode-card:has(input:checked) {
  border-color: var(--c-brand);
  background: var(--c-brand-bg);
}

.mode-icon { font-size: 1.5rem; }
.mode-name { font-family: var(--font-head); font-weight: var(--fw-bold); font-size: var(--fs-md); color: var(--c-text); }
.mode-desc { font-size: var(--fs-sm); color: var(--c-text-muted); }

/* Opcions checkboxes */
.config-section--opts { display: flex; flex-direction: column; gap: var(--sp-3); }

.opt-toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  cursor: pointer;
  min-height: var(--tap-min);
}

.opt-toggle input[type="checkbox"] {
  width: 20px; height: 20px;
  accent-color: var(--c-brand);
  cursor: pointer;
  flex-shrink: 0;
}

.opt-label { font-size: var(--fs-md); color: var(--c-text); }

/* Stepper de nombre d'elements (examen / contrarellotge) */
.count-stepper {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  margin-top: var(--sp-2);
}
.count-step {
  width: 38px;
  height: 38px;
  border: 2px solid var(--c-border);
  border-radius: 50%;
  background: none;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, background .15s;
}
.count-step:hover { border-color: var(--c-brand); background: color-mix(in srgb, var(--c-brand) 8%, transparent); }
.count-val {
  min-width: 52px;
  text-align: center;
  font-family: var(--font-head);
  font-weight: var(--fw-bold);
  font-size: 1.15rem;
  color: var(--c-text);
}
.count-hint {
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
  margin-top: var(--sp-2);
}

.btn-back {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
  font-family: inherit;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  transition: background var(--dur-fast);
  min-height: var(--tap-min);
  flex-shrink: 0;
}
.btn-back:hover { background: var(--c-surface-2); color: var(--c-text); }

/* ═══════════════════════════════════════════════════════════
   SCREEN: JOC
═══════════════════════════════════════════════════════════ */
#screen-game {
  padding: 0;
  overflow: hidden;
}

/* Quan el joc és actiu ocupa tota la finestra (per sobre de header/footer) */
#screen-game.screen--active {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
}

.game-layout {
  display: flex;
  flex-direction: row;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Zona dreta: topbar + mapa */
.game-right {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Topbar del joc */
.game-topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  min-height: 56px;
}

.game-mode-badge {
  font-family: var(--font-head);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--c-brand-50);
  color: var(--c-brand-600);
  border: 1px solid var(--c-brand-100);
  flex-shrink: 0;
}

.game-progress {
  flex: 1;
  height: 8px;
  background: var(--c-surface-2);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.game-progress-bar {
  height: 100%;
  background: var(--c-brand);
  border-radius: var(--radius-pill);
  transition: width var(--dur-slow) var(--ease);
  width: 0%;
}

.game-score {
  font-family: var(--font-head);
  font-size: var(--fs-xl);
  font-weight: var(--fw-black);
  color: var(--c-brand-600);
  flex-shrink: 0;
  min-width: 60px;
  text-align: right;
}

/* Safata lateral — alçada viewport completa, scroll propi independent */
.game-tray {
  flex-shrink: 0;
  width: 280px;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

/* Àrea mapa */
.game-map-area {
  flex: 1;
  min-height: 0;
  background: var(--c-map-ocean);
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
}
.game-map-area.is-panning { cursor: grabbing; }

/* Botons de zoom (overlaid sobre el mapa, fora del viewport transformable) */
.map-zoom-controls {
  position: absolute;
  bottom: var(--sp-4);
  right: var(--sp-4);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 3px;
  pointer-events: auto;
}
.zoom-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: 18px;
  font-weight: var(--fw-bold);
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  opacity: 0.88;
  transition: opacity var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
  user-select: none;
}
.zoom-btn:hover { opacity: 1; background: var(--c-surface-2); }
.zoom-btn:active { background: var(--c-brand-50); }
.zoom-btn.is-on { background: var(--c-brand); color: #fff; opacity: 1; }

/* Capa imatge realista — ara és un SVG <image> dins del SVG (alineat al viewBox) */
.map-photo-img {
  display: none;
  pointer-events: none;
}
.map-image-active .map-photo-img {
  display: block;
}

/* Quan la imatge és activa: fons oceà transparent (la foto el substitueix) */
#gameMapArea.map-image-active svg > rect:first-child {
  fill-opacity: 0;
}

/* Paths SVG semi-transparents perquè la foto es veja */
#gameMapArea.map-image-active svg path,
#gameMapArea.map-image-active svg polygon {
  fill-opacity: 0.18;
  stroke-opacity: 0.75;
}

/* El feedback manté plena opacitat */
#gameMapArea.map-image-active svg .map-correct,
#gameMapArea.map-image-active svg .map-error,
#gameMapArea.map-image-active svg .map-failed,
#gameMapArea.map-image-active svg .map-hint {
  fill-opacity: 0.85;
  stroke-opacity: 1;
}

/* ═══════════════════════════════════════════════════════════
   SCREEN: RESULTATS
═══════════════════════════════════════════════════════════ */
.results-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-6);
  padding: var(--sp-10) var(--sp-4);
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.results-score-hero {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.results-pct {
  font-family: var(--font-head);
  font-size: var(--fs-display);
  font-weight: var(--fw-black);
  color: var(--c-brand-600);
  line-height: 1;
}

.results-label {
  font-size: var(--fs-xl);
  color: var(--c-text-muted);
  margin-top: var(--sp-2);
}

.results-map-preview {
  width: 100%;
  max-width: 480px;
  aspect-ratio: 4/3;
  background: var(--c-map-land);
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--c-border);
  overflow: hidden;
}

.results-actions {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  justify-content: center;
}

/* ═══════════════════════════════════════════════════════════
   BOTONS GENERALS
═══════════════════════════════════════════════════════════ */
.btn {
  font-family: var(--font-head);
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  padding: var(--sp-3) var(--sp-6);
  border-radius: var(--radius-sm);
  min-height: var(--tap-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  transition: background var(--dur-fast), transform var(--dur-fast), box-shadow var(--dur-fast);
  text-decoration: none;
}

.btn:active { transform: translateY(1px); }

.btn--primary {
  background: var(--c-brand);
  color: var(--c-text-on-brand);
}
.btn--primary:hover { background: var(--c-brand-600); box-shadow: var(--shadow); }

.btn--secondary {
  background: var(--c-surface-2);
  color: var(--c-text);
  border: 1.5px solid var(--c-border);
}
.btn--secondary:hover { background: var(--c-border); }

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

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════
   MODALS
═══════════════════════════════════════════════════════════ */
.modal {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 560px;
  width: calc(100% - var(--sp-8));
  max-height: calc(90dvh - 68px);
  overflow: hidden;
  border: 1.5px solid var(--c-border);
  background: var(--c-surface);
  padding: 0;
  /* Evita que la barra sticky cobrisca la capçalera del modal */
  margin-top: 68px;
  margin-bottom: auto;
}

/* display:flex ONLY when dialog is open — prevents overriding UA display:none */
dialog[open].modal {
  display: flex;
  flex-direction: column;
}

.modal::backdrop {
  background: rgba(14, 23, 38, .55);
  backdrop-filter: blur(3px);
}

.modal-inner {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: calc(90dvh - 68px);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}

.modal-header h2 {
  font-family: var(--font-head);
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  color: var(--c-brand-600);
}

.modal-body {
  padding: var(--sp-5) var(--sp-6) var(--sp-6);
  overflow-y: auto;
  line-height: var(--lh-loose);
  color: var(--c-text-muted);
  font-size: var(--fs-md);
}

.modal-body p + p { margin-top: var(--sp-3); }

/* Crèdits dinàmics */
.credits-section-title {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semi);
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: var(--sp-2);
}

.credits-map-list {
  list-style: none;
  padding: 0;
  margin-bottom: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.credits-map-item {
  font-size: var(--fs-sm);
  line-height: var(--lh-normal);
}

.credits-map-item a {
  color: var(--c-brand);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.credits-map-item a:hover { color: var(--c-brand-600); }

.credits-img-attr {
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
}

/* Ajuda */
.help-steps { padding-left: var(--sp-5); }
.help-steps li {
  list-style: decimal;
  padding: var(--sp-1) 0;
}
.help-steps li + li { margin-top: var(--sp-2); }

.help-modes { margin-top: var(--sp-5); }
.help-modes h3 {
  font-family: var(--font-head);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--c-text-muted);
  margin-bottom: var(--sp-3);
}

.help-modes dl { display: grid; grid-template-columns: auto 1fr; gap: var(--sp-2) var(--sp-4); align-items: baseline; }
.help-modes dt { font-weight: var(--fw-bold); color: var(--c-text); }
.help-modes dd { color: var(--c-text-muted); }

/* ═══════════════════════════════════════════════════════════
   FOOTER
═══════════════════════════════════════════════════════════ */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-6);
  font-size: var(--fs-xs);
  color: var(--c-text-soft);
  border-top: 1px solid var(--c-border);
  background: var(--c-surface);
  gap: var(--sp-4);
}

.app-footer a { color: var(--c-text-muted); }
.footer-version { font-family: var(--font-mono); opacity: .6; flex-shrink: 0; }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  .app-header { padding: var(--sp-2) var(--sp-4); }
  .home-title { font-size: var(--fs-2xl); }
  .map-grid { grid-template-columns: 1fr 1fr; gap: var(--sp-3); }

  .game-layout {
    flex-direction: column;
  }

  .game-tray {
    width: 100%;
    flex-shrink: 0;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: 120px;
    border-right: none;
    border-bottom: 1px solid var(--c-border);
  }

  .game-right {
    flex: 1;
    min-height: 0;
  }

  .mode-list { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════════════════
   FASE 2 — TIMER (contrarellotge)
═══════════════════════════════════════════════════════════ */
.game-timer {
  font-family: var(--font-mono);
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  color: var(--c-accent-700);
  letter-spacing: .04em;
  flex-shrink: 0;
  min-width: 64px;
  text-align: right;
}

/* ═══════════════════════════════════════════════════════════
   FASE 2 — RESULTAT EXAMEN (vermell permanent)
═══════════════════════════════════════════════════════════ */
#gameMapArea svg .map-failed,
#resultsMapPreview svg .map-failed {
  fill: var(--c-error, #c8392a);
  stroke: #7a1a10;
}

/* ═══════════════════════════════════════════════════════════
   FASE 2 — RESULTATS COMPLETS
═══════════════════════════════════════════════════════════ */
.results-meta {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-lg);
}

.results-meta-label {
  color: var(--c-text-muted);
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: .07em;
  font-weight: var(--fw-bold);
  font-family: var(--font-head);
}

.results-meta-value {
  font-family: var(--font-mono);
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  color: var(--c-brand-600);
}

.results-record {
  background: var(--c-accent-100);
  border: 1.5px solid var(--c-accent-300);
  border-radius: var(--radius-pill);
  padding: var(--sp-2) var(--sp-6);
}

.results-record-text {
  font-family: var(--font-head);
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  color: var(--c-accent-700);
}

.results-ranking {
  width: 100%;
  max-width: 380px;
}

.results-ranking-title {
  font-family: var(--font-head);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--c-text-muted);
  margin-bottom: var(--sp-3);
  text-align: center;
}

.ranking-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.ranking-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  font-size: var(--fs-sm);
}

.ranking-item--best {
  border-color: var(--c-accent-300);
  background: var(--c-accent-100);
}

.ranking-pos {
  font-family: var(--font-head);
  font-weight: var(--fw-bold);
  color: var(--c-text-muted);
  text-align: right;
}

.ranking-item--best .ranking-pos { color: var(--c-accent-700); }

.ranking-time {
  font-family: var(--font-mono);
  font-weight: var(--fw-bold);
  color: var(--c-brand-600);
  font-size: var(--fs-md);
}

.ranking-item--best .ranking-time { color: var(--c-accent-700); }

.ranking-date {
  color: var(--c-text-soft);
  font-size: var(--fs-xs);
  text-align: right;
}

/* ═══════════════════════════════════════════════════════════
   FASE 1 — SAFATA D'ELEMENTS
═══════════════════════════════════════════════════════════ */
.tray-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-2);
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
  cursor: grab;
  user-select: none;
  touch-action: none;
  min-width: 72px;
  transition: border-color var(--dur-fast), background var(--dur-fast), opacity var(--dur-fast);
  flex-shrink: 0;
}

.tray-item:hover { border-color: var(--c-brand-300); background: var(--c-brand-bg); }

.tray-item--dragging {
  opacity: .4;
  cursor: grabbing;
}

.tray-item--placed {
  opacity: .35;
  cursor: default;
  pointer-events: none;
  border-color: var(--c-correct, #1c8f5c);
  background: color-mix(in srgb, var(--c-correct, #1c8f5c) 8%, var(--c-surface));
}

.tray-item--failed {
  opacity: .45;
  cursor: default;
  pointer-events: none;
  border-color: var(--c-error, #c8392a);
  background: color-mix(in srgb, var(--c-error, #c8392a) 8%, var(--c-surface));
}

.tray-item:focus-visible {
  outline: 2px solid var(--c-brand);
  outline-offset: 2px;
}

.tray-item--selected {
  border-color: var(--c-brand);
  background: color-mix(in srgb, var(--c-brand) 12%, var(--c-surface));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-brand) 30%, transparent);
  cursor: crosshair;
}

.tray-silhouette {
  width: 60px;
  height: 60px;
  color: var(--c-brand);
  flex-shrink: 0;
}

.tray-item--placed .tray-silhouette { color: var(--c-correct, #1c8f5c); }

.tray-line {
  width: 60px;
  height: 40px;
  color: var(--c-brand);
  flex-shrink: 0;
}

.tray-item--placed .tray-line { color: var(--c-correct, #1c8f5c); }

.tray-label {
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semi);
  color: var(--c-text);
  text-align: center;
  line-height: 1.2;
  word-break: break-word;
  max-width: 72px;
}

.tray-item--text-only {
  flex-direction: row;
  justify-content: center;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.tray-item--text-only .tray-label {
  max-width: none;
  font-size: var(--fs-xs);
}

/* ═══════════════════════════════════════════════════════════
   FASE 1 — GHOST (element arrossegat)
═══════════════════════════════════════════════════════════ */
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%) scale(0.85);
  opacity: .88;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-2);
  border: 2px solid var(--c-brand);
  border-radius: var(--radius);
  background: var(--c-surface);
  box-shadow: var(--shadow-md);
  width: 80px;
}

.drag-ghost .tray-silhouette { width: 56px; height: 56px; color: var(--c-brand); }
.drag-ghost .tray-line       { width: 56px; height: 36px; color: var(--c-brand); }
.drag-ghost .tray-label      { font-size: var(--fs-2xs); font-weight: var(--fw-semi); color: var(--c-text); text-align: center; max-width: 72px; }

/* Ghost icona: tots els elements — sense caixa ni etiqueta */
.drag-ghost--icon-only {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  padding: 0;
  width: auto;
  gap: 0;
}
.drag-ghost--icon-only .tray-pin { width: 28px; height: 28px; color: var(--c-accent, #d8a14a); filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }

/* ═══════════════════════════════════════════════════════════
   FASE 1 — HIGHLIGHT DE PROVINCES AL MAPA SVG
═══════════════════════════════════════════════════════════ */
#gameMapArea svg .map-correct {
  fill: var(--c-correct, #1c8f5c);
  stroke: #0d4a2d;
  transform-box: fill-box;
  transform-origin: center;
  animation: snap-bounce var(--dur-slow, .35s) cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes snap-bounce {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.07); }
  75%  { transform: scale(0.97); }
  100% { transform: scale(1); }
}

#gameMapArea svg .map-error {
  animation: map-error-flash .8s ease-out forwards;
}

@keyframes map-error-flash {
  0%   { fill: #d94f3d; }
  60%  { fill: #e8a090; }
  100% { fill: #f1e7d2; }
}

#gameMapArea svg .map-hint {
  fill: var(--c-accent, #d8a14a);
  fill-opacity: 0.35;
  stroke: var(--c-accent, #d8a14a);
  stroke-width: 2;
  animation: path-hint-pulse 1.3s ease-in-out infinite;
}

@keyframes path-hint-pulse {
  0%, 100% { fill-opacity: 0.2; stroke-opacity: 0.6; }
  50%       { fill-opacity: 0.5; stroke-opacity: 1; }
}

/* Resultat — provinces amb feedback complet */
/* Punts de localització (overlay opcional) */
.location-dot {
  fill: rgba(20, 20, 20, 0.45);
  stroke: #fff;
  stroke-width: 1.5;
  pointer-events: none;
}

#resultsMapPreview svg .map-correct { fill: var(--c-correct, #1c8f5c); stroke: #0d4a2d; }
#resultsMapPreview svg .map-error   { fill: var(--c-error, #c8392a); stroke: #7a1a10; }

/* Lines (rius, serralades) — feedback basat en stroke, no fill */
#gameMapArea svg #map-rius path.map-correct,
#gameMapArea svg #map-serralades path.map-correct {
  fill: none;
  stroke: var(--c-correct, #1c8f5c);
  stroke-width: 6;
}
#gameMapArea svg #map-rius path.map-error,
#gameMapArea svg #map-serralades path.map-error {
  fill: none;
  animation: line-error-flash .8s ease-out forwards;
}
#gameMapArea svg #map-rius path.map-failed,
#gameMapArea svg #map-serralades path.map-failed {
  fill: none;
  stroke: var(--c-error, #c8392a);
  stroke-width: 6;
}
#gameMapArea svg #map-rius path.map-hint,
#gameMapArea svg #map-serralades path.map-hint {
  fill: none;
  stroke: var(--c-accent, #d8a14a);
  stroke-width: 8;
  stroke-opacity: 0.7;
  animation: line-hint-pulse 1.3s ease-in-out infinite;
}
@keyframes line-error-flash {
  0%   { stroke: #d94f3d; stroke-width: 6; }
  60%  { stroke: #e8a090; stroke-width: 5; }
  100% { stroke: #4a90d9; stroke-width: 2.5; }
}
@keyframes line-hint-pulse {
  0%, 100% { stroke-opacity: 0.4; stroke-width: 6; }
  50%       { stroke-opacity: 0.9; stroke-width: 10; }
}

/* Lines overlay (rius-mon, serralades-mon) — paths dinàmics afegits al DOM */
#gameMapArea svg #lines-overlay path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
#gameMapArea svg #lines-overlay path.map-line--silhouette {
  stroke: rgba(50, 60, 80, 0.3);
  stroke-width: 2;
}
#gameMapArea svg #lines-overlay path.map-line--correct {
  stroke: var(--c-correct, #1c8f5c);
  stroke-width: 2.5;
  stroke-opacity: 0.85;
}
#gameMapArea svg #lines-overlay path.map-line--error {
  animation: line-error-flash .8s ease-out forwards;
}
#gameMapArea svg #lines-overlay path.map-line--failed {
  stroke: var(--c-error, #c8392a);
  stroke-width: 2.5;
  stroke-opacity: 0.7;
}
#gameMapArea svg #lines-overlay path.map-line--hint {
  stroke: var(--c-accent, #d8a14a);
  stroke-width: 3;
  stroke-opacity: 0.6;
  animation: line-hint-pulse 1.3s ease-in-out infinite;
}

/* ═══════════════════════════════════════════════════════════
   FASE 1 — CATEGORIA (selector al config)
═══════════════════════════════════════════════════════════ */
.cat-card {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: var(--fs-sm);
  font-family: var(--font-head);
  font-weight: var(--fw-semi);
  color: var(--c-text);
  transition: border-color var(--dur-fast), background var(--dur-fast);
  min-height: var(--tap-min);
}

.cat-card input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; }

.cat-card:has(input:checked) {
  border-color: var(--c-brand);
  background: var(--c-brand-bg);
  color: var(--c-brand-600);
}

.cat-card:hover { border-color: var(--c-brand-300); }

/* Selector de curs (espanya-fisica i futurs mapes amb courses[]) */
.course-list { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

.course-card {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: var(--fs-sm);
  font-family: var(--font-head);
  font-weight: var(--fw-semi);
  color: var(--c-text);
  transition: border-color var(--dur-fast), background var(--dur-fast);
  min-height: var(--tap-min);
}

.course-card input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; }

.course-card:has(input:checked) {
  border-color: var(--c-accent);
  background: color-mix(in srgb, var(--c-accent) 12%, transparent);
  color: var(--c-accent);
}

.course-card:hover { border-color: var(--c-accent); }

/* ═══════════════════════════════════════════════════════════
   FASE 1 — MISC
═══════════════════════════════════════════════════════════ */
.load-error {
  color: var(--c-error, #c0392b);
  font-size: var(--fs-sm);
  padding: var(--sp-4);
  text-align: center;
}

/* Thumbnail mapa — imatge SVG ocupa tota la caixa */
.map-card__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ═══════════════════════════════════════════════════════════
   MODE FOSC
═══════════════════════════════════════════════════════════ */
.theme-dark .map-card { background: var(--c-surface); border-color: var(--c-border); }
.theme-dark .app-header,
.theme-dark .app-footer,
.theme-dark .game-tray,
.theme-dark .game-topbar { background: var(--c-surface); }
.theme-dark .tray-item    { background: var(--c-surface); }
.theme-dark .drag-ghost   { background: var(--c-surface); }
.theme-dark .drag-ghost--icon-only { background: transparent; }
.theme-dark .ranking-item { background: var(--c-surface); }

/* ═══════════════════════════════════════════════════════════
   FASE 3 — PIN (elements puntuals a la safata)
═══════════════════════════════════════════════════════════ */
.tray-pin {
  width: 36px;
  height: 36px;
  color: var(--c-accent, #d8a14a);
  flex-shrink: 0;
}

.tray-item--placed .tray-pin { color: var(--c-correct, #1c8f5c); }

.drag-ghost .tray-pin { width: 32px; height: 32px; color: var(--c-accent, #d8a14a); }

/* ═══════════════════════════════════════════════════════════
   FASE 3 — MARCADORS SVG (overlay capitals)
═══════════════════════════════════════════════════════════ */
.map-marker-outer {
  fill-opacity: .25;
  stroke: none;
}

.map-marker-dot {
  fill-opacity: 1;
}

/* Correct — verd + bounce */
.map-marker--correct .map-marker-outer { fill: var(--c-correct, #1c8f5c); }
.map-marker--correct .map-marker-dot   { fill: var(--c-correct, #1c8f5c); }
.map-marker--correct {
  transform-box: fill-box;
  transform-origin: center;
  animation: snap-bounce var(--dur-slow, .35s) cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Failed — vermell permanent */
.map-marker--failed .map-marker-outer  { fill: var(--c-error, #c8392a); fill-opacity: .3; }
.map-marker--failed .map-marker-dot    { fill: var(--c-error, #c8392a); }

/* Error — flash ràpid (el JS l'elimina als 800ms) */
.map-marker--error .map-marker-outer   { fill: var(--c-error, #c8392a); fill-opacity: .35; }
.map-marker--error .map-marker-dot     { fill: var(--c-error, #c8392a); }
.map-marker--error {
  animation: marker-error-flash .8s ease-out forwards;
}

@keyframes marker-error-flash {
  0%   { opacity: 1; }
  70%  { opacity: .8; }
  100% { opacity: .5; }
}

/* Hint — ambre pulsant (mode professor) */
.map-marker--hint .map-marker-outer {
  fill: var(--c-accent, #d8a14a);
  fill-opacity: .45;
  transform-box: fill-box;
  transform-origin: center;
  animation: marker-hint-pulse 1.3s ease-in-out infinite;
}

.map-marker--hint .map-marker-dot {
  fill: var(--c-accent, #d8a14a);
}

@keyframes marker-hint-pulse {
  0%, 100% { transform: scale(1);   fill-opacity: .45; }
  50%       { transform: scale(1.6); fill-opacity: .12; }
}

/* ═══════════════════════════════════════════════════════════
   FASE 3 — BOTÓ PISTA (mode professor)
═══════════════════════════════════════════════════════════ */
.btn-icon.active {
  color: var(--c-accent-700, #9a6c1e);
  background: var(--c-accent-100, #fdf3e1);
}
