:root {
  --bg: #14161a;
  --surface: #1d2026;
  --surface-2: #272b33;
  --line: #333843;
  --text: #e9e6df;
  --muted: #959aa5;
  --accent: #f2b64c;
  --accent-ink: #1a1408;
  --ok: #5fd18b;
  --warn: #f07a5c;
  --chord: #f2b64c;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #faf8f4;
    --surface: #ffffff;
    --surface-2: #f0ece4;
    --line: #e2ddd3;
    --text: #1d1c1a;
    --muted: #6d6a64;
    --accent: #c4800e;
    --accent-ink: #ffffff;
    --ok: #1f9d55;
    --warn: #d0502f;
    --chord: #b06f00;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--sans);
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
body.reading { padding-bottom: calc(124px + env(safe-area-inset-bottom)); }
a { color: inherit; text-decoration: none; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#view { max-width: 860px; margin: 0 auto; padding: env(safe-area-inset-top) 16px 16px; }

.page-head h1 { font-size: 28px; margin: 20px 0 14px; letter-spacing: -0.01em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 28px 0 8px; font-weight: 600; }

/* search */
.search { display: flex; gap: 8px; margin: 12px 0; }
.search input {
  flex: 1; min-width: 0; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); outline: none;
}
.search input:focus { border-color: var(--accent); }
.search button {
  width: 48px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700;
}
.search button svg { width: 20px; height: 20px; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--line); }
.list > li > a { display: block; padding: 12px 2px; }
.title { display: block; font-weight: 600; }
.sub { display: block; color: var(--muted); font-size: 14px; }
.rating { color: var(--accent); font-size: .9em; white-space: nowrap; }
.group { padding: 12px 0; }
.versions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px;
  background: var(--surface-2); font-size: 14px;
}
.chip small { color: var(--muted); }
.empty, .loading { color: var(--muted); padding: 16px 0; }
.error { color: var(--warn); padding: 16px 0; }
.pager { display: flex; justify-content: space-between; align-items: center; margin: 16px 0; color: var(--muted); }
.btn {
  display: inline-block; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* bottom nav */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 48px;
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; font-size: 12px; color: var(--muted); padding: 4px 16px; }
.tabbar a.active { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; }

/* tab viewer */
.tab-head {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  margin: 0 -16px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.tab-title { flex: 1; min-width: 0; }
.tab-title strong, .tab-title > span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab-title > span { color: var(--muted); font-size: 13px; }
.icon-btn {
  width: 40px; height: 40px; flex: none; display: grid; place-items: center;
  border: 0; border-radius: 10px; background: transparent; font-size: 22px;
}
.icon-btn svg { width: 22px; height: 22px; }
.fav.on { color: var(--accent); }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }
.meta span { font-size: 13px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.version-select { margin: 8px 0; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); max-width: 100%; }

.chord-strip { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0; scrollbar-width: thin; }
.chord-card {
  flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  font-family: var(--mono); font-weight: 700; color: var(--chord); min-width: 52px;
}
.chord-card .diagram { width: 64px; }

.tab-content {
  font-family: var(--mono); line-height: 1.5; margin: 8px 0 0; padding: 4px 0 40px;
  white-space: pre; overflow-x: auto; tab-size: 4;
}
.chord { color: var(--chord); font-weight: 700; cursor: pointer; }
.section { color: var(--muted); font-weight: 700; font-family: var(--sans); }

.toolbar {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 15;
  bottom: calc(66px + env(safe-area-inset-bottom));
  display: flex; gap: 6px; padding: 6px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: 0 6px 24px rgba(0,0,0,.25);
  max-width: calc(100vw - 16px);
}
.toolbar .group { display: flex; align-items: center; background: var(--surface-2); border-radius: 11px; }
.toolbar button { border: 0; background: transparent; min-width: 40px; height: 40px; padding: 0 8px; font-weight: 700; border-radius: 11px; }
.toolbar .val { min-width: 24px; text-align: center; font-size: 14px; color: var(--muted); }
.toolbar .play.on { background: var(--accent); color: var(--accent-ink); }

/* chord sheet */
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-inner {
  width: 100%; max-width: 420px; background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; align-items: center; gap: 12px; }
.sheet-head strong { font: 700 24px var(--mono); color: var(--chord); flex: 1; }
.sheet-head span { color: var(--muted); }
.sheet-diagram { display: flex; align-items: center; justify-content: center; gap: 8px; }
.sheet-diagram .diagram { width: 180px; }
.sheet-diagram button { border: 0; background: var(--surface-2); border-radius: 50%; width: 44px; height: 44px; font-size: 24px; }

.diagram line { stroke: var(--muted); stroke-width: 1.2; }
.diagram .nut { fill: var(--text); stroke: none; }
.diagram .dot { fill: var(--chord); stroke: none; }
.diagram .open { stroke: var(--text); stroke-width: 1.5; }
.diagram .mark { fill: var(--muted); stroke: none; font: 12px var(--sans); text-anchor: middle; }
.diagram .finger { fill: var(--accent-ink); stroke: none; font: 700 9px var(--sans); text-anchor: middle; }
.diagram .basefret { fill: var(--muted); stroke: none; font: 10px var(--sans); }

