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

:root {
  --fg: #f1e6d2;
  --dim: rgba(241, 230, 210, 0.6);
  --faint: rgba(241, 230, 210, 0.3);
  --line: rgba(241, 230, 210, 0.12);
  --glass: rgba(26, 17, 11, 0.78);
  --panel: rgba(20, 13, 9, 0.96);
  --brass: #d8b46a;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, "Courier New", monospace;
}

html, body { height: 100%; }
body {
  background: #0b0705;
  color: var(--fg);
  overflow: hidden;
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#c {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
}

button, select, input { font: inherit; color: inherit; }

/* ── Intro ─────────────────────────────────────────────────────────────── */
#intro {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(11, 7, 5, 0.55), rgba(11, 7, 5, 0.9));
  cursor: pointer;
  transition: opacity 0.6s ease;
}
body.started #intro { opacity: 0; pointer-events: none; }
.intro-card { max-width: 30rem; text-align: center; }
.intro-card h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400; font-style: italic;
  font-size: clamp(2.2rem, 8vw, 3.4rem);
  color: var(--brass);
  margin-bottom: 1rem;
}
.intro-card p { line-height: 1.55; color: rgba(241, 230, 210, 0.85); }
.intro-sub { margin-top: 0.5rem; color: var(--dim) !important; font-size: 0.9rem; }
.intro-go {
  display: inline-block; margin-top: 1.6rem;
  padding: 0.7rem 1.4rem; border-radius: 999px;
  border: 1px solid rgba(216, 180, 106, 0.5);
  color: var(--brass); font-size: 0.92rem;
}

/* ── Barre d'outils ────────────────────────────────────────────────────── */
#bar {
  position: fixed; top: 10px; left: 10px; right: 10px; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  transition: opacity 0.3s ease;
}
#bar .grow { flex: 1; }
.tb {
  height: 38px; min-width: 38px; padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  cursor: pointer;
}
.tb:hover { border-color: rgba(216, 180, 106, 0.45); }
.tb svg { width: 18px; height: 18px; flex: none; }
.tb .lbl { font-size: 0.85rem; }
#btn-motor { padding: 0 14px 0 10px; }
#btn-motor .i-pause { display: none; }
#btn-motor[aria-pressed="true"] { border-color: var(--brass); color: var(--brass); }
#btn-motor[aria-pressed="true"] .i-play { display: none; }
#btn-motor[aria-pressed="true"] .i-pause { display: block; }
.sel { appearance: none; -webkit-appearance: none; padding: 0 12px; max-width: 13rem; font-size: 0.85rem; }
.sel option { background: #1a110b; }
.tempo {
  height: 38px; padding: 0 10px; display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--glass);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  font-family: var(--mono); font-size: 0.8rem;
}
.tempo input[type="range"] { width: 110px; }
.tempo .unit { color: var(--dim); margin-left: -4px; }
#tempo-val {
  width: 3.2ch; padding: 2px 0; text-align: center; font: inherit; color: var(--fg);
  background: transparent; border: 1px solid transparent; border-radius: 5px;
}
#tempo-val:hover { border-color: var(--line); }
#tempo-val:focus { outline: none; border-color: var(--brass); background: rgba(0, 0, 0, 0.25); }
.tempo .step {
  width: 22px; height: 22px; padding: 0; border: 1px solid var(--line); border-radius: 6px;
  background: transparent; color: var(--dim); font: inherit; line-height: 1; cursor: pointer;
}
.tempo .step:hover { color: var(--fg); border-color: var(--brass); }
.tempo { gap: 6px; }

input[type="range"] { accent-color: var(--brass); }
input[type="checkbox"] { accent-color: var(--brass); width: 18px; height: 18px; }

#btn-unhide {
  position: fixed; top: 10px; right: 10px; z-index: 21;
  width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--glass);
  display: none; align-items: center; justify-content: center; cursor: pointer;
  opacity: 0.55;
}
#btn-unhide svg { width: 18px; height: 18px; }
body.hide-ui #bar, body.hide-ui #panel { opacity: 0; pointer-events: none; }
body.hide-ui #btn-unhide { display: inline-flex; }

