/* Accords — direction « carnet de musicien » : papier ivoire, encre, vermillon, laiton. */

@font-face {
  font-family: "Fraunces";
  src: url("../fonts/fraunces.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("../fonts/fraunces-italic.woff2") format("woff2");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("../fonts/inter.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f4eee2;
  --paper-deep: #ebe3d2;
  --card: #fbf8f1;
  --ink: #211b17;
  --ink-soft: #6d6157;
  --line: #dccfb9;
  --accent: #d5432a;
  --accent-deep: #b23420;
  --accent-wash: #f7ddd3;
  --on-accent: #fffaf3;
  --brass: #b08d4a;
  --wood: #3b2a21;
  --wood-deep: #2a1d17;
  --string: #e8dcc2;
  --nacre: #f3ecdc;
  --key-white: #fffdf8;
  --key-white-edge: #cfc3ad;
  --key-black: #1e1916;
  --shadow: 0 1px 2px rgba(60, 40, 20, .08), 0 8px 24px -12px rgba(60, 40, 20, .28);
  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 14px;
  --tabbar: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171311;
    --paper-deep: #100d0c;
    --card: #221c19;
    --ink: #f1e9dc;
    --ink-soft: #a79a8b;
    --line: #3b312a;
    --accent: #ee5b3d;
    --accent-deep: #d5432a;
    --accent-wash: #46211a;
    --on-accent: #fff8f0;
    --brass: #c9a55e;
    --wood: #35261e;
    --wood-deep: #241913;
    --string: #d9cdb4;
    --nacre: #e9e0cd;
    --key-white: #ece4d5;
    --key-white-edge: #8d8272;
    --key-black: #0d0a09;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px -12px rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--paper);
  /* grain de papier */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .38 0 0 0 0 .3 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom));
}

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { display: block; }

/* ---------- En-tête et navigation ---------- */

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
}
.brand {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 600;
  font-variation-settings: "opsz" 72;
  letter-spacing: -.02em;
  color: var(--ink);
  text-decoration: none;
  margin-right: auto;
}
.brand i { color: var(--accent); font-style: normal; }
.tools { display: flex; align-items: center; gap: 8px; }

.tabs {
  position: fixed;
  z-index: 20;
  left: 0; right: 0; bottom: 0;
  display: flex;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .01em;
  transition: color .2s;
}
.tabs svg, .icon-btn svg, .btn svg, .play svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.tabs a[aria-current] { color: var(--accent); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  transition: background .2s, color .2s, opacity .2s;
}
.icon-btn:disabled { opacity: .35; }
#sound .cross { display: none; }
#sound.muted { color: var(--ink-soft); }
#sound.muted .waves { display: none; }
#sound.muted .cross { display: inline; }

/* ---------- Bascule segmentée ---------- */

.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--paper-deep);
  box-shadow: inset 0 0 0 1px var(--line);
}
.seg button {
  flex: 1;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  transition: background .25s, color .25s, box-shadow .25s;
}
.seg button[aria-pressed="true"] {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(60, 40, 20, .18), 0 0 0 1px var(--line);
}
.seg.mini button { min-height: 34px; padding: 0 12px; font-family: var(--serif); font-size: 15px; }
.seg.wrap { display: flex; flex-wrap: wrap; border-radius: 22px; }
.seg.wrap button { padding: 0 12px; font-size: 13px; }
.seg.wrap button[aria-pressed="true"] { background: var(--ink); color: var(--paper); box-shadow: none; }

/* ---------- Dictionnaire ---------- */

.view { max-width: 760px; margin: 0 auto; padding: 4px 16px 24px; }

.dico { display: grid; gap: 14px; grid-template-areas: "switches" "stage" "panel"; }
.switches { grid-area: switches; display: flex; gap: 10px; }
.switches .seg { flex: 1; }
.switches .seg button { padding: 0 8px; }
.stage { grid-area: stage; min-width: 0; }
.panel { grid-area: panel; min-width: 0; }

