/* ============================================================
   TONETZ — Feuille de style
   Esthétique « laboratoire / partition » : papier crème,
   encre profonde, accent terracotta, données en mono.
   ============================================================ */
:root {
  --paper:   #ece4d4;
  --paper-2: #e3d9c5;
  --card:    #f4eee0;
  --ink:     #20201d;
  --ink-soft:#76705f;
  --line:    #c9bfa9;
  --accent:  #c44d2c;   /* terracotta */
  --accent-2:#1f6b62;   /* teal profond */
  --gold:    #b08418;
  --shadow:  0 1px 0 #fff8, 0 12px 28px -16px #2a241680;
  --r: 4px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  background:
    radial-gradient(circle at 20% -10%, #f6f0e2 0%, transparent 45%),
    radial-gradient(circle at 100% 0%, #e8dfca 0%, transparent 40%),
    var(--paper);
  color: var(--ink);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

/* grain texture */
.grain {
  position: fixed; inset: 0; z-index: 9999; pointer-events: none; opacity: .045;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 22px 34px 14px;
  border-bottom: 1.5px solid var(--ink);
}
.brand { display: flex; align-items: baseline; gap: 14px; }
.logo { font-size: 26px; color: var(--accent); transform: translateY(2px); }
.brand-name { display: flex; flex-direction: column; }
.brand h1 {
  font-family: "Fraunces", serif; font-weight: 900; font-size: 38px;
  letter-spacing: -1.5px; line-height: .8;
}
.byline {
  font-family: "Fraunces", serif; font-style: italic; font-size: 13px;
  color: var(--accent); margin-top: 4px; letter-spacing: .3px;
}
.tagline { font-size: 11px; letter-spacing: 3px; text-transform: uppercase; color: var(--ink-soft); }

.tabs { display: flex; gap: 6px; }
.tab {
  font-family: "IBM Plex Mono", monospace; font-size: 13px; letter-spacing: .5px;
  background: transparent; border: 1.5px solid var(--ink); color: var(--ink);
  padding: 9px 18px; cursor: pointer; border-radius: var(--r) var(--r) 0 0;
  border-bottom: none; transition: all .15s; position: relative; top: 1.5px;
}
.tab:hover { background: var(--card); }
.tab.active { background: var(--ink); color: var(--paper); }

/* ---------- Panels ---------- */
.panel { display: none; flex: 1; padding: 26px 34px; gap: 26px; }
.panel.active { display: grid; }
#panel-harmony { grid-template-columns: minmax(340px, 420px) 1fr; }
#panel-rhythm  { grid-template-columns: 300px 1fr; }

.col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

.block {
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: var(--r);
  padding: 16px 16px 18px;
  box-shadow: var(--shadow);
}
.block.grow { flex: 1; }

.block-title {
  font-family: "Fraunces", serif; font-weight: 600; font-style: italic;
  font-size: 17px; margin-bottom: 12px; display: block;
}
.block-title.sub { font-size: 14px; margin-top: 16px; }
.block-title.sticky { position: sticky; top: 0; }

/* ---------- Inputs ---------- */
textarea#h-input {
  width: 100%; min-height: 64px; resize: vertical;
  font-family: "IBM Plex Mono", monospace; font-size: 16px; font-weight: 500;
  background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--r);
  padding: 12px; color: var(--ink); letter-spacing: .5px;
}
textarea#h-input:focus { outline: none; border-color: var(--accent); }

.row { display: flex; gap: 10px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.row.col-stack { flex-direction: column; align-items: stretch; }

.btn {
  font-family: "IBM Plex Mono", monospace; font-size: 13px; font-weight: 500;
  border: 1.5px solid var(--ink); border-radius: var(--r); cursor: pointer;
  padding: 9px 14px; background: var(--paper); color: var(--ink); transition: all .12s;
}
.btn:hover { transform: translate(-1px,-1px); box-shadow: 2px 2px 0 var(--ink); }
.btn:active { transform: translate(0,0); box-shadow: none; }
.btn-primary { background: var(--accent); color: #fff7ee; border-color: var(--accent); }
.btn-primary:hover { box-shadow: 2px 2px 0 var(--ink); }
.btn-ghost { background: transparent; }
.btn.playing {
  background: var(--accent-2); color: #f4eee0; border-color: var(--accent-2);
  animation: pulse 1.1s ease-in-out infinite;
}
.btn.playing:hover { box-shadow: 2px 2px 0 var(--ink); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-2) 55%, transparent); }
  50%      { box-shadow: 0 0 0 5px transparent; }
}

