/* Autotune — direction minimaliste : beaucoup d'air, une seule couleur
   d'accent, divulgation progressive des réglages. */

:root {
  --bg: #fbfbfd;
  --surface: #ffffff;
  --surface-2: #f2f2f6;
  --text: #1d1d1f;
  --muted: #86868b;
  --accent: #0071e3;
  --accent-soft: #e8f1fd;
  --border: #e3e3e8;
  --grid: #ececf1;
  --wave-idle: #ccccd2;
  --pitch-raw: #b4b4bc;
  --ring: #e5e5ea;
  --danger: #d7263d;
  --radius: 18px;
  --radius-sm: 11px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 28px rgba(0,0,0,.06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #f5f5f7;
    --muted: #98989d;
    --accent: #0a84ff;
    --accent-soft: #16283f;
    --border: #38383a;
    --grid: #2a2a2c;
    --wave-idle: #48484a;
    --pitch-raw: #6a6a70;
    --ring: #2c2c2e;
    --danger: #ff453a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 28px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 20px calc(40px + env(safe-area-inset-bottom));
}

/* ── écrans ─────────────────────────────────────────────────────────── */

.screen {
  display: none;
  flex: 1;
  animation: rise .38s cubic-bezier(.22,.61,.36,1);
}
.screen.is-active { display: flex; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  margin: auto 0;
}
.stack-center {
  align-items: center;
  text-align: center;
  gap: 24px;
}

/* Les écrans denses partent du haut ; seuls l'accueil et l'enregistrement,
   qui tiennent en quelques éléments, se centrent verticalement. */
#screen-result .stack,
#screen-library .stack { margin: 0; }

.display {
  font-size: clamp(40px, 11vw, 62px);
  font-weight: 700;
  letter-spacing: -.035em;
  margin: 0;
  line-height: 1.02;
}

.lede {
  font-size: clamp(17px, 4.4vw, 21px);
  line-height: 1.45;
  color: var(--muted);
  margin: -8px 0 4px;
  letter-spacing: -.01em;
}

.fine {
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
  margin: 0;
}

/* ── boutons ────────────────────────────────────────────────────────── */

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -.01em;
  padding: 11px 20px;
  border-radius: 980px;
  cursor: pointer;
  transition: transform .12s ease, background .18s ease, opacity .18s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; transform: none; }

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }

.btn-lg { font-size: 17px; padding: 14px 30px; }

.btn-quiet {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn-quiet:hover { background: var(--surface-2); color: var(--text); }

:where(button, select, input, summary, canvas[tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ── enregistrement ─────────────────────────────────────────────────── */

.rec-stage {
  position: relative;
  width: 196px;
  height: 196px;
  display: grid;
  place-items: center;
}
#level-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.rec-btn {
  position: relative;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform .15s cubic-bezier(.22,.61,.36,1);
}
.rec-btn:active { transform: scale(.94); }

.rec-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--danger);
  transition: width .25s cubic-bezier(.22,.61,.36,1),
              height .25s cubic-bezier(.22,.61,.36,1),
              border-radius .25s cubic-bezier(.22,.61,.36,1);
}
.rec-btn.is-recording .rec-icon {
  width: 34px;
  height: 34px;
  border-radius: 7px;
}

.rec-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.timer {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.hint { font-size: 14px; color: var(--muted); }

/* ── transport ──────────────────────────────────────────────────────── */

.transport {
  display: flex;
  align-items: center;
  gap: 14px;
}
.play-btn {
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform .12s ease;
}
.play-btn:active { transform: scale(.93); }
.play-btn svg { width: 22px; height: 22px; fill: currentColor; }
.play-btn .icon-pause { display: none; }
.play-btn.is-playing .icon-play { display: none; }
.play-btn.is-playing .icon-pause { display: block; }

.time {
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.segmented {
  margin-left: auto;
  display: flex;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 2px;
}
.segmented button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 15px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .2s ease, color .2s ease;
}
.segmented button.is-on {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
}

/* ── cartes et canvas ───────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 12px;
  flex-wrap: wrap;
}
.card-head h2 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -.005em;
  margin: 0;
}
.legend {
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.swatch {
  display: inline-block;
  width: 13px;
  height: 2.5px;
  border-radius: 2px;
  margin-right: 1px;
}
.swatch-raw { background: var(--pitch-raw); }
.swatch-tuned { background: var(--accent); margin-left: 8px; }

.wave { display: block; width: 100%; height: 84px; cursor: pointer; }
.wave-live { height: 60px; opacity: .9; cursor: default; }
.pitch { display: block; width: 100%; height: 150px; }

/* ── presets ────────────────────────────────────────────────────────── */

.presets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 9px;
}
.preset {
  appearance: none;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  cursor: pointer;
  font: inherit;
  transition: border-color .18s ease, background .18s ease, transform .12s ease;
}
.preset:hover { border-color: var(--muted); }
.preset:active { transform: scale(.98); }
.preset.is-on {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.preset .p-top {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.012em;
}
.preset .p-emoji { font-size: 17px; line-height: 1; }
.preset .p-tag {
  display: block;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--muted);
  margin-top: 3px;
}
.preset.is-on .p-tag { color: var(--text); opacity: .65; }

