/* Les Défis REXEL — mise en page commune des jeux (style arcade de Dix Pile !) */
:root {
  --red: #ff2b1c;
  --glow: rgba(255, 43, 28, .7);
  --gold: #ffd447;
  --gold-glow: rgba(255, 212, 71, .75);
  --orange: #ff9a1f;
  --bg: #050505;
  --panel: #121010;
  --line: #2c1513;
  --text: #f4ebe9;
  --muted: #9b8986;
  --accent: var(--red);
  --accent-glow: var(--glow);
  --digit: #ff2b1c;
  --digit-glow: rgba(255, 43, 28, .7);
  --digit-off: #2a0907;
  --seg: var(--digit);
  --seg-glow: var(--digit-glow);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 35%, var(--bg-tint, #1c0605) 0%, var(--bg) 62%);
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Orbitron', system-ui, sans-serif;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ---------- En-tête ---------- */
header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: max(10px, env(safe-area-inset-top)) 16px 6px;
}
.hdr-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.title {
  margin: 0;
  font-size: clamp(14px, 2.2vw, 30px);
  font-weight: 900;
  letter-spacing: .12em;
  color: var(--accent);
  text-shadow: 0 0 12px var(--accent-glow);
  white-space: nowrap;
}
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.modes { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; background: var(--panel); }
.modes button, .tool { font: inherit; color: var(--muted); background: transparent; border: 0; cursor: pointer; }
.modes button {
  font-size: clamp(11px, 1.3vw, 18px);
  font-weight: 700;
  letter-spacing: .06em;
  padding: .55em 1.1em;
  border-radius: 999px;
  transition: background .2s, color .2s;
}
.modes button[aria-pressed="true"] { background: var(--red); color: #fff; box-shadow: 0 0 14px var(--glow); }
.modes button:disabled { cursor: not-allowed; opacity: .55; }
.tool {
  width: clamp(38px, 3.6vw, 56px);
  height: clamp(38px, 3.6vw, 56px);
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  display: inline-grid;
  place-items: center;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
}
.tool svg { width: 55%; height: 55%; }
.tool:hover, .modes button:hover:not(:disabled) { color: #fff; }
.tool[aria-pressed="false"] { color: var(--muted); }

/* ---------- Zone de jeu ---------- */
main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  padding: 4px 16px max(12px, env(safe-area-inset-bottom));
  gap: 1.2vh;
}
.screen {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3%;
  padding: 2.4vmin 4vmin;
  background: linear-gradient(#0d0303, #070101);
  border: 2px solid #261009;
  border-radius: clamp(10px, 2vmin, 28px);
  box-shadow: inset 0 0 4vmin rgba(0,0,0,.9), 0 0 0 clamp(4px, .8vmin, 12px) #141414, 0 2vmin 6vmin rgba(0,0,0,.7);
}
.screen .dr-segs svg { filter: drop-shadow(0 0 .7vmin var(--seg-glow)); }
.screen.win { --seg: var(--gold); --seg-glow: var(--gold-glow); animation: blink .45s steps(1) 6; }
.screen.lose { animation: blink .5s steps(1) 3; }
.screen.early { --seg: var(--orange); --seg-glow: rgba(255,154,31,.7); }
.unit { font-weight: 900; color: var(--seg); text-shadow: 0 0 1vmin var(--seg-glow); }
@keyframes blink { 50% { opacity: .15; } }

.message {
  text-align: center;
  min-height: 2.6em;
  font-size: clamp(18px, 4.4vmin, 76px);
  line-height: 1.2;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.msg-main { font-weight: 900; letter-spacing: .06em; }
.msg-sub { font-size: .5em; color: var(--muted); margin-top: .3em; font-weight: 500; letter-spacing: .04em; }
.message.win .msg-main { color: var(--gold); text-shadow: 0 0 20px var(--gold-glow); animation: pop .6s cubic-bezier(.2,1.6,.4,1); }
.message.lose .msg-main { color: var(--red); text-shadow: 0 0 16px var(--glow); animation: shake .5s; }
.message.early .msg-main { color: var(--orange); animation: shake .4s; }
.message.idle .msg-main { font-size: .6em; font-weight: 700; color: var(--text); }
.message.alert .msg-main { color: #fff; font-size: .7em; }
@keyframes pop { from { transform: scale(.3); opacity: 0; } }
@keyframes shake { 20%,60% { transform: translateX(-3%); } 40%,80% { transform: translateX(3%); } }

/* ---------- Gros bouton rouge ---------- */
.btn-wrap {
  --b: clamp(120px, min(52vw, 30vh), 520px);
  width: calc(var(--b) * 1.16);
  height: calc(var(--b) * 1.16);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 30%, #4a4a4a, #161616 70%);
  box-shadow: 0 1vmin 3vmin rgba(0,0,0,.8), inset 0 2px 2px rgba(255,255,255,.15);
  flex-shrink: 0;
}
.bigbtn {
  width: var(--b);
  height: var(--b);
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  font-weight: 900;
  font-size: calc(var(--b) * .15);
  letter-spacing: .05em;
  color: rgba(255,255,255,.92);
  text-shadow: 0 2px 4px rgba(0,0,0,.5);
  background: radial-gradient(circle at 36% 28%, #ff8a7e 0%, #ff2b1c 32%, #c41208 66%, #7d0802 100%);
  box-shadow:
    0 calc(var(--b) * .045) 0 #5c0602,
    0 calc(var(--b) * .07) calc(var(--b) * .1) rgba(0,0,0,.6),
    inset 0 calc(var(--b) * -.04) calc(var(--b) * .08) rgba(0,0,0,.35);
  transition: transform .06s, box-shadow .06s;
  touch-action: none;
}
.bigbtn.pressed {
  transform: translateY(calc(var(--b) * .035));
  box-shadow:
    0 calc(var(--b) * .01) 0 #5c0602,
    0 calc(var(--b) * .02) calc(var(--b) * .05) rgba(0,0,0,.6),
    inset 0 calc(var(--b) * -.02) calc(var(--b) * .06) rgba(0,0,0,.4);
}
.bigbtn.running { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { filter: brightness(1.18); } }
.bigbtn:focus-visible { outline: 3px solid #fff; outline-offset: 8px; }

.stats-line { font-size: clamp(11px, 1.6vmin, 22px); color: var(--muted); text-align: center; letter-spacing: .04em; }
.stats-line b { color: var(--text); font-weight: 700; }

/* ---------- Fenêtres ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 20;
  user-select: text;
  -webkit-user-select: text;
}
.modal.open { display: flex; }
.panel {
  width: min(600px, 100%);
  max-height: 90vh;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  font-size: clamp(13px, 1.8vmin, 20px);
}
.panel h2 { margin: 0 0 14px; font-size: 1.2em; color: var(--accent); letter-spacing: .08em; }
.grid-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.card h3 { margin: 0 0 6px; font-size: .85em; color: var(--muted); letter-spacing: .08em; }
.card div { line-height: 1.6; font-variant-numeric: tabular-nums; }
.total-card { grid-column: 1 / -1; }
.hist-count { color: var(--muted); font-size: .8em; margin: 0 0 6px; }
.hist-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 60px; }
.hist-list li {
  display: grid;
  grid-template-columns: auto auto auto 1fr;
  gap: 12px;
  align-items: center;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.hist-list .t { font-weight: 700; }
.hist-list .num, .hist-list .m { color: var(--muted); font-size: .8em; }
.hist-list .num { min-width: 3.2em; }
.r-win { color: var(--gold); } .r-early { color: var(--orange); } .r-lose { color: var(--red); }
.empty { color: var(--muted); padding: 12px 0; display: block !important; }
.panel-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; }
.btn {
  font: inherit;
  font-size: .85em;
  font-weight: 700;
  padding: .7em 1.2em;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger { color: #ff8277; border-color: #5c0602; }
.btn.danger.confirm { background: var(--red); border-color: var(--red); color: #fff; }
.scroll { overflow-y: auto; flex: 1; min-height: 0; line-height: 1.6; font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 1.05em; }
.scroll h3 { font-family: 'Orbitron', sans-serif; font-size: .85em; letter-spacing: .08em; color: var(--accent); margin: 16px 0 6px; }
.scroll h3:first-child { margin-top: 0; }
.scroll p, .scroll ul, .scroll ol { margin: 0 0 8px; }
.scroll ul, .scroll ol { padding-left: 1.3em; }
.scroll kbd { font-family: inherit; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 0 .4em; background: #1b1716; }

@media (max-width: 560px) {
  .hist-list li { grid-template-columns: auto 1fr; }
  .hist-list li .r-win, .hist-list li .r-early, .hist-list li .r-lose { grid-column: 1 / -1; }
}
@media (max-height: 500px) {
  header { padding-top: 6px; }
  .btn-wrap { --b: clamp(90px, 28vh, 280px); }
  .stats-line { display: none; }
}
