:root {
  --accent: #84cc16;
  --accent-ink: #13200a;
  --rest: #f0aa2a;
  --bg: #16162a;
  --surface: #1f1f38;
  --surface-2: #2a2a48;
  --line: #34345a;
  --text: #f0e8d8;
  --muted: #a3a0b8;
  --danger: #ef4444;
  --radius: 16px;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(22, 22, 42, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; }
.brand b { color: var(--accent); }
.brand img { border-radius: 8px; }
.tabs { display: flex; background: var(--surface); border-radius: 999px; padding: 3px; }
.tab { border: 0; background: none; padding: 7px 14px; border-radius: 999px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--accent); color: var(--accent-ink); }
body.playing .topbar { display: none; }

main { max-width: 760px; margin: 0 auto; padding: 16px; }
.view { display: none; }
.view.active { display: block; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
h1 { font-size: 24px; margin: 0; }
.sub { font-size: 16px; margin: 24px 0 10px; }
.muted { color: var(--muted); font-weight: 400; }
.empty { color: var(--muted); text-align: center; padding: 20px; border: 1px dashed var(--line); border-radius: var(--radius); }

.btn {
  border: 1px solid transparent; border-radius: 12px; padding: 10px 16px;
  font-weight: 700; cursor: pointer; background: var(--surface-2); min-height: 44px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn:active { transform: scale(.97); }
.btn.huge { font-size: 24px; padding: 18px 40px; border-radius: 20px; display: block; margin: 8px auto 0; }
.btn.round { width: 72px; height: 72px; border-radius: 50%; font-size: 28px; }
.btn.icon { min-height: 36px; width: 36px; padding: 0; border-radius: 10px; }

/* Cartes séances */
.cards { display: grid; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h3 { margin: 0 0 4px; font-size: 18px; overflow-wrap: anywhere; }
.card .meta { color: var(--muted); font-size: 14px; }
.card .chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.chip { background: var(--surface-2); border-radius: 999px; padding: 3px 10px; font-size: 13px; }
.card .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card .actions .btn.primary { flex: 1; }

/* Tuiles exercices */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tiles.small { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.tile {
  position: relative; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; min-height: 92px; display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
}
.tile:hover { border-color: var(--accent); }
.tile .t-name { font-weight: 700; overflow-wrap: anywhere; }
.tile .t-val { font-size: 22px; font-weight: 800; color: var(--accent); }
.tile .t-kind { font-size: 12px; color: var(--muted); }
.tile.add { border-style: dashed; align-items: center; justify-content: center; color: var(--accent); font-weight: 700; text-align: center; }
.tile.flash { animation: flash .35s; }
@keyframes flash { from { background: var(--accent); } }

/* Liste ordonnée de la séance */
.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px 8px 8px 12px;
}
.item .num { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 13px; font-weight: 700; flex: none; }
.item .i-main { flex: 1; min-width: 0; }
.item .i-name { font-weight: 700; overflow-wrap: anywhere; }
.item .i-val { color: var(--accent); font-size: 14px; font-weight: 700; }
.item .i-tools { display: flex; gap: 4px; flex: none; }

/* Formulaires */
.field { display: grid; gap: 6px; margin-bottom: 14px; flex: 1; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
input[type=text], input[type=number] {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; min-height: 44px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.duration, .stepper { display: flex; align-items: center; gap: 6px; }
.duration input { width: 70px; text-align: center; }
.duration em { font-style: normal; color: var(--muted); }
.stepper input { width: 64px; text-align: center; }
.segmented { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.segmented label { flex: 1; }
.segmented input { display: none; }
.segmented span { display: block; text-align: center; padding: 9px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--muted); }
.segmented input:checked + span { background: var(--accent); color: var(--accent-ink); }
.error { color: var(--danger); margin: 0 0 10px; }

dialog {
  width: min(440px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 20px;
  background: var(--bg); color: var(--text); padding: 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 16px; }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.spacer { flex: 1; }

/* Lecteur */
.player { text-align: center; min-height: calc(100vh - 32px); display: none; flex-direction: column; align-items: center; padding-top: env(safe-area-inset-top); }
.player.active { display: flex; }
.player-top { width: 100%; display: flex; justify-content: space-between; align-items: center; }
.phase { margin: 24px 0 4px; text-transform: uppercase; letter-spacing: .12em; font-weight: 800; color: var(--accent); }
.player.is-rest .phase { color: var(--rest); }
.player-name { font-size: clamp(28px, 8vw, 44px); margin: 0 0 16px; overflow-wrap: anywhere; }
.ring-wrap { position: relative; width: min(72vw, 320px); aspect-ratio: 1; margin: 8px auto; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--surface-2); stroke-width: 8; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round; stroke-dasharray: 339.29; transition: stroke-dashoffset .25s linear; }
.player.is-rest .ring-fg { stroke: var(--rest); }
.big { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(56px, 18vw, 96px); font-weight: 800; font-variant-numeric: tabular-nums; }
.player.is-reps .big { font-size: clamp(40px, 12vw, 64px); }
.next { min-height: 1.5em; margin: 16px 0; }
.controls { display: flex; gap: 24px; align-items: center; margin-top: auto; padding: 16px 0 24px; }
.controls .btn.ghost { width: 56px; height: 56px; border-radius: 50%; font-size: 20px; }

.done { text-align: center; padding-top: 15vh; }
.done.active { display: block; }
.done-badge { width: 96px; height: 96px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 48px; font-weight: 800; display: grid; place-items: center; margin: 0 auto 20px; }
.done .btn { margin-top: 20px; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 40px);
  background: var(--surface-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px;
  opacity: 0; transition: .25s; pointer-events: none; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 420px) {
  .view-head h1 { font-size: 20px; }
  .tab { padding: 7px 10px; }
  .brand span { display: none; }
}
