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

body {
  background: #000;
  overflow: hidden;
  height: 100dvh;
  font-family: 'Courier New', monospace;
}

/* ── Canvases — WebGL spectrogram + 2D overlay (axis labels, draw cursor).
   JS sizes both backing stores. ────────────────────────────────────────── */
#c, #axis {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  -webkit-tap-highlight-color: transparent;
}

#c {
  touch-action: none;   /* finger drawing must not scroll or zoom the page */
}

#axis {
  pointer-events: none;
}

body.mode-draw #c {
  cursor: crosshair;
}

/* ── Overlay (brief parameter feedback) ─────────────────────────────── */
#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  color: white;
  text-align: center;
  gap: 16px;
  opacity: 0;
  transition: opacity 0.8s;
}

#status {
  font-size: 1.1rem;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
  padding: 0.5rem 1.5rem;
  white-space: pre-line;
  letter-spacing: 0.04em;
}

#count {
  font-size: clamp(2.2rem, 12vw, 4.5rem);
  font-weight: bold;
  line-height: 1;
  text-shadow: 0 0 40px rgba(255, 255, 255, 0.4);
  letter-spacing: 0.04em;
}

/* ── Pause badge ─────────────────────────────────────────────────────── */
#pause-badge {
  position: fixed;
  top: 1.4rem;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  font-size: 0.72rem;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.75);
  letter-spacing: 0.12em;
  pointer-events: none;
}

body.paused #pause-badge {
  display: block;
}

/* ── Keyboard shortcut bar (desktop only) ────────────────────────────── */
#tip {
  position: fixed;
  bottom: 1.2rem;
  left: 0;
  right: 0;
  padding: 0 1rem;
  text-align: center;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.32);
  letter-spacing: 0.04em;
  pointer-events: none;
  transition: opacity 0.8s;
}

body.touch #tip {
  display: none;
}

/* ── Camera preview (mode Caméra) — mirrored selfie thumbnail ───────── */
#cam-preview {
  position: fixed;
  left: 1rem;
  bottom: 3rem;
  width: clamp(120px, 16vw, 200px);
  aspect-ratio: 4 / 3;
  border-radius: 0.7rem;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: #000;
  display: none;
  pointer-events: none;
  z-index: 50;
}

body.mode-cam #cam-preview {
  display: block;
}

body.touch #cam-preview {
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
}

#cam-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  opacity: 0.75;
}

#cam-state {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.25rem 0.4rem;
  background: rgba(0, 0, 0, 0.55);
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  text-align: center;
}

/* ── Player (mode Fichier) ───────────────────────────────────────────── */
#player {
  position: fixed;
  left: 50%;
  bottom: 2.8rem;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 2rem));
  display: none;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem 0.8rem;
  background: rgba(8, 8, 8, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  color: #fff;
  z-index: 60;
  transition: opacity 0.4s;
}

body.mode-file #player {
  display: flex;
}

body.touch #player {
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
}

#player button {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.15s, border-color 0.15s;
}

#player button:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.55);
}

#player button svg {
  width: 17px;
  height: 17px;
}

#player-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

#player-name {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#player-time {
  flex-shrink: 0;
  font-size: 0.66rem;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.55);
}

@media (max-width: 420px) {
  #player-time { display: none; }
}

/* ── Drag & drop hint ────────────────────────────────────────────────── */
#drop-hint {
  position: fixed;
  inset: 1rem;
  z-index: 400;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px dashed rgba(255, 255, 255, 0.5);
  border-radius: 1.2rem;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  pointer-events: none;
}

body.dragging #drop-hint {
  display: flex;
}

/* ── Start screen ────────────────────────────────────────────────────── */
#start {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: radial-gradient(ellipse at center, rgba(20, 6, 40, 0.55), rgba(0, 0, 0, 0.85));
  transition: opacity 0.5s;
}

body.started #start {
  opacity: 0;
  pointer-events: none;
}

#start-panel {
  width: min(520px, 100%);
  text-align: center;
  color: #fff;
}

