:root {
  color-scheme: dark;
  --bg: #0d0e10;
  --surface: #151719;
  --surface-2: #1b1e22;       /* raised: popups, hovered rows, buttons */
  --surface-alt: #0f1113;     /* inset: inputs, wells */
  --text: #e9ebee;
  --muted: #8e949d;
  --border: #26292e;
  --border-hover: #3a3f46;
  --link: #7ab0ff;
  --error: #f87171;
  --success: #4ade80;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --shadow: rgba(0, 0, 0, 0.35);
  --shadow-strong: rgba(0, 0, 0, 0.5);
  --overlay: rgba(4, 5, 6, 0.68);
  --accent: #22c55e;
  --accent-contrast: #0f172a;
  --radius: 12px;
  --radius-sm: 8px;
  --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-alt: #f4f5f7;
  --text: #14171c;
  --muted: #667085;
  --border: #e3e6ea;
  --border-hover: #ccd1d8;
  --link: #2563eb;
  --error: #dc2626;
  --success: #16a34a;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --shadow: rgba(16, 24, 40, 0.07);
  --shadow-strong: rgba(16, 24, 40, 0.16);
  --overlay: rgba(16, 24, 40, 0.42);
}

* { box-sizing: border-box; scrollbar-width: thin; scrollbar-color: var(--border-hover) transparent; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--text);
  padding: 0 1.5rem 1.5rem;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Full-bleed header bar. The body's side padding is cancelled out with
   negative margins so the bar (and its bottom border) spans the viewport;
   the content inside re-aligns to the page's own column width. */
.topbar {
  width: calc(100% + 3rem);
  margin: 0 -1.5rem 1.5rem;
  padding: 0 1.5rem;
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-home { padding-inline: max(1.5rem, calc(50% + 1.5rem - 520px)); }
.topbar-title {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 650;
  font-size: 1rem;
  letter-spacing: -0.015em;
}
/* Small tab-staff mark in the accent color. */
.topbar-title::before {
  content: "";
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background:
    repeating-linear-gradient(to bottom, transparent 0 3px, color-mix(in srgb, var(--accent-contrast) 55%, transparent) 3px 4px) center / 12px 12px no-repeat,
    var(--accent);
}
.topbar-right { display: flex; align-items: center; gap: 0.15rem; }
.topbar-right .link-btn { padding: 0.4rem 0.7rem; border-radius: var(--radius-sm); font-size: 0.85rem; font-weight: 500; }
.topbar-right a.link-btn:hover, .topbar-right button.link-btn:hover { background: var(--surface-2); }
.topbar-right a.link-btn.current { color: var(--text); background: var(--surface-2); }
/* The signed-in username: a quiet chip, not a link. */
.topbar-right > span.link-btn {
  margin-right: 0.4rem;
  padding-right: 0.9rem;
  border-right: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
}
.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.88rem;
  padding: 0.3rem 0.5rem;
  text-decoration: none;
  font-family: inherit;
  transition: color 0.12s, background 0.12s;
}
.link-btn:hover { color: var(--text); }
.pill-btn {
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  text-decoration: none;
  display: inline-block;
  font-family: inherit;
  white-space: nowrap;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}
