:root {
  --bg: #0b0d12;
  --card: #161a22;
  --card-2: #1f2430;
  --text: #f3f4f6;
  --muted: #8b93a3;
  --accent: #ef4444;
  --radius: 18px;
  --phase: #ef4444;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

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

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}
input { font: inherit; color: inherit; -webkit-user-select: text; user-select: text; }

h1, h2, h3 { margin: 0; }
h3 {
  margin: 28px 4px 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.muted { color: var(--muted); }

.screen {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  padding: calc(16px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 4px 16px;
}
.row { display: flex; gap: 10px; margin-top: 10px; }
.row > * { flex: 1; }

/* ---------- Boutons ---------- */
.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  border-radius: 14px;
  padding: 14px 18px;
}
.primary:disabled { opacity: .4; }
.ghost {
  background: var(--card-2);
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 600;
}
.big { width: 100%; padding: 17px; font-size: 18px; margin-top: 12px; }
.link { color: var(--muted); font-size: 13px; text-transform: none; letter-spacing: 0; padding: 4px; }
.link.danger { color: #f87171; width: 100%; margin-top: 14px; font-size: 15px; }
.icon-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  font-size: 24px;
  display: grid; place-items: center;
  background: rgba(255,255,255,.08);
}
.icon-btn-spacer { width: 42px; }

/* ---------- Accueil ---------- */
.brand { padding: 12px 4px 20px; }
.brand h1 { font-size: 34px; font-weight: 800; letter-spacing: -.02em; }
.brand p { margin: 4px 0 0; }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode-card {
  text-align: left;
  background: linear-gradient(150deg, color-mix(in srgb, var(--c) 30%, var(--card)) 0%, var(--card) 70%);
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
  border-radius: var(--radius);
  padding: 16px;
  display: flex; flex-direction: column; gap: 4px;
  min-height: 118px;
  transition: transform .12s;
}
.mode-card:active { transform: scale(.97); }
.mode-icon { font-size: 26px; margin-bottom: 6px; }
.mode-name { font-size: 18px; font-weight: 700; }
.mode-desc { font-size: 13px; color: var(--muted); line-height: 1.3; }

.list { display: flex; flex-direction: column; gap: 8px; }
.list .empty { color: var(--muted); font-size: 14px; padding: 4px; }
.item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card);
  border-radius: 14px;
  padding: 12px 14px;
  text-align: left;
}
.item-main { flex: 1; min-width: 0; text-align: left; }
.item-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.item-icon { font-size: 22px; }
.item .icon-btn { width: 36px; height: 36px; font-size: 16px; }
.item .icon-btn.go { background: var(--accent); }

