*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  background: #0b0d12;
  overflow: hidden;
  height: 100dvh;
  font-family: 'Courier New', monospace;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;
}

#c {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;   /* le doigt joue le nuage, la page ne doit pas défiler */
  cursor: none;
  -webkit-tap-highlight-color: transparent;
}
body:not(.started) #c, body.recording #c { cursor: default; }

/* ── Readout: the machine's little display ─────────────────────────────── */
#readout {
  position: fixed;
  top: max(0.9rem, env(safe-area-inset-top));
  left: max(0.9rem, env(safe-area-inset-left));
  min-width: 11.5rem;
  padding: 0.5rem 0.75rem 0.55rem;
  background: rgba(10, 14, 12, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.55rem;
  box-shadow: inset 0 0 18px rgba(150, 190, 255, 0.06), 0 6px 18px rgba(0, 0, 0, 0.35);
  color: #c9d8ff;
  pointer-events: none;
  z-index: 40;
  transition: opacity 0.4s;
}
#ro-top {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(201, 216, 255, 0.6);
}
#ro-mode { flex: 1; }
#ro-time { font-variant-numeric: tabular-nums; }
#ro-rec {
  width: 7px; height: 7px; border-radius: 50%;
  background: #ff5a4a;
  box-shadow: 0 0 6px #ff5a4a;
}
#ro-rec { background: #555; box-shadow: none; transition: background 0.2s, box-shadow 0.2s; }
body.playing #ro-rec { background: #ffb36b; box-shadow: 0 0 6px #ffb36b; }
body.taking #ro-rec { background: #ff5a4a; box-shadow: 0 0 6px #ff5a4a; }
#ro-value {
  font-size: 1.25rem;
  font-weight: bold;
  line-height: 1.3;
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 10px rgba(150, 190, 255, 0.35);
}
#ro-sub {
  font-size: 0.64rem;
  letter-spacing: 0.06em;
  color: rgba(201, 216, 255, 0.55);
  min-height: 1em;
}


/* ── Toast ─────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  left: 50%;
  bottom: max(1.4rem, env(safe-area-inset-bottom));
  transform: translate(-50%, 1rem);
  max-width: min(34rem, calc(100vw - 2rem));
  padding: 0.6rem 1rem;
  background: rgba(12, 12, 12, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 0.6rem;
  font-size: 0.78rem;
  line-height: 1.4;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 400;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }


#drop-hint {
  position: fixed;
  inset: 1rem;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px dashed rgba(255, 255, 255, 0.5);
  border-radius: 1rem;
  background: rgba(0, 0, 0, 0.45);
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  z-index: 500;
  pointer-events: none;
}
body.dragging #drop-hint { display: flex; }

/* ── Start screen ──────────────────────────────────────────────────────── */
#start {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(8, 10, 12, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 600;
  transition: opacity 0.5s;
}
body.started #start { opacity: 0; pointer-events: none; }

#start-panel {
  width: min(31rem, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 1.8rem 1.6rem 1.4rem;
  background: rgba(14, 16, 18, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 1rem;
  text-align: center;
}
#start-panel h1 {
  font-size: 1.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 0.9rem;
}
#start-panel p { font-size: 0.86rem; line-height: 1.5; color: rgba(255, 255, 255, 0.78); }
#start-panel .start-sub { margin-top: 0.5rem; color: rgba(255, 255, 255, 0.55); font-size: 0.78rem; }

#start-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.8rem;
  margin: 1.4rem 0 1.1rem;
}
.start-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 1.1rem 0.6rem 0.9rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0.9rem;
  color: #fff;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, transform 0.12s, box-shadow 0.18s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.start-btn svg { width: 30px; height: 30px; }
.start-btn span { font-size: 0.92rem; font-weight: bold; letter-spacing: 0.08em; text-transform: uppercase; }
.start-btn small { font-size: 0.68rem; color: rgba(255, 255, 255, 0.5); }
.start-btn:hover, .start-btn:focus-visible {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 22px rgba(150, 190, 255, 0.28);
  transform: translateY(-2px);
  outline: none;
}
.privacy { font-size: 0.72rem !important; color: rgba(255, 255, 255, 0.5) !important; }
.privacy.small { font-size: 0.66rem !important; line-height: 1.5; color: rgba(255, 255, 255, 0.35) !important; }
#start-error { min-height: 1.2em; margin-top: 0.8rem; font-size: 0.78rem !important; color: #ff9a8a !important; }

