:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #14181d;
  --panel-2: #1a2027;
  --line: #28313b;
  --text: #edf2f7;
  --muted: #98a5b3;
  --accent: #3fb984;
  --accent-2: #e0b048;
  --danger: #e45d5d;
  --focus: #81c8ff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button, input, textarea, select {
  font: inherit;
}

button {
  border: 1px solid #3a4652;
  background: #222a33;
  color: var(--text);
  border-radius: 6px;
  padding: 8px 11px;
  cursor: pointer;
}

button:hover { border-color: var(--focus); }
button.active, button.primary { background: var(--accent); border-color: var(--accent); color: #06100b; }
button.ghost { background: transparent; color: var(--muted); }
button.danger { border-color: #6a3333; color: #ffd1d1; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

input, textarea, select {
  border: 1px solid var(--line);
  background: #0f1318;
  color: var(--text);
  border-radius: 6px;
  padding: 9px 10px;
  min-width: 0;
}

textarea { resize: vertical; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #101419;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.mark {
  width: 42px;
  height: 42px;
  border: 1px solid #4b5a67;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #1d252e;
  color: var(--accent);
  font-weight: 800;
}

h1, h2, p { margin: 0; }
h1 { font-size: 21px; }
h2 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0; }
.brand p, small, .hint { color: var(--muted); }

.search-box {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  min-height: 130px;
  overflow: hidden;
}

.library-panel { flex: 1; min-height: 260px; }

.panel-head {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.result-list, .song-list {
  padding: 8px;
  overflow: auto;
  max-height: 36vh;
}

.song-list { max-height: calc(100vh - 430px); }
.muted-list { color: var(--muted); font-size: 14px; }

.result-item, .song-item {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.result-item + .result-item, .song-item + .song-item { margin-top: 6px; }
.result-item:hover, .song-item:hover, .song-item.active { border-color: var(--line); background: var(--panel-2); }
.result-item strong, .song-item strong { display: block; font-size: 14px; }
.result-item span, .song-item span { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.row-actions { display: flex; gap: 6px; }
.row-actions button { padding: 6px 8px; font-size: 12px; }

.workspace {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
}

.title-input {
  width: 100%;
  font-size: 25px;
  font-weight: 760;
  padding: 11px 12px;
}

.meta-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1.3fr;
  gap: 8px;
  margin-top: 8px;
}

.meta-row label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.player-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1.5fr) minmax(300px, 0.9fr);
  gap: 16px;
}

.video-card, .practice-card, .tab-section {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}

.video-card { overflow: hidden; }
#player {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #030405;
}

.transport {
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--line);
}

.transport label, .stats-grid label {
  color: var(--muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.transport input { width: 78px; }

.practice-card {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.practice-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#timeReadout {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  color: var(--accent-2);
}

.loop-grid {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 8px;
}

.loop-grid input {
  grid-column: span 2;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.stats-grid {
  display: grid;
  grid-template-columns: 88px 118px 1fr;
  gap: 8px;
}

.stats-grid input { width: 100%; }
#notesInput { min-height: 132px; line-height: 1.35; }

.tab-section {
  min-height: 360px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tab-toolbar {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.tab-toolbar > div:first-child {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab-viewer {
  flex: 1;
  overflow: auto;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  line-height: 1.5;
}

.tab-line {
  min-height: 23px;
  white-space: pre;
  border-radius: 4px;
  padding: 1px 8px;
  display: grid;
  grid-template-columns: 66px 1fr;
  gap: 8px;
  cursor: pointer;
}

.tab-line:hover { background: #202730; }
.tab-line.selected { outline: 1px solid var(--focus); background: #152331; }
.tab-line.current { background: #243c32; color: #ffffff; }
.stamp { color: var(--accent-2); user-select: none; }

.tab-editor {
  flex: 1;
  display: none;
  min-height: 440px;
  border: 0;
  border-radius: 0;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  line-height: 1.5;
}

body.editing .tab-viewer { display: none; }
body.editing .tab-editor { display: block; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgb(0 0 0 / 0.68);
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal.hidden { display: none; }

.modal-panel {
  width: min(860px, 100%);
  max-height: calc(100vh - 36px);
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  border-bottom: 1px solid var(--line);
  padding: 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.modal-head p {
  color: var(--muted);
  font-size: 14px;
  margin-top: 4px;
}

#pasteTabInput {
  min-height: 420px;
  border: 0;
  border-radius: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.45;
}

.modal-actions {
  padding: 12px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .song-list, .result-list { max-height: 260px; }
  .player-grid, .topbar, .meta-row { grid-template-columns: 1fr; }
  .actions { justify-content: stretch; }
  .actions button { flex: 1; }
}
