:root {
  color-scheme: dark;
  --bg: #10131a;
  --surface: #181d26;
  --surface-raised: #222936;
  --surface-hover: #293244;
  --border: #344052;
  --text: #f2f5f8;
  --muted: #aeb8c7;
  --accent: #77d1b1;
  --accent-strong: #4eb990;
  --danger: #e27979;
  --focus: #a9e8d2;
  --shadow: 0 20px 46px rgba(0, 0, 0, .44);
  --lyrics-font-size: 30px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; min-height: 100%; margin: 0; background: var(--bg); }
body { color: var(--text); overflow: hidden; }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button:not(:disabled), input:not(:disabled) { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
button:disabled { opacity: .38; cursor: not-allowed; }

.app-shell, .stage { height: 100vh; min-height: 100vh; height: 100dvh; min-height: 100dvh; }
.stage { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.song-header { display: flex; align-items: center; gap: 16px; min-height: 74px; padding: calc(12px + env(safe-area-inset-top)) 24px 12px; border-bottom: 1px solid var(--border); background: rgba(16, 19, 26, .96); }
.menu-button, .icon-button { display: grid; place-items: center; width: 48px; height: 48px; flex: 0 0 auto; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); cursor: pointer; }
.menu-button { font-size: 26px; line-height: 1; }
.icon-button { font-size: 28px; line-height: .8; }
.menu-button:hover, .icon-button:hover { background: var(--surface-hover); }
.song-identification { min-width: 0; flex: 1; }
.song-identification h1 { overflow: hidden; margin: 0; font-size: clamp(18px, 2vw, 27px); font-weight: 700; line-height: 1.15; text-overflow: ellipsis; white-space: nowrap; }
.song-identification p { display: flex; align-items: center; gap: 10px; min-height: 22px; margin: 3px 0 0; color: var(--muted); font-size: 15px; }
.song-key { display: inline-flex; align-items: center; min-height: 26px; padding: 2px 9px; border-radius: 7px; background: rgba(119, 209, 177, .15); color: var(--accent); font-weight: 700; letter-spacing: .02em; }
.header-actions { display: flex; align-items: center; gap: 6px; }
.text-button { min-height: 42px; padding: 8px 11px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.text-button:hover { background: var(--surface-hover); color: var(--text); }
.danger-text:hover { color: var(--danger); }
.exit-stage { margin-left: auto; }

.lyrics-scroll { overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; scrollbar-color: var(--border) transparent; }
.lyrics { max-width: 1120px; margin: 0 auto; padding: clamp(28px, 4.6vw, 70px) clamp(26px, 7vw, 112px) 0; color: var(--text); font-size: var(--lyrics-font-size); font-weight: 500; line-height: 1.48; letter-spacing: .005em; white-space: pre-wrap; }
.lyrics.is-caps-lock { text-transform: uppercase; }
.lyrics p { margin: 0 0 1.15em; }
.lyrics .empty-lyrics { color: var(--muted); font-size: .72em; }
.lyrics .empty-lyrics button { margin-top: 18px; }
.lyrics-end-space { height: 40vh; min-height: 190px; }

.control-bar { display: grid; grid-template-columns: minmax(130px, 1fr) 58px minmax(230px, 1.5fr) auto minmax(130px, 1fr); align-items: center; gap: 14px; padding: 12px max(18px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); border-top: 1px solid var(--border); background: rgba(24, 29, 38, .98); }
.transport-button, .play-button, .font-button { min-height: 52px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-raised); cursor: pointer; }
.transport-button { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 8px 17px; font-size: 24px; font-weight: 600; }
.transport-button span { font-size: 15px; }
.transport-button:hover, .font-button:hover { background: var(--surface-hover); }
.play-button { width: 58px; padding: 0; border-color: rgba(119, 209, 177, .5); background: var(--accent-strong); color: #082017; font-size: 21px; font-weight: 800; }
.play-button.is-playing { background: #f0c66a; color: #2d2206; }
.speed-control { display: grid; grid-template-columns: auto minmax(90px, 1fr) auto; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.speed-slider-wrap { display: grid; min-width: 0; }
.speed-control input { grid-area: 1 / 1; width: 100%; height: 44px; margin: 0; appearance: none; -webkit-appearance: none; background: transparent; accent-color: var(--accent); cursor: pointer; }
.speed-control input::-webkit-slider-runnable-track { height: 6px; border-radius: 999px; background: var(--border); }
.speed-control input::-webkit-slider-thumb { width: 24px; height: 24px; margin-top: -9px; border: 2px solid #d8fff1; border-radius: 50%; background: var(--accent-strong); box-shadow: 0 2px 8px rgba(0, 0, 0, .45); -webkit-appearance: none; }
.speed-control input::-moz-range-track { height: 6px; border: 0; border-radius: 999px; background: var(--border); }
.speed-control input::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--accent-strong); }
.speed-control input::-moz-range-thumb { width: 22px; height: 22px; border: 2px solid #d8fff1; border-radius: 50%; background: var(--accent-strong); box-shadow: 0 2px 8px rgba(0, 0, 0, .45); }
.speed-dots { display: grid; grid-template-columns: repeat(10, 1fr); align-items: center; gap: 0; margin: -7px 5px 0; pointer-events: none; }
.speed-dots i { justify-self: center; width: 4px; height: 4px; border-radius: 50%; background: var(--border); transition: background-color .12s ease; }
.speed-dots i.is-passed { background: rgba(119, 209, 177, .72); }
.font-controls { display: flex; gap: 7px; }
.font-button { min-width: 54px; padding: 8px; font-size: 16px; font-weight: 700; }
.caps-button { min-width: 68px; }
.font-button.is-active { border-color: var(--accent); background: var(--accent-strong); color: #082017; }

.drawer-backdrop { position: fixed; z-index: 10; inset: 0; background: rgba(0, 0, 0, .4); }
.drawer { position: fixed; z-index: 11; top: 0; bottom: 0; left: 0; display: flex; flex-direction: column; width: min(32vw, 430px); min-width: 315px; padding: calc(18px + env(safe-area-inset-top)) 16px calc(14px + env(safe-area-inset-bottom)); border-right: 1px solid var(--border); background: #171c25; box-shadow: var(--shadow); transform: translateX(-105%); transition: transform .18s ease; }
.drawer.is-open { transform: translateX(0); }
.drawer-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.drawer-heading h2 { margin: 2px 0 0; font-size: 23px; }
.eyebrow { margin: 0; color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: .11em; text-transform: uppercase; }
.drawer-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; margin-bottom: 14px; padding: 4px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.drawer-tab { min-height: 44px; padding: 7px 8px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 700; cursor: pointer; }
.drawer-tab:hover { background: var(--surface-hover); color: var(--text); }
.drawer-tab.is-active { background: var(--surface-raised); color: var(--accent); box-shadow: inset 0 0 0 1px rgba(119, 209, 177, .28); }
.drawer-panels { flex: 1; min-height: 0; }
.drawer-panel { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.drawer-panel[hidden] { display: none !important; }
.search-box input { width: 100%; min-height: 48px; padding: 10px 13px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); color: var(--text); }
.playlist-switcher, .library-selector-row { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 8px; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.playlist-switcher select, .library-selector-row select, .sort-box select, .export-options select { min-height: 44px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.compact-actions { grid-column: 1 / -1; display: flex; gap: 6px; }
.small-button { min-height: 40px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-raised); color: var(--muted); cursor: pointer; }
.small-button:hover { background: var(--surface-hover); color: var(--text); }
.list-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; }
.organize-button { min-height: 48px; }
.organize-button[aria-pressed="true"] { border-color: var(--accent-strong); background: rgba(119, 209, 177, .14); color: var(--accent); }
.button { min-height: 44px; padding: 9px 14px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-raised); cursor: pointer; }
.button:hover { background: var(--surface-hover); }
.button-primary { border-color: var(--accent-strong); background: var(--accent-strong); color: #072118; font-weight: 700; }
.button-primary:hover { background: var(--accent); }
.danger-button { border-color: #9f5151; background: #862f34; color: #fff; }
.danger-outline { border-color: rgba(226, 121, 121, .55); color: var(--danger); }
.organize-hint { margin: 9px 4px 5px; color: var(--accent); font-size: 12px; }
.song-list { flex: 1; min-height: 0; margin: 0 -7px; padding: 0 7px; overflow-y: auto; list-style: none; }
.song-list:empty { flex: 0; }
.song-item { display: grid; grid-template-columns: 2.4em minmax(0, 1fr) auto; align-items: center; gap: 7px; min-height: 59px; padding: 5px 7px; border-bottom: 1px solid rgba(52, 64, 82, .62); cursor: pointer; }
.song-list.is-organizing .song-item { grid-template-columns: 34px 2.4em minmax(0, 1fr) auto 38px; cursor: default; }
.song-item:hover, .song-item.is-active { border-radius: 8px; background: var(--surface-hover); }
.song-item.is-active { box-shadow: inset 3px 0 var(--accent); }
.song-item.is-dragging { opacity: .45; background: var(--surface-hover); }
.drag-handle { display: none; place-items: center; width: 34px; height: 42px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: grab; touch-action: none; user-select: none; }
.song-list.is-organizing .drag-handle { display: grid; }
.drag-handle:active { cursor: grabbing; }
.song-number { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; text-align: right; }
.song-summary { min-width: 0; }
.song-summary strong, .song-summary span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.song-summary strong { font-size: 14px; }
.song-summary span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.song-summary .search-match { display: block; margin-top: 5px; overflow: visible; color: #cbd4df; font-size: 11px; line-height: 1.35; text-overflow: clip; white-space: normal; }
.search-match-label { color: var(--accent); font-weight: 700; }
.song-item-key { color: var(--accent); font-size: 13px; font-weight: 700; }
.remove-from-playlist { display: none; place-items: center; width: 36px; height: 40px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 24px; cursor: pointer; }
.song-list.is-organizing .remove-from-playlist { display: grid; }
.remove-from-playlist:hover { background: rgba(226, 121, 121, .14); color: var(--danger); }
.drawer-empty { margin: 14px 5px 0; color: var(--muted); }

.modal { width: min(840px, calc(100vw - 32px)); max-height: min(780px, calc(100vh - 32px)); max-height: min(780px, calc(100dvh - 32px)); padding: 0; overflow: auto; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(0, 0, 0, .62); }
.modal form, .modal > div { padding: 24px; }
.compact-modal { width: min(460px, calc(100vw - 32px)); }
.modal-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.modal-heading h2 { margin: 0; font-size: 23px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-top: 20px; }
.form-grid label { display: grid; gap: 7px; color: var(--muted); font-size: 14px; }
.form-grid input, .form-grid textarea { width: 100%; border: 1px solid var(--border); border-radius: 8px; background: #0e1117; color: var(--text); padding: 11px; }
.form-grid textarea { min-height: 248px; resize: vertical; line-height: 1.45; }
.lyrics-field { grid-column: 1 / -1; }
.editor-tools { display: flex; justify-content: space-between; align-items: center; min-height: 52px; }
.form-error { margin: 0; color: var(--danger); font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }
.library-selector-row { margin: 0 0 12px; }
.library-toolbar { display: grid; grid-template-columns: 1fr; gap: 9px; }
.sort-box, .export-options label, .name-field { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
.sort-box { grid-template-columns: auto minmax(0, 1fr); align-items: center; }
.library-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.library-tools .button { flex: 1 1 145px; }
.library-count { width: 100%; margin-left: 0; color: var(--muted); font-size: 13px; }
.library-target { color: var(--accent); font-size: 12px; }
.library-song-list { flex: 1; min-height: 0; margin: 0 -7px; padding: 0 7px; overflow-y: auto; border-top: 1px solid var(--border); list-style: none; }
.library-song-item { border-bottom: 1px solid rgba(52, 64, 82, .72); }
.library-song-item.is-expanded { background: rgba(34, 41, 54, .72); }
.library-song-main { display: grid; grid-template-columns: minmax(0, 1fr) auto 26px; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 9px 12px; border: 0; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.library-song-main:hover { background: var(--surface-hover); }
.library-song-identity { min-width: 0; }
.library-song-identity strong, .library-song-identity span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library-song-identity span { margin-top: 3px; color: var(--muted); font-size: 13px; }
.library-song-identity .search-match { margin-top: 6px; overflow: visible; color: #cbd4df; font-size: 11px; line-height: 1.35; text-overflow: clip; white-space: normal; }
.library-disclosure { color: var(--muted); text-align: center; }
.library-song-details { padding: 0 12px 14px; }
.library-lyrics-preview { max-height: 190px; margin: 0; padding: 12px; overflow: auto; border: 1px solid var(--border); border-radius: 9px; background: #0e1117; color: var(--text); font-family: inherit; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.library-song-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.library-song-actions .button { padding-inline: 10px; }
.files-panel { gap: 11px; overflow-y: auto; padding-right: 2px; }
.file-group { display: grid; gap: 8px; padding: 13px; border: 1px solid var(--border); border-radius: 10px; background: rgba(34, 41, 54, .5); }
.file-group h3 { margin: 0; font-size: 15px; }
.file-group p { margin: 0 0 2px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.file-group label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.file-group select { width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.export-options { display: grid; gap: 13px; margin-top: 20px; }
.name-field { margin-top: 20px; }
.name-field input { width: 100%; min-height: 46px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.toast-region { position: fixed; z-index: 20; right: 22px; bottom: calc(95px + env(safe-area-inset-bottom)); display: grid; gap: 8px; max-width: min(390px, calc(100vw - 32px)); }
.toast { padding: 12px 15px; border: 1px solid var(--border); border-radius: 9px; background: #273142; color: var(--text); box-shadow: var(--shadow); }
.toast.error { border-color: #a74d4d; background: #49262b; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.stage-mode .normal-only { display: none !important; }
.stage-mode .drawer-tabs { grid-template-columns: 1fr; }
.stage-mode .song-item { grid-template-columns: 2.4em minmax(0, 1fr) auto; }
.stage-mode .song-summary strong { overflow: visible; text-overflow: clip; white-space: normal; line-height: 1.25; }

@media (max-width: 820px) {
  body { overflow: hidden; }
  .song-header { gap: 10px; padding-inline: 14px; }
  .header-actions { display: none; }
  .control-bar { grid-template-columns: minmax(48px, 1fr) 54px auto minmax(48px, 1fr); gap: 8px; }
  .speed-control { grid-column: 1 / -1; grid-row: 2; }
  .font-controls { justify-content: flex-end; }
  .transport-button { min-width: 0; padding: 8px; }
  .transport-button span { display: none; }
  .drawer { width: min(88vw, 410px); min-width: 0; }
  .drawer-tabs { gap: 3px; }
  .drawer-tab { padding-inline: 5px; }
  .form-grid { grid-template-columns: 1fr; }
  .lyrics-field { grid-column: auto; }
}

@media (max-height: 600px) and (min-width: 821px) {
  .song-header { min-height: 63px; padding-top: 8px; padding-bottom: 8px; }
  .control-bar { padding-top: 8px; padding-bottom: 8px; }
  .transport-button, .play-button, .font-button { min-height: 46px; }
  .lyrics { padding-top: 25px; }
}