/* tuner */
.tuner-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.tuner-controls select {
  flex: 1 1 150px; min-width: 0; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
}
.tuner { padding-top: 16px; }
.tuner-controls select { padding: 12px; }
.tuner .search { margin: 8px 0 0; }
.tuner-settings { display: flex; justify-content: center; align-items: center; gap: 16px; flex-wrap: wrap; }
.a4 { display: flex; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.a4 button { border: 0; background: transparent; width: 34px; height: 34px; font-size: 16px; }
.a4 span { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 34px; height: 20px; border-radius: 10px; background: var(--line); position: relative; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.gauge { position: relative; max-width: 340px; margin: 20px auto 0; --state: var(--warn); }
.gauge.ok { --state: var(--ok); }
.gauge svg { display: block; width: 100%; }
.gauge .arc { stroke: var(--line); stroke-width: 6; }
.gauge .arc-ok { stroke: var(--ok); stroke-width: 6; opacity: .6; }
.gauge .tick { stroke: var(--muted); stroke-width: 2; }
.gauge .needle { stroke: var(--state); stroke-width: 4; }
.gauge .hub { fill: var(--state); stroke: none; }
.gauge #needle { transform-origin: 150px 160px; transition: transform .12s linear; }
.gauge.idle #needle { opacity: .25; }
.gauge.idle .readout { opacity: .4; }
.readout { text-align: center; margin-top: 2px; transition: opacity .2s; }
.note { font-size: 64px; font-weight: 700; line-height: 1; color: var(--state); }
.gauge.idle .note { color: var(--text); }
.note small { font-size: 22px; color: var(--muted); margin-left: 2px; }
.cents { margin-top: 4px; color: var(--muted); min-height: 1.4em; font-size: 16px; }
.gauge.ok .cents { color: var(--ok); font-weight: 700; }
.hint { text-align: center; color: var(--muted); font-size: 14px; margin: 12px 0 10px; min-height: 1.4em; }

.strings { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; }
.strings button {
  width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--line); background: var(--surface);
  font-weight: 700; font-size: 18px; position: relative;
}
.strings button small { font-size: 10px; color: var(--muted); font-weight: 400; }
.strings button.active { border-color: var(--accent); }
.strings button.locked { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.strings button.locked small { color: var(--accent-ink); }
.strings button.done::after {
  content: "✓"; position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--ok); color: #fff; font-size: 12px; line-height: 20px;
}
.tuner-actions { display: flex; justify-content: center; gap: 10px; margin: 22px 0 14px; }

@media (min-width: 700px) {
  .toolbar { bottom: 80px; }
}
.btn.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.gauge.tone .note { color: var(--accent); }
.gauge.tone .needle, .gauge.tone .hub { stroke: var(--accent); fill: var(--accent); }
.gauge.tone .cents { color: var(--accent); }
.meta .tuning-link {
  display: inline-flex; align-items: center; gap: 5px; font-size: 13px; padding: 3px 10px 3px 8px;
  border-radius: 999px; background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); font-weight: 600;
}
.meta .tuning-link svg { width: 14px; height: 14px; }
.hz { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; min-height: 1.3em; }
.cents { font-variant-numeric: tabular-nums; }
.trace { display: block; width: 100%; max-width: 340px; height: 110px; margin: 8px auto 0; }

/* Short screens (small phones, or a browser with toolbars): squeeze the tuner
   so it still fits without scrolling. */
@media (max-height: 720px) {
  .tuner { padding-top: 8px; }
  .tuner-controls select { padding: 8px 10px; }
  .gauge { max-width: 210px; margin-top: 6px; }
  .note { font-size: 40px; }
  .note small { font-size: 16px; }
  .cents { font-size: 14px; }
  .trace { height: 56px; }
  .hint { margin: 4px 0 6px; }
  .tuner-actions { margin: 10px 0 8px; }
  .tuner-actions .btn { padding: 8px 14px; }
  .strings { gap: 5px; }
  .strings button { width: 42px; height: 42px; }
}
.meta .tuning-link .from-tab {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 1px 5px; margin-left: 2px; border-radius: 6px; background: var(--accent); color: var(--accent-ink);
}

/* history */
.section-head { display: flex; align-items: baseline; justify-content: space-between; }
.section-head a { font-size: 14px; color: var(--accent); font-weight: 600; }
.page-head.with-back { display: flex; align-items: center; gap: 4px; margin: 12px 0 4px; }
.page-head.with-back .icon-btn { margin-left: -10px; }
.page-head.with-back h1 { flex: 1; margin: 0; }
.btn.small { padding: 6px 12px; font-size: 14px; }
.history-item { display: flex; align-items: center; gap: 8px; }
.history-item > a { flex: 1; min-width: 0; }
.history-item .title, .history-item .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item .when { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.history-item .remove { width: 32px; height: 32px; font-size: 14px; color: var(--muted); }