/* ── Sidebar toggle / unhide ───────────────────────────────────────────── */
#btn-sidebar-toggle, #btn-unhide {
  position: fixed;
  top: max(0.9rem, env(safe-area-inset-top));
  right: max(0.9rem, env(safe-area-inset-right));
  z-index: 101;
  width: 44px;
  height: 44px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, opacity 0.3s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#btn-sidebar-toggle svg, #btn-unhide svg { width: 20px; height: 20px; }
#btn-sidebar-toggle:hover, #btn-unhide:hover { background: rgba(255, 255, 255, 0.2); border-color: rgba(255, 255, 255, 0.5); }
body.sidebar-open #btn-sidebar-toggle { opacity: 0; pointer-events: none; }
#btn-unhide { display: none; opacity: 0.35; }
body.ui-hidden #btn-unhide { display: flex; }
body.ui-hidden #btn-sidebar-toggle, body.ui-hidden #readout { opacity: 0; pointer-events: none; }
body.ui-hidden:not(.touch) #btn-unhide { display: none; }

/* ── Sidebar ───────────────────────────────────────────────────────────── */
#sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(320px, 100vw);
  background: rgba(8, 8, 8, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 0 1.4rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  z-index: 300;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}
body.touch #sidebar { width: 100vw; padding-bottom: max(2rem, env(safe-area-inset-bottom)); }
body.sidebar-open #sidebar { transform: translateX(0); pointer-events: all; }

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 1.4rem;
  padding-bottom: 0.4rem;
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(8, 8, 8, 0.96);
}
#sidebar-header span { font-size: 0.72rem; font-weight: bold; color: rgba(255, 255, 255, 0.45); letter-spacing: 0.12em; text-transform: uppercase; }
#btn-sidebar-close { background: none; border: none; color: rgba(255, 255, 255, 0.4); font-size: 1.1rem; cursor: pointer; padding: 0.2rem 0.4rem; line-height: 1; }
#btn-sidebar-close:hover { color: #fff; }

