/* chords — guitar tabs app
   Built on shadcn_ui Flutter design tokens. */

html, body, #app { margin: 0; height: 100%; background: var(--background); color: var(--foreground);
  font-family: var(--font-sans); -webkit-font-smoothing: antialiased; }
* { box-sizing: border-box; }
::selection { background: var(--selection); color: var(--foreground); }

button { font-family: inherit; }

/* =========================================================================
   App shell  (responsive: sidebar on >= 880px, bottom tab bar on smaller)
   ========================================================================= */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  height: 100vh;        /* fallback for first paint / no-JS */
  height: 100dvh;       /* dynamic — excludes browser chrome on mobile */
  /* JS sets --app-height from visualViewport (see App()); the truest visible
     height on iOS/iPadOS, where vh is too tall and dvh is inconsistent. */
  height: var(--app-height, 100dvh);
  background: var(--background);
}
.app.no-chrome { grid-template-columns: 1fr; }
.app.no-chrome .sidebar, .app.no-chrome .bottom-nav { display: none; }

@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr 64px; }
  .app.no-chrome { grid-template-rows: 1fr; }
  .main { grid-row: 1; grid-column: 1; }
  .bottom-nav { grid-row: 2; grid-column: 1; }
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 14px 12px;
  display: flex; flex-direction: column;
  background: var(--background);
  overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 18px;
}
.brand-mark {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  display: block; flex-shrink: 0;
}
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; }
.brand-name .dim { color: var(--muted-foreground); font-weight: 400; }

.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted-foreground); font-weight: 600; padding: 14px 10px 6px; }

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--foreground); font-size: 14px; font-weight: 500;
  cursor: pointer; user-select: none;
  position: relative;
}
.nav-item:hover { background: var(--accent); }
.nav-item.active { background: var(--secondary); }
.nav-item .icon { color: var(--muted-foreground); }
.nav-item.active .icon { color: var(--foreground); }
.nav-item .count {
  margin-left: auto; font-size: 11px; font-weight: 600;
  background: var(--primary); color: var(--primary-foreground);
  border-radius: var(--radius-full); padding: 1px 7px; line-height: 1.5;
}

.sidebar-bottom {
  margin-top: auto; padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  padding: 14px 8px 4px;
}
.sb-avatar { width: 32px; height: 32px; border-radius: 9999px;
  display: grid; place-items: center; font-weight: 600; font-size: 13px;
  color: var(--primary-foreground); flex: 0 0 32px; }
.sb-user-name { font-size: 13px; font-weight: 600; }
.sb-user-handle { font-size: 12px; color: var(--muted-foreground); }

/* hide sidebar on mobile — must come AFTER .sidebar { display: flex } to win the cascade */
@media (max-width: 880px) { .sidebar { display: none; } }

/* mobile-only topbar elements (avatar + sign-out) */
.mobile-user { display: none; align-items: center; gap: 6px; }
@media (max-width: 880px) { .mobile-user { display: flex; } }

/* mobile bottom nav — hidden on desktop, shown via media query below */
.bottom-nav {
  border-top: 1px solid var(--border);
  background: var(--background);
  display: none;
  justify-content: space-around;
  align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (max-width: 880px) {
  .bottom-nav { display: flex; }
}
.bn-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; padding: 6px 4px;
  color: var(--muted-foreground); font-size: 11px; font-weight: 500;
  background: none; border: none; cursor: pointer;
  position: relative;
}
.bn-item.active { color: var(--foreground); }
.bn-dot { position: absolute; top: 8px; right: calc(50% - 16px);
  width: 7px; height: 7px; border-radius: 9999px; background: var(--primary); }

/* main */
.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; height: 100%; }

/* =========================================================================
   Topbar + page chrome
   ========================================================================= */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  gap: 16px; min-height: 64px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.topbar .sub { color: var(--muted-foreground); font-size: 13px; }

.scroll { overflow-y: auto; flex: 1; min-height: 0; }
.page { padding: 24px; max-width: 1280px; margin: 0 auto; width: 100%; }
@media (max-width: 600px) { .page { padding: 16px; } .topbar { padding: 12px 16px; min-height: 56px; } .topbar h1 { font-size: 17px; } }

