/* Batucada Rhythm Circle
 *
 * Look and feel follows drumteamparis.fr: white page, black bold sans,
 * uppercase accents, energy from contrast rather than ornament.
 *
 * Colour discipline:
 *   - Four BLUES identify the four instruments, ramped by pitch
 *     (Surdo 1 deepest, Repinique brightest). Defined per container in
 *     instruments.js as `accent` (light chrome) and `dot` (navy canvas).
 *   - ORANGE is reserved exclusively for the playhead — "this is sounding
 *     right now". Nothing else in the UI may use it, or the beat marker
 *     stops being unambiguous.
 */

:root {
  --ink: #0b0f19;
  --ink-soft: #4a5568;
  --ink-faint: #8b96a8;
  --page: #ffffff;
  --surface: #f5f7fa;
  --line: #e2e7ef;
  --line-strong: #cbd4e1;

  --navy: #0d1b33;
  --navy-edge: #16294a;

  --blue: #0a72c4;
  --blue-deep: #1b3a93;
  --orange: #ff7a1a;
  --orange-soft: #fff1e4;

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

/* ---------- header ---------- */
.app-header {
  padding: 18px 24px 14px;
  border-bottom: 2px solid var(--ink);
  background: var(--page);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { margin-bottom: 14px; }

.app-header h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}
.app-header h1 span { color: var(--blue); }

.tagline {
  margin: 2px 0 0;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.global-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}
.control-group output { min-width: 2.4em; text-align: right; color: var(--ink); }
.control-group input[type=range] { width: 118px; }
/* The song picker. Not uppercase like its label — these are song titles. */
.control-group select {
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  max-width: 190px;
}

.btn {
  background: var(--page);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 8px 16px;
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: background 0.12s, color 0.12s;
}
.btn:hover { background: var(--ink); color: var(--page); }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-deep); border-color: var(--blue-deep); color: #fff; }

.btn-sm {
  background: var(--page);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  width: 24px; height: 24px;
  line-height: 1;
  cursor: pointer;
  font-weight: 700;
  color: var(--ink);
}
.btn-sm:hover { border-color: var(--ink); }

.io-status {
  margin: 8px 0 0;
  font-size: 0.78rem;
  font-weight: 600;
  min-height: 1em;
  color: var(--ink-faint);
}
.io-status.ok { color: #0a7b3e; }
.io-status.err { color: #c62828; }

#share-url-box {
  margin-top: 10px;
  width: 100%;
  background: var(--surface);
  color: var(--ink-soft);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 0.78rem;
}

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  gap: 26px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--page);
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 14px 0;
  margin-bottom: -1px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  cursor: pointer;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--ink); border-bottom-color: var(--orange); }

.tab-panel { display: none; padding: 20px 24px; }
.tab-panel.active { display: block; }

/* ---------- visual tab ---------- */
.bar-cursor {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
#bar-label { min-width: 12em; }
.cursor-hint {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink-faint);
}

.instrument-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 1024px) {
  .instrument-grid { grid-template-columns: 1fr; }
}