.settings { padding: 0 16px; }
.toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
  cursor: pointer;
}
.toggle:last-child { border-bottom: 0; }
.toggle input { display: none; }
.toggle span small { display: block; color: var(--muted); font-size: 12px; }
.note { color: var(--muted); font-size: 13px; line-height: 1.4; margin: 10px 4px 0; }
.note.warn { color: #fbbf24; }
.toggle i {
  width: 50px; height: 30px; border-radius: 15px;
  background: #3a4150; position: relative; transition: background .2s;
}
.toggle i::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%; background: #fff;
  transition: transform .2s;
}
.toggle input:checked + i { background: #22c55e; }
.toggle input:checked + i::after { transform: translateX(20px); }

/* ---------- Configuration ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 8px;
}
.topbar h2 { font-size: 20px; }
.desc { margin: 4px 4px 18px; line-height: 1.4; font-size: 15px; }

.field {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.field:last-child { border-bottom: 0; }
.field-label { font-weight: 600; }
.field-label small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }

.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--card-2);
  font-size: 22px; font-weight: 600;
}
.stepper button:active { background: #2c3342; }
.stepper output {
  min-width: 72px; text-align: center;
  font-size: 20px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.step {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.step:last-child { border-bottom: 0; }
.step .kind {
  width: 24px; align-self: stretch; border-radius: 8px;
  background: #ef4444; flex: none;
}
.step[data-kind="rest"] .kind { background: #16a34a; }
.step-name {
  flex: 1; min-width: 0;
  background: transparent; border: 0; outline: 0;
  font-weight: 600; padding: 6px 0;
}
.step .stepper button { width: 34px; height: 34px; font-size: 18px; }
.step .stepper output { min-width: 52px; font-size: 16px; }
.step .icon-btn { width: 30px; height: 30px; font-size: 13px; flex: none; }

.save-row { display: flex; gap: 10px; margin-top: 22px; }
.save-row input {
  flex: 1; min-width: 0;
  background: var(--card); border: 1px solid transparent; border-radius: 14px;
  padding: 12px 14px; outline: 0;
}
.save-row input:focus { border-color: #3a4150; }

.sticky-start {
  position: sticky; bottom: 0;
  margin: 20px -16px 0;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: linear-gradient(transparent, var(--bg) 25%);
}
.total { display: flex; justify-content: space-between; color: var(--muted); padding: 0 4px; }
.total strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- Séance ---------- */
#run {
  max-width: none;
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center;
  background:
    radial-gradient(120% 80% at 50% 0%, color-mix(in srgb, var(--phase) 100%, #fff 8%) 0%, var(--phase) 45%, color-mix(in srgb, var(--phase) 60%, #000) 100%);
  transition: background .4s;
  position: relative;
}
#run > * { width: 100%; max-width: 560px; }
#run.paused { filter: saturate(.35) brightness(.85); }
#run .icon-btn { background: rgba(0,0,0,.18); }
.run-title { font-weight: 600; opacity: .85; text-align: center; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.phase { text-align: center; margin-top: 2vh; }
.phase-label {
  font-size: clamp(28px, 8vw, 44px); font-weight: 800;
  text-transform: uppercase; letter-spacing: .02em;
  line-height: 1.1;
}
.phase-info { font-size: 18px; font-weight: 600; opacity: .85; margin-top: 4px; min-height: 22px; }

.ring-wrap {
  position: relative;
  width: min(80vw, 44vh, 380px) !important;
  aspect-ratio: 1;
  margin: 2vh auto;
  cursor: pointer;
}
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring-bg { stroke: rgba(255,255,255,.22); }
.ring-fg {
  stroke: #fff;
  stroke-linecap: round;
  stroke-dasharray: 565.49;
  stroke-dashoffset: 0;
}
.ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.time {
  font-size: min(20vw, 11vh, 96px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  line-height: 1;
}
.time.long { font-size: min(14vw, 8vh, 70px); }
.paused-tag {
  margin-top: 8px; font-weight: 700; letter-spacing: .2em; font-size: 14px;
  padding: 4px 10px; border-radius: 8px; background: rgba(0,0,0,.25);
}

.next { text-align: center; font-weight: 600; opacity: .85; min-height: 22px; }

.counter {
  display: flex; align-items: center; justify-content: center; gap: 22px;
  margin-top: 14px;
}
.round-btn {
  width: 58px; height: 58px; border-radius: 50%;
  background: rgba(0,0,0,.2); font-size: 26px; font-weight: 700;
}
.round-btn.plus { width: 84px; height: 84px; background: #fff; color: #111; font-size: 28px; }
.round-btn:active { transform: scale(.94); }
.reps { display: flex; flex-direction: column; align-items: center; min-width: 70px; }
.reps span { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.reps small { opacity: .8; }

.laps-box { margin-top: 12px; }
.pill { padding: 14px; border-radius: 14px; background: rgba(0,0,0,.2); font-weight: 700; font-size: 17px; }
.pill.solid { background: #fff; color: #111; }
.laps { list-style: none; margin: 10px 0 0; padding: 0; max-height: 18vh; overflow: auto; }
.laps li {
  display: flex; justify-content: space-between;
  padding: 6px 4px; font-variant-numeric: tabular-nums;
  border-bottom: 1px solid rgba(255,255,255,.12);
}
.laps li:last-child { border-bottom: 0; }

.total-bar { margin-top: auto; padding-top: 16px; }
.total-text { display: flex; justify-content: space-between; font-weight: 600; font-size: 14px; opacity: .9; margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: rgba(0,0,0,.2); border-radius: 3px; overflow: hidden; }
#bar-fill { height: 100%; width: 0; background: #fff; border-radius: 3px; }

.controls {
  display: flex; align-items: center; justify-content: center; gap: 28px;
  padding: 18px 0 4px;
}
.ctrl {
  width: 62px; height: 62px; border-radius: 50%;
  background: rgba(0,0,0,.2);
  display: grid; place-items: center;
}
.ctrl svg { width: 26px; height: 26px; fill: currentColor; }
.ctrl.play { width: 84px; height: 84px; background: #fff; color: #111; }
.ctrl.play svg { width: 34px; height: 34px; }
.ctrl:active { transform: scale(.94); }
.ico-play { display: none; }
#run.paused .ico-play { display: block; }
#run.paused .ico-pause { display: none; }

.sheet-backdrop {
  position: fixed; inset: 0; max-width: none !important;
  background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 10;
}
.sheet {
  width: 100%; max-width: 560px;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  padding: 22px 18px calc(18px + var(--safe-bottom));
}
.sheet h3 { margin: 0 0 6px; justify-content: center; }

/* ---------- Fin ---------- */
.done-head { text-align: center; padding: 6vh 0 20px; }
.done-emoji { font-size: 64px; }
.done-head h2 { font-size: 34px; margin-top: 8px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 16px; }
.stat b { display: block; font-size: 28px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
#done-laps { margin-top: 12px; max-height: none; }
#done-laps:empty { display: none; }
