:root {
  --bg: #111317;
  --panel: #1a1d23;
  --line: #2a2f38;
  --text: #e6e8eb;
  --muted: #8a919c;
  --accent: #ffb347;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 16px 24px;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, sans-serif;
  user-select: none;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
}

.spacer { flex: 1; }
#status { color: var(--muted); }

button, .button, select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 12px;
  font: inherit;
  cursor: pointer;
}
button:disabled { opacity: 0.4; cursor: default; }
#tracks { max-width: 280px; text-overflow: ellipsis; }
.zoom input { width: 140px; }
#link-dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 18px 20px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
}
#link-dialog::backdrop { background: #000a; }
#link-dialog h2 { margin: 0 0 12px; font-size: 16px; }
#link {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
}
#link:disabled { opacity: 0.5; }
#link-status { min-height: 20px; margin: 10px 0; color: var(--muted); }
#link-status.error { color: #ff8a80; }
.actions { display: flex; justify-content: flex-end; gap: 8px; }
button.primary { background: #2f6fb0; border-color: #3d82c9; }
#time { font-variant-numeric: tabular-nums; min-width: 64px; }
label { color: var(--muted); display: flex; align-items: center; gap: 6px; }

.settings { position: relative; }
#settings-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 1;
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  white-space: nowrap;
}
#settings-panel[hidden] { display: none; }

canvas { display: block; width: 100%; }
#wave { height: 180px; background: #15181d; border-radius: 6px 6px 0 0; cursor: grab; touch-action: none; }
#overview { height: 40px; background: #1a1d23; border-radius: 0 0 6px 6px; border-top: 1px solid var(--line); cursor: pointer; touch-action: none; }
/* handle under the waveform: drag it down to make the waveform taller */
#wave-resize { position: relative; height: 14px; margin-bottom: 4px; cursor: ns-resize; touch-action: none; }
#wave-resize::after {
  content: ""; position: absolute; left: 50%; top: 5px; width: 48px; height: 4px; margin-left: -24px;
  border-radius: 2px; background: var(--line); transition: background 0.15s, width 0.15s, margin-left 0.15s;
}
#wave-resize:hover::after, #wave-resize.dragging::after { background: #1e88e5; width: 72px; margin-left: -36px; }