#sidebar-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; }
.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0.9rem;
  padding: 0.85rem 0.3rem 0.7rem;
  min-height: 84px;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.18s, border-color 0.18s, transform 0.12s;
}
.action-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: rgba(255, 255, 255, 0.75);
  transition: background 0.18s, border-color 0.18s, box-shadow 0.18s, color 0.18s;
}
.action-icon svg { width: 19px; height: 19px; display: block; }
.action-label {
  font-family: 'Courier New', monospace;
  font-size: 0.6rem;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.action-btn:hover, .action-btn:active { background: rgba(255, 255, 255, 0.07); border-color: rgba(255, 255, 255, 0.26); transform: translateY(-1px); }
.action-btn:hover .action-icon, .action-btn:active .action-icon { background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.55); box-shadow: 0 0 14px rgba(255, 255, 255, 0.3); color: #fff; }
.action-btn:hover .action-label { color: #fff; }
body.taking #btn-take { border-color: rgba(255, 110, 95, 0.7); background: rgba(255, 90, 74, 0.1); }
body.taking #btn-take .action-icon { color: #ff6a5a; border-color: rgba(255, 110, 95, 0.7); box-shadow: 0 0 14px rgba(255, 90, 74, 0.45); }
body:not(.has-sound) #btn-take, body:not(.has-sound) #btn-clear { opacity: 0.35; pointer-events: none; }
.action-btn.busy { opacity: 0.45; pointer-events: none; }

.setting { display: flex; flex-direction: column; gap: 0.45rem; }
.setting-name { display: flex; align-items: baseline; justify-content: space-between; font-size: 0.9rem; font-weight: bold; color: #fff; letter-spacing: 0.02em; }
.setting-value { font-size: 0.72rem; font-weight: normal; font-variant-numeric: tabular-nums; color: rgba(255, 255, 255, 0.45); }
.setting-labels { display: flex; justify-content: space-between; font-size: 0.68rem; color: rgba(255, 255, 255, 0.38); }
.hint { font-size: 0.66rem; line-height: 1.45; color: rgba(255, 255, 255, 0.38); }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; }
.seg-3 { grid-template-columns: repeat(3, 1fr); }
.seg button {
  padding: 0.6rem 0.2rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.55);
  font-family: 'Courier New', monospace;
  font-size: 0.7rem;
  font-weight: bold;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.seg button:hover { border-color: rgba(255, 255, 255, 0.35); color: rgba(255, 255, 255, 0.85); }
.seg button.active { background: rgba(255, 255, 255, 0.12); border-color: #fff; color: #fff; }
body.touch .seg button { padding: 0.85rem 0.2rem; }

.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.5rem; }
.swatch {
  height: 30px;
  border-radius: 999px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.swatch:hover { transform: scale(1.06); }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.8), 0 0 10px rgba(255, 255, 255, 0.45); }

.wide-btn {
  padding: 0.7rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 0.6rem;
  color: rgba(255, 255, 255, 0.7);
  font-family: inherit;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.wide-btn:hover { border-color: rgba(255, 255, 255, 0.45); color: #fff; }
.wide-btn.confirm { border-color: #ff8a7a; color: #ffb3a8; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 2px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  margin: 0.55rem 0;
}
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: #fff; border: none; box-shadow: 0 0 8px rgba(255, 255, 255, 0.4); }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: none; }
body.touch input[type="range"]::-webkit-slider-thumb { width: 26px; height: 26px; }

#shortcuts { display: flex; flex-direction: column; gap: 0.45rem; }
body.touch #shortcuts { display: none; }
#touch-hint { display: none; }
body.touch #touch-hint { display: block; }
.wide-btn + .wide-btn { margin-top: -0.9rem; }
.shortcut { font-size: 0.7rem; color: rgba(255, 255, 255, 0.45); }
kbd {
  display: inline-block;
  min-width: 3.6rem;
  margin-right: 0.4rem;
  padding: 0.1rem 0.35rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 0.3rem;
  font-family: inherit;
  font-size: 0.64rem;
  color: rgba(255, 255, 255, 0.75);
  text-align: center;
}

/* ── Debug ─────────────────────────────────────────────────────────────── */
#debug {
  position: fixed;
  left: 0.8rem;
  bottom: 0.8rem;
  padding: 0.5rem 0.7rem;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 0.4rem;
  font-size: 0.66rem;
  line-height: 1.45;
  color: #b8ffcf;
  z-index: 200;
  pointer-events: none;
  white-space: pre;
}


/* Écrans bas (téléphone en paysage) : carte d'accueil compacte */
@media (max-height: 480px) {
  #start-panel { padding: 1rem 1.2rem 0.8rem; }
  #start-panel h1 { font-size: 1.2rem; margin-bottom: 0.4rem; }
  #start-panel .start-sub { display: none; }
  #start-buttons { margin: 0.8rem 0 0.6rem; }
  .start-btn { padding: 0.6rem 0.5rem; }
  .start-btn svg { width: 22px; height: 22px; }
}

/* ── Enregistrement ────────────────────────────────────────────────────── */
#rec-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(22rem, calc(100vw - 2rem));
  padding: 1.4rem 1.3rem 1.1rem;
  background: rgba(12, 14, 20, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 1rem;
  text-align: center;
  z-index: 550;
  display: none;
}
body.recording #rec-panel { display: block; }
#rec-ring { position: relative; width: 112px; height: 112px; margin: 0 auto 0.9rem; }
#rec-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
#rec-ring circle { fill: none; stroke-width: 3; }
#rec-ring .track { stroke: rgba(255, 255, 255, 0.12); }
#rec-ring .prog { stroke: #ff6a5a; stroke-linecap: round; stroke-dasharray: 276.5; stroke-dashoffset: 276.5; }
body.armed #rec-ring .prog { stroke: rgba(201, 216, 255, 0.75); }
#rec-count {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}
#rec-text { font-size: 0.95rem; font-weight: bold; letter-spacing: 0.04em; }
#rec-sub { margin-top: 0.35rem; font-size: 0.72rem; line-height: 1.45; color: rgba(255, 255, 255, 0.5); }
#rec-buttons { display: grid; grid-template-columns: 1fr; gap: 0.5rem; margin-top: 1rem; }
#rec-buttons .wide-btn { margin: 0; }

@media (max-width: 520px) {
  #start-buttons { gap: 0.5rem; }
  .start-btn { padding: 0.9rem 0.3rem 0.8rem; }
  .start-btn span { font-size: 0.78rem; letter-spacing: 0.04em; }
  .start-btn small { font-size: 0.6rem; }
}

/* Le toast passe au-dessus de la forme d'onde */
body.has-sound #toast { bottom: calc(max(1.4rem, env(safe-area-inset-bottom)) + 4.2rem); }

/* ── Écouter le son entier ─────────────────────────────────────────────── */
#btn-listen {
  position: fixed;
  left: 1rem;
  bottom: 2rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 101;
  transition: background 0.15s, border-color 0.15s, opacity 0.3s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#btn-listen svg { width: 18px; height: 18px; }
#btn-listen:hover { background: rgba(255, 255, 255, 0.18); border-color: rgba(255, 255, 255, 0.6); }
body.has-sound #btn-listen { display: flex; }
body.ui-hidden #btn-listen { opacity: 0; pointer-events: none; }
.i-stop { display: none; }
body.listening .i-stop { display: block; }
body.listening .i-play { display: none; }
body.listening #btn-listen { border-color: rgba(255, 255, 255, 0.7); }
body:not(.has-sound) #btn-listen2 { opacity: 0.35; pointer-events: none; }
#btn-sidebar-toggle, #btn-unhide, #btn-listen { z-index: 650; }

/* Début et fin d'enregistrement bien visibles */
#rec-panel { transition: border-color 0.2s, box-shadow 0.2s; }
body.rec-live #rec-panel { border-color: rgba(255, 106, 90, 0.85); box-shadow: 0 0 0 1px rgba(255, 106, 90, 0.4), 0 0 40px rgba(255, 90, 74, 0.35); }
body.rec-live #rec-text { color: #ff7a6a; }
.rec-dot { display: inline-block; width: 9px; height: 9px; margin-right: 0.5rem; border-radius: 50%; background: #ff5a4a; box-shadow: 0 0 8px #ff5a4a; vertical-align: 1px; animation: rec-blink 1s steps(2, start) infinite; }
body.rec-live #rec-count { color: #ff7a6a; }
body.rec-done #rec-panel { border-color: rgba(140, 230, 170, 0.8); box-shadow: 0 0 36px rgba(120, 230, 160, 0.3); }
body.rec-done #rec-ring .prog { stroke: #8ce6aa; }
body.rec-done #rec-text, body.rec-done #rec-count { color: #a6f0c0; }
@keyframes rec-blink { to { visibility: hidden; } }

/* Décompte */
body.countdown #rec-count { font-size: 3rem; color: #fff; }
body.countdown #rec-count.tick { animation: rec-tick 0.9s ease-out; }
@keyframes rec-tick { from { transform: scale(1.5); opacity: 0.2; } 30% { opacity: 1; } to { transform: scale(1); } }

/* Vérification de la prise */
#rec-wave { display: none; width: 100%; height: 60px; margin: 0 0 0.9rem; border-radius: 0.4rem; background: rgba(255, 255, 255, 0.03); }
#rec-review { display: none; grid-template-columns: 1fr 1fr 1fr; gap: 0.5rem; margin-top: 1rem; }
#rec-review .wide-btn { margin: 0; padding: 0.75rem 0.3rem; }
#rec-review .primary { border-color: rgba(140, 230, 170, 0.8); color: #a6f0c0; background: rgba(120, 230, 160, 0.08); }
#rec-review .primary:hover { background: rgba(120, 230, 160, 0.18); color: #fff; }
body.rec-review #rec-ring { display: none; }
body.rec-review #rec-wave { display: block; }
body.rec-review #rec-review { display: grid; }
body.rec-review #rec-buttons { margin-top: 0.5rem; }
body.rec-review #rec-cancel { border-color: transparent; color: rgba(255, 255, 255, 0.45); padding: 0.4rem; }
body.rec-review.rec-empty #rec-wave, body.rec-review.rec-empty #rec-play, body.rec-review.rec-empty #rec-ok { display: none; }
body.rec-review.rec-empty #rec-review { grid-template-columns: 1fr; }
body.rec-review #rec-panel { width: min(26rem, calc(100vw - 2rem)); }
#rec-play .i-stop { display: none; }
body.rec-playing #rec-play .i-stop { display: inline; }
body.rec-playing #rec-play .i-play { display: none; }
