/* ============================================================
   Acords - guitarra i piano.
   Outfit en negre (900) per a l'acord, JetBrains Mono per a les
   xifres. Tipografia sobre vidre, cap caixa.

   El fons és llis: un sol negre, amb una mica més de llum al centre
   i prou. Cap vidre, cap ombra, cap costura entre seccions.

   Sistema: dos micro-rètols (58/66 per mil de rem, tracking .16em),
   beix només per a l'extensió, l'accent i allò triat.
   ============================================================ */

:root {
  --bg:    #060605;   /* el fons de tot, el pla més llunyà */
  --plane: #060605;   /* el pla que llisca: el mateix negre llis */
  --line:  #3A3733;   /* tics i punts apagats */
  --text:  #F4F1EB;
  --beige: #DCC9A6;
  --muted: #948D83;
  --dim:   #66605A;

  --top-h: 196px;
  --bot-h: 116px;
  --pad:   14px;

  --sans:  "Outfit", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono:  "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
:focus-visible { outline: 2px solid var(--beige); outline-offset: 2px; }

#app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}
/* l'unica llum de tota la pantalla: al centre, quieta */
#app::before {
  content: "";
  position: absolute; inset: 0; z-index: 0;
  background: radial-gradient(120% 66% at 50% 48%, rgba(255, 255, 255, .055), transparent 70%);
  pointer-events: none;
}