/* =========================================================================
   Primitives
   ========================================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 14px; font-weight: 500;
  height: 36px; padding: 0 14px;
  border-radius: var(--radius); border: 1px solid transparent;
  cursor: pointer; user-select: none; line-height: 1;
  white-space: nowrap;
  transition: background-color .12s ease, color .12s ease, border-color .12s ease, opacity .12s ease;
}
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover:not(:disabled) { opacity: .9; }
.btn-secondary { background: var(--secondary); color: var(--secondary-foreground); }
.btn-secondary:hover:not(:disabled) { background: color-mix(in oklab, var(--secondary) 80%, var(--foreground)); }
.btn-outline { background: transparent; color: var(--foreground); border-color: var(--border); }
.btn-outline:hover:not(:disabled) { background: var(--accent); }
.btn-outline.active { background: var(--secondary); }
.btn-ghost { background: transparent; color: var(--foreground); }
.btn-ghost:hover:not(:disabled) { background: var(--accent); }
.btn-destructive { background: var(--destructive); color: var(--destructive-foreground); }
.btn-destructive:hover:not(:disabled) { opacity: .9; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-lg { height: 40px; padding: 0 18px; font-size: 15px; }
.btn-icon { width: 36px; height: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; height: 30px; }

.input {
  font-family: var(--font-sans); font-size: 14px;
  height: 36px; padding: 0 12px;
  border-radius: var(--radius); border: 1px solid var(--input);
  background: var(--background); color: var(--foreground);
  width: 100%;
}
.input::placeholder { color: var(--muted-foreground); }
.input:focus { outline: 2px solid var(--ring); outline-offset: 2px; }

.input-with-icon { position: relative; }
.input-with-icon .input { padding-left: 36px; }
.input-with-icon .leading {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--muted-foreground); pointer-events: none;
}

.label { font-size: 13px; font-weight: 500; display: block; margin-bottom: 6px; }
.helper { font-size: 12px; color: var(--muted-foreground); margin-top: 6px; }

.textarea {
  font-family: var(--font-mono); font-size: 13px; line-height: 1.55;
  padding: 12px;
  border-radius: var(--radius); border: 1px solid var(--input);
  background: var(--background); color: var(--foreground);
  width: 100%; resize: vertical; min-height: 160px;
}
.textarea:focus { outline: 2px solid var(--ring); outline-offset: 2px; }

.card {
  background: var(--card); color: var(--card-foreground);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px;
}

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: var(--radius-full);
  border: 1px solid transparent; line-height: 1.6;
  white-space: nowrap;
}
.badge-primary { background: var(--primary); color: var(--primary-foreground); }
.badge-secondary { background: var(--secondary); color: var(--secondary-foreground); }
.badge-outline { background: transparent; color: var(--foreground); border-color: var(--border); }
.badge-destructive { background: var(--destructive); color: var(--destructive-foreground); }
.badge-soft { background: var(--muted); color: var(--muted-foreground); }

.switch { position: relative; display: inline-block; width: 40px; height: 22px;
  background: var(--input); border-radius: 9999px; cursor: pointer; border: none; padding: 0;
  transition: background-color .15s ease; flex: 0 0 40px; }
.switch.on { background: var(--primary); }
.switch::after { content:""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 9999px; background: var(--background); box-shadow: var(--shadow-sm);
  transition: transform .15s ease; }
.switch.on::after { transform: translateX(18px); }

.tabs-list { background: var(--muted); padding: 4px; border-radius: var(--radius);
  display: inline-flex; gap: 2px; }
.tab-trigger { background: transparent; border: 0; padding: 6px 12px;
  border-radius: calc(var(--radius) - 2px);
  font-family: var(--font-sans); font-size: 13px; font-weight: 500;
  color: var(--muted-foreground); cursor: pointer; line-height: 1.4; }
.tab-trigger.active { background: var(--background); color: var(--foreground); box-shadow: var(--shadow-sm); }

.separator { height: 1px; background: var(--border); width: 100%; margin: 16px 0; }

/* =========================================================================
   Overlays
   ========================================================================= */
