/* Fretwork — theme: warm, precise, luthier's bench. Dark ebony surfaces, brass accent. */
:root {
  --bg: #14100d;
  --surface: #1e1814;
  --surface-2: #29211b;
  --line: #43362c;
  --line-strong: #7a6553;
  --text: #f2e9da;
  --muted: #b9a993;
  --brass: #e8b04b;
  --brass-hi: #ffd27a;
  --brass-ink: #241303;
  --danger: #ff8a70;
  --ok: #8fd9a8;
  --radius: 10px;
  --display: Bahnschrift, "DIN Alternate", "Roboto Condensed", "Segoe UI", system-ui, sans-serif;
  --body: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: 72px; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--body); }
h1, h2, h3, legend, .brand, .chord-name { font-family: var(--display); line-height: 1.2; }
h2 { margin: 0 0 8px; font-size: 1.2rem; font-weight: 600; }
h3 { margin: 18px 0 8px; font-size: 1.05rem; }
p { margin: 0 0 10px; }
a { color: var(--brass); }
:focus-visible { outline: 2px solid var(--brass-hi); outline-offset: 2px; }
.muted { color: var(--muted); font-size: .9rem; }
.eyebrow { display: block; color: var(--muted); font: 600 .75rem var(--display); letter-spacing: .08em; text-transform: uppercase; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; z-index: 50; background: var(--brass); color: var(--brass-ink); padding: 8px 12px; border-radius: 6px; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px; padding: 10px max(16px, calc((100vw - 1240px) / 2)); background: #100c0a; border-bottom: 1px solid var(--line); }
.brand { font-size: 1.35rem; font-weight: 700; color: var(--text); text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { padding: 8px 14px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; }
.nav a:hover { color: var(--text); background: var(--surface); }
.nav a[aria-current="page"] { color: var(--brass-ink); background: var(--brass); }
.volume { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .85rem; }

main { max-width: 1272px; margin: 0 auto; padding: 16px; }
main:focus { outline: none; }

button, .button, select, input[type="text"], input[type="search"], textarea {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
}
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 6px 14px; cursor: pointer; font-weight: 600; }
button:hover:not(:disabled), .button:hover { border-color: var(--line-strong); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--brass); border-color: var(--brass); color: var(--brass-ink); }
button.primary:hover:not(:disabled) { background: var(--brass-hi); }
button.on:not(.primary) { border-color: var(--brass); color: var(--brass-hi); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
select, input[type="text"], input[type="search"] { min-height: 38px; padding: 6px 10px; }
textarea { width: 100%; padding: 10px 12px; font-family: Consolas, ui-monospace, monospace; font-size: .85rem; resize: vertical; }
input[type="range"] { accent-color: var(--brass); }
input[type="checkbox"] { accent-color: var(--brass); width: 18px; height: 18px; }
kbd { display: inline-block; min-width: 1.7em; padding: 0 5px; border: 1px solid var(--line-strong); border-bottom-width: 3px; border-radius: 5px; background: #120e0b; color: var(--text); font: 600 .8rem/1.5 var(--display); text-align: center; }

.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { color: var(--muted); font-size: .8rem; font-weight: 600; }
.segmented { display: inline-flex; padding: 3px; gap: 3px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.segmented button { min-height: 30px; border: 0; background: transparent; color: var(--muted); }
.segmented button[aria-checked="true"] { background: var(--brass); color: var(--brass-ink); }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper button { min-width: 38px; padding: 0; }
.stepper output { min-width: 6.5em; text-align: center; font-variant-numeric: tabular-nums; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }

.guide { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; padding: 10px 14px; border: 1px solid var(--brass); border-radius: var(--radius); background: #2a2014; }
.guide p { margin: 0; flex: 1 1 320px; }

.stage { margin-bottom: 12px; border: 1px solid var(--line); border-radius: 14px; background: #0c0907; overflow: hidden; box-shadow: 0 14px 40px rgba(0, 0, 0, .45); }
.fretboard { display: block; width: 100%; height: clamp(220px, 27vw, 300px); touch-action: none; cursor: pointer; user-select: none; }

.panel { margin-bottom: 14px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.play-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1.55fr) minmax(170px, .55fr) minmax(0, 1fr); align-items: stretch; margin-bottom: 14px; }
.play-grid .panel { margin: 0; }

.bank-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.bank-tabs button { min-height: 30px; padding: 2px 10px; font-size: .82rem; color: var(--muted); }
.bank-tabs button[aria-selected="true"] { color: var(--text); border-color: var(--brass); background: #3a2b17; }

.keyboard { display: flex; flex-direction: column; gap: 8px; }
.keyrow { display: grid; grid-template-columns: repeat(5, minmax(0, 88px)); gap: 8px; }
.keyrow.row1 { margin-left: 22px; }
.keyrow.row2 { margin-left: 48px; }
.keycap { flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 2px; min-height: 66px; padding: 6px 8px; border-bottom-width: 4px; text-align: left; overflow: hidden; }
.keycap kbd { border: 0; background: none; color: var(--muted); padding: 0; min-width: 0; }
.keycap strong { font: 700 1.12rem var(--display); align-self: center; white-space: nowrap; }
.keycap.active { background: var(--brass); border-color: var(--brass-hi); color: var(--brass-ink); }
.keycap.active kbd { color: var(--brass-ink); }
.keycap.hit, .pad-btn.hit { transform: translateY(2px); filter: brightness(1.25); }
.keycap.empty { border-style: dashed; color: var(--muted); }

.now { text-align: center; display: flex; flex-direction: column; align-items: center; }
.chord-name { font-size: 2.8rem; font-weight: 700; color: var(--brass-hi); overflow-wrap: anywhere; }
.notes { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .82rem; white-space: pre-wrap; }
.diagram { display: inline-block; line-height: 0; }
.diagram svg { height: auto; max-width: 100%; }
.d-line { stroke: var(--line-strong); stroke-width: 1; }
.d-nut { stroke: var(--text); stroke-width: 4; }
.d-dot { fill: var(--brass); }
.d-open { fill: none; stroke: var(--ok); stroke-width: 1.6; }
.d-mark { fill: var(--danger); font: 700 13px var(--display); }
.d-finger { fill: var(--brass-ink); font: 700 9.5px var(--display); }
.d-base { fill: var(--muted); font: 600 9px var(--display); }

.strum-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.pad-btn { justify-content: flex-start; touch-action: manipulation; user-select: none; }
.pluck-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(40px, 1fr)); gap: 5px; margin-bottom: 10px; }
.pluck-row .pad-btn { flex-direction: column; justify-content: center; gap: 2px; padding: 4px 2px; font-size: .8rem; }
.neck-controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 10px; }
.tips { margin: 0; padding-left: 18px; color: var(--muted); }
.pad:has(.neck-controls) { grid-column: span 2; }

.rhythm-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; margin-bottom: 10px; }
.rhythm .tempo { flex-direction: row; align-items: center; gap: 8px; min-height: 38px; }
.rhythm .tempo output { min-width: 5.5em; font-variant-numeric: tabular-nums; }
.steps { display: flex; gap: 4px; }
.step { display: flex; flex-direction: column; align-items: center; flex: 1; max-width: 62px; padding: 5px 0; border: 1px solid var(--line); border-radius: 7px; font: 700 1.15rem var(--display); }
.step small { color: var(--muted); font-size: .68rem; }
.step.beat { background: var(--surface-2); }
.step.on { background: var(--brass); color: var(--brass-ink); border-color: var(--brass-hi); }
.step.on small { color: var(--brass-ink); }

summary { cursor: pointer; font: 600 1.1rem var(--display); }
.song details[open] summary { margin-bottom: 10px; }
.sheet { max-height: 260px; overflow-y: auto; padding: 8px 12px; background: #120e0b; border-radius: 8px; position: relative; }
.sheet h3 { margin: 6px 0; color: var(--muted); text-transform: capitalize; }
.sheet-line { display: flex; flex-wrap: wrap; margin-bottom: 8px; }
.seg { display: inline-flex; flex-direction: column; white-space: pre; border-radius: 5px; }
.seg b { color: var(--brass); font-family: var(--display); padding-right: 8px; }
.seg.next { outline: 2px dashed var(--brass); }
.seg.current { background: #4a3516; }

.picker { margin: 14px 0; }
.picker input { flex: 1 1 240px; }
.chip-grid { display: flex; flex-wrap: wrap; gap: 6px; max-height: 190px; overflow-y: auto; padding: 2px; }
.chip { min-height: 32px; min-width: 52px; padding: 2px 10px; }
.chip.own { border-color: var(--ok); }
.chip.active { background: var(--brass); color: var(--brass-ink); border-color: var(--brass); }

.editor { display: flex; flex-wrap: wrap; gap: 28px; }
.editor-grid { display: grid; grid-template-columns: 64px repeat(var(--strings), 48px); gap: 3px; margin-bottom: 10px; }
.editor-grid .axis { display: flex; align-items: center; justify-content: center; color: var(--muted); font: 600 .8rem var(--display); }
.editor-grid .cell { min-height: 34px; padding: 0; border-radius: 4px; }
.editor-grid .cell.on { background: var(--brass); color: var(--brass-ink); border-color: var(--brass); }
.editor-grid select { padding: 2px; min-height: 32px; }
.editor-side { flex: 1 1 220px; max-width: 360px; }
.my-chords { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.chord-card { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 8px; background: var(--surface-2); border-radius: var(--radius); }
.chord-card .actions { margin: 0; justify-content: center; }
.report { color: var(--ok); padding-left: 18px; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 390px), 1fr)); gap: 14px; }
.guitar-card { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 14px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.guitar-card.active { border-color: var(--brass); }
.guitar-card h3 { margin: 2px 0 8px; font-size: 1.2rem; }
.guitar-art svg { width: 100%; }
dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 10px; font-size: .86rem; margin: 0 0 12px; }
dt { color: var(--muted); }
dd { margin: 0; }

.toc { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.prose > p, .prose > ul { max-width: 72ch; }
.prose li { margin-bottom: 4px; }
.table-wrap { overflow-x: auto; margin-bottom: 12px; }
table { border-collapse: collapse; font-size: .88rem; }
caption { text-align: left; color: var(--muted); padding-bottom: 6px; }
th, td { border: 1px solid var(--line); padding: 5px 10px; text-align: left; }
.fret-table td { padding: 0; }
.fret-table td button { width: 44px; min-height: 32px; padding: 0; border: 0; border-radius: 0; background: transparent; }
.fret-table td button:hover { background: var(--brass); color: var(--brass-ink); }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-bottom: 14px; }
.slider input { width: 100%; }
.toggle { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; cursor: pointer; }
.toggle span { display: flex; flex-direction: column; }
.toggle small { color: var(--muted); }
.bind-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 14px; margin: 10px 0; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; min-width: 0; margin: 0; }
legend { padding: 0 6px; font-weight: 600; }
.bind-row { display: grid; grid-template-columns: minmax(0, 1fr) 96px 76px auto; gap: 6px; align-items: center; padding: 3px 0; }
.bind { min-height: 32px; padding: 0 6px; white-space: nowrap; font-family: var(--display); }
.bind.empty { color: var(--muted); border-style: dashed; }
.bind.waiting { background: var(--brass); color: var(--brass-ink); }