/* ---------------- el plano deslizante ---------------- */
.deck {
  position: absolute; inset: 0;
  display: flex;
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.deck::-webkit-scrollbar { display: none; }

.panel {
  position: relative;
  flex: 0 0 100%;
  height: 100%;
  overflow: hidden;                 /* dentro no se hace scroll: todo cabe */
  scroll-snap-align: center;
  background: transparent;          /* el fons llis de sota es veu i prou */
}
.panel-inner {
  position: relative;
  height: 100%;
  display: flex; flex-direction: column; justify-content: center; gap: 8px;
  padding: calc(var(--top-h) + 8px) var(--pad) calc(var(--bot-h) + 8px);
}
.panel-inner > * { position: relative; z-index: 1; }

/* ---------------- capas fijas ---------------- */
.pinned {
  position: absolute; left: 0; right: 0; z-index: 5;
  pointer-events: none;
  transition: opacity .32s ease, filter .32s ease;
}
.pinned-inner { position: relative; z-index: 1; pointer-events: auto; }

.pinned-top { top: 0; }
.pinned-top .pinned-inner {
  position: relative;
  padding: calc(74px + env(safe-area-inset-top)) var(--pad) 14px;
  text-align: center;
}

/* la icona del pianet lliure: tres tecles, com la de l'app */
.piano-btn {
  position: absolute; top: calc(20px + env(safe-area-inset-top)); right: 12px;
  width: 44px; height: 40px;
  display: flex; align-items: center; justify-content: center; gap: 3px;
  appearance: none; border: 0; background: none; cursor: pointer; padding: 0;
}
.piano-btn i { width: 4px; height: 17px; background: var(--dim); }
.piano-btn i:last-child { background: var(--beige); }
.piano-btn:active i { background: var(--beige); }

.pinned-bottom { bottom: 0; }
.pinned-bottom .pinned-inner {
  display: flex; flex-direction: column; align-items: center; gap: 9px;
  padding: 8px var(--pad) calc(8px + env(safe-area-inset-bottom));
}

/* ---------------- el acorde, que es el mando ---------------- */
.chord-name {
  display: flex; align-items: baseline; justify-content: center; gap: .05em;
  margin: 0;
  font-size: clamp(4.2rem, 26vw, 7rem);
  font-weight: 900; line-height: .9; letter-spacing: -.03em;
}
.tok {
  position: relative;
  appearance: none; background: none; border: 0; padding: 0 2px;
  font: inherit; letter-spacing: inherit; color: var(--text);
  cursor: pointer;
}
/* la fundamental en blanco, la extensión en beige: cada pieza abre su panel */
.tok-root { color: var(--text); }
.tok-ext { color: var(--beige); font-size: .56em; letter-spacing: -.03em; }
.tok::after {
  content: "";
  position: absolute; left: 2px; right: 2px; bottom: .1em; height: 3px;
  background: currentColor; opacity: 0;
  transform: scaleX(.3); transform-origin: center;
  transition: opacity .18s ease, transform .18s ease;
}
.tok.active::after { opacity: .95; transform: scaleX(1); }

.chord-line {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin: 8px 0 0;
  font-size: .66rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase;
  color: var(--beige);
}
/* la paraula del tipus és el mando de l'extensió, sempre */
.line-ext {
  appearance: none; border: 0; background: none; cursor: pointer;
  padding: 6px 2px; margin: -6px 0;
  font: inherit; letter-spacing: inherit; text-transform: inherit;
  color: var(--beige);
  border-bottom: 2px solid transparent;
}
.line-ext.active { border-bottom-color: var(--beige); }
.chord-line em {
  font-style: normal; font-family: var(--mono); font-weight: 800;
  letter-spacing: .1em; text-transform: none; color: var(--muted);
}

/* ---------------- diagramas ---------------- */
.diagram { flex: 1 1 auto; min-height: 0; display: flex; justify-content: center; }
.diagram svg { width: 100%; height: 100%; }
.diagram.narrow { max-width: 420px; margin: 0 auto; }

.empty {
  flex: 1 1 auto; display: flex; flex-direction: column; justify-content: center;
  align-items: center; gap: 10px; text-align: center;
}
.empty b {
  font-size: .66rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase;
  color: var(--beige);
}
.empty span { font-size: .82rem; color: var(--dim); max-width: 260px; }

/* un teclado por mano */
/* la caja del dibujo ya lleva su proporción exacta, así que el bloque
   se ajusta al contenido y los dos teclados quedan juntos en el centro */
.kb { flex: 0 0 auto; display: flex; flex-direction: column; gap: 2px; }
/* cada mano se rotula en su lado, como está en el teclado de verdad:
   la izquierda a la izquierda y la derecha a la derecha */
.kb-head {
  flex: none; display: flex;
  font-size: .58rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  color: var(--dim);
}
.kb-head.kb-r { justify-content: flex-end; }
.kb-head.kb-l { justify-content: flex-start; }

/* ---------------- posición / inversión ---------------- */
.pager { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }
.pager-main {
  display: grid; grid-template-columns: 52px minmax(0, 1fr) 52px;
  align-items: center; gap: 8px; width: 100%; max-width: 340px;
}
/* flechas tipográficas: sin caja, solo el glifo */
.chev {
  appearance: none; border: 0; background: none; cursor: pointer;
  height: 48px; padding: 0;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 2rem; font-weight: 500; line-height: 1;
}
.chev:active { color: var(--beige); }
.chev:disabled { opacity: .2; }
.pager-label { text-align: center; min-width: 0; }
.pager-label b {
  display: block;
  font-family: var(--mono); font-size: 1.35rem; font-weight: 800; letter-spacing: -.01em;
}
.pager-label span {
  display: block; margin-top: 4px;
  font-size: .62rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase;
  color: var(--muted);
}

.dots { display: flex; gap: 2px; }
.dot {
  appearance: none; border: 0; background: none; cursor: pointer; padding: 0;
  width: 24px; height: 16px; position: relative;
}
.dot::before {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 10px; height: 5px; margin: -2.5px 0 0 -5px;
  background: var(--line);
}
.dot.on::before { background: var(--beige); }

/* ---------------- desenfoque al cambiar ---------------- */
.fx-out { animation: fx-out .13s ease-in both; will-change: filter, opacity; }
.fx-in  { animation: fx-in .34s cubic-bezier(.2,.8,.2,1) both; will-change: filter, opacity; }

@keyframes fx-out {
  from { filter: blur(0);    opacity: 1; }
  to   { filter: blur(10px); opacity: .2; }
}
@keyframes fx-in {
  from { filter: blur(10px); opacity: 0; }
  to   { filter: blur(0);    opacity: 1; }
}

/* ----------------------------------------------------------------
   el selector: tipografía sobre cristal, sin una sola caja.
   La opción elegida va en el color de su pieza del título y con el
   mismo subrayado; las demás, en gris apagado.
   ---------------------------------------------------------------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; display: flex; }
.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(6, 6, 5, .74);
  backdrop-filter: blur(26px) saturate(.8);
  -webkit-backdrop-filter: blur(26px) saturate(.8);
  animation: fade-in .2s ease both;
}
.sheet {
  position: relative; margin: auto; width: 100%; max-width: 480px;
  max-height: 100%; overflow-y: auto; scrollbar-width: none;
  padding: max(36px, env(safe-area-inset-top)) 22px calc(30px + env(safe-area-inset-bottom));
  text-align: center;
  animation: sheet-in .3s cubic-bezier(.2,.8,.2,1) both;
}
.sheet::-webkit-scrollbar { display: none; }
.sheet-wrap.closing .sheet { animation: sheet-out .18s ease both; }
.sheet-wrap.closing .sheet-backdrop { animation: fade-out .18s ease both; }

@keyframes fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes sheet-in {
  from { opacity: 0; filter: blur(12px); transform: scale(.97); }
  to   { opacity: 1; filter: blur(0);   transform: none; }
}
@keyframes sheet-out { to { opacity: 0; filter: blur(10px); } }

.opt-grid { display: grid; gap: 14px 8px; }
.opt-grid + .opt-grid { margin-top: 22px; }
/* files sempre plenes: 6+3+3 fonamentals i 3+9+16 extensions */
.opt-grid.tier1, .opt-grid.tier2 { grid-template-columns: repeat(3, 1fr); }
.opt-grid.tier3 { grid-template-columns: repeat(4, 1fr); }

.opt {
  appearance: none; border: 0; background: none; cursor: pointer; padding: 4px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  color: var(--dim);
  font-family: var(--sans); font-weight: 900;
  animation: opt-in .32s cubic-bezier(.2,.8,.2,1) both;
  animation-delay: calc(var(--i, 0) * 14ms);
}
.opt .opt-big { line-height: 1.05; letter-spacing: -.03em; }
/* la mida diu la popularitat: com més tocat, més gran */
.opt-grid.roots.tier1 .opt-big { font-size: 2.6rem; }
.opt-grid.roots.tier2 .opt-big { font-size: 1.7rem; }
.opt-grid.roots.tier3 .opt-big { font-size: 1.2rem; }
.opt-grid.exts.tier1 .opt-big { font-size: 2.2rem; }
.opt-grid.exts.tier2 .opt-big { font-size: 1.4rem; }
.opt-grid.exts.tier3 .opt-big { font-size: .95rem; }

.opt[aria-pressed="true"] { color: var(--text); }
.opt[aria-pressed="true"] .opt-big {
  text-decoration-line: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 7px;
}
.sheet[data-kind="ext"] .opt[aria-pressed="true"] { color: var(--beige); }
.opt:active .opt-big { color: var(--text); }

@keyframes opt-in {
  from { opacity: 0; filter: blur(7px); transform: translateY(8px); }
  to   { opacity: 1; filter: blur(0);  transform: none; }
}

/* ----------------------------------------------------------------
   eines: afinador i tempo com a plans del carrusel. En arribar-hi,
   les capes fixes es dissolen amb desenfocament.
   ---------------------------------------------------------------- */
/* a les eines, les capes fixes es dissolen — i tampoc no es poden
   clicar: sense això, el títol invisible seguia obrint el selector */
#app.on-tool .pinned { opacity: 0; filter: blur(10px); }
#app.on-tool .pinned .pinned-inner { pointer-events: none; }

.tool-inner {
  position: relative;
  height: 100%;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 0;
  padding: calc(20px + env(safe-area-inset-top)) 22px calc(20px + env(safe-area-inset-bottom));
  text-align: center;
}
.tool-hint {
  margin-top: 18px; min-height: 1.2em;
  font-size: .58rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase;
  color: var(--dim);
}

/* afinador */
.tuner-note {
  font-size: clamp(4.4rem, 30vw, 7rem);
  font-weight: 900; line-height: .9; letter-spacing: -.03em;
}
.tuner-note small {
  font-size: .3em; font-weight: 700; color: var(--muted);
  letter-spacing: 0; margin-left: .06em;
}
.tuner-note.good { color: var(--beige); }
.ticks { display: flex; justify-content: center; align-items: center; gap: 4px; margin: 28px 0 12px; }
.ticks i { width: 3px; height: 15px; background: var(--line); }
.ticks i.mid { height: 25px; background: var(--dim); }
.ticks i.on { background: var(--text); height: 25px; }
.ticks i.mid.on { background: var(--beige); }
.tuner-cents {
  font-family: var(--mono); font-size: .74rem; font-weight: 700;
  color: var(--muted); min-height: 1.2em;
}
.mic-btn {
  appearance: none; border: 0; background: none; cursor: pointer;
  margin-top: 14px; padding: 8px 4px;
  color: var(--beige);
  font-size: .66rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase;
  border-bottom: 2px solid var(--beige);
}
.mic-btn[hidden] { display: none; }

/* tempo: el numero mana; tocar engega, arrossegar canvia */
.mn-bpm {
  appearance: none; border: 0; background: none; cursor: ns-resize; padding: 0;
  font-family: var(--sans); font-size: clamp(5rem, 36vw, 8rem);
  font-weight: 900; line-height: .9; letter-spacing: -.04em;
  color: var(--text);
  touch-action: none;
  -webkit-user-select: none; user-select: none;
}
.mn-bpm.running { color: var(--beige); }
/* el batec de cada toc del tap tempo */
.mn-bpm.tapped { animation: bpm-tap .18s ease; }
@keyframes bpm-tap {
  50% { transform: scale(1.05); color: var(--beige); }
}

/* punts del compas: rodons i ben visibles; els accents, en blanc */
.mn-beats { display: flex; justify-content: center; gap: 14px; margin: 28px 0 0; }
.mn-beats i {
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--line);
  transition: transform .07s ease, background .07s ease;
}
.mn-beats i.on { background: var(--beige); transform: scale(1.35); }
.mn-beats i.one.on { background: var(--text); }

