/* Thème sombre par défaut ; le thème clair est appliqué via data-look="light" sur <html>. */
:root {
  --bg: #181a20;
  --panel: #23262e;
  --idle: #2c3039;
  --strong: #3a3f4b;
  --paused: #4b5160;
  --border: #3a3f4b;
  --active: #2ecc71;
  --active-text: #0d1f14;
  --low: #e74c3c;
  --on-low: #ffffff;
  --text: #eceef2;
  --soft: #c4c8d0;
  --muted: #8a909c;
  --chip: rgba(0, 0, 0, .3);
  --press: brightness(1.3);
  --backdrop: rgba(0, 0, 0, .6);
  --bar-h: 64px;
  color-scheme: dark;
}
:root[data-look="light"] {
  --bg: #e9ecf0;
  --panel: #ffffff;
  --idle: #d7dce3;
  --strong: #c3cad4;
  --paused: #aeb6c2;
  --border: #c3cad4;
  --active: #27ae60;
  --active-text: #ffffff;
  --low: #d63c2c;
  --on-low: #ffffff;
  --text: #15171c;
  --soft: #363b45;
  --muted: #5d6470;
  --chip: rgba(255, 255, 255, .7);
  --press: brightness(.86);
  --backdrop: rgba(20, 22, 28, .45);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#clock {
  height: 100%;
  display: grid;
  grid-template-rows: 1fr var(--bar-h) 1fr;
  gap: 6px;
  padding: max(6px, env(safe-area-inset-top)) 6px max(6px, env(safe-area-inset-bottom));
}

.player {
  all: unset;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  background: var(--idle);
  color: var(--text);
  cursor: pointer;
  transition: background-color .15s;
  overflow: hidden;
}
#p1 { transform: rotate(180deg); }

