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

html, body { height: 100%; }

body {
  background: #14171b;
  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;   /* dragging the strip must not scroll the page */
  cursor: grab;
  -webkit-tap-highlight-color: transparent;
}
body.scrubbing #c { cursor: grabbing; }

/* ── 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(120, 255, 170, 0.06), 0 6px 18px rgba(0, 0, 0, 0.35);
  color: #9ff0b8;
  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(159, 240, 184, 0.65);
}
#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;
}
body.paused #ro-rec, body.scrubbing #ro-rec { background: #777; box-shadow: none; }
#ro-value {
  font-size: 1.7rem;
  font-weight: bold;
  line-height: 1.15;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 10px rgba(120, 255, 170, 0.35);
}
#ro-sub {
  font-size: 0.64rem;
  letter-spacing: 0.06em;
  color: rgba(159, 240, 184, 0.6);
  min-height: 1em;
}

/* Portrait: the readout sits over the take-up roll, at the bottom */
body.portrait #readout {
  top: auto;
  bottom: max(0.8rem, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  min-width: 0;
  width: min(15rem, calc(100vw - 2rem));
}

/* ── Playing file chip ─────────────────────────────────────────────────── */
#file-chip {
  position: fixed;
  top: max(0.9rem, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 0.6rem;
  max-width: min(26rem, calc(100vw - 9rem));
  padding: 0.35rem 0.4rem 0.35rem 0.9rem;
  background: rgba(10, 12, 14, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  font-size: 0.72rem;
  z-index: 45;
}
body.has-file #file-chip { display: flex; }
#file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: rgba(255,255,255,0.8); }
#file-stop {
  flex-shrink: 0;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  cursor: pointer;
}
body.portrait #file-chip { top: max(0.9rem, env(safe-area-inset-top)); left: 1rem; transform: none; max-width: calc(100vw - 5.5rem); }

/* ── 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); }
body.portrait #toast { bottom: 7.5rem; }

#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: 1fr 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(255, 120, 130, 0.25);
  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, body.ui-hidden #file-chip { 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; }
#btn-pause .i-play { display: none; }
body.paused #btn-pause .i-play { display: block; }
body.paused #btn-pause .i-pause { display: none; }
body.paused #btn-pause { border-color: rgba(255, 255, 255, 0.45); background: rgba(255, 255, 255, 0.08); }
.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); }
body:not(.has-file) #hear-setting { display: none; }

.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); }
body.mode-poly .swatches { opacity: 0.35; }

.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; }
.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;
}
body.portrait #debug { bottom: auto; top: 4.5rem; }

/* É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; }
}