/* ── Panneau ───────────────────────────────────────────────────────────── */
#panel {
  position: fixed; top: 58px; right: 10px; bottom: 50px; z-index: 30;
  width: 300px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px 16px;
  transform: translateX(calc(100% + 20px)); transition: transform 0.25s ease, opacity 0.3s ease;
}
body.panel-open #panel { transform: none; }
.ph { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-family: Georgia, serif; font-style: italic; color: var(--brass); font-size: 1.1rem; }
.ph button { background: none; border: 0; cursor: pointer; color: var(--dim); font-size: 1rem; padding: 4px 6px; }
#panel section { padding: 10px 0; border-top: 1px solid var(--line); }
#panel h2 { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--dim); font-weight: 500; margin-bottom: 8px; }
.row { display: grid; grid-template-columns: 6.2rem 1fr 2.4rem; align-items: center; gap: 8px; min-height: 34px; font-size: 0.86rem; }
.row.chk { grid-template-columns: 1fr auto; }
.row output { font-family: var(--mono); font-size: 0.78rem; color: var(--dim); text-align: right; }
.row:has(.seg) { grid-template-columns: 6.2rem 1fr; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; padding: 6px 4px; background: none; border: 0; cursor: pointer; font-size: 0.78rem; color: var(--dim); }
.seg button.on { background: rgba(216, 180, 106, 0.18); color: var(--brass); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid button { padding: 8px 6px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255, 240, 210, 0.04); cursor: pointer; font-size: 0.8rem; }
.grid button:hover, .grid button.on { border-color: rgba(216, 180, 106, 0.5); color: var(--brass); }
.note { margin-top: 8px; font-size: 0.76rem; color: var(--dim); line-height: 1.4; }
#keys { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 0.8rem; }
#keys dt { font-family: var(--mono); color: var(--brass); }
#keys dd { color: var(--dim); }

/* ── Toast, dépôt, debug ───────────────────────────────────────────────── */
#toast {
  position: fixed; left: 50%; bottom: 56px; z-index: 40;
  transform: translate(-50%, 10px); opacity: 0;
  padding: 9px 16px; border-radius: 999px;
  background: rgba(26, 17, 11, 0.92); border: 1px solid rgba(216, 180, 106, 0.35);
  font-size: 0.86rem; pointer-events: none; white-space: nowrap; max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#drop-hint {
  position: fixed; inset: 16px; z-index: 45; display: none;
  align-items: center; justify-content: center;
  border: 2px dashed rgba(216, 180, 106, 0.6); border-radius: 18px;
  background: rgba(11, 7, 5, 0.7); color: var(--brass); font-size: 1.1rem;
}
body.dragging #drop-hint { display: flex; }
#debug {
  position: fixed; right: 40px; bottom: 50px; z-index: 25;
  padding: 6px 9px; border-radius: 8px; background: rgba(0, 0, 0, 0.7);
  font: 11px/1.45 var(--mono); color: #b9f0a8; pointer-events: none;
}

/* ── Petits écrans ─────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  #bar { gap: 4px; left: 8px; right: 8px; top: 8px; flex-wrap: nowrap; }
  .tb { height: 36px; min-width: 36px; padding: 0 8px; }
  #btn-motor .lbl, #btn-share, #btn-fs { display: none; }
  #btn-motor { padding: 0 8px; }
  .tempo { height: 36px; padding: 0 8px; gap: 4px; }
  .tempo input[type="range"] { width: 64px; }
  .tempo .unit { display: none; }
  .sel { max-width: 6.6rem; padding: 0 8px; }
  #panel { left: 8px; right: 8px; width: auto; top: 52px; bottom: 46px; }
}
@media (max-width: 460px) {
  #btn-clear, #btn-hide { display: none; }
  .tempo input[type="range"] { width: 48px; }
  .sel { max-width: 5.6rem; }
}
@media (pointer: coarse) {
  .row { min-height: 42px; }
  .seg button, .grid button { padding: 10px 6px; }
}
