/* ---------- Base / theme ---------- */
:root {
  /* Dark theme (default) */
  --bg: #111215;
  --bg-elev: #23262c;        /* lighter button background */
  --bg-elev-2: #2d3037;
  --bg-elev-3: #383c44;
  --fg: #f2f3f5;
  --fg-dim: #b4b8bf;
  --fg-mute: #6d727b;
  /* Brighter, warmer amber */
  --accent: #ffb84a;
  --accent-strong: #ffcf6b;
  --accent-soft: #d99434;
  /* Signature gradient used for primary actions / progress */
  --accent-gradient: linear-gradient(135deg, #ffd275 0%, #ffb23c 50%, #f09122 100%);
  --accent-gradient-soft: linear-gradient(135deg, rgba(255,210,117,0.18) 0%, rgba(240,145,34,0.14) 100%);
  --track: #32353c;
  --radius: 14px;
  --radius-lg: 22px;
  --tap-highlight: rgba(255, 184, 74, 0.2);
  /* Theme-aware tokens */
  --border: rgba(255,255,255,0.06);
  --border-strong: rgba(255,255,255,0.10);
  --border-dashed: rgba(255,255,255,0.08);
  --inner-glow: rgba(255,255,255,0.04);
  --inner-glow-strong: rgba(255,255,255,0.06);
  --section-bg: rgba(241, 228, 191, 0.04);
  --legend-bg: rgba(241, 228, 191, 0.10);
  --shadow-sm: 0 3px 10px rgba(0,0,0,0.22);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.35);
  --shadow-sheet: 0 -10px 30px rgba(0,0,0,0.45);
  --shell-tint-1: rgba(255,184,74,0.08);
  --shell-tint-2: rgba(255,184,74,0.05);
  --scrim: rgba(0,0,0,0.55);
  /* Top bar — slightly darker than --bg */
  --bar-bg: #0b0c0f;
  --bar-border: rgba(0,0,0,0.5);
}

[data-theme="light"] {
  --bg: #f6f3ec;
  --bg-elev: #ffffff;
  --bg-elev-2: #f0ede3;
  --bg-elev-3: #e4e0d2;
  --fg: #1a1a1d;
  --fg-dim: #4a4d54;
  --fg-mute: #7c8089;
  --track: #d8d4c8;
  --border: rgba(0,0,0,0.08);
  --border-strong: rgba(0,0,0,0.14);
  --border-dashed: rgba(0,0,0,0.14);
  --inner-glow: rgba(255,255,255,0.6);
  --inner-glow-strong: rgba(255,255,255,0.8);
  --section-bg: rgba(241, 228, 191, 0.45);
  --legend-bg: rgba(241, 228, 191, 0.55);
  --shadow-sm: 0 2px 8px rgba(74, 50, 10, 0.06);
  --shadow-md: 0 6px 20px rgba(74, 50, 10, 0.12);
  --shadow-sheet: 0 -10px 30px rgba(74, 50, 10, 0.18);
  --shell-tint-1: rgba(255,184,74,0.18);
  --shell-tint-2: rgba(255,184,74,0.10);
  --scrim: rgba(40, 30, 12, 0.45);
  --bar-bg: #ece8db;
  --bar-border: rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 700px at 80% -200px, var(--shell-tint-1), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, var(--shell-tint-2), transparent 60%),
    var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  transition: background-color 240ms ease, color 240ms ease;
}

button {
  font-family: inherit;
  color: inherit;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 32px;
}

/* ---------- Header ---------- */
.app-header {
  width: 100%;
  background: var(--bar-bg);
  border-bottom: 1px solid var(--bar-border);
  margin-bottom: 16px;
}
.app-header-inner {
  display: grid;
  grid-template-columns: 44px 1fr 44px 44px 44px;
  align-items: center;
  gap: 4px;
  padding: 10px 20px;
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
}
.app-header.is-hidden { display: none; }
.app-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.2px;
  text-align: center;
  color: var(--fg);
}
.nav-btn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-dim);
  border-radius: 12px;
  transition: background 140ms ease, color 140ms ease, transform 140ms ease;
}
.nav-btn:hover { background: var(--bg-elev); color: var(--fg); }
.nav-btn:active { transform: scale(0.96); }
.nav-btn.active { color: var(--accent); }