/* ── barre de navigation ────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
  min-height: 32px;
}
.topbar[hidden] { display: none; }
.brand {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.015em;
}
.link {
  appearance: none;
  border: none;
  background: none;
  font: inherit;
  font-size: 13.5px;
  color: var(--accent);
  cursor: pointer;
  padding: 5px 2px;
  border-radius: 6px;
}
.link:hover { text-decoration: underline; }
.link[hidden] { display: none; }
#btn-library { margin-left: auto; }
#lib-count { color: var(--muted); }

.title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.025em;
  margin: 0;
}
.lib-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* ── bibliothèque ───────────────────────────────────────────────────── */

.lib-list { display: flex; flex-direction: column; gap: 9px; }

.lib-item {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
}
.lib-play {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform .12s ease;
}
.lib-play:active { transform: scale(.92); }
.lib-main { min-width: 0; cursor: pointer; }
.lib-name {
  font-size: 14.5px;
  font-weight: 500;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lib-meta { font-size: 12px; color: var(--muted); margin-top: 1px; }
.lib-thumb { display: block; width: 100%; height: 22px; margin-top: 5px; }
.lib-actions { display: flex; gap: 3px; }
.icon-btn {
  appearance: none;
  border: none;
  background: none;
  font-size: 14px;
  line-height: 1;
  padding: 7px;
  border-radius: 8px;
  cursor: pointer;
  opacity: .55;
  transition: opacity .16s ease, background .16s ease;
}
.icon-btn:hover { opacity: 1; background: var(--surface-2); }

/* ── boucle ─────────────────────────────────────────────────────────── */

.loop-row { display: flex; gap: 7px; flex-wrap: wrap; }
.btn-sm { font-size: 13px; padding: 7px 14px; }
#btn-loop[aria-pressed="true"] {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.loop-controls {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 13px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.loop-controls[hidden] { display: none; }

/* ── beat de fond ───────────────────────────────────────────────────── */

.beat-styles {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}
.beat-chip {
  appearance: none;
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 980px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease, transform .12s ease;
}
.beat-chip:hover { border-color: var(--muted); }
.beat-chip:active { transform: scale(.96); }
.beat-chip.is-on {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.beat-controls {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid var(--border);
}
.beat-controls[hidden] { display: none; }

/* ── réglages avancés ───────────────────────────────────────────────── */

.advanced {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.advanced summary {
  padding: 14px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary::after {
  content: '';
  width: 7px;
  height: 7px;
  border-right: 1.8px solid var(--muted);
  border-bottom: 1.8px solid var(--muted);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform .22s ease;
}
.advanced[open] summary::after { transform: rotate(-135deg) translate(-2px, -2px); }

.adv-body {
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.adv-group { display: flex; flex-direction: column; gap: 9px; }
.adv-group h3 {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .055em;
  color: var(--muted);
  margin: 0 0 2px;
}
.tag {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 7px;
  border-radius: 5px;
  margin-left: 6px;
}

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}
.row.range { grid-template-columns: 116px 1fr 52px; }
.row label { color: var(--text); }
.row output {
  font-size: 12.5px;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

select {
  appearance: none;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 30px 7px 11px;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

input[type=range] {
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
input[type=range]::-webkit-slider-thumb {
  appearance: none;
  width: 19px;
  height: 19px;
  margin-top: -8.5px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,.22);
  border: .5px solid var(--border);
}
input[type=range]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
input[type=range]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,.22);
  border: .5px solid var(--border);
}

/* ── actions ────────────────────────────────────────────────────────── */

.actions {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  justify-content: center;
  padding-top: 2px;
}
.actions-note {
  text-align: center;
  margin-top: -6px;
}

/* ── mode live ──────────────────────────────────────────────────────── */

.live-row {
  display: flex;
  gap: 9px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
#btn-live[aria-pressed="true"] {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

dialog {
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 26px;
  max-width: min(420px, calc(100vw - 32px));
  font-family: var(--font);
}
dialog::backdrop { background: rgba(0, 0, 0, .38); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 10px; font-size: 20px; letter-spacing: -.02em; }
dialog p { margin: 0 0 10px; font-size: 14.5px; line-height: 1.5; color: var(--muted); }
dialog p.fine { margin-bottom: 18px; }
.dlg-actions { display: flex; gap: 9px; justify-content: flex-end; margin: 0; }

/* ── état et erreurs ────────────────────────────────────────────────── */

/* L'attribut `hidden` ne masque que via `display:none` dans la feuille de
   style du navigateur : n'importe quelle règle `display` de l'auteur le
   neutralise. Ces deux éléments en ont une, il faut donc le rétablir. */
.status[hidden], .toast[hidden] { display: none; }

.status {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 980px;
  padding: 9px 17px 9px 13px;
  font-size: 13px;
  color: var(--muted);
  z-index: 20;
}
.status-bar {
  width: 58px;
  height: 3px;
  border-radius: 2px;
  background: var(--surface-2);
  overflow: hidden;
}
.status-bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 2px;
  transition: width .12s linear;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(440px, calc(100vw - 32px));
  background: var(--text);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 13px;
  font-size: 14px;
  line-height: 1.4;
  box-shadow: var(--shadow);
  z-index: 30;
  animation: rise .3s cubic-bezier(.22,.61,.36,1);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}

@media (max-width: 420px) {
  .row.range { grid-template-columns: 96px 1fr 46px; font-size: 13.5px; }
  .presets { grid-template-columns: repeat(auto-fill, minmax(133px, 1fr)); }
  .transport { flex-wrap: wrap; }
  .segmented { margin-left: 0; width: 100%; }
  .segmented button { flex: 1; }
}