.pill-btn:hover:not(:disabled) { border-color: var(--border-hover); background: color-mix(in srgb, var(--text) 6%, var(--surface-2)); }
.pill-btn.active {
  border-color: color-mix(in srgb, var(--accent) 70%, transparent);
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  color: var(--accent);
}
.card {
  width: 100%;
  max-width: 720px;
  padding: 2rem;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px var(--shadow);
}
h1 { margin: 0 0 1.25rem; font-size: 1.3rem; font-weight: 650; letter-spacing: -0.02em; }
h2 { margin: 0 0 0.9rem; font-size: 1.05rem; font-weight: 650; letter-spacing: -0.015em; }
form { display: flex; gap: 0.5rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input[type="text"], input[type="email"], input[type="password"] { flex: 1; }
input::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
input[type="text"]:hover, input[type="email"]:hover, input[type="password"]:hover, input[type="number"]:hover, select:hover { border-color: var(--border-hover); }
input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus, input[type="number"]:focus, input[type="search"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
select { cursor: pointer; padding-right: 0.4rem; font-size: 0.85rem; }
input[type="text"], input[type="email"], input[type="password"] { padding: 0.6rem 0.75rem; }
input[type="file"] { color: var(--muted); font-family: inherit; font-size: 0.85rem; }
input[type="file"]::file-selector-button {
  margin-right: 0.7rem;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}
input[type="range"] { accent-color: var(--accent); }
button { font-family: inherit; }
form button[type="submit"] {
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: filter 0.12s;
}
form button[type="submit"]:hover:not(:disabled) { filter: brightness(1.08); }
button:disabled { opacity: 0.45; cursor: default; }
.song-info { margin-top: 1.25rem; color: var(--muted); font-size: 0.9rem; }
.error { margin-top: 1rem; color: var(--error); font-size: 0.9rem; }

.hidden { display: none; }

/* Generic "small muted explainer text under a control" utility -- used on
   every page that has settings/controls to explain (index's convert flow,
   the tablature player, the sample library, and every Settings tab). */
.hint { color: var(--muted); font-size: 0.85rem; margin: -0.4rem 0 1rem; }

/* Base data-table look, shared by the Settings page's mapping tables and
   the Sample Library page's reference tables (gm-families, convert-table,
   scan-table, app-slots-table) -- each of those layers its own column
   widths/colors on top via its own page's CSS file. */
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--border); }
th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* "Search for a song" results list -- identical markup/behavior on the
   index page's MIDI converter and the tablature page's search overlay. */
.search-results {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.search-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.search-result:hover { border-color: var(--border-hover); background: var(--surface-2); }
.search-result-title {
  font-size: 0.9rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-result-artist { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.search-result-count { color: var(--muted); font-size: 0.75rem; white-space: nowrap; }

/* Fixed-viewport shell, used by both the tablature page and the settings
   page: the page itself never scrolls -- whichever content fills the space
   below the topbar scrolls internally instead. Each page's own CSS file
   defines how ITS content (.tab-page vs .settings-page) fills that space. */
body.fixed-viewport {
  height: 100vh;
  overflow: hidden;
}

/* Modal shell, shared by the tablature page, Sample Library, and Settings
   (drum/Clone Hero mapping "quarantine" dialogs, the delete-sound-file
   confirm, Sample Library's MIDI reference modal). Each caller adds its
   own width/content classes (.confirm-modal-panel, .modal-section, etc.)
   on top of this base. */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  z-index: 100;
  backdrop-filter: blur(3px);
}
.modal-overlay.hidden { display: none; }
.modal-panel {
  width: 100%;
  max-width: 900px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 60px var(--shadow-strong);
  padding: 1.5rem 2rem;
}
.modal-panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: -1.5rem;
  background: var(--surface);
  padding: 0.25rem 0;
}
.modal-panel-header h1, .modal-panel-header h2 { margin: 0; }
/* .hint's own -0.4rem top margin (see its rule above) is tuned for sitting
   right under a form control, not under this sticky, opaque header -- left
   as-is, that negative margin pulled a hint immediately following a header
   up underneath the header's own box, clipping the top of its text (every
   modal with a hint right after its header had this, not just one --
   confirmed against tab.html's Sound Sources modal and this page's own
   delete-sound-file-modal, not something new). This cancels just that
   overlap back out to a normal, non-negative gap. */
.modal-panel-header + .hint { margin-top: 0.4rem; }

/* Hidden for non-admins; public/auth.js sets body.is-admin. Server routes enforce the same rule. */
body:not(.is-admin) .admin-only { display: none !important; }