/* Theme toggle: show moon in dark, sun in light */
.theme-toggle .theme-icon-sun { display: none; }
.theme-toggle .theme-icon-moon { display: block; }
[data-theme="light"] .theme-toggle .theme-icon-sun { display: block; }
[data-theme="light"] .theme-toggle .theme-icon-moon { display: none; }

#view-root {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
}

/* ---------- Home ---------- */
.home { padding: 8px 4px 0; width: 100%; }

/* Brand block on home */
.brand {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 18px 0 24px;
}
.brand-mark {
  width: 52px;
  height: 52px;
  display: block;
  flex: 0 0 auto;
  margin-right: 4px;
  transform: translateY(2px);
  filter: drop-shadow(0 6px 18px rgba(255,184,74,0.32));
}
.brand-mark-f {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 34px;
  font-weight: 700;
  fill: #1a1408;
  letter-spacing: -0.5px;
}
.brand-name {
  margin: 0;
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.8px;
  color: var(--fg);
  line-height: 1;
}
@media (min-width: 640px) {
  .brand-mark { width: 60px; height: 60px; }
  .brand-name { font-size: 46px; }
}
.section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--fg-mute);
  margin: 10px 4px 16px;
}
.tile-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (min-width: 640px) { .tile-grid { grid-template-columns: repeat(3, 1fr); gap: 16px; } }
@media (min-width: 900px) { .tile-grid { grid-template-columns: repeat(4, 1fr); gap: 18px; } }

.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  background:
    linear-gradient(160deg, var(--inner-glow), transparent 55%),
    var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--fg);
  box-shadow: var(--shadow-sm);
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}
.tile:hover:not(:disabled) {
  background:
    linear-gradient(160deg, var(--inner-glow-strong), transparent 55%),
    var(--bg-elev-2);
  border-color: rgba(255,184,74,0.35);
  box-shadow: var(--shadow-md);
}
.tile:active:not(:disabled) { transform: scale(0.98); }
.tile:disabled { opacity: 0.55; cursor: not-allowed; }
.tile-icon {
  font-size: 42px;
  line-height: 1;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 6px rgba(255,184,74,0.25));
}
.tile-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--fg);
}
.tile-soon {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 10px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--fg-mute);
  background: var(--bg-elev-3);
  padding: 3px 7px;
  border-radius: 6px;
}

/* ---------- Metronome ---------- */
.metronome {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 8px;
  gap: 18px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

/* Subdivision selector */
.subdivisions {
  display: flex;
  gap: 10px;
  width: 100%;
  padding: 0 2px;
}
.sub-btn {
  flex: 1;
  height: 60px;
  background:
    linear-gradient(160deg, var(--inner-glow), transparent 55%),
    var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease, transform 140ms ease;
}
.sub-btn:hover { background: var(--bg-elev-2); color: var(--fg); }
.sub-btn:active { transform: scale(0.97); }
.sub-btn.active {
  background:
    linear-gradient(160deg, rgba(255,210,117,0.12), rgba(255,184,74,0.05) 60%),
    var(--bg-elev-2);
  color: var(--accent);
  border-color: rgba(255,210,117,0.45);
  box-shadow: inset 0 0 0 1px rgba(255,184,74,0.15), 0 4px 18px rgba(255,184,74,0.12);
}
.sub-btn svg { display: block; }

/* Tempo row */
.tempo-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 4px 14px;
  max-width: 480px;
}
.tempo-step {
  width: 52px;
  height: 52px;
  font-size: 36px;
  line-height: 1;
  color: var(--fg-dim);
  font-weight: 300;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 140ms ease, color 140ms ease, transform 140ms ease;
}
.tempo-step:hover { background: var(--bg-elev); color: var(--fg); }
.tempo-step:active { background: var(--tap-highlight); color: var(--accent); transform: scale(0.95); }
.tempo-display { text-align: center; }
.tempo-display #bpm-value {
  font-size: 48px;
  font-weight: 500;
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* Dial + play */
.dial-wrap {
  position: relative;
  width: 100%;
  max-width: 420px;
  margin-top: 4px;
  display: flex;
  justify-content: center;
}
#dial {
  width: 100%;
  height: auto;
  display: block;
  touch-action: none;
  pointer-events: none;
}
#dial-track,
#dial-hit,
#dial-handle {
  pointer-events: auto;
}
#dial-track {
  fill: none;
  stroke: var(--track);
  stroke-width: 6;
  stroke-linecap: round;
}
#dial-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 32;
  stroke-linecap: round;
  cursor: pointer;
}
#dial-progress {
  fill: none;
  stroke: url(#dialGradient);
  stroke-width: 7;
  stroke-linecap: round;
  pointer-events: none;
  filter: drop-shadow(0 0 6px rgba(255,184,74,0.35));
}
#dial-handle {
  fill: url(#dialGradient);
  stroke: var(--bg);
  stroke-width: 2;
  cursor: grab;
  transition: r 140ms ease;
  filter: drop-shadow(0 2px 8px rgba(255,184,74,0.55));
}
#dial-handle:active { cursor: grabbing; r: 14; }
.dial-label {
  fill: var(--fg-dim);
  font-size: 12px;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}

