:root {
  --bg: #17140f;
  --surface: #221e17;
  --surface-2: #2d281f;
  --line: #3a3428;
  --text: #f3ece0;
  --muted: #a99f8d;
  --accent: #e9a84c;
  --accent-ink: #1b1508;
  --loop: #7cc2a4;
  --danger: #e07a6a;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

button { font: inherit; color: inherit; }

[hidden] { display: none !important; }

/* Header */
.top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.top h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  background: none;
  border: 0;
  font-size: 32px;
  line-height: 1;
  padding: 0 8px 4px 0;
  cursor: pointer;
}

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Library */
#libraryView { padding: 16px; overflow-y: auto; }

.add { display: flex; gap: 8px; }
.add input {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
}
.add input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.hint { color: var(--muted); font-size: 14px; margin: 20px 4px; }

.songs { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 10px; }
.song {
  display: grid;
  grid-template-columns: 96px 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  cursor: pointer;
}
.song.active { border-color: var(--accent); }
.song img { width: 96px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; display: block; background: var(--surface-2); }
.song .info { min-width: 0; }
.song .name { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.song .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.song .badge { color: var(--accent); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.song .actions { display: flex; flex-direction: column; gap: 4px; }
.song .actions button {
  background: none; border: 0; padding: 6px 8px; font-size: 20px; cursor: pointer; color: var(--muted);
}
.song .actions .star.on { color: var(--accent); }

/* Practice */
.player-wrap { flex: none; background: #000; }
.player-wrap > div, .player-wrap iframe { display: block; width: 100%; aspect-ratio: 16 / 9; height: auto; border: 0; }

.sections {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 8px 12px;
}
.section {
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 10px;
  padding: 4px 4px 4px 12px;
  margin-bottom: 4px;
  border: 1px solid transparent;
  cursor: pointer;
}
.section.playing { background: var(--surface); }
.section.selected { border-color: var(--loop); background: var(--surface-2); }
.section .label { flex: 1; min-width: 0; padding: 8px 0; }
.section .sname { font-weight: 600; }
.section .range { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.section .mini {
  background: none; border: 0; color: var(--muted); font-size: 18px; padding: 10px; cursor: pointer;
}
.nudge {
  display: flex; align-items: center; gap: 6px; padding: 0 0 8px 12px; color: var(--muted); font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.nudge button {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer;
}

.controls {
  flex: none;
  border-top: 1px solid var(--line);
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  display: grid;
  gap: 8px;
  background: var(--bg);
}
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

.btn {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 6px;
  min-height: 48px;
  cursor: pointer;
  font-weight: 600;
  user-select: none;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn.big { min-height: 60px; font-size: 18px; flex: 1.4; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.toggle[aria-pressed="true"] { background: var(--loop); color: #0d1f17; border-color: var(--loop); }
.btn.mark { flex: 2.5; border-style: dashed; }

.add .btn { padding: 0 18px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 200px);
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  max-width: calc(100vw - 32px);
  text-align: center;
  z-index: 10;
}

/* Landscape phones: player on the left, everything else on the right */
@media (orientation: landscape) and (max-height: 520px) {
  .practice { display: grid; grid-template-columns: 55% 45%; grid-template-rows: 1fr auto; }
  .player-wrap { grid-row: 1 / 3; display: flex; align-items: center; }
  .player-wrap > div, .player-wrap iframe { width: 100%; }
  .sections { grid-column: 2; }
  .controls { grid-column: 2; }
  .btn { min-height: 40px; padding: 8px 4px; }
  .btn.big { min-height: 44px; }
}
