/* ---- Theme variables ---- */
:root {
  --bg: #fafafa;
  --fg: #1a1a1a;
  --muted: #666666;
  --bar-bg: #ffffff;
  --border: #dddddd;
  --chord: #b03060;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --btn-bg: #eeeeee;
  --btn-fg: #1a1a1a;
  --shadow: rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] {
  --bg: #121417;
  --fg: #e8e8e8;
  --muted: #9aa0a6;
  --bar-bg: #1c1f24;
  --border: #333940;
  --chord: #7fd4ff;
  --accent: #3b82f6;
  --accent-fg: #ffffff;
  --btn-bg: #2a2f36;
  --btn-fg: #e8e8e8;
  --shadow: rgba(0, 0, 0, 0.4);
}

/* ---- Base ---- */
* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
}

/* ---- Buttons ---- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--btn-fg);
  border-radius: 8px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  filter: brightness(0.92);
}

/* ---- Top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--bar-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px var(--shadow);
}

.app-title {
  font-size: 1.15rem;
  margin: 0;
  flex: 1;
}

.song-heading {
  flex: 1;
  min-width: 0;
}

.song-title-sm {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.song-meta-sm {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.transpose-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.transpose-controls .btn {
  min-width: 40px;
  min-height: 40px;
  font-size: 1.2rem;
  font-weight: 700;
}

.transpose-value {
  font-variant-numeric: tabular-nums;
}

.topbar .theme-toggle,
#settings-toggle {
  font-size: 1.1rem;
}

#settings-toggle {
  font-weight: 700;
  letter-spacing: 1px;
  padding: 0 8px;
}

/* ---- Settings panel ---- */
.settings-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 12px;
  z-index: 11;
  min-width: 220px;
  max-width: calc(100vw - 24px);
  padding: 12px;
  background: var(--bar-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 16px var(--shadow);
  display: none;
  flex-direction: column;
  gap: 14px;
}

.settings-panel.open {
  display: flex;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-label {
  font-size: 0.9rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-panel .transpose-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.settings-panel .transpose-controls .btn {
  flex: 1;
  min-width: 44px;
  min-height: 44px;
  font-size: 1.2rem;
  font-weight: 700;
}

#font-size {
  width: 100%;
  accent-color: var(--accent);
  min-height: 36px;
}

/* ---- Index / search ---- */
.index-main {
  padding: 12px;
  max-width: 720px;
  margin: 0 auto;
}

.search-form {
  margin-bottom: 12px;
}

#search-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1.05rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bar-bg);
  color: var(--fg);
}

.song-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.song-item a {
  display: block;
  padding: 16px;
  background: var(--bar-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--fg);
}

.song-item a:active {
  filter: brightness(0.95);
}

.song-item .song-title {
  display: inline;
  font-size: 1.1rem;
  font-weight: 700;
}

.song-item .song-artist {
  display: inline;
  font-size: 0.9rem;
  font-style: italic;
  color: var(--muted);
  margin-left: 6px;
}

.song-item .song-meta {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 2px;
}

.song-dir {
  display: inline-block;
  margin-right: 6px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--muted);
}

.empty {
  color: var(--muted);
  text-align: center;
  margin-top: 40px;
}

/* ---- Song body ---- */
.song-main {
  padding: 16px 12px;
  /* Room for the fixed scroll bar at the bottom. */
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  /* max-width: 760px; */
  margin: 0 auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: clamp(13px, 3.8vw, 17px);
  font-size: calc(clamp(13px, 3.8vw, 17px) * var(--song-zoom, 1));
  line-height: 1.55;
}

.line {
  /* white-space: pre-wrap; */
  overflow-wrap: anywhere;
}

.line.blank {
  height: 1.2em;
}

.chord-line {
  margin-top: 0.6em;
}

.chord {
  color: var(--chord);
  font-weight: 700;
}

/* ---- Auto-scroll control bar ---- */
.scroll-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--bar-bg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -1px 4px var(--shadow);
}

.play-btn {
  min-width: 72px;
  font-weight: 700;
}

.play-btn.playing {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.speed-label {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}

#speed {
  flex: 1;
  accent-color: var(--accent);
  min-height: 36px;
}

@media (min-width: 720px) {
  .song-main {
    font-size: calc(17px * var(--song-zoom, 1));
  }
}