/* Row under the waveform: marker | A | A-B loop | B, « play », speed, pitch (like AudioStretch) */
#controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 12px 28px;
  margin-bottom: 12px;
}
.segmented {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.segmented button {
  height: 34px;
  min-width: 48px;
  padding: 0 12px;
  border: none;
  border-radius: 0;
  border-left: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  touch-action: none;
}
.segmented button:first-child { border-left: none; }
.segmented button:active { background: #232831; }
#loop span { font-size: 13px; font-weight: 500; }
#loop[aria-pressed="true"] { background: #1e88e5; color: #fff; }
.transport { display: flex; align-items: center; gap: 6px; }
.transport button { background: none; border: none; color: var(--text); padding: 4px; display: flex; }
#play { width: 38px; height: 38px; justify-content: center; align-items: center; border-radius: 50%; background: var(--panel); border: 1px solid var(--line); }
/* AudioStretch-style speed / pitch pills: [− value +] */
.pill {
  display: flex;
  align-items: center;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--panel);
  overflow: hidden;
}
.pill button {
  height: 100%;
  width: 30px;
  padding: 0;
  border: none;
  border-radius: 0;
  background: none;
  color: var(--muted);
  font-size: 17px;
}
.pill button:active { background: #232831; }
.pill .value {
  min-width: 66px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  cursor: ew-resize;
  touch-action: none;
}
.pill .value.bypassed { color: var(--muted); text-decoration: line-through; }
#play .icon-pause, #play.playing .icon-play { display: none; }
#play.playing .icon-pause { display: block; }
#wave.dragging { cursor: grabbing; }
#piano { height: 120px; background: #0d0f12; border-radius: 6px; }
#piano.with-spectrum { height: 260px; }
#piano[hidden] { display: none; }

#view-toggles { display: flex; gap: 6px; }
#view-toggles button { min-width: 92px; color: var(--muted); }
#view-toggles button[aria-pressed="true"] { background: #1e88e5; border-color: #1e88e5; color: #fff; }

body.drop::after {
  content: "Drop audio file to analyze";
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: #000a; font-size: 28px;
}

/* Harmony suggestion under the piano */
#harmony[hidden] { display: none; }
#harmony {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 24px;
  margin-top: 12px;
  padding: 12px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.harmony-main { display: flex; align-items: baseline; gap: 18px; min-width: 0; }
.harmony-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }
#harmony-chord { font-size: 40px; font-weight: 700; color: var(--accent); line-height: 1.1; }
#harmony-next { color: var(--muted); }
.harmony-alt { color: var(--muted); }
#harmony-instant { color: var(--text); font-weight: 600; }

/* Loading progress bars (YouTube dialog, and the top bar when opening a file) */
.progress { height: 6px; margin-top: 12px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.progress[hidden] { display: none; }
.progress > div { height: 100%; width: 0; background: #1e88e5; border-radius: 3px; transition: width 0.25s linear; }
.progress.small { width: 120px; margin-top: 0; background: var(--panel); }

/* Page switch (player <-> metronome) */
.page-switch { display: flex; justify-content: center; margin: 20px 0 8px; }
.page-switch .button { text-decoration: none; }

/* Metronome page */
.metronome-page { min-height: 100vh; display: flex; flex-direction: column; }
.metronome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 24px 0;
}
.bpm-display { display: flex; align-items: baseline; gap: 10px; }
#bpm-value { font-size: 112px; font-weight: 700; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.bpm-unit { color: var(--muted); font-size: 18px; letter-spacing: 0.1em; }
.bpm-controls { display: flex; align-items: center; gap: 12px; width: min(560px, 100%); }
.bpm-controls .pill { flex: 1; }
#bpm-slider { flex: 1; min-width: 0; }
#tap { height: 34px; min-width: 64px; }
.beats { display: flex; gap: 14px; min-height: 22px; }
.beats span { width: 18px; height: 18px; border-radius: 50%; background: var(--panel); border: 1px solid var(--line); transition: background 0.05s; }
.beats span.on { background: #1e88e5; border-color: #1e88e5; }
.beats span.on.accent { background: var(--accent); border-color: var(--accent); }
.metronome-row { display: flex; align-items: center; gap: 28px; }
.big-play { width: 72px; height: 72px; border-radius: 50%; display: flex; align-items: center; justify-content: center; padding: 0; }
.big-play .icon-stop, .big-play.playing .icon-play { display: none; }
.big-play.playing .icon-stop { display: block; }
.metronome-hint { color: var(--muted); font-size: 12px; margin: 0; }

/* Play-along page */
.playalong { gap: 24px; }
.playalong-title { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.playalong-style { color: var(--text); font-size: 18px; }
.key-picker { display: grid; grid-template-columns: repeat(12, 1fr); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; width: min(640px, 100%); }
.key-picker button { border: none; border-left: 1px solid var(--line); border-radius: 0; padding: 8px 0; color: var(--muted); }
.key-picker button:first-child { border-left: none; }
.key-picker button[aria-pressed="true"] { background: #1e88e5; color: #fff; }
.chart { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: min(640px, 100%); }
.chart div { padding: 18px 0; text-align: center; font-size: 22px; font-weight: 600; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; transition: background 0.08s; }
.chart div.current { background: var(--accent); border-color: var(--accent); color: #111317; }
.chorus { min-height: 20px; color: var(--muted); }
.playalong .pill .value { min-width: 84px; cursor: default; }
#tempo-slider { width: 200px; }
.mixer { display: flex; gap: 24px; }
.mixer input { width: 120px; }
.page-switch { gap: 8px; }

/* Play-along: progression editing */
.prog-bar { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
#prog { max-width: 260px; }
.chart div { cursor: text; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 6px; padding-right: 6px; }
.chart div[data-n="2"] { font-size: 19px; }
.chart div[data-n="4"] { font-size: 14px; }
.chart div:hover { border-color: #3d82c9; }
.chart input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid #3d82c9;
  border-radius: 4px;
  padding: 2px 6px;
  font: inherit;
  font-size: 16px;
  text-align: center;
}
.chart div.empty::before { content: "+"; color: var(--muted); font-weight: 400; }
.chart div.empty.current::before { color: #111317; }
.chart input.invalid { border-color: #ff8a80; outline: 1px solid #ff8a80; }
#save-dialog,
#confirm-dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 18px 20px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
}
#save-dialog::backdrop,
#confirm-dialog::backdrop { background: #000a; }
#confirm-dialog p { margin: 0 0 16px; }
#save-dialog h2 { margin: 0 0 12px; font-size: 16px; }
#save-name { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font: inherit; }
#save-status { min-height: 20px; margin: 10px 0; color: #ff8a80; }
.chart div[data-n="3"] { font-size: 15px; }
.segmented-small { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.segmented-small button { border: none; border-radius: 0; color: var(--muted); }
.segmented-small button + button { border-left: 1px solid var(--line); }
.segmented-small button[aria-pressed="true"] { background: #1e88e5; color: #fff; }

/* Play-along: chord syntax cheat sheet */
.cheatsheet { width: min(640px, 100%); margin-top: -8px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.key-row { display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(640px, 100%); }
.key-row .key-picker { width: 100%; }
.transpose-row { display: flex; align-items: center; gap: 10px; }
.cheatsheet summary { padding: 8px 14px; cursor: pointer; color: var(--muted); user-select: none; }
.cheatsheet[open] summary { border-bottom: 1px solid var(--line); color: var(--text); }
.cheatsheet-body { padding: 4px 16px 14px; font-size: 13px; line-height: 1.5; color: var(--muted); }
.cheatsheet h3 { margin: 12px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.cheatsheet p, .cheatsheet ul { margin: 4px 0; }
.cheatsheet ul { padding-left: 18px; }
.cheatsheet code { color: var(--accent); font-family: ui-monospace, monospace; font-size: 12.5px; }
.cheatsheet table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.cheatsheet th { text-align: left; font-weight: 600; color: var(--text); padding: 4px 8px 4px 0; border-bottom: 1px solid var(--line); }
.cheatsheet td { padding: 3px 8px 3px 0; border-bottom: 1px solid #ffffff08; vertical-align: top; }
.cheatsheet td:first-child, .cheatsheet td:last-child { color: var(--text); white-space: nowrap; }

/* Home page */
.home { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 32px 0; }
.home-title { margin: 0; font-size: 56px; font-weight: 700; color: var(--accent); letter-spacing: -0.01em; }
.home-subtitle { margin: 0 0 28px; color: var(--muted); font-size: 14px; text-transform: uppercase; letter-spacing: 0.12em; }
.home-cards { display: grid; grid-template-columns: repeat(5, 180px); justify-content: center; gap: 16px; width: min(980px, 100%); }
@media (max-width: 1000px) { .home-cards { grid-template-columns: repeat(2, minmax(0, 200px)); gap: 14px; } }
.home-card {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  aspect-ratio: 1; padding: 24px;
  background: linear-gradient(160deg, #1d2129, var(--panel));
  border: 1px solid var(--line); border-radius: 18px;
  color: var(--text); text-decoration: none;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}
/* a soft light that follows the card on hover */
.home-card::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 35%, rgba(30, 136, 229, 0.28), transparent 65%);
  opacity: 0; transition: opacity 0.25s;
}
.home-card:hover, .home-card:focus-visible {
  border-color: #1e88e5; transform: translateY(-4px); outline: none;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(30, 136, 229, 0.35);
}
.home-card:hover::before, .home-card:focus-visible::before { opacity: 1; }
.home-card svg { position: relative; width: 64px; height: 64px; color: #1e88e5; transition: color 0.2s, transform 0.25s; }
.home-card:hover svg, .home-card:focus-visible svg { color: var(--accent); transform: scale(1.12); }
.home-card-name { position: relative; font-size: 19px; font-weight: 700; letter-spacing: 0.01em; }
@media (prefers-reduced-motion: reduce) { .home-card, .home-card svg { transition: none; } .home-card:hover { transform: none; } .home-card:hover svg { transform: none; } }

/* Pomodoro */
.pomodoro { gap: 22px; }
.ring { position: relative; width: 280px; height: 280px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--panel); stroke-width: 8; }
.ring-fill { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset 0.25s linear; }
#clock { position: absolute; inset: 0; display: grid; place-items: center; font-size: 64px; font-weight: 700; font-variant-numeric: tabular-nums; }
.round-small { width: 46px; height: 46px; border-radius: 50%; display: flex; align-items: center; justify-content: center; padding: 0; color: var(--muted); }
.timer-length { padding: 0 12px 0 0; color: var(--muted); }
.pill-unit { margin-left: 4px; font-size: 13px; }
.timer-length input[type="number"] {
  width: 46px; background: none; border: none; color: var(--text); font: inherit; text-align: center;
  -moz-appearance: textfield; appearance: textfield;
}
.timer-length input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }
.page-switch { flex-wrap: wrap; }
.page-switch .button[aria-current="page"] { background: #1e88e5; border-color: #1e88e5; color: #fff; cursor: default; }

/* Pomodoro badge on the other pages while the timer is going */
.pomodoro-badge {
  position: fixed; bottom: 16px; right: 16px; z-index: 10;
  padding: 4px 12px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--accent); color: var(--accent);
  font-size: 13px; font-variant-numeric: tabular-nums; text-decoration: none;
}
.pomodoro-badge[hidden] { display: none; }
.pomodoro-badge.done { background: var(--accent); color: #111317; }

/* Play Along: delete a bar with the × that appears on hover */
.chart div { position: relative; }
.bar-delete {
  position: absolute; top: 3px; right: 3px; display: none;
  width: 22px; height: 22px; padding: 0; border-radius: 50%;
  font-size: 15px; line-height: 1; color: var(--muted); background: var(--bg);
}
.bar-delete:hover { color: #ff8a80; border-color: #ff8a80; }
.chart div:hover .bar-delete { display: block; }
@media (hover: none) { .bar-delete { display: block; } }
.chart div.current .bar-delete { color: var(--muted); }

/* Play Along: drag a bar to move it */
.chart div { touch-action: none; }
.chart div.dragging { opacity: 0.4; cursor: grabbing; }
.chart div.drop-before { box-shadow: inset 4px 0 0 #1e88e5; }
.chart div.drop-after { box-shadow: inset -4px 0 0 #1e88e5; }

/* Tuner page */
.tuner { gap: 22px; }
.tuner-note { display: flex; align-items: baseline; min-height: 112px; }
#note { font-size: 112px; font-weight: 700; line-height: 1; color: var(--accent); transition: color 0.15s; }
#note.in-tune { color: #1e88e5; }
#note.idle { color: var(--line); }
#octave { font-size: 30px; font-weight: 600; color: var(--muted); margin-left: 4px; min-width: 20px; }
#note.idle + #octave { visibility: hidden; }
.tuner-meter { position: relative; width: min(560px, 100%); height: 56px; }
/* ticks every 10 cents from −50 to +50 */
.tuner-scale {
  position: absolute; left: 0; right: 0; top: 14px; bottom: 14px;
  background: repeating-linear-gradient(to right, var(--line) 0 2px, transparent 2px 10%);
  border-right: 2px solid var(--line);
}
.tuner-centre { position: absolute; left: 50%; top: 4px; bottom: 4px; width: 2px; margin-left: -1px; background: var(--muted); border-radius: 1px; transition: background 0.15s, box-shadow 0.15s; }
.tuner-meter.in-tune .tuner-centre { background: #1e88e5; box-shadow: 0 0 12px 2px rgba(30, 136, 229, 0.6); }
.tuner-needle { position: absolute; left: 50%; top: 0; bottom: 0; width: 4px; margin-left: -2px; border-radius: 2px; background: var(--accent); transition: left 0.12s ease-out, background 0.15s, opacity 0.3s; }
.tuner-needle.in-tune { background: #1e88e5; }
.tuner-needle.idle { left: 50% !important; opacity: 0.2; }
.tuner-readout { display: flex; gap: 18px; color: var(--muted); font-variant-numeric: tabular-nums; min-height: 20px; }
#ref-val { min-width: 96px; cursor: default; }
#mic-status:empty { display: none; }
.drone { display: flex; flex-direction: column; align-items: center; gap: 18px; width: min(640px, 100%); padding-top: 22px; border-top: 1px solid var(--line); }
.drone-label { margin: 0; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; }
#octave-val { min-width: 84px; cursor: default; }