.mn-meter {
  appearance: none; border: 0; background: none; cursor: pointer;
  margin-top: 24px; padding: 6px 2px;
  font-family: var(--mono); font-size: 1rem; font-weight: 700;
  color: var(--beige);
  border-bottom: 2px solid var(--beige);
}
.opt-grid.meters.tier1 { grid-template-columns: repeat(2, 1fr); }
.opt-grid.meters.tier2 { grid-template-columns: repeat(3, 1fr); }
.opt-grid.meters.tier1 .opt-big { font-size: 2.6rem; }
.opt-grid.meters.tier2 .opt-big { font-size: 1.3rem; }

/* ---------------- pianet lliure: el mobil sencer es un piano ---------------- */
.fp-wrap {
  position: fixed; inset: 0; z-index: 40;
  background: var(--bg);
  animation: fade-in .2s ease both;
}
.fp-wrap.closing { animation: fade-out .18s ease both; }
/* el rotor es dimensiona per JS i en vertical gira 90 graus */
.fp-rotor {
  position: absolute; top: 50%; left: 50%;
  display: flex; flex-direction: column;
}
.fp-bar {
  flex: none; height: 62px;
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 6px;
}
.fp-close {
  appearance: none; border: 0; background: none; cursor: pointer;
  width: 64px; height: 48px; padding: 0;
  color: var(--dim);
  font-family: var(--sans); font-size: 2.5rem; font-weight: 400; line-height: 1;
}
.fp-close:active { color: var(--beige); }
/* El teclat es mes ample que la pantalla. Res de scroll natiu: dins
   d'un contenidor girat, el navegador arbitra els gestos en eixos de
   pantalla i es queda els tocs de les tecles. touch-action: none = cada
   toc va directe a la tecla; el despcalament es fa arrossegant per la
   franja dels Do o per l'aire de sobre/sota. */
