/* Chords to Numerals: a white page on a grey desk, thin app chrome around it. */

:root {
  --desk: #e9eaed;
  --desk-line: #d6d8dd;
  --chrome: #f7f7f9;
  --chrome-line: #dcdee3;
  --page: #ffffff;
  --page-shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 10px 30px -12px rgba(20, 24, 40, .22);
  --fg: #1a1c22;
  --fg-2: #4d5160;
  --fg-3: #6b7080;
  --line: #e4e6ea;
  --accent: #14487F;
  --accent-ink: #ffffff;
  --accent-soft: #e6eef8;
  --focus: #2b74c9;
  --danger: #b3261e;
  --chip-chord-bg: #e8e8ea;
  --chip-chord-fg: #1a1c22;
  --chip-num-bg: #d8e7f7;
  --chip-num-fg: #14487F;
  --chip-out-bg: #fbe7c6;
  --chip-out-fg: #7a4a00;
  --diagram-fg: #1a1c22;
  --diagram-degree: #14487F;
  --sel: #cfe0f5;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --sheet-size: 14px;
  --r: 8px;
  --panel-w: 320px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --desk: #1b1d21;
    --desk-line: #2a2d33;
    --chrome: #222429;
    --chrome-line: #33363d;
    --page: #ffffff;
    --page-shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 14px 40px -14px rgba(0, 0, 0, .7);
    --fg: #1a1c22;
    --fg-2: #4d5160;
    --fg-3: #6b7080;
    --line: #e4e6ea;
    --sel: #cfe0f5;
    /* chrome text lives on the dark desk */
    --chrome-fg: #ececef;
    --chrome-fg-2: #b6b9c2;
    --chrome-fg-3: #9296a3;
    --accent-soft: #223b5a;
    --focus: #7fb0ea;
  }
}
:root { --chrome-fg: var(--fg); --chrome-fg-2: var(--fg-2); --chrome-fg-3: var(--fg-3); }
@media (prefers-color-scheme: dark) { :root { --chrome-fg: #ececef; --chrome-fg-2: #b6b9c2; --chrome-fg-3: #9296a3; } }
html[data-size="s"]  { --sheet-size: 12px; }
html[data-size="m"]  { --sheet-size: 14px; }
html[data-size="l"]  { --sheet-size: 17px; }
html[data-size="xl"] { --sheet-size: 21px; }

/* ------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; }
body {
  margin: 0; min-height: 100%; background: var(--desk); color: var(--chrome-fg);
  font-family: var(--sans); font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; display: flex; flex-direction: column;
}
::selection { background: var(--sel); color: var(--fg); }
a { color: var(--accent); text-underline-offset: 2px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
* { scrollbar-width: thin; scrollbar-color: var(--desk-line) transparent; }
h1, h2, h3, p, dl, dd { margin: 0; }
.icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ------------------------------------------------------------ app bar */
.appbar {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 16px;
  height: 56px; padding: 0 16px; background: var(--chrome); border-bottom: 1px solid var(--chrome-line);
  position: sticky; top: 0; z-index: 30;
}
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--chrome-fg); text-decoration: none; font-weight: 650; letter-spacing: -.005em; white-space: nowrap; }
.mark { width: 24px; height: 24px; color: var(--accent); }
.search { position: relative; display: flex; align-items: center; max-width: 720px; width: 100%; justify-self: center; }
.search > .icon { position: absolute; left: 12px; color: var(--chrome-fg-3); pointer-events: none; }
.search input {
  flex: 1; min-width: 0; height: 38px; padding: 0 84px 0 36px; border-radius: 10px;
  border: 1px solid var(--chrome-line); background: var(--page); color: var(--fg); font-size: 14px;
}
.search input::placeholder { color: #6f7482; }
.search input:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.search button {
  position: absolute; right: 4px; height: 30px; padding: 0 14px; border-radius: 7px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.search button:hover { filter: brightness(1.08); }
.search button:disabled { cursor: default; }
.search button.busy { color: transparent; position: absolute; }
.search button.busy::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.iconbtn {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; border-radius: 9px;
  border: 1px solid transparent; background: transparent; color: var(--chrome-fg-2);
}
.iconbtn:hover { background: var(--accent-soft); color: var(--chrome-fg); }
.iconbtn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
@media (prefers-color-scheme: dark) { .iconbtn[aria-expanded="true"] { color: #cfe0f5; } }

/* search results dropdown escapes the bar */
.results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; margin: 0; padding: 6px; list-style: none;
  background: var(--page); color: var(--fg); border: 1px solid var(--chrome-line); border-radius: 12px;
  box-shadow: 0 12px 34px -10px rgba(20, 24, 40, .35); max-height: min(60vh, 520px); overflow: auto; z-index: 40;
}
.results a { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; padding: 9px 10px; border-radius: 8px; text-decoration: none; color: inherit; }
.results a:hover, .results a:focus-visible { background: var(--accent-soft); outline: none; }
.r-title { font-weight: 600; }
.r-artist { color: var(--fg-2); margin-left: 6px; }
.r-meta { grid-column: 2; grid-row: 1; color: var(--fg-3); font-size: 12px; white-space: nowrap; align-self: center; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ toolbar */
.toolbar {
  display: flex; align-items: center; gap: 4px 22px; flex-wrap: wrap; min-height: 48px; padding: 6px 16px;
  background: var(--chrome); border-bottom: 1px solid var(--chrome-line); position: sticky; top: 56px; z-index: 20;
}
.tool { display: inline-flex; align-items: center; gap: 8px; }
.tool.actions { margin-left: auto; gap: 6px; }
.tl { font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--chrome-fg-3); }
.tn { font-size: 12px; color: var(--chrome-fg-3); font-variant-numeric: tabular-nums; }
select {
  height: 32px; padding: 0 28px 0 10px; border-radius: 7px; border: 1px solid var(--chrome-line); background: var(--page); color: var(--fg);
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%237d8290' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 14px;
}
select:hover { border-color: #b9bdc7; }
.seg { display: inline-flex; height: 32px; padding: 2px; border-radius: 8px; background: var(--desk); border: 1px solid var(--chrome-line); }
.seg button { border: 0; border-radius: 6px; padding: 0 11px; background: transparent; color: var(--chrome-fg-2); font-size: 13px; font-weight: 500; transition: background .15s var(--ease), color .15s var(--ease); }
.seg button:hover { color: var(--chrome-fg); }
.seg button.on { background: var(--page); color: var(--accent); font-weight: 650; box-shadow: 0 1px 2px rgba(20, 24, 40, .12); }
.stepper { display: inline-flex; align-items: center; height: 32px; border-radius: 8px; border: 1px solid var(--chrome-line); background: var(--page); color: var(--fg); overflow: hidden; }
.stepper button { width: 32px; height: 100%; border: 0; background: transparent; color: var(--fg-2); display: grid; place-items: center; }
.stepper button:hover { background: var(--accent-soft); color: var(--accent); }
.stepper output { min-width: 40px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; border-left: 1px solid var(--line); border-right: 1px solid var(--line); height: 100%; display: grid; place-items: center; }
.btn, .ghost {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--chrome-line); background: var(--page); color: var(--fg); font-weight: 500;
}
.btn:hover { border-color: #b9bdc7; }
.btn .chev { width: 14px; height: 14px; margin-left: -2px; opacity: .6; }
.ghost { height: 28px; padding: 0 9px; border-color: transparent; background: transparent; color: var(--chrome-fg-3); font-size: 12px; }
.ghost:hover { background: var(--accent-soft); color: var(--accent); }
.menu { margin: 0; padding: 6px; border: 1px solid var(--chrome-line); border-radius: 12px; background: var(--page); color: var(--fg); box-shadow: 0 12px 34px -10px rgba(20, 24, 40, .35); min-width: 220px; }
.menu:popover-open { display: grid; }
.menu button { text-align: left; border: 0; background: transparent; padding: 9px 10px; border-radius: 8px; }
.menu button:hover, .menu button:focus-visible { background: var(--accent-soft); outline: none; }

/* ------------------------------------------------------------ workspace */
.workspace { display: flex; flex: 1; min-height: 0; }
.desk { flex: 1; min-width: 0; padding: 28px 24px 64px; overflow-x: hidden; }
.page {
  background: var(--page); color: var(--fg); box-shadow: var(--page-shadow); border-radius: 3px;
  max-width: 1120px; margin: 0 auto; padding: 34px 48px 40px;
  animation: page-in .28s var(--ease);
}
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .page { animation: none; } * { transition: none !important; } }

/* empty and loading */
.page.empty { max-width: 720px; padding: 56px 56px 48px; }
.page.empty h1 { font-size: 26px; letter-spacing: -.01em; margin-bottom: 12px; text-wrap: balance; }
.page.empty p { color: var(--fg-2); font-size: 15px; max-width: 62ch; }
.page.empty .try { margin-top: 18px; color: var(--fg-3); }
.error { color: var(--danger); margin-top: 16px; font-size: 14px; }
.skeleton .sk { background: linear-gradient(90deg, #eef0f3 25%, #f6f7f9 50%, #eef0f3 75%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: 4px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.sk.t { height: 26px; width: 40%; margin-bottom: 10px; }
.sk.s { height: 14px; width: 22%; margin-bottom: 26px; }
.sk-row { display: flex; gap: 12px; margin-bottom: 26px; }
.sk.c { height: 96px; width: 84px; }
.sk-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; }
.sk.l { height: 12px; margin-bottom: 14px; width: 80%; }
.sk.l.w { width: 55%; }

/* title block */
.titleblock { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 40px; flex-wrap: wrap; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.titleblock h1 { font-size: 28px; letter-spacing: -.012em; line-height: 1.15; text-wrap: balance; }
.artist { color: var(--fg-2); font-size: 16px; margin-top: 4px; }
.facts { display: flex; gap: 22px; flex-wrap: wrap; }
.facts div { display: flex; flex-direction: column; gap: 1px; }
.facts dt { font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-3); }
.facts dd { font-size: 14px; font-weight: 550; color: var(--fg); font-variant-numeric: tabular-nums; }

/* summary */
.legend { display: flex; flex-wrap: wrap; gap: 10px 22px; font-family: var(--mono); font-size: 13.5px; padding: 16px 3px 6px; }
.band { display: flex; flex-wrap: wrap; gap: 8px 32px; align-items: flex-start; padding: 6px 0 4px; }
.pair { white-space: nowrap; }
.pair .eq { color: var(--fg-3); margin: 0 9px; font-family: var(--sans); }
.structure { border-collapse: collapse; font-size: 13px; display: block; overflow-x: auto; max-width: 100%; flex: none; }
.structure th, .structure td { text-align: left; padding: 4px 16px 4px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
.structure th { color: var(--fg-3); font-weight: 650; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.structure td:nth-child(2) { font-family: var(--mono); color: var(--accent); font-weight: 700; }
.structure td:nth-child(3) { font-family: var(--mono); }

/* diagrams */
.diagrams { display: flex; flex-wrap: wrap; gap: 2px 8px; padding: 0; align-items: flex-start; flex: 1 1 320px; min-width: 0; }
.diagram svg { width: 110px; }
.diagram { margin: 0; position: relative; }
.diagram svg { display: block; max-width: 100%; height: auto; }
.diagram.clickable { cursor: pointer; border-radius: 8px; transition: background .15s var(--ease); }
.diagram.clickable:hover { background: #f2f4f7; }
.diagram .alts { position: absolute; right: 2px; top: 0; font-size: 11px; color: var(--fg-3); font-variant-numeric: tabular-nums; border: 0; background: transparent; padding: 3px 5px; border-radius: 6px; }
.diagram .alts:hover { color: var(--accent); background: var(--accent-soft); }
.diagram .keyboard { border-radius: 6px; }

/* sheets */
.part-switch { display: none; }
.sheets { display: grid; gap: 40px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; padding-top: 14px; }
.sheet { min-width: 0; }
.sheets.chords .numerals, .sheets.numerals .chords { display: none; }
.sheets.chords, .sheets.numerals { grid-template-columns: minmax(0, 1fr); }
.sheet h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-3); margin: 0 0 8px; font-weight: 650; }
.sheet pre {
  margin: 0; font-family: var(--mono); font-size: var(--sheet-size); line-height: 1.7;
  white-space: pre; overflow-x: auto; padding: 4px 6px 4px 4px; color: var(--fg);
}
.line.section { font-weight: 700; margin-top: 4px; }
.line.chord { font-weight: 700; }
/* the chip is drawn with a shadow so it takes no width and columns stay put */
.chip { border-radius: 4px; }
.chip.chord { background: var(--chip-chord-bg); color: var(--chip-chord-fg); box-shadow: 0 0 0 3px var(--chip-chord-bg); }
.chip.numeral { background: var(--chip-num-bg); color: var(--chip-num-fg); box-shadow: 0 0 0 3px var(--chip-num-bg); }
.chip.out { background: var(--chip-out-bg); color: var(--chip-out-fg); box-shadow: 0 0 0 3px var(--chip-out-bg); }

.pagefoot { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 36px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--fg-3); font-size: 12px; }

/* ------------------------------------------------------------ panel */
.panel {
  width: var(--panel-w); flex: none; background: var(--chrome); border-left: 1px solid var(--chrome-line);
  padding: 4px 18px 28px; overflow-y: auto; position: sticky; top: 104px; height: calc(100vh - 104px); color: var(--chrome-fg);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; height: 48px; }
.panel-head h2 { font-size: 14px; font-weight: 650; }
.pgroup { padding: 12px 0 8px; border-top: 1px solid var(--chrome-line); }
.pgroup h3 { font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--chrome-fg-3); margin-bottom: 4px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; color: var(--chrome-fg); text-decoration: none; }
.row > span:first-child { display: flex; flex-direction: column; }
.row small { color: var(--chrome-fg-3); font-size: 12px; }
.row.link:hover { color: var(--accent); }
@media (prefers-color-scheme: dark) { .row.link:hover { color: #9fc4f0; } }
.note { color: var(--chrome-fg-3); font-size: 12px; line-height: 1.5; margin-top: 6px; }
.panel .seg { height: 30px; }
.panel .seg button { padding: 0 10px; font-size: 12.5px; }
.panel select { height: 30px; max-width: 170px; }
.switch { appearance: none; -webkit-appearance: none; width: 34px; height: 20px; border-radius: 10px; background: #c3c6ce; position: relative; margin: 0; flex: none; transition: background .18s var(--ease); }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .18s var(--ease); }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(14px); }
@media (prefers-color-scheme: dark) { .switch { background: #4a4e58; } }

/* ------------------------------------------------------------ narrow */
@media (max-width: 1100px) {
  .panel { position: fixed; top: 0; right: 0; height: 100vh; z-index: 50; box-shadow: -12px 0 40px -18px rgba(0, 0, 0, .35); }
  .panel-head { height: 56px; }
}
@media (max-width: 860px) {
  .appbar { grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; padding: 0 12px; }
  .wordmark { display: none; }
  .iconbtn .label { display: none; }
  .search input { padding-right: 62px; }
  .toolbar { flex-wrap: nowrap; overflow-x: auto; gap: 4px 18px; scrollbar-width: none; padding: 6px 40px 6px 12px;
    mask-image: linear-gradient(90deg, #000 calc(100% - 44px), transparent); -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 44px), transparent); }
  .toolbar::-webkit-scrollbar { display: none; }
  html[data-size="m"] { --sheet-size: 13px; }
  .sheet pre { margin: 0 -18px; padding: 4px 28px 4px 18px;
    mask-image: linear-gradient(90deg, #000 calc(100% - 26px), transparent); -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 26px), transparent); }
  .diagram svg { width: 118px; }
  .band { gap: 12px 24px; }
  .tool { flex: none; }
  .tool.actions { margin-left: 8px; }
  .desk { padding: 12px 10px 48px; }
  .page { padding: 24px 18px 28px; border-radius: 6px; }
  .page.empty { padding: 32px 22px; }
  .page.empty h1 { font-size: 22px; }
  .titleblock h1 { font-size: 24px; }
  .facts { gap: 16px; }
  .sk-cols { grid-template-columns: 1fr; }
  .diagram .keyboard { width: 160px; }
  /* one sheet at a time on a phone, with a switch */
  .part-switch { display: inline-flex; margin: 14px 0 0; padding: 2px; border-radius: 8px; background: var(--desk); border: 1px solid var(--chrome-line); }
  .part-switch button { border: 0; border-radius: 6px; padding: 6px 12px; background: transparent; color: var(--fg-2); font-size: 13px; }
  .part-switch button.on { background: var(--page); color: var(--accent); font-weight: 650; box-shadow: 0 1px 2px rgba(20, 24, 40, .12); }
  .sheets.both { grid-template-columns: 1fr; }
  .sheets.both.show-chords .numerals, .sheets.both.show-numerals .chords { display: none; }
  .sheets.chords + .part-switch, .sheets.numerals ~ .part-switch { display: none; }
  .panel { width: min(100vw, 360px); }
}
@media (max-width: 480px) {
  .search input { font-size: 16px; }   /* stops iOS zooming the field */
}

/* ------------------------------------------------------------ print */
@media print {
  @page { margin: 12mm; }
  html, body { background: #fff; }
  .appbar, .toolbar, .panel, .part-switch, .diagram .alts, .pagefoot a[href]::after { display: none !important; }
  .desk { padding: 0; }
  .page { box-shadow: none; max-width: none; padding: 0; animation: none; border-radius: 0; }
  .titleblock h1 { font-size: 22px; }
  .sheets { gap: 18px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .sheets.both .numerals, .sheets.both .chords { display: block; }
  .print-stack .sheets { grid-template-columns: minmax(0, 1fr); }
  .sheet pre { font-size: 10.5px; line-height: 1.55; overflow: visible; }
  .chip { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .chip.chord { box-shadow: 0 0 0 2px var(--chip-chord-bg); }
  .chip.numeral { box-shadow: 0 0 0 2px var(--chip-num-bg); }
  .chip.out { box-shadow: 0 0 0 2px var(--chip-out-bg); }
  .line { break-inside: avoid; }
  .diagrams { gap: 2px 8px; }
  .diagram svg { width: 92px; height: auto; }
}

/* ------------------------------------------------------------ toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  background: #1a1c22; color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 13px; z-index: 60;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .5); transition: opacity .18s var(--ease), transform .18s var(--ease);
  max-width: min(90vw, 480px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