#start-panel h1 {
  font-size: clamp(1.8rem, 7vw, 2.8rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 0 30px rgba(255, 120, 80, 0.45);
}

#start-panel > p {
  margin-top: 0.8rem;
  font-size: 0.9rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.6);
}

#start-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
  margin-top: 1.8rem;
}

/* Short landscape screens (phones turned sideways): 4 in a row */
@media (max-height: 520px) and (min-width: 600px) {
  #start-buttons { grid-template-columns: repeat(4, 1fr); margin-top: 1rem; }
  #start-panel { width: min(760px, 100%); }
  .start-btn { padding: 0.9rem 0.5rem 0.8rem; }
}

.start-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1.3rem 0.6rem 1.1rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 1rem;
  color: #fff;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.18s, border-color 0.18s, box-shadow 0.18s, transform 0.12s;
}

.start-btn svg {
  width: 34px;
  height: 34px;
}

.start-btn span {
  font-size: 1rem;
  font-weight: bold;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.start-btn small {
  font-size: 0.7rem;
  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, 140, 90, 0.3);
  transform: translateY(-2px);
  outline: none;
}

#start-error {
  min-height: 1.2em;
  margin-top: 1rem;
  font-size: 0.78rem;
  color: #ff9a8a;
}

/* ── Sidebar toggle button ───────────────────────────────────────────── */
#btn-sidebar-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 101;
  width: 44px;
  height: 44px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: white;
  font-size: 1.1rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

#btn-sidebar-toggle: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;
}

/* ── 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.6rem;
  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;
  gap: 2rem;
  padding-bottom: env(safe-area-inset-bottom, 2rem);
}

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;
  transition: color 0.15s;
  line-height: 1;
}

#btn-sidebar-close:hover {
  color: rgba(255, 255, 255, 0.9);
}

/* Action tiles: icon badge + caption, 3 per row */
#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.4rem 0.7rem;
  min-height: 84px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  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.64rem;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: color 0.18s;
}

.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.35);
  color: #fff;
}

.action-btn:hover .action-label,
.action-btn:active .action-label {
  color: rgba(255, 255, 255, 0.95);
}

/* Pause tile lit while paused */
#btn-pause.on {
  border-color: rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.08);
}

body.touch .action-btn {
  min-height: 92px;
  padding: 1rem 0.4rem 0.8rem;
}

/* Segmented controls (Mode, Voix / Musique) */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.seg button {
  padding: 0.6rem 0.4rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 0.6rem;
  color: rgba(255, 255, 255, 0.55);
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
  font-weight: bold;
  letter-spacing: 0.06em;
  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.4rem;
}

/* Four modes in one row: tighter type */
.seg-4 {
  grid-template-columns: repeat(4, 1fr);
}

.seg-4 button {
  padding-left: 0.1rem;
  padding-right: 0.1rem;
  font-size: 0.62rem;
  letter-spacing: 0.01em;
}

/* Palette swatches: a horizontal gradient of each color map (see PALETTES) */
#palette-swatches {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.swatch {
  height: 30px;
  width: 100%;
  border-radius: 0.5rem;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.swatch:hover {
  transform: scale(1.05);
}

.swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.8), 0 0 12px rgba(255, 255, 255, 0.5);
}

body.touch .swatch {
  height: 40px;
}

/* Credit line at the very bottom of the sidebar */
#credit {
  font-size: 0.66rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.32);
  letter-spacing: 0.02em;
}

#credit a {
  color: rgba(255, 255, 255, 0.55);
  text-underline-offset: 2px;
}

#credit a:hover {
  color: #fff;
}

/* Individual setting row */
.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-family: 'Courier New', monospace;
  font-size: 0.72rem;
  font-weight: normal;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.45);
  letter-spacing: 0;
}

.setting-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.38);
  letter-spacing: 0.03em;
}

/* Relief only matters in 3D */
body.view-2d .setting.relief {
  opacity: 0.4;
}

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

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.4);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: none;
  cursor: pointer;
}