.fp-kb {
  flex: 1 1 auto; min-height: 0;
  display: flex; align-items: center;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}
.fp-kb svg { width: auto; display: block; flex: none; }
/* la tecla s'enfonsa un pel en polsar-la */
.fp-kb svg rect { transition: fill .06s linear; }
/* on ets de les quatre octaves: nomes es veu mentre arrossegues */
.fp-pos {
  position: absolute; left: 18%; right: 18%; bottom: 9px; height: 3px;
  background: rgba(244, 241, 235, .08); border-radius: 2px;
  opacity: 0; transition: opacity .3s ease;
  pointer-events: none;
}
.fp-pos i {
  position: absolute; top: 0; height: 100%;
  background: var(--beige); border-radius: 2px;
}

/* ---------------- móvil en horizontal ---------------- */
@media (max-height: 480px) {
  /* aqui l'alcada es or, pero l'acord tambe baixa i creix: mes peca de
     la pagina que titol, nomes amb mesures d'apaisat */
  :root { --top-h: 122px; --bot-h: 92px; }
  .chord-name { font-size: clamp(3.2rem, 9vh, 4rem); }
  .chord-line { display: none; }
  .pinned-top .pinned-inner { padding: calc(34px + env(safe-area-inset-top)) var(--pad) 10px; }
  .piano-btn { top: calc(10px + env(safe-area-inset-top)); }
  .chev { height: 36px; }
  .kb-head { font-size: .52rem; }

  /* tot l'ample de pantalla */
  .panel-inner { max-width: none; }

  /* les dues mans, costat a costat: l'esquerra a l'esquerra */
  .panel[data-ins="piano"] .panel-inner {
    flex-direction: row; align-items: center; gap: 16px;
  }
  .panel[data-ins="piano"] .kb { flex: 1 1 50%; min-width: 0; }

  /* el mastil ajagut pot ser ben ample */
  .panel[data-ins="guitar"] .diagram.narrow { max-width: min(620px, 88vw); }
}

/* ---------------- pantallas anchas ---------------- */
@media (min-width: 760px) {
  .panel-inner { max-width: 640px; margin: 0 auto; }
  .sheet { max-width: 640px; margin: 0 auto; }
}

.boot-error {
  height: 100%; display: flex; flex-direction: column; justify-content: center;
  align-items: center; gap: 12px; text-align: center; padding: 0 26px;
}
.boot-error b {
  font-size: .66rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase;
  color: var(--beige);
}
.boot-error span { font-family: var(--mono); font-size: .74rem; color: var(--muted); }
.boot-error em { font-style: normal; font-size: .82rem; color: var(--dim); max-width: 340px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