.play-btn {
  position: absolute;
  left: 50%;
  top: 62%;
  z-index: 2;
  transform: translate(-50%, -50%);
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: #1a1408;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 12px 28px rgba(255,184,74,0.32),
    0 2px 6px rgba(0,0,0,0.35),
    inset 0 -3px 0 rgba(0,0,0,0.15),
    inset 0 2px 0 rgba(255,255,255,0.35);
  transition: transform 140ms ease, filter 140ms ease;
}
.play-btn:hover { filter: brightness(1.07); }
.play-btn:active { transform: translate(-50%, -50%) scale(0.96); }

/* Beat bars — one per beat, 3 volume levels */
.beat-bars {
  display: flex;
  gap: 10px;
  width: 100%;
  justify-content: center;
  align-items: flex-end;
  flex-wrap: wrap;
  padding: 2px 0;
}
.beat {
  position: relative;
  min-width: 42px;
  flex: 0 1 56px;
  height: 66px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding: 8px 6px;
  background:
    linear-gradient(160deg, var(--inner-glow), transparent 55%),
    var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: transform 100ms ease, background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}
.beat:hover { background: var(--bg-elev-2); }
.beat:active { transform: scale(0.96); }
.beat .seg {
  display: block;
  width: 60%;
  border-radius: 3px;
  background: var(--fg-mute);
  opacity: 0.25;
  transition: background 140ms ease, opacity 140ms ease;
}
.beat .s1 { height: 10px; }
.beat .s2 { height: 14px; }
.beat .s3 { height: 18px; }
/* Level 1 — only bottom seg lit (soft) */
.beat[data-level="1"] .s1 { opacity: 1; background: var(--accent-soft); }
/* Level 2 — bottom + middle lit (medium) */
.beat[data-level="2"] .s1,
.beat[data-level="2"] .s2 { opacity: 1; background: var(--accent); }
/* Level 3 — all three lit (accent / downbeat) */
.beat[data-level="3"] .s1,
.beat[data-level="3"] .s2,
.beat[data-level="3"] .s3 { opacity: 1; background: var(--accent-strong); }
.beat[data-level="3"] {
  box-shadow: inset 0 0 0 1px rgba(255,210,117,0.25);
}

.beat.playing {
  border-color: rgba(255,210,117,0.6);
  background:
    linear-gradient(160deg, rgba(255,210,117,0.14), rgba(255,184,74,0.04) 60%),
    var(--bg-elev-2);
  box-shadow: 0 0 16px rgba(255,184,74,0.35), inset 0 0 0 1px rgba(255,210,117,0.4);
}
.beat.playing .seg { filter: brightness(1.15); }

/* Bottom row */
.bottom-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: 100%;
  padding: 4px 10px 0;
}
.bottom-btn {
  color: var(--fg-dim);
  font-size: 15px;
  font-weight: 500;
  padding: 10px 8px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 10px;
  transition: color 140ms ease, background 140ms ease;
}
.bottom-btn:hover { color: var(--fg); background: var(--bg-elev); }
#ts-btn { justify-self: start; }
#tap-btn { justify-self: end; }
.ts-note { color: var(--fg-dim); font-size: 17px; }