.key-badge {
  margin-left: auto; font-size: 13px; color: var(--ink-soft);
  border-left: 2px solid var(--accent); padding-left: 10px;
}
.key-badge strong { color: var(--accent-2); }

.hint { font-size: 11px; color: var(--ink-soft); margin-top: 10px; line-height: 1.5; }
.hint code, code { background: var(--paper-2); padding: 1px 5px; border-radius: 3px; font-size: 11px; }

/* ---------- Staff / contrepoint ---------- */
.staff {
  width: 100%; height: 170px; background: var(--paper);
  border: 1.5px solid var(--line); border-radius: var(--r); display: block;
}
.cp-info { font-size: 11.5px; color: var(--ink-soft); margin: 10px 0; line-height: 1.5; }
.cp-info strong { color: var(--accent); }

.modified {
  background: var(--paper); border: 1.5px dashed var(--line); border-radius: var(--r);
  padding: 10px 12px; font-size: 15px; letter-spacing: .5px; word-break: break-word;
}

/* ---------- Cards (substitutions) ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; align-content: start; }
.chord-card {
  background: var(--card); border: 1.5px solid var(--ink); border-radius: var(--r);
  padding: 12px; transition: all .15s; box-shadow: var(--shadow);
}
.chord-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1.5px var(--accent), var(--shadow); }
.chord-card.playing { background: #f7e6d8; }

.cc-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.cc-roman { font-family: "Fraunces", serif; font-style: italic; color: var(--accent-2); font-size: 16px; min-width: 32px; }
.cc-name {
  font-family: "Fraunces", serif; font-weight: 600; font-size: 22px;
  background: none; border: none; cursor: pointer; color: var(--ink); letter-spacing: -.5px;
}
.cc-name:hover { color: var(--accent); }

/* diagramme guitare */
.cc-guitar { margin: 8px 0 10px; display: flex; justify-content: center; }
.gtr { width: 88px; height: auto; }
.gtr svg, .cc-guitar svg { cursor: pointer; transition: transform .12s; }
.cc-guitar svg:hover { transform: scale(1.06); }
.gtr-name { fill: var(--ink); font-family: "Fraunces", serif; font-weight: 600; font-size: 11px; }
.gtr-line { stroke: var(--ink-soft); stroke-width: 1; }
.gtr-nut { fill: var(--ink); }
.gtr-dot { fill: var(--accent); }
.gtr-open { fill: none; stroke: var(--ink); stroke-width: 1.3; }
.gtr-mk { fill: var(--ink-soft); font-family: "IBM Plex Mono", monospace; font-size: 9px; }
.gtr-fr { fill: var(--ink-soft); font-family: "IBM Plex Mono", monospace; font-size: 8px; }

