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

:root {
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --fg: #ece2cf;
  --fg-dim: rgba(236, 226, 207, 0.7);
  --glass: rgba(22, 18, 15, 0.8);
  --line: rgba(236, 226, 207, 0.25);
  --accent: #d9a35f;
}

html, body { width: 100%; height: 100%; }

body {
  background: #0b0a0a;
  overflow: hidden;
  height: 100dvh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
body.idle.started { cursor: none; }

#scene {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;           /* pas de zoom ni de défilement sur la scène */
}

button { font: inherit; color: inherit; }
kbd {
  font-family: inherit;
  font-size: 0.75rem;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
}

/* ── Note chantée ────────────────────────────────────────────────────────── */
#pitch {
  position: fixed;
  left: 50%;
  top: max(0.9rem, var(--sat));
  transform: translate(-50%, -0.4rem);
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  background: rgba(22, 18, 15, 0.55);
  color: var(--fg-dim);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity 0.8s, transform 0.8s;
  pointer-events: none;
  z-index: 20;
}
body.voiced #pitch { opacity: 1; transform: translate(-50%, 0); }
#pitch-note { color: var(--fg); font-weight: 500; min-width: 3.2rem; text-align: center; }
#pitch-cents { font-size: 0.78rem; min-width: 3.4rem; }

/* ── Barre d'outils ──────────────────────────────────────────────────────── */
#toolbar {
  position: fixed;
  left: 50%;
  bottom: max(0.8rem, var(--sab));
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.1rem;
  width: max-content;
  max-width: calc(100vw - 1rem - var(--sal) - var(--sar));
  padding: 0.25rem;
  border-radius: 1.6rem;
  background: var(--glass);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4);
  z-index: 30;
  transition: opacity 0.5s, transform 0.5s;
}
body:not(.started) #toolbar,
body.idle #toolbar {
  opacity: 0;
  transform: translate(-50%, 0.6rem);
  pointer-events: none;
}
#toolbar button {
  position: relative;
  min-width: 2.75rem;
  height: 2.75rem;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 1.4rem;
  background: transparent;
  color: rgba(236, 226, 207, 0.85);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
#toolbar button.txt { padding: 0 0.85rem; font-size: 0.88rem; white-space: nowrap; }
#toolbar button:hover { background: rgba(236, 226, 207, 0.1); color: #fff; }
#toolbar svg { width: 21px; height: 21px; }
#toolbar .group { display: flex; align-items: center; }
#tonic-name { min-width: 2.6rem; text-align: center; font-size: 0.95rem; }
button:focus-visible, input:focus-visible { outline: 1px solid rgba(236, 226, 207, 0.75); outline-offset: 2px; }

#b-mic .i-off, body.mic-off #b-mic .i-on { display: none; }
body.mic-off #b-mic .i-off { display: block; }
body.mic-off #b-mic { color: rgba(236, 226, 207, 0.45); }
#mic-lvl {
  position: absolute;
  left: 30%; right: 30%;
  bottom: 0.32rem;
  height: 2px;
  border-radius: 1px;
  background: var(--accent);
  transform-origin: left;
  transform: scaleX(0);
}
body.mic-off #mic-lvl { display: none; }
#b-instr .i-sitar, body.sitar #b-instr .i-bols { display: none; }
body.sitar #b-instr .i-sitar { display: block; }

/* ── Réglages ────────────────────────────────────────────────────────────── */
#panel {
  position: fixed;
  left: 50%;
  bottom: calc(max(0.8rem, var(--sab)) + 3.7rem);
  transform: translateX(-50%);
  width: min(23rem, calc(100vw - 1rem));
  padding: 0.7rem 0.9rem;
  border-radius: 0.9rem;
  background: rgba(22, 18, 15, 0.94);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  font-size: 0.86rem;
  max-height: calc(100dvh - 5rem - var(--sab) - var(--sat));
  overflow: auto;
  z-index: 32;
}
#panel[hidden], body.idle #panel { display: none; }
body.narrow #panel { bottom: calc(max(0.8rem, var(--sab)) + 6.6rem); }
#panel .row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
}
#panel .lab { width: 5.6rem; flex: none; color: var(--fg-dim); }
#panel .hint { font-size: 0.74rem; color: rgba(236, 226, 207, 0.5); line-height: 1.2; }
#panel input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); height: 2rem; cursor: pointer; }
#panel output { min-width: 4.6rem; text-align: center; font-variant-numeric: tabular-nums; }
#tol-val { text-align: right; }
.round {
  width: 2.75rem; height: 2.75rem;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
}
.round:hover, .wide:hover { background: rgba(236, 226, 207, 0.08); }
.seg { display: flex; padding: 0.15rem; border-radius: 999px; background: rgba(236, 226, 207, 0.06); }
.seg button {
  min-height: 2.4rem;
  padding: 0 0.9rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--fg-dim);
  cursor: pointer;
}
.seg button[aria-pressed="true"] { background: rgba(236, 226, 207, 0.16); color: var(--fg); }
.switch {
  width: 2.9rem; height: 1.7rem;
  flex: none;
  position: relative;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(236, 226, 207, 0.06);
  cursor: pointer;
}
.switch::before { content: ""; position: absolute; inset: -0.55rem -0.1rem; }  /* cible tactile 44 px */
.switch span {
  position: absolute;
  top: 0.2rem; left: 0.22rem;
  width: 1.15rem; height: 1.15rem;
  border-radius: 50%;
  background: rgba(236, 226, 207, 0.6);
  transition: transform 0.2s, background 0.2s;
}
.switch[aria-checked="true"] { background: rgba(217, 163, 95, 0.35); border-color: rgba(217, 163, 95, 0.6); }
.switch[aria-checked="true"] span { transform: translateX(1.15rem); background: var(--fg); }
body:not(.sitar) #jawari-row { display: none; }
.wide {
  flex: 1;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
}
.wide kbd { margin-left: 0.4rem; }

