:root {
  --bg: #0d0e12;
  --panel: #16181f;
  --panel-2: #1d2029;
  --line: #2a2e3a;
  --text: #e9e6df;
  --muted: #a19d94;
  --accent: #c9a45c;
  --accent-soft: rgba(201, 164, 92, .14);
  --danger: #e07a6e;
  --ok: #7cbf96;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(120% 60% at 50% 0%, #1a1c26 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font: 18px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: normal; line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 2rem; letter-spacing: .02em; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; color: var(--accent); }
p { margin: 0 0 .8em; }
.text { white-space: pre-line; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.loading { text-align: center; color: var(--muted); padding: 4rem 1rem; }
a { color: var(--accent); }

/* Boutons et champs : grandes cibles tactiles */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: 52px; padding: 12px 20px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel-2); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  touch-action: manipulation;
}
button:hover:not(:disabled), .btn:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, .btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: #1a1408; }
.primary:hover:not(:disabled) { background: #d8b675; }
.ghost { background: transparent; }
.danger-btn { border-color: rgba(224, 122, 110, .5); }
.wide { width: 100%; }
.row { display: flex; flex-wrap: wrap; gap: 10px; }
.row > * { flex: 1 1 200px; }
input[type=text] {
  width: 100%; min-height: 56px; padding: 12px 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: #0f1116; color: var(--text);
  font: inherit; font-size: 1.2rem; /* ≥ 16px : pas de zoom automatique sur iPhone */
}
label { display: block; font-weight: 600; margin-bottom: .4em; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.badge {
  display: inline-block; padding: 2px 10px; margin: 0 6px 6px 0;
  border: 1px solid var(--line); border-radius: 999px;
  font-size: .82rem; color: var(--muted);
}
.msg { padding: 12px 14px; border-radius: 10px; margin: 12px 0; }
.msg.error { background: rgba(224, 122, 110, .12); border: 1px solid rgba(224, 122, 110, .4); }
.msg.ok { background: rgba(124, 191, 150, .12); border: 1px solid rgba(124, 191, 150, .4); }
.msg.info { background: var(--accent-soft); border: 1px solid rgba(201, 164, 92, .35); }

/* Accueil */
.hero { text-align: center; padding: 28px 0 12px; }
.hero p { color: var(--muted); max-width: 34em; margin: 0 auto 1em; }
.stories { display: grid; gap: 16px; }
@media (min-width: 760px) { .stories { grid-template-columns: repeat(2, 1fr); } }
.story h2 { margin-bottom: .3em; }
.story .row { margin-top: 14px; }

/* Barre de jeu, toujours visible */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  margin: -16px -16px 16px; padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(13, 14, 18, .94);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.timer {
  font: 700 2rem/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  min-width: 4.2ch;
}
.timer.warn { color: #e8b75a; }
.timer.over { color: var(--danger); }
.timer-label { font-size: .72rem; color: var(--muted); display: block; text-transform: uppercase; letter-spacing: .08em; }
.topbar .progress-text { flex: 1; min-width: 0; font-size: .9rem; color: var(--muted); line-height: 1.3; }
.topbar .progress-text strong { color: var(--text); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar button { min-height: 48px; padding: 8px 14px; }
.quit { min-width: 48px; padding: 8px 12px !important; }

.game { display: grid; gap: 16px; align-items: start; }
@media (min-width: 900px) {
  .game { grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr); }
  .side { position: sticky; top: 96px; }
}
.ambiance { font-style: italic; color: var(--muted); border-left: 3px solid var(--accent); padding-left: 12px; }
.enigme { font-size: 1.08rem; }
.hints { margin-top: 16px; }
.hints ol { margin: 0; padding-left: 1.4em; }
.hints li { margin-bottom: .4em; }
.answer { display: grid; gap: 10px; margin-top: 16px; }
@media (min-width: 560px) { .answer { grid-template-columns: 1fr auto; } }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); } }

.carnet-entry { padding: 10px 0; border-top: 1px solid var(--line); }
.carnet-entry:first-of-type { border-top: 0; }
.carnet-entry ul { margin: .4em 0 0; padding-left: 1.2em; color: var(--muted); font-size: .92rem; }

/* Sacoche : gadgets micro et appareil photo */
.kit { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); display: grid; gap: 12px; }
.kit h3 { margin: 0; }
.kit-items { display: flex; flex-wrap: wrap; gap: 10px; }
.kit-items > * { flex: 1 1 200px; }
.gadget-icon { font-size: 1.5rem; line-height: 1; }
.kit-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 10px; }
.kit-list li { display: flex; gap: 12px; align-items: flex-start; }
.kit-list p { margin: 0; }
.kit details { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.kit summary { cursor: pointer; color: var(--muted); font-size: .92rem; min-height: 32px; display: flex; align-items: center; }
.kit details[open] summary { margin-bottom: 10px; }
.sensor { display: grid; gap: 12px; }
.sensor:empty { display: none; }
.meter { height: 18px; border-radius: 999px; background: #0f1116; border: 1px solid var(--line); overflow: hidden; }
.meter > div { height: 100%; width: 0; background: var(--accent); transition: width .1s linear; }
.meter.level > div { background: #6c7a93; }
.camera { position: relative; border-radius: 12px; overflow: hidden; background: #000; }
.camera video, .camera canvas { display: block; width: 100%; max-height: 60vh; object-fit: cover; }
.handoff { display: grid; gap: 14px; align-items: center; background: var(--accent-soft); border: 1px solid rgba(201, 164, 92, .35); border-radius: 12px; padding: 16px; }
@media (min-width: 560px) { .handoff { grid-template-columns: 200px 1fr; } }
.qr { background: #fff; border-radius: 8px; padding: 6px; width: 200px; max-width: 100%; justify-self: center; }
.qr svg { display: block; width: 100%; height: auto; }
.link-copy { word-break: break-all; font-size: .82rem; color: var(--muted); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* Fin de partie et classement */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 16px 0; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--panel-2); border-radius: 12px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 1.5rem; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat span { font-size: .82rem; color: var(--muted); }
.score-detail { font-size: .92rem; color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { padding: 10px 6px; text-align: left; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
td.num, th.num { text-align: right; }
tr.me td { color: var(--accent); font-weight: 700; }
.table-wrap { overflow-x: auto; }
@media (max-width: 520px) { .hide-sm { display: none; } }

dialog {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--accent); border-radius: var(--radius);
  background: var(--panel); color: var(--text); padding: 24px;
}
dialog::backdrop { background: rgba(0, 0, 0, .7); }
dialog h2 { color: var(--accent); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