/* ---------- TS picker popover ---------- */
.ts-popover {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}
.ts-sheet {
  width: 100%;
  max-width: 520px;
  background: var(--bg-elev);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  padding: 20px 20px 30px;
  box-shadow: var(--shadow-sheet);
}
.ts-sheet h3 {
  margin: 0 0 14px;
  font-size: 12px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--fg-mute);
  font-weight: 700;
}
.ts-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ts-option {
  background: var(--bg-elev-2);
  border-radius: 12px;
  padding: 14px 0;
  font-size: 17px;
  font-weight: 500;
  color: var(--fg);
  transition: background 140ms ease, color 140ms ease, transform 140ms ease;
}
.ts-option:hover { background: var(--bg-elev-3); }
.ts-option:active { transform: scale(0.97); }
.ts-option.active {
  background: var(--accent-gradient);
  color: #1a1408;
}

/* ---------- Preset tempos strip ---------- */
.preset-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  width: 100%;
  padding: 4px 2px 2px;
  scrollbar-width: none;
  flex-wrap: nowrap;
}
.preset-strip::-webkit-scrollbar { display: none; }
@media (min-width: 640px) {
  .preset-strip { flex-wrap: wrap; justify-content: center; overflow: visible; }
}
.preset-chip {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--fg-dim);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border);
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease, transform 140ms ease;
}
.preset-chip:hover { background: var(--bg-elev-2); color: var(--fg); }
.preset-chip:active { transform: scale(0.96); }
.preset-chip.active {
  background: var(--accent-gradient);
  color: #1a1408;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(255,184,74,0.3);
}

/* ---------- Journal ---------- */
.journal {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 16px;
  width: 100%;
  min-height: calc(100vh - 140px);
  align-items: stretch;
}

/* Sidebar */
.journal-sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.journal-new-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  background: var(--accent-gradient);
  color: #1a1408;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.2px;
  box-shadow: 0 4px 14px rgba(255,184,74,0.28);
  transition: transform 140ms ease, filter 140ms ease;
}
.journal-new-btn:hover { filter: brightness(1.05); }
.journal-new-btn:active { transform: scale(0.98); }
.journal-new-icon {
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}
.journal-page-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  max-height: calc(100vh - 220px);
  scrollbar-width: thin;
}
.journal-page-empty {
  list-style: none;
  padding: 16px 12px;
  color: var(--fg-mute);
  font-size: 13px;
  text-align: center;
  background: var(--bg-elev);
  border: 1px dashed var(--border-dashed);
  border-radius: 10px;
}
.journal-page-item {
  position: relative;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px 10px 16px;
  border-radius: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 100ms ease;
  outline: none;
  min-width: 0;
}
.journal-page-item:hover { background: var(--bg-elev-2); }
.journal-page-item:active { transform: scale(0.99); }
.journal-page-item:focus-visible {
  border-color: rgba(255,184,74,0.55);
  box-shadow: 0 0 0 2px rgba(255,184,74,0.18);
}
.journal-page-item.is-active {
  background: #5a606b;
  border-color: rgba(255,210,117,0.55);
  box-shadow: inset 0 0 0 1px rgba(255,184,74,0.2);
}
[data-theme="light"] .journal-page-item.is-active {
  background: #ffffff;
}
/* Orange indicator bar on the left of the active item */
.journal-page-item.is-active::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}
.journal-page-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.journal-page-item.is-active .journal-page-title {
  color: var(--fg);
  font-weight: 700;
}
.journal-page-date {
  font-size: 11px;
  color: var(--fg-mute);
  font-variant-numeric: tabular-nums;
}