/* ── Aide ────────────────────────────────────────────────────────────────── */
#help {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(1rem, var(--sat)) max(1rem, var(--sar)) max(1rem, var(--sab)) max(1rem, var(--sal));
  background: rgba(8, 7, 6, 0.45);
  z-index: 55;                   /* au-dessus de l'accueil */
}
#help[hidden] { display: none; }
#help-panel {
  max-width: 28rem;
  max-height: calc(100dvh - 2rem);
  overflow: auto;
  padding: 1.2rem 1.4rem 1rem;
  border-radius: 0.7rem;
  background: #17130f;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  font-size: 0.86rem;
  line-height: 1.45;
  -webkit-user-select: text;
  user-select: text;
}
#help h2 { font-size: 1rem; font-weight: 600; margin-bottom: 0.5rem; }
#help p { color: var(--fg-dim); margin-bottom: 0.8rem; }
#help p.small { font-size: 0.78rem; margin: 0.9rem 0 0; }
#help dl { display: grid; grid-template-columns: auto 1fr; gap: 0.4rem 1rem; }
#help dt { white-space: nowrap; }
#help dd { color: var(--fg-dim); }
#help-close {
  display: block;
  margin: 1rem auto 0;
  min-height: 2.75rem;
  padding: 0 1.2rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
}
#help-close:hover { background: rgba(236, 226, 207, 0.08); }

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  left: 50%;
  top: calc(max(0.9rem, var(--sat)) + 3rem);
  transform: translate(-50%, -0.4rem);
  max-width: calc(100vw - 2rem);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  background: rgba(22, 18, 15, 0.9);
  font-size: 0.85rem;
  text-align: center;
  opacity: 0;
  transition: opacity 0.4s, transform 0.4s;
  pointer-events: none;
  z-index: 60;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Accueil ─────────────────────────────────────────────────────────────── */
#start {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(1rem, var(--sat)) max(1rem, var(--sar)) max(1rem, var(--sab)) max(1rem, var(--sal));
  background: radial-gradient(ellipse at 50% 55%, rgba(30, 22, 16, 0.55), rgba(8, 7, 6, 0.85));
  z-index: 50;
  transition: opacity 0.6s;
}
body.started #start { opacity: 0; pointer-events: none; }
#start-panel {
  max-width: 27rem;
  max-height: calc(100dvh - 2rem);
  overflow: auto;
  padding: 1.6rem 1.6rem 1.3rem;
  border-radius: 0.9rem;
  background: rgba(23, 19, 15, 0.94);
  box-shadow: 0 12px 44px rgba(0, 0, 0, 0.5);
  text-align: center;
  line-height: 1.5;
}
#start h1 { font-size: 1.35rem; font-weight: 600; letter-spacing: 0.01em; margin-bottom: 0.7rem; }
#start p { font-size: 0.92rem; color: var(--fg-dim); margin-bottom: 1.1rem; }
#start-mic {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.9rem;
  padding: 0 1.4rem;
  border: 0;
  border-radius: 999px;
  background: #e9d9b8;
  color: #1a140e;
  font-size: 0.98rem;
  font-weight: 500;
  cursor: pointer;
}
#start-mic svg { width: 20px; height: 20px; }
#start-mic:hover { background: #f3e6c9; }
.link {
  display: block;
  margin: 0.6rem auto 1rem;
  min-height: 2.75rem;
  padding: 0 0.6rem;
  border: 0;
  background: none;
  color: var(--fg-dim);
  font-size: 0.86rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
#start p.small { font-size: 0.8rem; margin-bottom: 0.4rem; }
#start .privacy { font-size: 0.78rem; color: rgba(236, 226, 207, 0.5); margin-bottom: 0.6rem; }
#start .keys { font-size: 0.78rem; color: rgba(236, 226, 207, 0.5); margin-bottom: 0; }
#start-error { color: #e6a98f; font-size: 0.85rem; margin: 0.8rem 0 0 !important; }
#start-error:empty { display: none; }
@media (hover: none) { #start .keys { display: none; } }

#debug {
  position: fixed;
  left: 0.5rem; top: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: rgba(0, 0, 0, 0.6);
  color: #b8f0c0;
  font: 11px/1.35 ui-monospace, Menlo, monospace;
  z-index: 70;
  pointer-events: none;
  white-space: pre;
}