.scrim {
  position: fixed; inset: 0; background: rgb(0 0 0 / .60);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; animation: fadeIn .15s ease;
  padding: 16px;
}
.dialog {
  background: var(--background); color: var(--foreground);
  border: 1px solid var(--border); border-radius: var(--radius);
  max-width: 480px; width: 100%;
  padding: 24px; box-shadow: var(--shadow-lg);
  animation: dialogIn .18s cubic-bezier(.16,1,.3,1);
}
.dialog.wide { max-width: 640px; }
.dialog-title { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.dialog-desc { color: var(--muted-foreground); font-size: 14px; margin-top: 4px; }
.dialog-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
@keyframes fadeIn { from {opacity:0} to {opacity:1} }
@keyframes spin { to { transform: rotate(360deg) } }
.spin { animation: spin 1s linear infinite; transform-origin: center; transform-box: fill-box; }
@keyframes dialogIn { from { opacity:0; transform: scale(.95)} to {opacity:1; transform: scale(1)} }

/* sheet from bottom */
.sheet {
  background: var(--background); color: var(--foreground);
  border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 560px;
  padding: 20px; box-shadow: var(--shadow-lg);
  animation: sheetIn .2s cubic-bezier(.16,1,.3,1);
  align-self: flex-end;
  max-height: 90vh; overflow-y: auto;
}
@keyframes sheetIn { from { transform: translateY(100%) } to { transform: translateY(0) } }
.sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 9999px;
  margin: -4px auto 14px; }

.menu {
  background: var(--popover); color: var(--popover-foreground);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px; box-shadow: var(--shadow-md);
  min-width: 200px;
}
.menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  font-size: 13px; cursor: pointer; user-select: none;
  color: var(--foreground);
}
.menu-item:hover { background: var(--accent); }
.menu-item.destructive { color: var(--destructive); }
.menu-item.destructive:hover { background: color-mix(in oklab, var(--destructive) 14%, transparent); }
.menu-sep { height: 1px; background: var(--border); margin: 4px 0; }

.toast-region {
  position: fixed; bottom: 24px; right: 24px; z-index: 80;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--popover); color: var(--popover-foreground);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow-md);
  min-width: 260px; max-width: 360px;
  display: flex; align-items: flex-start; gap: 10px;
  pointer-events: auto;
  animation: toastIn .2s ease;
}
.toast .title { font-size: 13px; font-weight: 600; }
.toast .desc { font-size: 12px; color: var(--muted-foreground); margin-top: 2px; }
@keyframes toastIn { from { opacity:0; transform: translateY(6px) } to { opacity:1; transform: translateY(0) } }
@media (max-width: 600px) {
  .toast-region { bottom: 84px; right: 12px; left: 12px; }
  .toast { max-width: none; }
}

/* =========================================================================
   Library
   ========================================================================= */
.lib-toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin-bottom: 18px;
}
.lib-toolbar .search { flex: 1; min-width: 200px; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: transparent; color: var(--foreground);
  cursor: pointer; font-size: 12px; font-weight: 500;
  white-space: nowrap;
}
.tag-chip:hover { background: var(--accent); }
.tag-chip.on { background: var(--primary); color: var(--primary-foreground); border-color: transparent; }

/* Playlist filter chips — tinted in the brand color so they read as a distinct
   category from plain tag chips, and fill solid when active. */
.tag-chip-pl {
  background: color-mix(in oklab, var(--primary) 12%, var(--card));
  color: var(--primary);
  border-color: color-mix(in oklab, var(--primary) 35%, transparent);
  max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}
.tag-chip-pl:hover { background: color-mix(in oklab, var(--primary) 20%, var(--card)); }
.tag-chip-pl.on { background: var(--primary); color: var(--primary-foreground); border-color: transparent; }

.tag-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }

.song-list {
  display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
  background: var(--card);
  container-type: inline-size;   /* enable container queries for the rows */
}

/* Playlist view: each song sits in its own bordered card. */
.pl-song-list {
  border: none; background: transparent; overflow: visible;
  gap: 8px;
}
.pl-song-list .song-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}
.pl-song-list .song-row:last-child { border-bottom: 1px solid var(--border); }

/* Playlist rows: reorder buttons at the front, then index, then a content
   block (title/artist + key) that wraps the key onto its own line when tight,
   then the ⋮ menu at the back. */
.pl-song-list .pl-song-row {
  display: flex; align-items: center; gap: 10px;
}
.pl-song-row .pl-reorder { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 2px; }
.pl-song-row .pl-index {
  flex: 0 0 auto; width: 20px; text-align: right;
  font-family: var(--font-mono); font-size: 12px; color: var(--muted-foreground);
}
.pl-song-row .sr-content {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 14px;
}
.pl-song-row .sr-meta { flex: 1 1 200px; min-width: 0; }
.pl-song-row .sr-key { flex: 0 0 auto; white-space: nowrap; }
.pl-song-row > .btn { flex: 0 0 auto; }