/* Editor */
.journal-editor {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
.journal-empty[hidden],
.journal-pane[hidden] { display: none; }
.journal-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  color: var(--fg-mute);
  font-size: 14px;
  line-height: 1.6;
  padding: 40px 20px;
}
.journal-empty-icon {
  width: 96px;
  height: 96px;
  color: var(--fg-mute);
  opacity: 0.6;
}
.journal-empty-link {
  background: transparent;
  border: none;
  padding: 4px 6px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  border-radius: 6px;
  transition: color 140ms ease, background 140ms ease;
}
.journal-empty-link:hover { color: var(--accent-strong); background: rgba(255,184,74,0.08); }
.journal-empty-link:active { transform: scale(0.98); }
.journal-empty-link:focus-visible {
  outline: 2px solid rgba(255,184,74,0.6);
  outline-offset: 2px;
}
.journal-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.journal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.journal-back {
  display: none;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--fg-dim);
  transition: background 140ms ease, color 140ms ease;
}
.journal-back:hover { background: var(--bg-elev-2); color: var(--fg); }
.journal-title {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  background: transparent;
  border: none;
  outline: none;
  font: inherit;
  color: var(--fg);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.2px;
  padding: 6px 4px;
  border-radius: 6px;
  min-width: 0;
}
.journal-title::placeholder { color: var(--fg-mute); }
.journal-title:focus { background: var(--bg-elev-2); }
.journal-date {
  width: 140px;
  flex: 0 0 auto;
  margin-left: auto;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  outline: none;
  color: var(--fg-dim);
  font: inherit;
  font-size: 12px;
  padding: 6px 6px;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
  color-scheme: light dark;
}
.journal-date:focus { border-color: rgba(255,184,74,0.45); color: var(--fg); }
.journal-delete {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--fg-mute);
  transition: background 140ms ease, color 140ms ease;
}
.journal-delete:hover { background: rgba(255,90,90,0.12); color: #ff8080; }

/* Toolbar */
.journal-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--section-bg);
}
.journal-toolbar button {
  min-width: 34px;
  height: 32px;
  padding: 0 8px;
  border-radius: 8px;
  color: var(--fg-dim);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 140ms ease, color 140ms ease, transform 100ms ease;
}
.journal-toolbar button:hover { background: var(--bg-elev-2); color: var(--fg); }
.journal-toolbar button:active { transform: scale(0.96); }
.journal-toolbar button.is-active {
  background: var(--accent-gradient-soft);
  color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px rgba(255,210,117,0.35);
}
.journal-toolbar .t-h { font-size: 12px; letter-spacing: 0.4px; }
.journal-toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
  align-self: center;
}

/* Editable body */
.journal-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px 32px;
  outline: none;
  color: var(--fg);
  font-size: 15px;
  line-height: 1.65;
  background: var(--bg-elev);
  min-height: 280px;
  caret-color: var(--accent);
}
.journal-body:empty::before {
  content: attr(data-placeholder);
  color: var(--fg-mute);
  pointer-events: none;
}
.journal-body:focus { outline: none; }
.journal-body h1 { font-size: 26px; margin: 18px 0 8px; line-height: 1.25; font-weight: 700; }
.journal-body h2 { font-size: 21px; margin: 16px 0 6px; line-height: 1.3; font-weight: 700; }
.journal-body h3 { font-size: 17px; margin: 14px 0 4px; line-height: 1.35; font-weight: 600; }
.journal-body p { margin: 6px 0; }
.journal-body ul, .journal-body ol { margin: 6px 0; padding-left: 24px; }
.journal-body li { margin: 2px 0; }
.journal-body b, .journal-body strong { font-weight: 700; }
.journal-body i, .journal-body em { font-style: italic; }
.journal-body a { color: var(--accent); text-decoration: underline; }

/* ---------- Login screen ---------- */
.login {
  min-height: calc(100vh - 40px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 36px 28px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.login-brand {
  margin-bottom: 18px;
}
.login-title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 600;
  color: var(--fg);
}
.login-sub {
  margin: 0 0 20px;
  color: var(--fg-dim);
  font-size: 14px;
  line-height: 1.4;
}
.login-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login-form input[type="email"] {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 15px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--fg);
  outline: none;
  transition: border-color 140ms ease, background 140ms ease;
}
.login-form input[type="email"]:focus {
  border-color: rgba(255,184,74,0.55);
  background: var(--bg-elev-3);
}
.login-form input[type="email"]::placeholder { color: var(--fg-mute); }
.login-form button {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  background: var(--accent-gradient);
  color: #1a1408;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 100ms ease, opacity 140ms ease;
}
.login-form button:hover { opacity: 0.95; }
.login-form button:active { transform: scale(0.99); }
.login-form button:disabled { opacity: 0.6; cursor: default; }
.login-form.is-sent input[type="email"],
.login-form.is-sent button { display: none; }
.login-message {
  margin: 16px 0 0;
  padding: 12px 14px;
  background: var(--section-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--fg);
  font-size: 14px;
  line-height: 1.45;
  width: 100%;
}
.login-message.is-error {
  background: rgba(255,90,90,0.10);
  border-color: rgba(255,90,90,0.35);
  color: #ffb0b0;
}
[data-theme="light"] .login-message.is-error { color: #b03030; }

/* ---------- Avatar (header + settings) ---------- */
.avatar-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #444;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.2px;
  user-select: none;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.12);
}
.nav-avatar {
  padding: 0;
}
.nav-avatar:hover { background: var(--bg-elev); }
.nav-avatar .avatar-circle {
  width: 30px;
  height: 30px;
  font-size: 13px;
}
.nav-avatar.active .avatar-circle {
  box-shadow: 0 0 0 2px var(--accent);
}