.instrument-box {
  background: var(--page);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  overflow: hidden;
}
.instrument-box h2 {
  margin: 2px 4px 10px;
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.instrument-box[data-container=container1] h2 { color: #1b3a93; }
.instrument-box[data-container=container2] h2 { color: #1256b8; }
.instrument-box[data-container=container3] h2 { color: #0a72c4; }
.instrument-box[data-container=container4] h2 { color: #0090c9; }

canvas.instrument-canvas {
  width: 100%;
  height: 230px;
  display: block;
  background: var(--navy);
  border-radius: 8px;
  cursor: pointer;
}

.legend {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 18px 0 0;
  font-size: 0.74rem;
  color: var(--ink-soft);
}
.key {
  width: 11px; height: 11px;
  border-radius: 50%;
  display: inline-block;
  margin-left: 14px;
}
.key:first-child { margin-left: 0; }
.key-hit { background: var(--blue); }
.key-rest { border: 1.5px solid var(--line-strong); }
.key-now { background: var(--orange); box-shadow: 0 0 7px rgba(255,122,26,0.85); }
.key-next { background: rgba(10,114,196,0.5); width: 8px; height: 8px; }

/* ---------- tablature tab ---------- */
.notation-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  margin-bottom: 18px;
  overflow-x: auto;
  background: var(--page);
  min-height: 120px;
}
.notation-fallback {
  margin: 12px;
  color: var(--ink-faint);
  font-size: 0.82rem;
}

/* Per-line sound captions overlaid on the notation. alphaTab gives each
 * sound its own staff line but nothing says which is which, so these are
 * positioned from the rendered note bounds. */
.at-line-label {
  position: absolute;
  transform: translate(0, -120%);
  font-family: var(--font);
  font-size: 6.8px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  color: var(--blue);
  /* Opaque: captions start at the very beginning of the line, which puts
   * them over the clef — a translucent backing would muddle both. */
  background: #fff;
  padding: 1px 3px;
  border-radius: 2px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
}

.tab-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar-hint { font-size: 0.78rem; color: var(--ink-faint); }

/* ---------- arrangement (the running order) ---------- */
.arrangement {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 20px;
  background: var(--surface);
}
.arrangement-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}
.arrangement-head h3 {
  margin: 0;
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.arrangement-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 34px;
  margin-bottom: 10px;
}
.arrangement-empty { margin: 4px 0; font-size: 0.8rem; color: var(--ink-faint); }
.arrangement-add { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.arrangement-add select { font-size: 0.78rem; padding: 4px 6px; }

/* Chips are coloured by section kind so the shape of the song is legible
 * at a glance: grooves blue, breaks orange-free (orange stays reserved for
 * the playhead), intro/outro neutral. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border: 1.5px solid var(--line-strong);
  border-radius: 999px;
  padding: 3px 4px 3px 10px;
  background: var(--page);
  font-size: 0.78rem;
  cursor: grab;
}
.chip.dragging { opacity: 0.4; }
.chip.drop-target { border-color: var(--ink); box-shadow: 0 0 0 2px rgba(11,15,25,0.12); }
.chip-selected { box-shadow: 0 0 0 2px rgba(10,114,196,0.35); }
.chip-intro  { border-color: #9aa7bd; }
.chip-groove { border-color: var(--blue); }
.chip-break  { border-color: #6b3fa0; }
.chip-outro  { border-color: #9aa7bd; }

.chip-name {
  background: none; border: none; padding: 0;
  font: inherit; font-weight: 700; cursor: pointer; color: var(--ink);
}
.chip-name:hover { text-decoration: underline; }
.chip-rep {
  width: 3.2em;
  font: inherit;
  font-size: 0.72rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 2px;
  text-align: center;
}
.chip-move, .chip-del {
  background: none;
  border: none;
  padding: 0 3px;
  font: inherit;
  line-height: 1;
  cursor: pointer;
  color: var(--ink-faint);
}
.chip-move:hover:not(:disabled), .chip-del:hover { color: var(--ink); }
.chip-move:disabled { opacity: 0.25; cursor: default; }
.chip-del:hover { color: #c62828; }

/* ---------- section editor ---------- */
.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 2px solid var(--line-strong);
}
.section-head label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}
.section-head select, .section-head input[type=text] {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
  padding: 4px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}
.section-head .btn { padding: 5px 11px; font-size: 0.74rem; }
.section-head .btn:disabled { opacity: 0.4; cursor: not-allowed; }
.section-head .btn:disabled:hover { background: var(--page); color: var(--ink); }

.bar-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 14px;
  overflow-x: auto;
}
.bar-card.selected {
  border-left-color: var(--orange);
  background: var(--orange-soft);
}

.bar-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.bar-title {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  color: var(--ink);
}
.bar-title:hover { color: var(--orange); }
/* Per-bar audition. Sits next to the bar title, deliberately small and
   quiet - it is a utility, not the transport. */
.bar-play {
  background: none;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  width: 20px;
  height: 20px;
  padding: 0;
  margin-left: 6px;
  font-size: 0.6rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink-soft);
  flex: 0 0 auto;
}
.bar-play:hover { border-color: var(--orange); color: var(--orange); }
.bar-play:active { transform: scale(0.92); }
.bar-ctl {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.bar-ctl input[type=number] { width: 3.2em; }
.bar-spacer { flex: 1; }
.bar-del {
  background: none;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 0.72rem;
  cursor: pointer;
  color: var(--ink-soft);
}
.bar-del:hover:not(:disabled) { border-color: #d33; color: #d33; }
.bar-del:disabled { opacity: 0.4; cursor: not-allowed; }

/* Step grid. Rows are flex so every line spans the same width regardless
 * of its step count — the grid reads as aligned TIME, and a coarse line
 * simply gets wider cells. */
.tab-grid { font-size: 0.72rem; min-width: 640px; }

.tab-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}
.tab-row.group-start { border-top: 2px solid var(--line-strong); margin-top: 4px; padding-top: 5px; }

.row-label {
  width: 148px;
  flex: 0 0 148px;
  color: var(--ink-soft);
  line-height: 1.25;
}
.row-label em {
  display: block;
  font-style: normal;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.64rem;
  color: var(--accent);
}

.row-ctl { flex: 0 0 auto; font-size: 0.7rem; padding: 1px 2px; }
.row-pattern { width: 92px; }

.row-steps {
  display: flex;
  flex: 1 1 auto;
  min-width: 300px;
  gap: 1px;
}
.tab-cell {
  flex: 1 1 0;
  min-width: 0;
  height: 18px;
  border: 1px solid var(--line);
  background: var(--page);
  cursor: pointer;
  padding: 0;
}
.tab-cell.beat { border-left: 2px solid var(--line-strong); }
.tab-cell:hover { background: var(--line); }
.tab-cell.on { background: var(--accent); border-color: var(--accent); }
.tab-cell.on:hover { opacity: 0.75; }

/* ---------- alphaTex editor ---------- */
.tex-editor { margin-top: 20px; }
.tex-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}
.tex-header h3 {
  margin: 0;
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.tex-status { font-size: 0.76rem; color: var(--ink-faint); }
.tex-status.ok { color: #0a7b3e; }
.tex-status.err { color: #c62828; font-weight: 600; }

#alphatex-box {
  width: 100%;
  height: 260px;
  background: var(--navy);
  color: #d6e4ff;
  border: 1px solid var(--navy-edge);
  border-radius: var(--radius);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.55;
  padding: 12px 14px;
  resize: vertical;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}
.tex-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ---------- Simplified tab ---------- */
.simp-order {
  margin: 0 0 20px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.86rem;
}
.simp-order strong {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.72rem;
  margin-right: 8px;
  color: var(--ink-faint);
}

.simp-section {
  border-left: 4px solid var(--line-strong);
  padding: 0 0 4px 14px;
  margin-bottom: 22px;
}
.simp-section.playing { border-left-color: var(--orange); }

.simp-section h3 {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 10px;
  font-size: 0.95rem;
  font-weight: 800;
}
.simp-kind {
  font-size: 0.6rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 2px 6px;
  border-radius: 3px;
  color: #fff;
  background: var(--ink-faint);
}
.simp-kind-groove { background: var(--blue); }
.simp-kind-break  { background: #6b3fa0; }
.simp-bars {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--ink-faint);
}

.simp-table { display: table; width: 100%; }
.simp-row { display: table-row; }
.simp-row > span { display: table-cell; padding: 2px 0; vertical-align: baseline; }
.simp-row.group-start > span { padding-top: 8px; }

.simp-inst {
  width: 120px;
  font-size: 0.64rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  white-space: nowrap;
}
.simp-sound {
  width: 120px;
  font-size: 0.78rem;
  color: var(--ink-soft);
  white-space: nowrap;
  padding-right: 16px !important;
}
/* Monospaced and tabular so the digits line up down the page. */
.simp-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  color: var(--ink);
}
.simp-value.silent { color: var(--line-strong); }
.simp-value.off-grid { color: #c62828; font-style: italic; letter-spacing: 0; }

/* ---------- Sounds tab ---------- */
.sounds-hint {
  margin: 0 0 16px;
  font-size: 0.8rem;
  color: var(--ink-faint);
}
.config-root {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 14px;
}
.config-box {
  background: var(--page);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent, var(--blue));
  border-radius: var(--radius);
  padding: 12px 14px;
}
.config-box h3 {
  margin: 0 0 8px;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}
.config-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
  font-size: 0.76rem;
}
.config-row:first-of-type { border-top: none; }
.config-row label { display: flex; align-items: center; gap: 7px; color: var(--ink-soft); }
.config-row input[type=range] { flex: 1; min-width: 0; }

.cfg-top { display: flex; align-items: center; gap: 8px; }
.cfg-enable { font-weight: 700; color: var(--ink) !important; flex: 1; }

.cfg-test {
  flex: 0 0 auto;
  background: var(--page);
  border: 1.5px solid var(--blue);
  color: var(--blue);
  border-radius: 6px;
  padding: 2px 10px;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.cfg-test:hover:not(:disabled) { background: var(--blue); color: #fff; }
.cfg-test:active:not(:disabled) { background: var(--blue-deep); border-color: var(--blue-deep); }
.cfg-test:disabled {
  border-color: var(--line-strong);
  color: var(--ink-faint);
  cursor: not-allowed;
}
.cfg-pitch output { min-width: 4.6em; text-align: right; font-variant-numeric: tabular-nums; }
.cfg-nopitch { font-size: 0.72rem; color: var(--ink-faint); font-style: italic; }

/* Keyboard access to the step circles. The canvas is the focus target; the
   cursor itself is painted inside it by app.js, because a DOM focus ring
   cannot point at one dot on a canvas. */
canvas.instrument-canvas:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 3px;
}
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}