#toast { position: fixed; left: 50%; bottom: 20px; z-index: 30; max-width: min(92vw, 520px); padding: 10px 16px; border-radius: 10px; background: var(--text); color: #201710; font-weight: 600; box-shadow: 0 8px 28px rgba(0, 0, 0, .5); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1080px) {
  .play-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .play-grid .pad, .pad:has(.neck-controls) { grid-column: 1 / -1; }
}
.setup-toggle, .strum-chord, .touch-only { display: none; }
.keycap, .pad-btn, .fretboard { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button, .button, summary, label { -webkit-tap-highlight-color: transparent; }
.pad-btn.on { background: var(--brass); color: var(--brass-ink); }

/* Touch screens: no keyboard hints, finger-sized targets, no zoom-on-focus. */
.touch kbd, .touch .key-help { display: none; }
.touch .touch-only { display: inline-flex; }
@media (pointer: coarse) {
  button, .button, select, input[type="text"], input[type="search"] { min-height: 44px; }
  select, input, textarea { font-size: 16px; }
  textarea { font-size: 16px; }
  .keycap, .pad-btn { touch-action: manipulation; }
}

@media (max-width: 680px) {
  .topbar { flex-wrap: wrap; gap: 4px 8px; position: static; padding-top: max(8px, env(safe-area-inset-top)); }
  .brand { font-size: 1.15rem; }
  .nav { order: 3; flex-basis: 100%; justify-content: space-between; }
  .nav a { padding: 8px 9px; }
  .volume { margin-left: auto; }
  .volume span { display: none; }
  main { padding: 8px; }

  #view-play > .toolbar { gap: 8px; margin-bottom: 8px; }
  #view-play > .toolbar .style { flex: 1 1 0; }
  #view-play > .toolbar .style > span { display: none; }
  #view-play > .toolbar .segmented { display: flex; }
  #view-play > .toolbar .segmented button { flex: 1; padding: 4px; }
  #view-play > .toolbar .long { display: none; }
  #view-play > .toolbar .extra { display: none; }
  #view-play > .toolbar.open .extra { display: flex; }
  .setup-toggle { display: inline-flex; flex: none; padding: 0 10px; background: transparent; }
  .guide { padding: 8px 10px; margin-bottom: 8px; font-size: .85rem; }
  .guide p { flex-basis: 200px; }

  .stage { margin-bottom: 8px; border-radius: 10px; }
  .fretboard { height: 170px; }
  .panel { padding: 10px; margin-bottom: 10px; }
  .play-grid { display: block; margin-bottom: 10px; }
  .play-grid .panel { margin-bottom: 10px; }
  .play-grid .now { display: none; }
  .pad > .muted { display: none; }
  .pad:has(.neck-controls) > .muted, .pad > .neck-hint { display: block; }

  .bank-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .bank-tabs button { flex: none; }
  .keyboard { gap: 6px; }
  .keyrow { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
  .keyrow.row1, .keyrow.row2 { margin-left: 0; }
  .keycap { min-height: 52px; justify-content: center; padding: 2px; }
  .keycap strong { font-size: 1rem; }
  .touch .keycap kbd { display: none; }
  .keycap kbd { align-self: flex-start; font-size: .65rem; line-height: 1; }

  /* The strumming hand stays under the thumb. */
  #view-play { padding-bottom: 214px; }
  .play-grid .strum { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; margin: 0; padding: 6px 8px max(8px, env(safe-area-inset-bottom)); border-width: 1px 0 0; border-radius: 14px 14px 0 0; background: #17110d; box-shadow: 0 -10px 28px rgba(0, 0, 0, .55); touch-action: none; }
  .strum h2, .strum .key-help, .strum kbd { display: none; }
  .strum-chord { display: block; text-align: center; font: 700 1.2rem/1.3 var(--display); color: var(--brass-hi); }
  .strum-grid { grid-template-columns: repeat(12, 1fr); gap: 6px; margin-bottom: 6px; }
  .strum-grid .pad-btn { grid-column: span 2; justify-content: center; padding: 0 1px; font-size: .74rem; line-height: 1.15; text-align: center; touch-action: none; }
  .strum-grid .pad-btn.big { grid-column: span 6; min-height: 58px; font: 700 1.2rem var(--display); }
  .pluck-row { grid-template-columns: repeat(auto-fit, minmax(36px, 1fr)); margin-bottom: 0; }
  .pluck-row .pad-btn { min-height: 40px; touch-action: none; }
  #view-play:has(.strum[hidden]) { padding-bottom: 0; }
  #toast { bottom: auto; top: 12px; }

  .rhythm-row { gap: 8px; }
  .rhythm .tempo { flex: 1 1 100%; }
  .rhythm .tempo input { flex: 1; min-width: 0; }
  .guitar-card { grid-template-columns: 70px minmax(0, 1fr); }
  .editor-grid { grid-template-columns: 52px repeat(var(--strings), minmax(0, 1fr)); width: calc(100vw - 38px); }
  .editor-grid .cell, .editor-grid select { min-width: 0; min-height: 38px; }
  .bind-row { grid-template-columns: minmax(0, 1fr) 70px 56px auto; }
  .bind-row button { padding: 0 4px; }
}

/* Short phones: shrink the neck and keys so all three chord rows stay above the strum bar. */
@media (max-width: 680px) and (max-height: 740px) {
  .guide { display: none; }
  .fretboard { height: 130px; }
  .keyboard { gap: 4px; }
  .keycap { min-height: 44px; }
  .strum-grid .pad-btn.big { min-height: 50px; }
}

/* Phone held sideways: neck on top, chords under the left thumb, strum under the right. */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 500px) {
  .topbar { position: static; flex-wrap: nowrap; padding-top: 4px; padding-bottom: 4px; gap: 10px; }
  .nav { order: 0; flex-basis: auto; }
  .nav a { padding: 6px 8px; }
  .volume span { display: none; }
  main { padding: 6px max(8px, env(safe-area-inset-right)) 8px max(8px, env(safe-area-inset-left)); }
  #view-play { padding-bottom: 0; }
  #view-play > .toolbar { gap: 8px; margin-bottom: 6px; }
  #view-play > .toolbar .style > span, #view-play > .toolbar .long, #view-play > .toolbar .extra { display: none; }
  #view-play > .toolbar.open .extra { display: flex; }
  #view-play > .toolbar .style { flex: 1; }
  #view-play > .toolbar .segmented { display: flex; }
  #view-play > .toolbar .segmented button { flex: 1; }
  .setup-toggle { display: inline-flex; flex: none; }
  .guide { display: none; }
  .stage { margin-bottom: 6px; }
  /* Whatever height is left once the chords fit; the whole screen in Fretboard style. */
  .fretboard { height: clamp(76px, calc(100vh - 284px), 160px); height: clamp(76px, calc(100dvh - 284px), 160px); }
  #view-play:has(.strum[hidden]) .fretboard { height: max(160px, calc(100vh - 120px)); height: max(160px, calc(100dvh - 120px)); }
  .play-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 8px; }
  .play-grid .pad { grid-column: auto; padding: 6px; margin: 0; }
  .play-grid .now { display: none; }
  .pad > .muted:not(.neck-hint), .pad .keycap kbd { display: none; }
  .bank-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-bottom: 4px; }
  .bank-tabs button { flex: none; min-height: 30px; }
  .keyboard { gap: 4px; }
  .keyrow { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
  .keyrow.row1, .keyrow.row2 { margin-left: 0; }
  .keycap { min-height: 40px; justify-content: center; align-items: center; padding: 2px; }
  .play-grid .strum { position: static; margin: 0; padding: 6px; border-radius: var(--radius); }
  .strum h2, .strum .key-help, .strum kbd { display: none; }
  .strum-chord { display: block; text-align: center; font: 700 1rem/1.2 var(--display); color: var(--brass-hi); }
  .strum-grid { grid-template-columns: repeat(12, 1fr); gap: 4px; margin-bottom: 4px; }
  .strum-grid .pad-btn { grid-column: span 2; min-height: 36px; justify-content: center; padding: 0 1px; font-size: .68rem; line-height: 1.1; text-align: center; touch-action: none; }
  .strum-grid .pad-btn.big { grid-column: span 6; min-height: 50px; font: 700 1.05rem var(--display); }
  .pluck-row { margin: 0; gap: 4px; }
  .pluck-row .pad-btn { min-height: 34px; padding: 0; justify-content: center; touch-action: none; }
}

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