:root {
  --sky: #f3ead2;
  --sand: #e3d3a8;
  --mesa: #cda477;
  --mesa-2: #b98a64;
  --night: #1f2650;
  --night-2: #283166;
  --night-3: #343e7c;
  --night-deep: #151a3a;
  --grid: #e8dcb8;
  --cream: #f6efdc;
  --muted: #a3abd0;
  --accent: #f2a33a;
  --accent-2: #ffcf7a;
  --danger: #e8604f;
  --radius: 16px;
  --display: 'Fredoka', ui-rounded, 'Arial Rounded MT Bold', system-ui, sans-serif;
  --text: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(120% 60% at 85% 0%, rgba(255,255,255,.05) 0 30%, transparent 30.2%),
    radial-gradient(120% 60% at 85% 0%, transparent 0 38%, rgba(255,255,255,.035) 38.2% 39%, transparent 39.2%),
    radial-gradient(120% 60% at 85% 0%, transparent 0 48%, rgba(255,255,255,.03) 48.2% 49%, transparent 49.2%),
    var(--night);
  color: var(--cream);
  font: 16px/1.45 var(--text);
}
button, input { font: inherit; }

/* ---------- En-tête : surface de la mine ---------- */
.surface {
  position: relative;
  background: linear-gradient(var(--sky), var(--sky) 60%, var(--sand));
  color: var(--night);
  padding: 18px 16px 0;
  overflow: hidden;
  border-bottom: 3px solid #c9a978;
}
@media (min-width: 720px) {
  .surface { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding-left: max(16px, calc((100vw - 1040px) / 2)); padding-right: max(16px, calc((100vw - 1040px) / 2)); }
  .title-wrap { margin: 0 0 18px; flex: none; }
  .skyline { max-width: 460px; margin: 0; }
}
.skyline { display: block; width: 100%; max-width: 1040px; height: auto; max-height: 56px; margin: 4px auto 0; }
.skyline .mesa { fill: var(--mesa); }
.skyline .mesa2 { fill: var(--mesa-2); opacity: .8; }
.skyline .tower path { fill: none; stroke: #6b4a3a; stroke-width: 1.6; stroke-linecap: round; }
.skyline .tower .roof { fill: #d0704a; stroke: #6b4a3a; }
.skyline .rig rect, .skyline .rig circle { fill: #8a6a52; }
.skyline .rig path { fill: none; stroke: #8a6a52; stroke-width: 1.6; }
.title-wrap { max-width: 1040px; margin: 0 auto; }
h1 {
  margin: 0;
  font: 700 clamp(28px, 8vw, 40px)/1 var(--display);
  letter-spacing: .06em;
  color: var(--night);
}
h1 span { color: var(--accent); margin: 0 .08em; }
.tagline { margin: 4px 0 0; font-size: 14px; color: #4b4f6b; }

/* ---------- Mise en page ---------- */
main {
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 16px 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}
.play { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.game-card:not(.no-game) + .play { margin-top: -6px; }
.play[hidden] { display: none; }
@media (min-width: 960px) {
  main { max-width: 1040px; }
  .play { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: start; }
  .board-card { grid-row: span 3; position: sticky; top: 12px; }
}

.card {
  background: var(--night-2);
  border: 1px solid rgba(255,255,255,.06);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
h2 { margin: 0 0 10px; font: 600 17px/1.2 var(--display); letter-spacing: .02em; color: var(--grid); }

/* ---------- Boutons & champs ---------- */
.btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  min-height: 46px;
  background: var(--night-3);
  color: var(--cream);
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: .02em;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:focus-visible, .field:focus-visible, .seg button:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--night-deep); }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; border: 1px solid rgba(255,255,255,.18); }
.btn.small { min-height: 38px; padding: 8px 12px; font-size: 14px; }
.btn.icon { width: 46px; padding: 0; display: grid; place-items: center; flex: none; }
.btn.icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }
.btn.icon.done { background: #3f8a5a; }

.row { display: flex; gap: 8px; }
.field {
  flex: 1;
  min-width: 0;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.14);
  background: var(--night-deep);
  color: var(--cream);
  padding: 10px 12px;
  min-height: 46px;
  font-size: 16px;
}
.field.big { font: 600 20px var(--display); letter-spacing: .06em; text-transform: uppercase; }
.field::placeholder { color: #6c74a3; text-transform: none; letter-spacing: 0; font-weight: 400; }

/* ---------- Carte partie ---------- */
.code-label { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.code-row { display: flex; gap: 10px; align-items: center; margin: 4px 0 8px; }
.code {
  flex: 1;
  font: 600 clamp(19px, 5.4vw, 24px)/1.25 var(--display);
  color: var(--accent-2);
  overflow-wrap: anywhere;
}
.code .sep { color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--night-3); color: var(--grid); }
.setup { display: grid; gap: 16px; }
.current:not([hidden]) + .setup { margin-top: 14px; padding-top: 14px; border-top: 1px dashed rgba(255,255,255,.14); }

/* Bloc partie replié en nœud discret pendant le jeu. */
.node > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 4px 4px;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  border-radius: 10px;
  -webkit-tap-highlight-color: transparent;
}
.node > summary::-webkit-details-marker { display: none; }
.node > summary:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
.node .chev { width: 14px; height: 14px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; transition: transform .15s ease; }
.node[open] .chev { transform: rotate(90deg); }
.node .node-label { text-transform: uppercase; letter-spacing: .1em; font-size: 12px; }
.node .node-body { margin-top: 6px; }
.game-card.no-game .node > summary { display: none; }
.game-card.no-game .node .node-body { margin-top: 0; }
.options { display: grid; gap: 8px; margin-bottom: 12px; }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; min-height: 36px; }
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check .box {
  width: 24px; height: 24px; border-radius: 7px; flex: none;
  border: 2px solid var(--muted); display: grid; place-items: center;
}
.check input:checked + .box { background: var(--accent); border-color: var(--accent); }
.check input:checked + .box::after { content: ''; width: 6px; height: 11px; border: solid var(--night-deep); border-width: 0 3px 3px 0; transform: rotate(45deg) translate(-1px, -1px); }
.check input:focus-visible + .box { outline: 3px solid var(--accent-2); outline-offset: 2px; }
#newBtn { width: 100%; }
.msg { min-height: 1.2em; margin: 8px 0 0; font-size: 14px; color: var(--muted); }
.msg.err { color: var(--danger); }
.recent { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.recent button {
  width: 100%; text-align: left; background: var(--night-deep); color: var(--cream);
  border: 1px solid rgba(255,255,255,.08); border-radius: 10px; padding: 8px 10px; cursor: pointer;
}
.recent .rc { display: block; font: 600 15px var(--display); color: var(--accent-2); overflow-wrap: anywhere; }
.recent .rm { display: block; font-size: 12px; color: var(--muted); }
.recent .is-current { border-color: var(--accent); }

/* ---------- Plateau ---------- */
.board-card { margin: 0; }
.board {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  background: var(--night-deep);
  box-shadow: 0 10px 30px rgba(0,0,0,.3);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.board .frame { fill: #262f60; }
.board .cell { fill: transparent; cursor: pointer; }
.board .cell:hover { fill: rgba(255,255,255,.05); }
.board .cell.sel { fill: rgba(242,163,58,.22); stroke: var(--accent); stroke-width: .6; }
.board .gridline { stroke: var(--grid); stroke-width: .28; opacity: .8; }
.board .border { fill: none; stroke: var(--grid); stroke-width: .5; }
.board .lbl { cursor: pointer; }
.board .lbl .hit { fill: transparent; }
.board .lbl .base { fill: #121634; stroke: rgba(232,220,184,.55); stroke-width: .35; }
.board .lbl .base.absorbed { stroke: var(--danger); stroke-width: .7; stroke-dasharray: 1 .7; }
.board .lbl .disc { stroke: #0b0d1e; stroke-width: .3; }
.board .lbl .ring-sel { fill: none; stroke: #fff; stroke-width: .7; stroke-dasharray: 1.3 .9; animation: march 1s linear infinite; }
@keyframes march { to { stroke-dashoffset: -4.4; } }
.board .lbl .ring-hl { fill: none; stroke: var(--accent-2); stroke-width: .6; stroke-dasharray: 1.2 .8; }
.board .lbl text { fill: var(--grid); font: 700 4.1px var(--display); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.board .mark { pointer-events: none; }
.board .mark text { font: 700 3.2px var(--display); text-anchor: middle; dominant-baseline: central; fill: var(--muted); }
.board .gem { pointer-events: none; }
.board .ray { pointer-events: none; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.board .ray.dim { opacity: .15; }
.hint { margin: 8px 2px 0; font-size: 13px; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 10px 2px 0; font-size: 13px; color: var(--grid); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend svg { width: 18px; height: 18px; }

/* ---------- Réponse ---------- */
.answer:empty { display: none; }
.answer {
  margin-top: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 12px;
  background: var(--night-deep);
  animation: pop .25s ease;
}
@keyframes pop { from { transform: scale(.96); opacity: .4; } to { transform: none; opacity: 1; } }
.swatch {
  width: 46px; height: 46px; border-radius: 10px; flex: none;
  background: var(--c);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.25);
}
.swatch.clear { background: repeating-linear-gradient(45deg, #3b4372 0 5px, #2b3260 5px 10px); }
.swatch.absorbed { background: #050508; box-shadow: inset 0 0 0 2px var(--danger); }
.swatch.empty { background: transparent; box-shadow: inset 0 0 0 2px rgba(255,255,255,.2); }
.answer .big { font: 700 22px/1.1 var(--display); color: var(--cream); }
.answer .big .arr { color: var(--muted); margin: 0 .2em; }
.answer .txt { font-size: 15px; color: var(--grid); }
.answer .note { font-size: 12px; color: var(--muted); }
.answer.err { color: var(--danger); }
.answer.notice { color: var(--accent-2); font-size: 15px; }

/* ---------- Historique ---------- */
.history-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.history-head h2 { margin: 0; }
.count { display: inline-block; min-width: 26px; padding: 1px 8px; margin-left: 4px; border-radius: 999px; background: var(--accent); color: var(--night-deep); font-size: 14px; text-align: center; }
.seg { display: inline-flex; background: var(--night-deep); border-radius: 10px; padding: 3px; }
.seg[hidden] { display: none; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 6px 10px; border-radius: 8px; font: 600 13px var(--display); cursor: pointer; }
.seg button.on { background: var(--night-3); color: var(--cream); }
.shots { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.shot {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--night-deep);
  border: 1px solid transparent;
  cursor: pointer;
}
.shot.on { border-color: var(--accent); }
.shot .n { font: 600 13px var(--display); color: var(--muted); }
.shot .q { font: 700 17px var(--display); }
.shot .q .arr { color: var(--muted); margin: 0 .25em; font-weight: 500; }
.shot .c { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--grid); text-align: right; }
.dot { width: 16px; height: 16px; border-radius: 50%; flex: none; background: var(--c); box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.3); }
.dot.clear { background: repeating-linear-gradient(45deg, #59618f 0 3px, #2b3260 3px 6px); }
.dot.absorbed { background: #050508; box-shadow: inset 0 0 0 1.5px var(--danger); }
.dot.empty { background: transparent; box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.3); }
.empty { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.empty[hidden] { display: none; }

/* ---------- Révélation ---------- */
.hold {
  position: relative;
  width: 100%;
  overflow: hidden;
  background: #3a2230;
  border: 1px solid rgba(232,96,79,.5);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}
.hold .fill { position: absolute; inset: 0; width: 0; background: var(--danger); transition: none; }
.hold .txt { position: relative; }
.hold.holding .txt { color: #fff; }
.hold[hidden], #hideBtn[hidden] { display: none; }
#hideBtn { width: 100%; }

footer {
  max-width: 560px;
  margin: 8px auto 32px;
  padding: 0 16px;
  font-size: 12px;
  color: #7a82b0;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .answer { animation: none; }
  .btn { transition: none; }
  .board .lbl .ring-sel { animation: none; }
}