/* Touch: larger slider thumbs and taller track hit area */
body.touch input[type="range"] {
  height: 28px;
  background: transparent;
  display: flex;
  align-items: center;
}

body.touch input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 3px;
}

body.touch input[type="range"]::-webkit-slider-thumb {
  width: 28px;
  height: 28px;
  margin-top: -12px;
}

body.touch input[type="range"]::-moz-range-thumb {
  width: 28px;
  height: 28px;
}

body.touch input[type="range"]::-moz-range-track {
  height: 3px;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 3px;
}

/* ── Effects rack ────────────────────────────────────────────────────── */
#fx-section {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 1.2rem;
}

#fx-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

#fx-header span {
  font-size: 0.72rem;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.45);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

#btn-fx-off {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.45);
  font-family: 'Courier New', monospace;
  font-size: 0.72rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 0;
}

#btn-fx-off:hover {
  color: rgba(255, 255, 255, 0.85);
}

#fx-note {
  font-size: 0.66rem;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.35);
}

/* Micro and Fichier modes: effects don't apply, the rack is dimmed (still editable) */
body.mode-mic #fx-list,
body.mode-file #fx-list {
  opacity: 0.45;
}

#fx-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  transition: opacity 0.2s;
}

.fx {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 0.75rem 0.85rem 0.9rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0.8rem;
  background: rgba(255, 255, 255, 0.02);
  transition: border-color 0.18s, background 0.18s;
}

.fx.on {
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.05);
}

.fx-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.86rem;
  font-weight: bold;
  color: #fff;
}

.fx-head kbd {
  margin-left: 0.5rem;
  min-width: 1.3rem;
  font-size: 0.6rem;
  vertical-align: middle;
}

body.touch .fx-head kbd {
  display: none;
}

/* On/off switch */
.fx-toggle {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.18s, border-color 0.18s;
}

.fx-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  transition: transform 0.18s, background 0.18s;
}

.fx.on .fx-toggle {
  background: rgba(255, 255, 255, 0.85);
  border-color: #fff;
}

.fx.on .fx-toggle::after {
  transform: translateX(18px);
  background: #111;
}

body.touch .fx-toggle {
  width: 48px;
  height: 28px;
}

body.touch .fx-toggle::after {
  width: 22px;
  height: 22px;
}

body.touch .fx.on .fx-toggle::after {
  transform: translateX(20px);
}

/* Params of an effect that's off read as dormant (touching one turns it on) */
.fx:not(.on) .setting {
  opacity: 0.55;
}

.fx .setting {
  gap: 0.3rem;
}

.fx .setting-name {
  font-size: 0.74rem;
  font-weight: normal;
  color: rgba(255, 255, 255, 0.75);
}

/* Keyboard shortcuts reference */
#shortcuts {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 1.2rem;
  margin-top: 0.4rem;
}

body.touch #shortcuts {
  display: none;
}

.shortcut {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.38);
  letter-spacing: 0.03em;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.8rem;
  padding: 0.1rem 0.4rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0.3rem;
  font-family: 'Courier New', monospace;
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.55);
  white-space: nowrap;
  flex-shrink: 0;
}

#btn-reset-settings {
  align-self: flex-start;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.45);
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 0;
  transition: color 0.15s;
}

#btn-reset-settings:hover {
  color: rgba(255, 255, 255, 0.8);
}

/* ── Hide UI (H key) — hides everything, forces sidebar closed ───────── */
body.ui-hidden #overlay,
body.ui-hidden #tip,
body.ui-hidden #pause-badge,
body.ui-hidden #axis,
body.ui-hidden #cam-preview,
body.ui-hidden #player,
body.ui-hidden #btn-sidebar-toggle {
  opacity: 0 !important;
  pointer-events: none !important;
}

body.ui-hidden #sidebar {
  transform: translateX(100%) !important;
  pointer-events: none !important;
  opacity: 0 !important;
}