.readout { display: flex; align-items: center; gap: 14px; min-height: 96px; }
.readout-text { flex: 1; min-width: 0; }
.eyebrow {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
}
.chord-name {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-variation-settings: "opsz" 144;
  font-size: clamp(46px, 14vw, 76px);
  line-height: 1.05;
  letter-spacing: -.03em;
  white-space: nowrap;
}
.chord-name .suffix { font-weight: 400; font-size: .62em; letter-spacing: -.01em; margin-left: .04em; }
.chord-name .bass { font-weight: 400; font-size: .62em; color: var(--ink-soft); }
.chord-name.is-notes { font-size: clamp(26px, 8vw, 40px); font-weight: 500; letter-spacing: -.01em; white-space: normal; line-height: 1.2; padding: 8px 0; }
.chord-name.is-empty { font-size: clamp(26px, 8vw, 40px); font-weight: 400; font-style: italic; color: var(--ink-soft); letter-spacing: -.01em; padding: 8px 0; }
.chord-sub { margin: 2px 0 0; color: var(--ink-soft); font-size: 13.5px; min-height: 1.45em; }

.play {
  flex: none;
  display: grid;
  place-items: center;
  width: 60px; height: 60px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 2px 0 var(--accent-deep), 0 10px 20px -8px color-mix(in srgb, var(--accent) 70%, transparent);
  transition: transform .12s, box-shadow .12s, opacity .2s;
}
.play svg { width: 26px; height: 26px; fill: currentColor; stroke-width: 1; margin-left: 2px; }
.play:active { transform: translateY(2px); box-shadow: 0 0 0 var(--accent-deep), 0 4px 10px -6px var(--accent); }
.play:disabled { opacity: .3; box-shadow: none; }

.notes { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; padding: 0; list-style: none; min-height: 40px; }
.notes li {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.15;
}
.notes small { font-family: var(--sans); font-size: 10px; font-weight: 600; color: var(--ink-soft); letter-spacing: .04em; }

.instrument { margin: 6px 0 0; }
.instrument svg { width: 100%; height: auto; }
.instrument.piano { margin-inline: -16px; }
.instrument.piano svg { max-height: 56vh; }
.instrument.guitar.find svg { max-width: 300px; max-height: 60vh; margin: 0 auto; }
.fretboard-scroll { margin-inline: -16px; padding-inline: 8px; overflow-x: auto; scrollbar-width: thin; }
.fretboard-scroll svg { min-width: 600px; }

.variants { margin-top: 14px; display: flex; justify-content: center; }
.pager { display: flex; align-items: center; gap: 14px; }
.pager-count { min-width: 124px; text-align: center; color: var(--ink-soft); font-size: 14px; }
.pager-count b { font-family: var(--serif); font-size: 19px; color: var(--ink); }

