:root {
  color-scheme: dark;
  --red: #c12626;
}
* { margin:0; padding:0; box-sizing: border-box; }
html, body {
  height: 100%;
  background: #0c0b0a;
  color: #aaa;
  font-family: ui-monospace, monospace;
  overflow-y: auto; overflow-x: hidden;
}
body {
  display: flex; flex-direction: column;
  align-items: center;
  padding: 5vh 16px 10vh;
  gap: 5vh;
}

/* soupe primordiale derrière tout, pluie de 303 par-dessus */
#soupe, #rain303 {
  position: fixed; inset: 0;
  width: 100vw; height: 100vh;
  z-index: 0;
  pointer-events: none;
}
.poem, .tb303, #mode-hud { position: relative; z-index: 1; }
#mode-hud { position: fixed; }

/* ── panneau soupe (bas gauche) ── */
#soupe-ui {
  position: fixed; left: 16px; bottom: 16px; z-index: 50;
  font-family: ui-monospace, monospace;
}
#soupe-toggle {
  border: 1px solid #333;
  background: rgba(0,0,0,0.7);
  color: #888;
  font-family: inherit;
  font-size: 10px; letter-spacing: 3px;
  padding: 6px 12px;
  cursor: pointer;
}
#soupe-toggle:hover, #soupe-toggle.open { color: #f4f1e8; border-color: #555; }
#soupe-panel {
  position: absolute; left: 0; bottom: 34px;
  width: 230px;
  background: rgba(0,0,0,0.82);
  border: 1px solid #333;
  padding: 12px 14px;
}
#soupe-panel[hidden] { display: none; }
.sp-row {
  display: grid;
  grid-template-columns: 58px 1fr 34px;
  align-items: center; gap: 8px;
  margin: 5px 0;
  font-size: 10px; letter-spacing: 1px; color: #888;
}
.sp-row span { text-align: right; color: #aaa; }
.sp-row input[type="range"] {
  width: 100%;
  accent-color: var(--red);
  background: transparent;
  cursor: ew-resize;
}
.sp-actions {
  display: flex; align-items: center; gap: 10px;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid #222;
}
.sp-actions button {
  border: 1px solid #333; background: none;
  color: #888; font-family: inherit;
  font-size: 10px; letter-spacing: 2px;
  padding: 4px 10px; cursor: pointer;
}
.sp-actions button:hover { color: #f4f1e8; border-color: #555; }
.sp-actions a {
  margin-left: auto;
  color: #666; text-decoration: none;
  font-size: 10px; letter-spacing: 1px;
}
.sp-actions a:hover { color: #f4f1e8; }

/* h1 pour les machines, invisible pour les humains */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
  white-space: nowrap;
}

/* ── poème ────────────────────────────────────────── */
.poem {
  text-align: center;
  color: #888;
  font-size: 12px; letter-spacing: 3px;
  line-height: 2; max-width: 720px;
  font-style: italic;
  border: 1px solid #26221d;
  background: rgba(12, 11, 10, 0.82);
  border-radius: 4px;
  padding: 26px 40px;
}
.poem p { margin: 0; }
.poem .emph { color: #f4f1e8; margin-top: 14px; letter-spacing: 6px; }

/* "résonne" brille doucement : l'indice de la résonance au max */
.poem .glint {
  color: #f4f1e8;
  animation: glint 4s ease-in-out infinite;
}
@keyframes glint {
  0%, 100% { text-shadow: 0 0 0 rgba(255, 90, 90, 0); }
  50%      { color: #fff; text-shadow: 0 0 12px rgba(255, 90, 90, 0.75); }
}

/* ── tb303 panel + overlays ─────────────────────────── */
/* Pas de photo : le panneau est nu, les zones colorées de placement
   SONT l'interface. */
.tb303 {
  position: relative;
  width: min(860px, 90vw);
  aspect-ratio: 1656 / 814;
  background: #14120f;
  border: 1px solid #26221d;
  border-radius: 4px;
  box-shadow: 0 30px 90px rgba(0,0,0,0.85);
  user-select: none;
}

/* ── KNOB OVERLAY ─────────────────────────────────── */
/* Chaque knob est un cercle invisible à dragger.
   À l'intérieur, .ki est un petit indicateur rouge qui tourne
   pour montrer la position. */
.ko {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--d);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  cursor: ns-resize;
  border-radius: 50%;
  /* zones de placement assumées comme design */
  background: rgba(255, 80, 80, 0.25);
  outline: 2px dashed rgba(255, 80, 80, 0.8);
  z-index: 10;
  touch-action: none;
  pointer-events: auto;
}
.ko:hover  { background: rgba(255, 80, 80, 0.45); }
.ko:active { background: rgba(255, 80, 80, 0.7); }
.ko::before {
  /* léger highlight au hover pour aider à viser, sinon transparent */
  content: '';
  position: absolute; inset: 0;
  border-radius: 50%;
  background: rgba(255,80,80, 0);
  transition: background .15s;
  pointer-events: none;
}
.ko:hover::before { background: rgba(255,80,80, 0.06); }
.ko:active::before { background: rgba(255,80,80, 0.12); }

/* indicateur rotatif à l'intérieur du knob */
.ki {
  position: absolute;
  left: 50%; top: 50%;
  width: 100%; height: 100%;
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(var(--angle, -135deg));
  transition: transform 0.08s ease-out;
}
.ki::before {
  content: '';
  position: absolute;
  left: 50%; top: 8%;
  width: 5%; height: 28%;
  background: linear-gradient(180deg, #ff5050 0%, #c12626 100%);
  transform: translateX(-50%);
  border-radius: 1px;
  box-shadow: 0 0 6px #ff505099;
}
.ki.big::before {
  height: 22%;
  top: 12%;
}

/* RESONANCE halo */
.ko.reso .halo {
  position: absolute;
  inset: -50%;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle, transparent 30%, transparent 60%);
  transition: background 0.2s;
}
.ko.reso.hot .halo {
  background: radial-gradient(circle,
    rgba(193,38,38,calc(var(--res, 0) * 0.6)) 30%,
    transparent 65%);
  animation: halo-pulse 0.6s ease-in-out infinite alternate;
}
@keyframes halo-pulse {
  from { transform: scale(1); }
  to   { transform: scale(1.1); }
}

/* ── ROTARY (PATT.GROUP / MODE) ── */
/* le knob central tourne, on garde la même base */
.ko.rotary .ki::before {
  /* triangle indicator vers l'extérieur */
  background: linear-gradient(180deg, #1a1a1a 0%, #000 100%);
  width: 6%;
  box-shadow: 0 0 4px #fff5;
}

/* ── KEYBOARD KEYS ── */
.key, .pat-btn, .sysbtn {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--w);
  height: var(--h);
  border: 0;
  cursor: pointer;
  border-radius: 2px;
  transition: background .12s, box-shadow .12s;
}
/* couleurs distinctes par type de contrôle, gardées comme design */
.key     { background: rgba( 80, 200, 255, 0.30); outline: 1px dashed rgba( 80,200,255,0.9); }
.pat-btn { background: rgba(255, 220,  60, 0.30); outline: 1px dashed rgba(255,220,60,0.9); }
.sysbtn  { background: rgba( 80, 255, 120, 0.30); outline: 1px dashed rgba( 80,255,120,0.9); }
.key:hover, .pat-btn:hover, .sysbtn:hover { filter: brightness(1.5); }
.key:active, .pat-btn:active, .sysbtn:active { filter: brightness(2); }
.key.lit {
  background: rgba(255,80,80, 0.35);
  box-shadow: 0 0 14px var(--red);
}

.pat-btn.active {
  box-shadow: inset 0 0 0 2px var(--red), 0 0 10px #c1262688;
}
.pat-btn.step {
  background: rgba(255,80,80, 0.5);
  box-shadow: 0 0 14px var(--red);
}
.pat-btn.write { box-shadow: inset 0 0 0 2px #fff; }

.sysbtn.on {
  background: rgba(255,80,80, 0.35);
  box-shadow: 0 0 12px var(--red);
}

/* ── HUD ─── */
#mode-hud {
  position: fixed; top: 16px; right: 16px; z-index: 50;
  background: rgba(0,0,0,0.7);
  border: 1px solid #333;
  padding: 8px 12px;
  font-size: 10px; letter-spacing: 2px;
  color: #aaa;
  text-align: right;
  min-width: 200px;
}
#mode-hud .mh-mode {
  font-size: 14px; font-weight: 700;
  letter-spacing: 5px;
  color: #d8d2c2;
  text-transform: uppercase;
  margin-bottom: 4px;
}
#mode-hud.pitch .mh-mode { color: #f4f1e8; }
#mode-hud.time  .mh-mode { color: var(--red); }
#mode-hud .mh-info { font-size: 9px; color: #666; }

/* fade out à l'ouverture */
#fade {
  position: fixed; inset: 0;
  background: #000; z-index: 100;
  opacity: 0; pointer-events: none;
  transition: opacity 1.4s;
}
#fade.show { opacity: 1; pointer-events: all; }