/* No room for the key/capo — drop it entirely (it wraps first, then hides). */
@container (max-width: 380px) {
  .pl-song-row .sr-key { display: none; }
}
.song-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.song-row:last-child { border-bottom: none; }
.song-row:hover { background: var(--accent); }
.song-row .sr-meta { min-width: 0; }
.song-row .sr-title { font-size: 14px; font-weight: 600; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-row .sr-artist { font-size: 12px; color: var(--muted-foreground); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-row .sr-key { font-family: var(--font-mono); font-size: 12px; color: var(--muted-foreground); }
.song-row .sr-key strong { color: var(--foreground); font-weight: 600; }
.song-row .sr-tags { display: flex; gap: 4px; flex-wrap: wrap; }

/* Library rows: meta + key flow on one line but the key/capo wraps to a new
   line when space is tight, and the ⋯ menu stays pinned to the right. */
.song-row.sr-lib { display: flex; align-items: center; gap: 12px; }
.sr-lib .sr-content {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 14px;
}
.sr-lib .sr-meta { flex: 1 1 220px; min-width: 0; }
.sr-lib .sr-tags { flex: 0 1 auto; }
.sr-lib .sr-key { flex: 0 0 auto; white-space: nowrap; }
.sr-lib > .btn { flex: 0 0 auto; align-self: center; }

/* When the list is too narrow, drop the tags and key/capo — keep just the
   title/artist and the ⋯ menu. */
@container (max-width: 460px) {
  .sr-lib .sr-tags { display: none; }
  .sr-lib .sr-key { display: none; }
}

@media (max-width: 600px) {
  .song-row { grid-template-columns: 1fr auto; padding: 12px 14px; }
  .song-row .sr-tags { display: none; }
}

/* generic data table (playlists list, etc.) */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.data-table thead th {
  text-align: left;
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted-foreground); font-weight: 600;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.data-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tr.row-clickable { cursor: pointer; }
.data-table tbody tr.row-clickable:hover { background: var(--accent); }

.empty {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px; text-align: center;
  color: var(--muted-foreground);
}

/* =========================================================================
   Song view
   ========================================================================= */
/* flex: 1 + min-height: 0 is more reliable than height: 100% across mobile browsers */
.sv-shell { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--background); }
.sv-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 6; background: var(--background);
}
.sv-title { font-size: 18px; font-weight: 700; letter-spacing: -0.02em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sv-artist { font-size: 13px; color: var(--muted-foreground);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sv-actions { display: flex; gap: 6px; }
.sv-actions-direct { display: flex; gap: 6px; }
.sv-actions-more { display: none; }
@media (max-width: 600px) {
  .sv-header { padding: 10px 12px; gap: 10px; }
  .sv-title { font-size: 15px; }
  .sv-artist { font-size: 12px; }
  /* Not enough room for the individual buttons — collapse to a ⋮ menu. */
  .sv-actions-direct { display: none; }
  .sv-actions-more { display: flex; }
}

.sv-meta-bar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 8px 16px; border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--background) 92%, var(--foreground));
}
/* meta bar popup buttons (Key / Capo / BPM) */
.meta-pop-btn {
  display: inline-flex; flex-direction: row; align-items: center;
  padding: 9px 18px; gap: 8px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--background); color: var(--foreground);
  cursor: pointer; font-family: inherit;
}
.meta-pop-btn:hover { background: var(--accent); }
.meta-pop-btn.on { background: var(--secondary); color: var(--secondary-foreground); border-color: var(--primary); }
.meta-pop-btn .label { font-size: 11px; font-weight: 600; color: var(--muted-foreground);
  text-transform: uppercase; letter-spacing: .06em; }
.meta-pop-btn .val { font-family: var(--font-mono); font-size: 16px; font-weight: 700; }
.meta-pop-btn.on .label { color: inherit; opacity: .7; }
/* screen-centred popup (Key / Capo / BPM / Chords) */
.sv-center-popup {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 50;
  background: var(--popover); color: var(--popover-foreground);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 20px 24px; min-width: 220px; max-width: 90vw;
}
.sv-center-popup-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
  font-size: 13px; font-weight: 600;
}
.meta-stepper-row {
  display: flex; align-items: center; justify-content: center; gap: 20px;
}
.meta-stepper-val {
  font-family: var(--font-mono); font-size: 28px; font-weight: 700;
  min-width: 64px; text-align: center;
}
/* make the stepper buttons a bit bigger inside popup */
.sv-center-popup .as-icon-btn { width: 40px; height: 40px; }
@media (max-width: 600px) { .sv-meta-bar { padding: 6px 12px; gap: 6px; } }

