:root {
    --bg: #0b1220;
    --bg-2: #111a2e;
    --card: #141f36;
    --line: #23314f;
    --text: #e2e8f0;
    --muted: #8b9ab5;
    --accent: #38bdf8;
    --danger: #f87171;
    --radius: 16px;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    min-height: 100dvh;
    background: radial-gradient(120% 80% at 50% 0%, #13213d 0%, var(--bg) 60%);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.01em; }
h2 { margin: 0 0 .5rem; }
code { background: var(--bg-2); padding: .1em .4em; border-radius: 6px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--danger); display: block; margin-top: .3rem; }
.hint { color: var(--muted); font-size: .85rem; }

/* ── Structure ─────────────────────────────────────────── */
.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 1rem clamp(1rem, 4vw, 2rem);
    max-width: 960px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; letter-spacing: .18em; text-decoration: none; }
.brand-mark { width: 18px; height: 18px; border: 3px solid var(--accent); border-radius: 4px; }
.nav { display: flex; align-items: center; gap: 1rem; font-size: .95rem; }
.nav a { text-decoration: none; color: var(--muted); }
.nav a:hover { color: var(--text); }
.chip { padding: .25rem .75rem; border: 1px solid var(--line); border-radius: 999px; color: var(--text) !important; }
.container { max-width: 720px; margin: 0 auto; padding: 0 clamp(1rem, 4vw, 2rem) 3rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 1.5rem 0 1rem; }
.empty { text-align: center; color: var(--muted); padding: 2rem 0; }

/* ── Boutons ───────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .6rem 1.1rem; border-radius: 999px; border: 1px solid var(--line);
    background: var(--bg-2); color: var(--text); font: inherit; font-weight: 600;
    text-decoration: none; cursor: pointer; transition: transform .1s, background .2s;
}
.btn:hover { background: var(--line); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04121f; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.big { min-width: 11rem; padding: .9rem 1.5rem; font-size: 1.1rem; }
.btn.round { width: 3rem; height: 3rem; padding: 0; }

/* ── Accueil ───────────────────────────────────────────── */
.hero { text-align: center; padding: 3rem 0 1rem; }
.hero h1 { font-size: clamp(2rem, 6vw, 3rem); margin-top: 2rem; }
.lead { color: var(--muted); max-width: 32rem; margin: .75rem auto 2rem; font-size: 1.1rem; }
.hero-square { position: relative; width: 120px; height: 120px; margin: 0 auto; border: 4px solid var(--line); border-radius: 12px; }
.hero-square span {
    position: absolute; width: 16px; height: 16px; margin: -8px; border-radius: 50%;
    background: #fff; box-shadow: 0 0 16px var(--accent), 0 0 4px var(--accent);
    animation: box 16s linear infinite; left: -2px; top: calc(100% + 2px);
}
@keyframes box {
    0%   { left: -2px; top: calc(100% + 2px); }
    25%  { left: -2px; top: -2px; }
    50%  { left: calc(100% + 2px); top: -2px; }
    75%  { left: calc(100% + 2px); top: calc(100% + 2px); }
    100% { left: -2px; top: calc(100% + 2px); }
}
.login { max-width: 28rem; margin: 0 auto; text-align: left; }
.login label { display: block; font-weight: 600; margin-bottom: .5rem; }
.row { display: flex; gap: .5rem; }
input:not([type=radio]):not([type=checkbox]):not([type=range]) {
    flex: 1; min-width: 0; padding: .65rem .9rem; border-radius: 12px; border: 1px solid var(--line);
    background: var(--bg); color: var(--text); font: inherit;
}
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Profils ───────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; margin-top: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem; text-align: center; }
.stat strong { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .85rem; }

