/* =============================================================================
   Train Express Runner : style harmonisé avec la charte Sacripland
   ============================================================================= */
:root {
  --bg: #F4F5F8;
  --surface: #FFFFFF;
  --fg: #1A1E29;
  --muted: #667085;
  --line: #D6DAE3;
  --accent: #2D5BE3;
  --accent-text: #FFFFFF;
  --ok: #1F8A5B;
  --warn: #E2552B;
  --font: 'DM Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151C;
    --surface: #1B2030;
    --fg: #E8EAF0;
    --muted: #98A2B3;
    --line: #2C3345;
    --accent: #7C9BFF;
    --accent-text: #12151C;
    --ok: #5FD3A0;
    --warn: #FF8A65;
  }
}

:root[data-theme="dark"] {
  --bg: #12151C;
  --surface: #1B2030;
  --fg: #E8EAF0;
  --muted: #98A2B3;
  --line: #2C3345;
  --accent: #7C9BFF;
  --accent-text: #12151C;
  --ok: #5FD3A0;
  --warn: #FF8A65;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 16px/1.4 var(--font);
  padding-block: 20px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.wrap {
  max-width: 400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

button, a { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }

.retour {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: .875rem;
}
.retour a { color: var(--muted); text-decoration: none; }
.retour a:hover { color: var(--fg); }
.solde { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ok); }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
h1 { font-size: 1.5rem; font-weight: 700; }
.ghost {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: .875rem;
  color: var(--muted);
}
.ghost:hover { color: var(--fg); border-color: var(--muted); }

.carte {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.carte h2 { font-size: 1.125rem; }
.carte p { color: var(--muted); }
.carte[hidden], #jeu[hidden], [hidden] { display: none !important; }

#jeu {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.hud {
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
}
.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.hud-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
}
.hud-val {
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

#status { min-height: 1.5em; font-weight: 500; text-align: center; }
.gainline { text-align: center; font-weight: 700; color: var(--ok); margin-top: -6px; }

/* Canvas des rails */
.canvas-wrap {
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  aspect-ratio: 3/4;
  background: #0f172a;
  border: 2px solid #f59e0b;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 8px 25px rgba(0,0,0,0.5);
  touch-action: none;
}
#plateau {
  width: 100%;
  height: 100%;
  display: block;
}

/* Boutons de changement de voie */
.voies-controles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.btn-voie {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  font-size: 1.2rem;
  font-weight: 700;
}
.btn-voie:active {
  background: var(--accent);
  color: var(--accent-text);
}

.actions { display: flex; justify-content: center; }
.primary {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 10px;
  padding: 12px 24px;
  font-weight: 700;
  font-size: 1rem;
  width: 100%;
}
.primary:hover:not(:disabled) { opacity: .9; }
.primary:disabled { opacity: .5; cursor: default; }

.note { font-size: .8125rem; color: var(--muted); text-align: center; }

.legal {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: .75rem;
  color: var(--muted);
  text-align: center;
}
.legal a { color: var(--muted); margin-inline: 4px; }