.sv-scroll {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  /* 1/3-viewport of blank space top & bottom so the first lines start lower and
     the last line can scroll up to a comfortable reading position. */
  padding: 33.333dvh 24px;
  /* No scroll-behavior:smooth: the autoscroll rAF loop writes scrollTop every
     frame, and CSS smooth-scroll restarts an animation each write, stalling the
     scroll on iOS Safari. scrollToTop/jumpToSection animate via scrollTo() instead. */
  scrollbar-width: none;
}
.sv-scroll::-webkit-scrollbar { display: none; }
.sv-content {
  max-width: 820px; margin: 0 auto;
  font-family: var(--font-mono);
  font-size: var(--lyric-size, 16px);
  line-height: 1.65;
  color: var(--foreground);
  /* Never let a long line scroll sideways and hide itself — wrap instead. */
  overflow-wrap: anywhere;
}
@media (max-width: 600px) {
  .sv-scroll { padding: 33.333dvh 14px; }
}

/* Segmented 3-way switch (Add song: Web / Text or image / Manual) */
.seg-switch {
  display: inline-flex; max-width: 100%; margin-bottom: 18px;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--card);
}
.seg-item {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; line-height: 1; white-space: nowrap;
  border: 0; border-left: 1px solid var(--border);
  background: transparent; color: var(--muted-foreground);
  font-family: var(--font-sans); font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.seg-item:first-child { border-left: 0; }
.seg-item:hover:not(.on) { background: var(--accent); color: var(--foreground); }
.seg-item.on { background: var(--primary); color: var(--primary-foreground); }
@media (max-width: 600px) {
  .seg-switch { display: flex; width: 100%; }
  .seg-item { flex: 1; padding: 0 8px; min-width: 0; }
}

.section-tag {
  display: inline-block;
  font-family: var(--font-sans); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted-foreground);
  margin: 22px 0 8px;
  padding: 3px 9px; border: 1px solid var(--border); border-radius: var(--radius-full);
  background: var(--background);
}
.section-tag:first-child { margin-top: 0; }

/* inline (monospace tab-style) */
.line.inline-chords {
  white-space: pre-wrap;       /* wrap long tab/chord lines instead of overflowing */
  overflow-wrap: anywhere;
  color: var(--primary);
  font-weight: 700;
  margin-top: 6px;
  letter-spacing: 0;
}
.line.lyric { white-space: pre-wrap; overflow-wrap: anywhere; }
.line.lyric.with-chord-above { margin-bottom: 0; }

/* chip style */
.line.chip-line {
  display: flex; flex-wrap: wrap;
  align-items: flex-end;
  gap: 0 2px;
  margin-bottom: 4px;
  white-space: normal;
  font-family: var(--font-mono);
}
.chip-token { position: relative; display: inline-flex; flex-direction: column; align-items: flex-start;
  white-space: pre; min-width: 0; max-width: 100%; }
.chip-token .lyric { white-space: pre-wrap; overflow-wrap: anywhere; }
.chip {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: calc(var(--lyric-size, 16px) * 0.792);
  font-weight: 700; color: var(--primary);
  padding: 1px 6px; border-radius: var(--radius-sm);
  background: color-mix(in oklab, var(--primary) 14%, transparent);
  line-height: 1.3;
}
.chip-token .chip { margin-bottom: 3px; }
.chip-token .lyric { font-family: var(--font-mono); }
.chip-token.no-chip { margin-top: calc(var(--lyric-size, 16px) * 0.792 + 6px); }

/* progression / chord-only bar line: chords shown as chips inline with the
   bar markers (| : x4), wrapping naturally on one flowing row. */
.line.prog-line {
  margin: 8px 0 6px;
  font-family: var(--font-mono);
  color: var(--foreground);
  white-space: pre-wrap; overflow-wrap: anywhere;
  line-height: 2;
}
.prog-line .prog-text { white-space: pre; }
.prog-line .chip { vertical-align: middle; }