.profiles, .history { list-style: none; padding: 0; margin: 0; display: grid; gap: .75rem; }
.profile { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.profile:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.profile-main { flex: 1; display: flex; align-items: center; gap: 1rem; padding: 1rem 1.1rem; text-decoration: none; }
.profile-icon { flex: none; width: 28px; height: 28px; border: 3px solid var(--accent); border-radius: 6px; }
.profile-text { flex: 1; display: grid; }
.profile-text .muted { font-size: .9rem; }
.play { width: 2.5rem; height: 2.5rem; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: #04121f; font-size: .9rem; }
.profile-edit { display: grid; place-items: center; width: 3.25rem; border-left: 1px solid var(--line); text-decoration: none; color: var(--muted); font-size: 1.2rem; }
.profile-edit:hover { color: var(--text); background: var(--bg-2); }

/* ── Formulaire ────────────────────────────────────────── */
.form { display: grid; gap: 1.25rem; }
.field { display: grid; gap: .4rem; border: 0; padding: 0; margin: 0; }
.field > span:first-child, legend { font-weight: 600; font-size: .95rem; }
.phases { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.phases legend { margin-bottom: .75rem; }
.phase-field > span:first-child { font-weight: 500; color: var(--muted); font-size: .9rem; }
.stepper { display: flex; align-items: stretch; }
.stepper input { text-align: center; border-radius: 0; -moz-appearance: textfield; font-variant-numeric: tabular-nums; font-size: 1.1rem; }
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }
.stepper button { width: 2.75rem; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font-size: 1.2rem; cursor: pointer; }
.stepper button:first-child { border-radius: 12px 0 0 12px; border-right: 0; }
.stepper button:last-child { border-radius: 0 12px 12px 0; border-left: 0; }
.swatches { display: flex; gap: .6rem; }
.swatch input { position: absolute; opacity: 0; }
.swatch span { display: block; width: 2rem; height: 2rem; border-radius: 50%; background: var(--c); cursor: pointer; border: 3px solid transparent; }
.swatch input:checked + span { border-color: var(--text); }
.swatch input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 2px; }
.actions { display: flex; justify-content: flex-end; gap: .75rem; }
.danger-zone { margin-top: 1.5rem; text-align: center; }

/* ── Historique ────────────────────────────────────────── */
.history li { display: flex; align-items: center; gap: 1rem; padding: .85rem 1rem; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.history-main { flex: 1; display: grid; }
.history-main .muted, .history time { font-size: .85rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: #34d399; }

/* ── Séance ────────────────────────────────────────────── */
.trainer { display: grid; gap: 1.25rem; padding-top: .5rem; }
.trainer-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.trainer-head > div:nth-child(2) { flex: 1; }
.trainer-head p { margin: 0; }
.back { width: 2.5rem; height: 2.5rem; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line); text-decoration: none; }
.viz-switch { display: flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.viz-switch button { border: 0; background: none; color: var(--muted); font: inherit; font-size: .85rem; padding: .35rem .8rem; border-radius: 999px; cursor: pointer; }
.viz-switch button.active { background: var(--line); color: var(--text); }

.stage { display: grid; gap: 1rem; }
.stage[data-viz=square] .scope-wrap, .stage[data-viz=scope] .square-wrap { display: none; }
.stage[data-viz=scope] .scope { height: min(55vh, 420px); }

.square-wrap { position: relative; width: min(100%, 62vh, 440px); aspect-ratio: 1; margin: 0 auto; }
.square { width: 100%; height: 100%; overflow: visible; }
.square .track { fill: none; stroke: var(--line); stroke-width: 3; }
.square .fill { fill: var(--accent); opacity: .1; transition: opacity .2s; }
.square .side { fill: none; stroke: transparent; stroke-width: 3.5; stroke-linecap: round; transition: stroke .3s; }
.square .side.done { stroke: color-mix(in srgb, var(--accent) 35%, transparent); }
.square .side.active { stroke: var(--accent); filter: drop-shadow(0 0 3px var(--accent)); }
.square .cursor { fill: #fff; filter: drop-shadow(0 0 4px var(--accent)); }
.readout { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.phase { font-size: clamp(1.3rem, 5vw, 2rem); font-weight: 600; }
.count { font-size: clamp(3.5rem, 16vw, 6.5rem); font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.cycle { margin-top: .4rem; font-size: .95rem; }
.trainer[data-phase=inhale] .phase, .trainer[data-phase=exhale] .phase { color: var(--accent); }

.scope-wrap { background: #050a14; border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem; box-shadow: inset 0 0 40px rgba(0, 0, 0, .6); }
.scope { display: block; width: 100%; height: 160px; }
.scope-legend { display: flex; justify-content: space-between; font-size: .75rem; padding: 0 .4rem; text-transform: uppercase; letter-spacing: .08em; }

.progress { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); }
.controls { display: flex; justify-content: center; align-items: center; gap: 1rem; }
.done { text-align: center; }

@media (max-width: 520px) {
    .phases { grid-template-columns: 1fr; }
    .nav { gap: .6rem; font-size: .85rem; }
    .viz-switch { width: 100%; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
    .hero-square span { animation: none; }
}

.nowrap { white-space: nowrap; }
#sound .slash { display: none; }
#sound.muted-off { color: var(--muted); }
#sound.muted-off .slash { display: inline; }

.scope-wrap { position: relative; }
.scope-readout { display: none; position: absolute; top: 1rem; left: 1.25rem; pointer-events: none; }
.stage[data-viz=scope] .scope-readout { display: grid; }
.scope-readout span { font-size: 1.6rem; font-weight: 600; color: var(--accent); }
.scope-readout strong { font-size: 1rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ── Réglages sonores ──────────────────────────────────── */
.sounds { gap: .75rem; }
.presets { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip-btn { border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font: inherit; font-size: .85rem; padding: .35rem .8rem; border-radius: 999px; cursor: pointer; }
.chip-btn:hover { border-color: var(--accent); }
.sound-events { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: .4rem .75rem; }
.sound-events li { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .4rem .6rem; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.check { display: flex; align-items: center; gap: .55rem; cursor: pointer; }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.listen { width: 2rem; height: 2rem; flex: none; border-radius: 50%; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); cursor: pointer; font-size: .7rem; }
.listen:hover { border-color: var(--accent); color: var(--accent); }
.sound-row { display: flex; align-items: center; gap: 1rem; }
.sound-row > .muted { width: 4.5rem; flex: none; font-size: .9rem; }
.sound-row input[type=range] { flex: 1; accent-color: var(--accent); padding: 0; border: 0; background: none; }
.segmented { display: flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; padding: .3rem .8rem; border-radius: 999px; font-size: .85rem; color: var(--muted); cursor: pointer; }
.segmented input:checked + span { background: var(--line); color: var(--text); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }
@media (max-width: 520px) { .sound-events { grid-template-columns: 1fr; } }
.segmented { flex-wrap: nowrap; }
@media (max-width: 520px) {
    .sound-row { flex-wrap: wrap; gap: .4rem; }
    .sound-row > .muted { width: 100%; }
    .segmented { width: 100%; justify-content: space-between; }
    .segmented span { padding: .3rem .7rem; }
}

/* ── Connexion ─────────────────────────────────────────── */
.login-title { text-align: center; margin-bottom: .5rem; }
.login { display: grid; gap: .5rem; margin-top: 2rem; }
.login label { margin: .5rem 0 0; }
.login .actions { margin-top: 1rem; }
.login .btn { white-space: nowrap; }