.time {
  font-size: clamp(64px, 22vw, 180px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
}
.time.long { font-size: clamp(52px, 17vw, 150px); }

.meta {
  position: absolute;
  bottom: 14px;
  left: 18px;
  right: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  color: var(--muted);
}
.who { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  flex: none;
}
.dot.white { background: #ffffff; border-color: #8a909c; }
.dot.black { background: #000000; border-color: #8a909c; }
.flag { display: none; font-weight: 700; }
.cad { text-align: right; }
.player.flagged .cad { display: none; }
.delay {
  min-height: 1.4em;
  margin-top: 6px;
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  opacity: .8;
}

.player.active { background: var(--active); color: var(--active-text); }
.player.active .meta { color: var(--active-text); opacity: .8; }
.player.low .time { color: var(--low); }
.player.active.low { background: var(--low); color: var(--on-low); }
.player.active.low .time, .player.active.low .meta { color: var(--on-low); }
.player.flagged { background: var(--low); color: var(--on-low); }
.player.flagged .flag { display: inline; color: var(--on-low); }
.player.flagged .meta { color: var(--on-low); opacity: 1; }
.paused .player.active { background: var(--paused); color: var(--text); }
.paused .player.active .meta { color: var(--text); opacity: .75; }

.bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
}
.icon-btn {
  width: 46px;
  height: 46px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--panel);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn.big { width: 56px; height: 56px; background: var(--strong); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn svg { width: 26px; height: 26px; fill: currentColor; }
.icon-btn:focus-visible, .actions button:focus-visible, .presets button:focus-visible { outline: 2px solid var(--active); outline-offset: 2px; }
.ico-play, .ico-off { display: none; }
.paused .ico-play { display: block; }
.paused .ico-pause { display: none; }
#btn-sound[aria-pressed="false"] .ico-on { display: none; }
#btn-sound[aria-pressed="false"] .ico-off { display: block; }

.hint {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--chip);
  font-size: 13px;
  white-space: nowrap;
  transition: opacity .3s;
}
.hint.hidden { opacity: 0; }

.toast {
  position: fixed;
  left: 50%;
  top: calc(50% + var(--bar-h) / 2 + 14px);
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .3);
  font-size: 14px;
  text-align: center;
  z-index: 10;
  pointer-events: none;
}

/* Fenêtres */
dialog {
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  border: 0;
  border-radius: 18px;
  background: var(--panel);
  color: var(--text);
  padding: 20px;
  user-select: auto;
  overflow-y: auto;
}
dialog::backdrop { background: var(--backdrop); }
dialog h2 { margin: 0 0 12px; font-size: 20px; text-wrap: balance; }
dialog h3 { margin: 18px 0 8px; font-size: 15px; color: var(--muted); font-weight: 600; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.head h2 { margin: 0; }

#help { width: min(560px, calc(100vw - 24px)); }
#help .head { position: sticky; top: -20px; margin: -20px -20px 4px; padding: 16px 20px 12px; background: var(--panel); z-index: 1; }
.icon-btn.small { width: 40px; height: 40px; background: var(--idle); }
.icon-btn.small svg { width: 22px; height: 22px; }
.help-body { font-size: 15px; line-height: 1.5; }
.help-body details { border-top: 1px solid var(--idle); padding: 4px 0; }
.help-body summary { cursor: pointer; padding: 10px 0; font-weight: 700; font-size: 16px; }
.help-body summary::marker { color: var(--active); }
.help-body ul { margin: 0 0 10px; padding-left: 20px; }
.help-body li + li { margin-top: 6px; }
.help-body dl { margin: 0 0 10px; }
.help-body dt { font-weight: 600; margin-top: 10px; }
.help-body dd { margin: 2px 0 0; color: var(--soft); }
.help-body em { color: var(--muted); font-style: normal; font-size: 14px; }
.help-body p { margin: 6px 0 10px; color: var(--soft); }

#confirm { width: min(360px, calc(100vw - 32px)); }
#confirm p { margin: 4px 0 0; font-size: 16px; line-height: 1.45; }

#summary { width: min(420px, calc(100vw - 24px)); }
.stats { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.stats th, .stats td { padding: 9px 4px; text-align: right; border-bottom: 1px solid var(--idle); }
.stats th:first-child, .stats td:first-child { text-align: left; color: var(--muted); font-weight: 400; }
.stats thead th { font-weight: 700; color: var(--text); }
.stats thead .dot { display: inline-block; vertical-align: -2px; margin-right: 6px; }
.stats tr:last-child td { border-bottom: 0; }

.seg { display: inline-flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 2px; }
.seg.wide { display: flex; }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; white-space: nowrap; padding: 8px 10px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg input:checked + span { background: var(--idle); color: var(--text); }
.seg input:focus-visible + span { outline: 2px solid var(--active); }
.help { margin: 8px 0 0; font-size: 13px; color: var(--muted); line-height: 1.4; }
.error { margin: 14px 0 0; color: var(--low); font-size: 14px; }

.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.preset { position: relative; display: grid; }
.presets button.pick {
  border: 2px solid transparent;
  border-radius: 12px;
  background: var(--idle);
  color: var(--text);
  padding: 10px 4px;
  font: inherit;
  cursor: pointer;
  min-width: 0;
}
.presets button.pick b { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.presets button.pick small { color: var(--muted); font-size: 12px; }
.presets button.pick.selected { border-color: var(--active); }
.presets button.del {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: var(--strong);
  color: var(--text);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 4px 0 6px; }
.steps button {
  border: 0;
  border-radius: 10px;
  background: var(--idle);
  color: var(--text);
  padding: 10px 2px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
#adjust { width: min(400px, calc(100vw - 24px)); }
.custom { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.custom.two { grid-template-columns: repeat(2, 1fr); }
.custom[hidden] { display: none; }
.custom label, .inline { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.inline { flex-direction: row; align-items: center; justify-content: space-between; margin-top: 8px; }
.inline input[type="number"] { width: 90px; }
input[type="number"] {
  font: inherit;
  font-size: 18px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
.check { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--active); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; font-size: 15px; }

.link-btn {
  margin-top: 6px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: none;
  color: var(--text);
  padding: 10px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  width: 100%;
  cursor: pointer;
}

.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.actions button { border: 0; border-radius: 10px; padding: 12px 18px; font: inherit; font-weight: 600; cursor: pointer; }
.primary { background: var(--active); color: var(--active-text); }
.secondary { background: var(--idle); color: var(--text); }

/* Effet d'appui : la classe .pressed est posée par app.js dès le toucher,
   ce qui marche aussi sur les zones de jeu qui bloquent le comportement par défaut. */
button, .seg label, .check { transition: transform .1s ease, filter .1s ease, background-color .15s; }
button.pressed:not(:disabled), .seg label.pressed, .check.pressed {
  transform: scale(.94);
  filter: var(--press);
}
button.player.pressed:not(:disabled) { transform: scale(.985); filter: var(--press); }
#p1.pressed { transform: rotate(180deg) scale(.985); }
.presets button.del.pressed { transform: scale(.85); }
.check.pressed { transform: scale(.98); }
.seg label.pressed { transform: scale(.94); }
.link-btn.pressed:not(:disabled) { transform: scale(.98); }

@media (orientation: landscape) and (max-height: 500px) {
  #clock { grid-template-rows: none; grid-template-columns: 1fr var(--bar-h) 1fr; padding: 6px max(6px, env(safe-area-inset-left)); }
  #p1 { transform: none; }
  #p1.pressed { transform: scale(.985); }
  .bar { flex-direction: column; }
  .time { font-size: clamp(48px, 12vw, 140px); }
  .time.long { font-size: clamp(40px, 9.5vw, 120px); }
  .toast { top: auto; bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .player, .hint { transition: none; }
  button.pressed:not(:disabled), .seg label.pressed, .check.pressed, button.player.pressed:not(:disabled) { transform: none; }
  #p1.pressed { transform: rotate(180deg); }
}