/* chords bar */
.sv-chords-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--background);
  cursor: pointer; user-select: none;
  overflow: hidden;
}
.sv-chords-bar:hover { background: var(--accent); }
.sv-chords-label {
  font-size: 11px; font-weight: 600; color: var(--muted-foreground);
  text-transform: uppercase; letter-spacing: .06em; flex-shrink: 0;
}
.sv-chords-list {
  display: flex; gap: 6px; flex: 1; min-width: 0;
  overflow: hidden; flex-wrap: nowrap;
}
.sv-chords-bar.has-overflow .sv-chords-list {
  -webkit-mask-image: linear-gradient(to right, black calc(100% - 28px), transparent);
  mask-image: linear-gradient(to right, black calc(100% - 28px), transparent);
}
.sv-chord-chip {
  font-family: var(--font-mono); font-size: 12px; font-weight: 700;
  padding: 2px 8px; border-radius: var(--radius-sm);
  background: color-mix(in oklab, var(--primary) 14%, transparent);
  color: var(--primary); white-space: nowrap; flex-shrink: 0;
}
.sv-chords-ellipsis {
  font-size: 13px; color: var(--muted-foreground); flex-shrink: 0; letter-spacing: .05em;
}
@media (max-width: 600px) { .sv-chords-bar { padding: 7px 14px; } }

/* Grey chord style — Settings → Appearance → Chord color = "Grey".
   Swaps the orange brand accent on song-view chord chips (over lyrics, in
   progression lines, and in the "Used" bar) for a neutral, high-contrast tone.
   Default ("orange") leaves the rules above untouched. */
.sv-shell[data-chord-color="grey"] .chip,
.sv-shell[data-chord-color="grey"] .sv-chord-chip {
  color: var(--foreground);
  background: color-mix(in oklab, var(--foreground) 12%, transparent);
}

/* autoscroll bottom bar — 3-column grid: left | centre | right */
.autoscroll-bar {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  background: var(--popover); color: var(--popover-foreground);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  height: 74px;   /* not playing: 20% larger than base 62px */
  /* push content above browser chrome / home indicator */
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transition: height .2s ease;
}
/* playing: 20% smaller than base, buttons stay same size */
.autoscroll-bar.playing { height: 50px; }

/* Metronome count-in — when autoscroll starts with the metronome enabled, the
   bar pulses once per beat for --beat-count beats, then scrolling begins.
   --beat-period (= 60000/BPM ms) and --beat-count are set inline on the bar, so
   the flashes track the song's tempo and the configured count. */
@keyframes metro-pulse {
  0%        { background: color-mix(in oklab, var(--primary) 34%, var(--popover));
              box-shadow: inset 0 3px 0 -1px var(--primary); }
  55%, 100% { background: var(--popover);
              box-shadow: inset 0 3px 0 -1px transparent; }
}
.autoscroll-bar.metronome {
  animation: metro-pulse var(--beat-period, 600ms) ease-out var(--beat-count, 4);
}
/* centre group */
.as-group { display: flex; align-items: center; gap: 6px; }
.as-divider { width: 1px; height: 20px; background: var(--border); margin: 0 6px; flex: 0 0 1px; }
/* left / right columns */
.as-left  { display: flex; align-items: center; gap: 6px; padding-left: 16px; justify-content: flex-start; }
.as-right { display: flex; align-items: center; gap: 4px; padding-right: 16px; justify-content: flex-end; }
.as-hidden { visibility: hidden; pointer-events: none; }
.as-play {
  width: 34px; height: 34px; border-radius: 9999px;
  background: var(--primary); color: var(--primary-foreground);
  border: 0; cursor: pointer; display: grid; place-items: center;
  flex: 0 0 34px;
  transition: width .2s, height .2s, flex-basis .2s;
}
.as-play:hover { opacity: .9; }
.as-speed { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.as-speed-head { display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; color: var(--muted-foreground); text-transform: uppercase; letter-spacing: .07em; font-weight: 600; }
.as-speed-head .val { color: var(--foreground); font-family: var(--font-mono); font-size: 12px; text-transform: none; letter-spacing: 0; }
.as-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; background: var(--input);
  border-radius: 9999px; outline: none;
}
.as-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 9999px;
  background: var(--primary); border: 2px solid var(--background);
  cursor: pointer;
}
.as-slider::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 9999px;
  background: var(--primary); border: 2px solid var(--background); cursor: pointer;
}
.as-icon-btn { width: 32px; height: 32px; border-radius: var(--radius-sm);
  background: transparent; border: 0; color: var(--foreground); cursor: pointer;
  display: grid; place-items: center; }