.btn.active { background: var(--accent-2); color: #f4eee0; border-color: var(--accent-2); }

.cc-subs { display: flex; flex-direction: column; gap: 6px; }
.sub {
  display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto;
  gap: 1px 8px; text-align: left; cursor: pointer;
  background: var(--paper); border: 1px solid var(--line); border-radius: 3px; padding: 6px 9px;
  transition: all .12s;
}
.sub:hover { border-color: var(--accent); background: #f8f1e3; }
.sub.picked { border-color: var(--accent); background: #f6e3d6; box-shadow: inset 0 0 0 1px var(--accent); }
.sub-sym { font-weight: 600; font-size: 15px; }
.sub-rule { grid-column: 1; font-size: 10px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .5px; }
.sub-meta { grid-column: 2; grid-row: 1 / 3; display: flex; flex-direction: column; align-items: flex-end; justify-content: center; gap: 3px; }
.score {
  font-size: 11px; font-weight: 600; color: #fff;
  background: linear-gradient(90deg, var(--accent-2), var(--gold));
  padding: 1px 6px; border-radius: 8px;
  filter: saturate(calc(var(--s) / 100 + .3));
}
.tension { font-size: 9px; letter-spacing: -1px; }
.tension.t1 { color: var(--accent-2); }
.tension.t2 { color: var(--gold); }
.tension.t3 { color: #c98a2a; }
.tension.t4 { color: var(--accent); }
.tension.t5 { color: #9c2a13; }

/* ---------- Rythme ---------- */
.ctl { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px 10px; margin-bottom: 14px; font-size: 12px; }
.ctl output { font-weight: 600; color: var(--accent); }
.ctl input[type=range], .density input[type=range] { grid-column: 1 / 3; width: 100%; }
.ctl select, .ctl .num-input { grid-column: 2; background: var(--paper); border: 1.5px solid var(--line); border-radius: 3px; padding: 4px 8px; font-family: inherit; }
.ctl .num-input { width: 80px; color: var(--ink); }
.ctl .num-input:focus { outline: none; border-color: var(--accent); }

input[type=range] { -webkit-appearance: none; appearance: none; height: 3px; background: var(--line); border-radius: 2px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%; background: var(--accent); border: 2px solid var(--paper); cursor: pointer; box-shadow: 0 0 0 1px var(--ink); }
input[type=range]::-moz-range-thumb { width: 15px; height: 15px; border-radius: 50%; background: var(--accent); border: 2px solid var(--paper); cursor: pointer; }

.density { display: flex; flex-direction: column; gap: 10px; }
.dens-row { display: grid; grid-template-columns: 1fr; gap: 3px; font-size: 11px; }
.dens-row span { color: var(--ink-soft); }

.hint.nudge { margin-top: -6px; margin-bottom: 14px; }
.row.inline { flex-wrap: nowrap; gap: 6px; margin-top: 0; }
.row.inline .btn { flex: 1; }
.bar-pick { background: var(--paper); border: 1.5px solid var(--ink); border-radius: var(--r); padding: 0 8px; font-family: inherit; cursor: pointer; }

/* piano roll */
.roll-block { flex: 1; display: flex; padding: 8px; }
.piano-roll {
  width: 100%; height: 100%; min-height: 360px; display: block; cursor: pointer;
  background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--r);
}
.col-grid { min-height: 420px; }

/* ---------- Analyse d'accords ---------- */
#panel-analyser { grid-template-columns: minmax(320px, 400px) 1fr; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 130px; padding: 18px; text-align: center; cursor: pointer;
  background: var(--paper); border: 2px dashed var(--line); border-radius: var(--r);
  color: var(--ink-soft); transition: all .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: #f8f1e3; color: var(--ink); }
.dropzone.loaded { border-style: solid; border-color: var(--accent-2); }
.dz-icon { font-size: 30px; color: var(--accent); line-height: 1; }
.dz-text { font-size: 12.5px; line-height: 1.5; }
.dz-text em { font-style: italic; color: var(--accent); }
.dz-file { font-size: 12px; font-weight: 600; color: var(--accent-2); word-break: break-all; }
.dz-file:empty { display: none; }

.progress {
  height: 0; margin: 0; opacity: 0; overflow: hidden;
  background: var(--paper); border: 1.5px solid var(--line); border-radius: 4px;
  transition: opacity .2s;
}
.progress.show { opacity: 1; height: 8px; margin: 12px 0 8px; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width .12s; }

.a-transport { margin-bottom: 12px; }
.a-now { font-size: 13px; font-weight: 600; color: var(--accent-2); margin-left: auto; }

/* timeline des segments */
.timeline {
  position: relative; height: 56px; width: 100%;
  background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--r);
  overflow: hidden;
}
.seg {
  position: absolute; top: 0; bottom: 0; display: flex; align-items: center; justify-content: center;
  border-right: 1px solid var(--paper); cursor: pointer; overflow: hidden;
  background: color-mix(in srgb, var(--accent-2) 24%, var(--card));
  transition: background .12s;
}
.seg:hover { background: color-mix(in srgb, var(--accent-2) 42%, var(--card)); }
.seg.active { background: var(--accent); }
.seg.active .seg-lbl { color: #fff7ee; }
.seg.nc { background: repeating-linear-gradient(45deg, var(--paper-2), var(--paper-2) 4px, var(--paper) 4px, var(--paper) 8px); }
.seg-lbl {
  font-family: "Fraunces", serif; font-weight: 600; font-size: 13px; color: var(--ink);
  white-space: nowrap; padding: 0 2px; pointer-events: none;
}
.playhead {
  position: absolute; top: 0; bottom: 0; width: 2px; left: 0; background: var(--ink);
  pointer-events: none; z-index: 3; box-shadow: 0 0 0 1px #fff6;
}

/* galerie de diagrammes guitare */
.grids-gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 12px; align-content: start;
}
.grids-gallery:empty::before {
  content: "Aucune analyse pour l'instant."; color: var(--ink-soft); font-size: 12px;
}
.grid-cell {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 6px; background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r);
  cursor: pointer; transition: all .12s;
}
.grid-cell:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.grid-cell.active { border-color: var(--accent); box-shadow: 0 0 0 1.5px var(--accent), var(--shadow); background: #f7e6d8; }
.grid-dur { font-size: 10px; color: var(--ink-soft); }

/* ---------- Documentation ---------- */
#panel-help { grid-template-columns: 1fr; }
.doc { max-width: 860px; margin: 0 auto; width: 100%; line-height: 1.65; }
.doc-hero { border-bottom: 1.5px solid var(--ink); padding-bottom: 20px; margin-bottom: 8px; }
.doc-hero h2 { font-family: "Fraunces", serif; font-weight: 900; font-size: 40px; letter-spacing: -1.5px; }
.doc .lead { font-size: 16px; color: var(--ink); max-width: 70ch; margin-top: 10px; }
.doc em { font-style: italic; color: var(--accent-2); }

.doc-sec { margin-top: 40px; }
.doc-tag {
  display: inline-block; font-size: 11px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--paper); background: var(--accent); padding: 3px 10px; border-radius: 2px; margin-bottom: 10px;
}
.doc-sec h3 { font-family: "Fraunces", serif; font-weight: 600; font-size: 27px; letter-spacing: -.5px; margin-bottom: 8px; }
.doc-sec h4 {
  font-family: "IBM Plex Mono", monospace; font-size: 14px; font-weight: 600; letter-spacing: .3px;
  margin: 26px 0 8px; padding-left: 12px; border-left: 3px solid var(--accent);
}
.doc-sec h4 em { font-style: italic; }
.doc p { margin-bottom: 12px; max-width: 72ch; }
.doc ul { margin: 0 0 14px 0; padding-left: 22px; max-width: 72ch; }
.doc li { margin-bottom: 7px; }
.doc strong { font-weight: 600; }

.doc-table {
  width: 100%; border-collapse: collapse; margin: 6px 0 16px;
  background: var(--card); border: 1.5px solid var(--ink); border-radius: var(--r); overflow: hidden;
}
.doc-table th, .doc-table td { text-align: left; padding: 9px 12px; vertical-align: top; font-size: 13px; }
.doc-table thead th { background: var(--ink); color: var(--paper); font-weight: 500; letter-spacing: .5px; }
.doc-table tbody tr + tr { border-top: 1px solid var(--line); }
.doc-table td:first-child { font-weight: 600; white-space: nowrap; color: var(--accent-2); }

.doc .note {
  background: var(--paper-2); border-left: 3px solid var(--gold);
  padding: 10px 14px; font-size: 13px; border-radius: 0 var(--r) var(--r) 0;
}
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: middle; margin: 0 1px; border: 1px solid #0003; }
.doc-foot { margin-top: 36px; padding-top: 18px; border-top: 1.5px solid var(--line); font-size: 12px; color: var(--ink-soft); }

/* ---------- Footer ---------- */
.footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 34px; border-top: 1.5px solid var(--ink);
  font-size: 11px; color: var(--ink-soft); letter-spacing: .5px;
}
.kbd { font-size: 10px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  #panel-harmony, #panel-rhythm { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 14px; }
  .tabs { width: 100%; }
  .tab { flex: 1; }
}