/* ---------- Settings page ---------- */
.settings {
  display: flex;
  justify-content: center;
  padding: 20px 16px 40px;
}
.settings-card {
  width: 100%;
  max-width: 560px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: var(--shadow-md);
}
.settings-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
}
.settings-avatar {
  width: 64px;
  height: 64px;
  font-size: 26px;
  flex: 0 0 auto;
}
.settings-headings { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.settings-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--fg);
}
.settings-sub {
  margin: 0;
  color: var(--fg-dim);
  font-size: 14px;
  line-height: 1.4;
}
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.settings-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.settings-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--fg-dim);
}
.settings-form input {
  width: 100%;
  padding: 11px 13px;
  font: inherit;
  font-size: 15px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--fg);
  outline: none;
  transition: border-color 140ms ease, background 140ms ease;
}
.settings-form input:focus {
  border-color: rgba(255,184,74,0.55);
  background: var(--bg-elev-3);
}
.settings-form input[readonly] {
  color: var(--fg-dim);
  cursor: default;
}
.settings-form input::placeholder { color: var(--fg-mute); }
.settings-hint {
  font-size: 12px;
  color: var(--fg-mute);
  line-height: 1.4;
}
.avatar-upload-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.avatar-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}
.avatar-btn:hover { background: var(--bg-elev-3); border-color: rgba(255,184,74,0.45); }
.avatar-btn:disabled { opacity: 0.6; cursor: default; }
.avatar-btn-ghost {
  background: transparent;
  color: var(--fg-dim);
}
.avatar-btn-ghost:hover {
  background: rgba(255,90,90,0.10);
  border-color: rgba(255,90,90,0.45);
  color: #ff8080;
}
[data-theme="light"] .avatar-btn-ghost:hover { color: #b03030; }

.settings-status {
  margin: 0;
  padding: 10px 12px;
  background: var(--section-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--fg-dim);
  font-size: 13px;
}
.settings-status.is-error {
  background: rgba(255,90,90,0.10);
  border-color: rgba(255,90,90,0.35);
  color: #ffb0b0;
}
[data-theme="light"] .settings-status.is-error { color: #b03030; }
.settings-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.settings-signout {
  padding: 10px 18px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}
.settings-signout:hover {
  background: rgba(255,90,90,0.10);
  border-color: rgba(255,90,90,0.45);
  color: #ff8080;
}
[data-theme="light"] .settings-signout:hover { color: #b03030; }
.settings-signout:disabled { opacity: 0.6; cursor: default; }

/* Mobile: single-pane (sidebar OR editor at a time) */
@media (max-width: 720px) {
  .journal {
    grid-template-columns: 1fr;
    min-height: calc(100vh - 120px);
  }
  .journal-page-list { max-height: none; }
  .journal[data-mode="editor"] .journal-sidebar { display: none; }
  .journal[data-mode="list"] .journal-editor { display: none; }
  .journal-back { display: inline-flex; }
}

/* ---------- Fretboard view (Scales / Triads / Chords) ---------- */
.fbview {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 8px;
}

/* Section wrappers visually separate Key from Quality */
.fb-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  background: var(--section-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.fb-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--fg-mute);
}
.fb-section-quality .quality-strip { width: 100%; }

.quality-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 0 0;
  width: 100%;
}
.quality-chip {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--fg-dim);
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}
.quality-chip:hover { background: var(--bg-elev-2); color: var(--fg); }
.quality-chip:active { transform: scale(0.97); }
.quality-chip.active {
  background: var(--accent-gradient);
  color: #1a1408;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(255,184,74,0.3);
}