.as-icon-btn:hover { background: var(--accent); }
.as-icon-btn.on { background: var(--secondary); color: var(--secondary-foreground); }

/* section jump button inside sections popup */
.section-jump-btn {
  display: block; width: 100%; text-align: left;
  background: none; border: 0; padding: 6px 8px; margin: 1px 0;
  cursor: pointer; color: var(--foreground);
  font-family: var(--font-sans); font-size: 13px; font-weight: 500;
  border-radius: var(--radius-sm);
}
.section-jump-btn:hover { background: var(--accent); }

/* playlist context banner */
.sv-playlist-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 24px;
  background: color-mix(in oklab, var(--primary) 12%, var(--background));
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

/* popover anchor / card */
.popover-anchor { position: relative; }
.popover-card {
  position: absolute; bottom: 100%; right: 0; margin-bottom: 6px;
  background: var(--popover); color: var(--popover-foreground);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-md); padding: 12px;
  min-width: 220px; z-index: 11;
}

/* =========================================================================
   Editor
   ========================================================================= */
.editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 880px) { .editor-grid { grid-template-columns: 1fr; } }
.editor-pane {
  display: flex; flex-direction: column; gap: 12px;
}
.editor-pane h3 { font-size: 14px; font-weight: 600; margin: 0; }
.preview-area {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card);
  padding: 18px;
  min-height: 320px;
  max-height: 540px;
  overflow-y: auto;
  font-family: var(--font-mono); font-size: 14px; line-height: 1.6;
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 500px) { .field-row { grid-template-columns: 1fr; } }

/* =========================================================================
   Playlists
   ========================================================================= */