.label {
  margin: 4px 0 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.panel .label:not(:first-child) { margin-top: 18px; }

.roots { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.types { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.roots button, .types button {
  min-height: 48px;
  padding: 0 2px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-weight: 600;
  font-size: 14px;
  transition: background .2s, color .2s, border-color .2s, transform .1s;
}
.roots button { font-family: var(--serif); font-size: 17px; font-weight: 500; }
.roots button.accidental {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--key-black); color: #efe6d6; border-color: var(--key-black);
  font-size: 12.5px; line-height: 1.2;
}
.roots button.accidental span + span { opacity: .6; }
.roots button:active, .types button:active { transform: scale(.96); }
.roots button[aria-pressed="true"], .types button[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: var(--on-accent);
}

.alternatives { display: flex; flex-wrap: wrap; gap: 8px; min-height: 48px; align-items: center; }
.alt {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 500;
}
.hint { margin: 0; color: var(--ink-soft); font-size: 13.5px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; margin-top: 18px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); font-weight: 600;
  transition: opacity .2s, background .2s;
}
.btn:disabled { opacity: .4; }

/* ---------- SVG : piano ---------- */

.hit { fill: transparent; }
.interactive .hit { cursor: pointer; }
svg text { font-family: var(--sans); text-anchor: middle; pointer-events: none; user-select: none; -webkit-user-select: none; }

.piano-rail { fill: var(--wood-deep); }
.piano-felt { fill: var(--accent-deep); }
.key { transition: fill .28s ease; }
.key.white { fill: var(--key-white); stroke: var(--key-white-edge); stroke-width: 1.5; }
.key.black { fill: var(--key-black); stroke: var(--key-black); stroke-width: 1; }
.key.white.lit { fill: var(--accent); stroke: var(--accent-deep); }
.key.black.lit { fill: var(--accent); stroke: var(--accent-deep); }
.key-label { font-size: 14.5px; font-weight: 700; opacity: 0; transition: opacity .28s ease; }
.key-label.on { opacity: 1; }
.key-label.inside { fill: var(--on-accent); }
.key-label.above { fill: var(--accent); }
.key-mark { font-size: 12px; font-weight: 600; fill: var(--key-white-edge); transition: opacity .2s; }
.key-mark.off { opacity: 0; }

/* ---------- SVG : guitare ---------- */

.board { fill: var(--wood); stroke: var(--wood-deep); stroke-width: 2; }
.fret { fill: var(--brass); }
.nut { fill: var(--nacre); stroke: var(--key-white-edge); stroke-width: 1; transition: opacity .25s; }
.nut.off { opacity: 0; }
.string { stroke: var(--string); stroke-linecap: round; }
.inlay { fill: var(--nacre); opacity: .32; transition: opacity .25s; }
.inlay.off { opacity: 0; }
.marker { font-size: 22px; font-weight: 500; fill: var(--ink); transition: opacity .2s; }
.marker.muted { fill: var(--ink-soft); }
.marker.off { opacity: 0; }
.base-fret { font-family: var(--serif); font-size: 26px; font-weight: 600; fill: var(--ink); opacity: 0; transition: opacity .25s; }
.base-fret.on { opacity: 1; }
.string-note { font-size: 13px; font-weight: 600; fill: var(--ink-soft); }
.string-name { font-size: 13px; font-weight: 600; fill: var(--ink-soft); }
.fret-number { font-family: var(--serif); font-size: 16px; fill: var(--ink-soft); }

.dot { opacity: 0; transition: transform .32s cubic-bezier(.3, 1.3, .5, 1), opacity .2s; }
.dot.on { opacity: 1; }
.dot circle { fill: var(--accent); stroke: var(--accent-deep); stroke-width: 1.5; }
.dot text { font-size: 15px; font-weight: 700; fill: var(--on-accent); }
.fretboard .dot text { font-size: 12.5px; }
.fretboard .dot.open circle { fill: var(--card); stroke: var(--accent); stroke-width: 3; }
.fretboard .dot.open text { fill: var(--accent); }
.barre { fill: var(--accent); opacity: 0; transition: opacity .25s, x .3s, y .3s, width .3s; }
.barre.on { opacity: 1; }

/* ---------- Écrans larges ---------- */

@media (min-width: 640px) {
  body { padding-bottom: 0; }
  .top { padding-inline: max(24px, env(safe-area-inset-left)); gap: 20px; }
  .brand { margin-right: 0; }
  .tabs {
    position: static; height: auto; padding: 0; margin-right: auto; gap: 4px;
    background: none; border: 0; -webkit-backdrop-filter: none; backdrop-filter: none;
  }
  .tabs a { flex: none; flex-direction: row; gap: 7px; padding: 8px 14px; border-radius: 999px; font-size: 14px; }
  .tabs a[aria-current] { background: var(--card); box-shadow: 0 0 0 1px var(--line); }
  .tabs svg { width: 19px; height: 19px; }
  .view { padding-inline: 24px; }
  .instrument.piano, .fretboard-scroll { margin-inline: 0; padding-inline: 0; }
  .fretboard-scroll svg { min-width: 0; }
}

@media (min-width: 1020px) {
  .view.dico {
    max-width: 1180px;
    grid-template-columns: minmax(0, 1fr) 380px;
    grid-template-areas: "stage switches" "stage panel";
    grid-template-rows: auto 1fr;
    column-gap: 40px;
    padding-top: 20px;
  }
  .stage, .panel-card { align-self: start; }
  .stage {
    padding: 28px 32px 32px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
  .chord-name { font-size: 88px; }
  .instrument { margin-top: 24px; }
  .instrument.guitar.find svg { max-width: 340px; }
}

/* Téléphone à l'horizontale : en-tête resserré, l'instrument prend toute la largeur */
@media (orientation: landscape) and (max-height: 520px) {
  .top { padding-top: calc(6px + env(safe-area-inset-top)); padding-bottom: 4px; }
  .dico { gap: 8px; }
  .seg button { min-height: 34px; }
  .eyebrow { display: none; }
  .readout { min-height: 0; }
  .chord-name { font-size: 40px; }
  .chord-name.is-notes, .chord-name.is-empty { font-size: 26px; padding: 4px 0; }
  .play { width: 48px; height: 48px; }
  .notes { display: none; }
  .instrument { margin-top: 4px; }
  .instrument.piano svg { max-height: none; }
  .instrument.guitar.find svg { max-height: 78vh; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01s !important; }
}