.key-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.key-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--fg-mute);
}
.key-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.key-chip {
  width: 42px;
  height: 38px;
  border-radius: 10px;
  background: var(--bg-elev);
  color: var(--fg-dim);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}
.key-chip:hover { background: var(--bg-elev-2); color: var(--fg); }
.key-chip:active { transform: scale(0.96); }
.key-chip.active {
  background: var(--accent-gradient);
  color: #1a1408;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(255,184,74,0.3);
}

.fb-titlebar {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  padding: 4px 2px 2px;
}
.fb-subtitle {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--fg);
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.fb-hint {
  font-size: 12px;
  letter-spacing: 0.4px;
  color: var(--fg-mute);
}

.fretboard-wrap {
  width: 100%;
  overflow-x: auto;
  padding: 4px 0 6px;
  scrollbar-width: thin;
}
.fb-group-title {
  margin: 14px 0 4px;
  padding: 0 2px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--fg-mute);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}
.fretboard-wrap.is-triads .fb-group-title:first-child {
  margin-top: 0;
}
.fretboard-svg {
  width: 100%;
  min-width: 680px;
  height: auto;
  display: block;
}

.fb-label-str,
.fb-label-fret,
.fb-note-text {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
.fb-label-str { font-size: 12px; font-weight: 600; fill: var(--fg-mute); }
.fb-label-fret { font-size: 11px; font-weight: 500; fill: var(--fg-dim); }
.fb-note-text { font-size: 11px; font-weight: 700; pointer-events: none; }

.fb-legend {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  padding: 10px 14px;
  flex-wrap: wrap;
  background: var(--legend-bg);
  border-radius: 10px;
  color: var(--fg-dim);
  margin-top: 8px;
}
.fb-legend .legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #3a362f;
  border: 1px solid #121009;
  display: inline-block;
}
.fb-legend .legend-dot.root {
  background: var(--accent-gradient);
  border-color: rgba(122,74,16,0.6);
}
.fb-legend .legend-tip {
  margin-left: auto;
  color: var(--fg-mute);
  font-size: 11px;
  letter-spacing: 0.3px;
}

/* ---------- Chord grid (chords view) ---------- */
.fretboard-wrap.is-chords {
  overflow-x: visible;
  padding: 8px 2px 4px;
}
.chord-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  width: 100%;
}
.chord-section-title {
  grid-column: 1 / -1;
  margin: 14px 0 0;
  padding: 0 2px 2px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--fg-mute);
  border-bottom: 1px solid var(--border);
}
.chord-section-title:first-child { margin-top: 0; }
.chord-card {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px 4px 10px;
  color: var(--fg);
  transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chord-card.highlighted {
  border-color: rgba(255,184,74,0.45);
  background: linear-gradient(180deg, rgba(255,184,74,0.09) 0%, rgba(240,145,34,0.03) 100%);
  box-shadow: 0 6px 16px rgba(255,184,74,0.14);
}
.chord-diagram {
  width: 100%;
  height: auto;
  display: block;
}
.chord-name {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 11px;
  font-weight: 700;
  fill: var(--fg-mute);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.chord-card.highlighted .chord-name { fill: #ffd275; }
.chord-fret-num {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 12px;
  font-weight: 700;
  fill: var(--fg);
  letter-spacing: 0.2px;
}
.chord-mark {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 12px;
  font-weight: 600;
}
.chord-degree {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 9.5px;
  font-weight: 700;
  pointer-events: none;
  letter-spacing: -0.2px;
}
.chord-degree.wide {
  font-size: 8.5px;
  letter-spacing: -0.5px;
}
.chord-empty {
  padding: 24px 18px;
  border-radius: 14px;
  background: var(--bg-elev);
  color: var(--fg-mute);
  border: 1px dashed var(--border-dashed);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

/* Legend variants */
.fb-legend.is-chords .legend-dot,
.fb-legend.is-chords .legend-dot.root,
.fb-legend.is-chords .legend-dot + span {
  display: none;
}

/* ---------- Wider screens ---------- */
@media (min-width: 900px) {
  .metronome { max-width: 640px; gap: 22px; }
  .play-btn { width: 108px; height: 108px; }
  .tempo-display #bpm-value { font-size: 56px; }
  .chord-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
}