.pl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.pl-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; cursor: pointer; transition: background-color .12s ease;
  display: flex; flex-direction: column; gap: 12px;
}
.pl-card:hover { background: var(--accent); }
.pl-cover {
  height: 100px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--secondary), color-mix(in oklab, var(--primary) 26%, var(--secondary)));
  position: relative; overflow: hidden;
}
.pl-cover.gradient-1 { background: linear-gradient(135deg, #1e293b, #475569); }
.pl-cover.gradient-2 { background: linear-gradient(135deg, #422006, #f97316); }
.pl-cover.gradient-3 { background: linear-gradient(135deg, #052e16, #16a34a); }
.pl-cover.gradient-4 { background: linear-gradient(135deg, #4a044e, #c026d3); }
.pl-cover.gradient-5 { background: linear-gradient(135deg, #1e1b4b, #6366f1); }
.pl-cover.gradient-6 { background: linear-gradient(135deg, #450a0a, #dc2626); }
.pl-cover-name {
  position: absolute; bottom: 10px; left: 12px;
  color: #fff; font-weight: 700; font-size: 16px; letter-spacing: -0.01em;
  text-shadow: 0 2px 8px rgb(0 0 0 / .4);
}
.pl-shared-badge {
  position: absolute; top: 8px; right: 8px;
  background: rgb(0 0 0 / .55); color: #fff;
  font-size: 10px; font-weight: 600;
  padding: 3px 7px; border-radius: var(--radius-full);
  display: inline-flex; align-items: center; gap: 4px;
}
.pl-meta { font-size: 12px; color: var(--muted-foreground); }

/* playlist detail */
.pl-detail-hero {
  display: grid; grid-template-columns: 160px 1fr; gap: 20px; margin-bottom: 24px;
}
@media (max-width: 600px) { .pl-detail-hero { grid-template-columns: 1fr; } .pl-detail-cover { height: 160px; } }
.pl-detail-cover { border-radius: var(--radius); height: 160px; }
.pl-detail-info h2 { font-size: 28px; font-weight: 700; letter-spacing: -0.025em; margin: 0; }
.pl-detail-info .sub { color: var(--muted-foreground); font-size: 14px; margin-top: 6px; }
.pl-collab-row { display: flex; gap: 6px; align-items: center; margin-top: 12px; }
.collab-avatars { display: flex; }
.collab-avatars .av {
  width: 26px; height: 26px; border-radius: 9999px;
  display: grid; place-items: center; font-weight: 600; font-size: 11px;
  color: #fff; margin-left: -6px;
  border: 2px solid var(--background);
}
.collab-avatars .av:first-child { margin-left: 0; }

/* =========================================================================
   Inbox
   ========================================================================= */
.inbox-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 14px; align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.inbox-row:last-child { border-bottom: none; }
.inbox-row:hover { background: var(--accent); }
.inbox-row.unread .ib-title::before {
  content: ""; width: 7px; height: 7px; border-radius: 9999px;
  background: var(--primary); display: inline-block; margin-right: 8px;
  vertical-align: middle;
}
.ib-av { width: 36px; height: 36px; border-radius: 9999px;
  display: grid; place-items: center; font-weight: 600; font-size: 13px; color: #fff; }
.ib-title { font-size: 14px; font-weight: 600; }
.ib-desc { font-size: 13px; color: var(--muted-foreground); margin-top: 2px; }
.ib-time { font-size: 12px; color: var(--muted-foreground); white-space: nowrap; }

/* =========================================================================
   Settings
   ========================================================================= */
.settings-section { margin-bottom: 28px; }
.settings-section h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; letter-spacing: -0.01em; }
.settings-row {
  display: flex; align-items: center; gap: 16px;
  padding: 16px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card);
  margin-bottom: 8px;
}
.settings-row .grow { flex: 1; min-width: 0; }
.settings-row .row-title { font-size: 14px; font-weight: 600; }
.settings-row .row-desc { font-size: 13px; color: var(--muted-foreground); margin-top: 2px; }

.theme-swatch-row { display: flex; gap: 10px; flex-wrap: wrap; }
.theme-swatch {
  width: 64px; height: 48px; border-radius: var(--radius); cursor: pointer;
  border: 2px solid transparent; position: relative;
  display: grid; place-items: center; font-size: 11px; font-weight: 600;
  text-transform: capitalize;
}
.theme-swatch.on { border-color: var(--primary); }
.theme-swatch::after { content: ""; position: absolute; inset: 4px; border-radius: calc(var(--radius) - 2px);
  background: var(--card); opacity: 0; }

/* =========================================================================
   Versions panel (drawer)
   ========================================================================= */
.drawer-scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .55);
  z-index: 40; animation: fadeIn .15s ease; }
.drawer { position: fixed; right: 0; top: 0; bottom: 0; width: min(420px, 100%);
  background: var(--background); color: var(--foreground);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-xl); z-index: 41;
  display: flex; flex-direction: column;
  animation: drawerIn .22s cubic-bezier(.16,1,.3,1);
}
@keyframes drawerIn { from { transform: translateX(100%) } to { transform: translateX(0) } }
.drawer-head { display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border); }
.drawer-title { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.drawer-body { flex: 1; overflow-y: auto; padding: 12px 12px 24px; }

.version-row {
  display: flex; gap: 12px; align-items: center;
  padding: 12px; border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 8px; cursor: pointer;
  background: var(--card);
}
.version-row:hover { background: var(--accent); }
.version-row.active { border-color: var(--primary); }
.version-row .v-info { flex: 1; min-width: 0; }
.version-row .v-name { font-size: 13px; font-weight: 600; }
.version-row .v-meta { font-size: 11px; color: var(--muted-foreground); margin-top: 2px; font-family: var(--font-mono); }

/* =========================================================================
   Tags chips inside song view, badges in lists
   ========================================================================= */
.tag-pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 500;
  padding: 2px 8px; border-radius: var(--radius-full);
  background: var(--muted); color: var(--muted-foreground);
  border: 1px solid var(--border);
}

/* Library rows that are a playlist's own copy get a tinted pill naming the
   playlist, so they read differently from plain library songs. */
.tag-pill.sr-pl-pill {
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: color-mix(in oklab, var(--primary) 14%, var(--card));
  color: var(--primary);
  border-color: color-mix(in oklab, var(--primary) 35%, transparent);
}

/* avatar palette */
.av-1 { background: #2563eb; }
.av-2 { background: #16a34a; }
.av-3 { background: #f97316; }
.av-4 { background: #dc2626; }
.av-5 { background: #7c3aed; }
.av-6 { background: #db2777; }
.av-7 { background: #0891b2; }
.av-8 { background: #65a30d; }

/* misc */
.kbd {
  font-family: var(--font-mono); font-size: 11px;
  background: var(--muted); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: var(--radius-sm);
  color: var(--muted-foreground);
}
.section-headline { font-size: 22px; font-weight: 700; letter-spacing: -0.025em; margin: 0 0 4px; }
.section-sub { color: var(--muted-foreground); font-size: 14px; margin-bottom: 18px; }
