:root {
  --bg: #ffffff;
  --raise: #ffffff;
  --soft: #f6f6f5;
  --line: #e8e8e6;
  --fg: #0d0d0d;
  --muted: #7a7a78;
  --faint: #cfcfcc;
  --danger: #c93a2b;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --r: 6px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0c0c0c; --raise: #141414; --soft: #181818; --line: #252525; --fg: #ececec; --muted: #8c8c8c; --faint: #3a3a3a; --danger: #ef6b5b; color-scheme: dark; }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; background: var(--bg); color: var(--fg); font: 14px/1.5 var(--sans); font-feature-settings: "cv11", "ss03"; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; border-radius: 3px; }
[hidden] { display: none !important; }
.num-font, .mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; color: var(--muted); }

input, select, textarea { background: transparent; border: 1px solid var(--line); color: var(--fg); border-radius: var(--r); padding: 7px 10px; font: inherit; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--muted); }
select { appearance: none; cursor: pointer; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 13px) 50%, calc(100% - 9px) 50%; background-size: 4px 4px; background-repeat: no-repeat; padding-right: 26px; }
select option { background: var(--bg); color: var(--fg); }

.btn { height: 32px; padding: 0 12px; border-radius: var(--r); border: 1px solid var(--line); font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.btn.primary:hover { opacity: .88; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: default; }
.text-btn { color: var(--muted); }
.text-btn:hover { color: var(--fg); }
.icon-btn { color: var(--muted); display: grid; place-items: center; width: 28px; height: 28px; border-radius: var(--r); flex: none; }
.icon-btn:hover { color: var(--fg); background: var(--soft); }

/* inline rename: anything with [data-rename] */
[data-rename] { cursor: text; border-radius: 4px; }
[data-rename]:hover { box-shadow: 0 0 0 4px var(--soft); background: var(--soft); }
.inline-input { font: inherit; letter-spacing: inherit; padding: 0 4px; margin: 0 -5px; border-radius: 4px; width: calc(100% + 10px); }

/* top bar */
.top { position: sticky; top: 0; z-index: 15; padding-top: env(safe-area-inset-top, 0px); background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1120px; margin: 0 auto; padding: 0 24px; height: 52px; display: flex; align-items: center; gap: 28px; }
.brand { font-weight: 600; letter-spacing: -.01em; }
.top nav { display: flex; gap: 20px; flex: 1; }
.top nav a { color: var(--muted); }
.top nav a:hover, .top nav a.on { color: var(--fg); }

.page { max-width: 1120px; margin: 0 auto; padding: 40px 24px 140px; display: flex; flex-direction: column; gap: 36px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
h1 { font-size: 26px; font-weight: 600; letter-spacing: -.022em; line-height: 1.2; margin: 0; text-wrap: balance; }
h2 { font-size: 14px; font-weight: 600; margin: 0; }
.crumb { color: var(--muted); font-size: 13px; }
.crumb:hover { color: var(--fg); }

/* dashboard */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 32px 24px; }
.card { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.art { aspect-ratio: 1; width: 100%; border-radius: var(--r); background: var(--soft); overflow: hidden; display: grid; place-items: center; color: var(--faint); position: relative; }
.art img { width: 100%; height: 100%; object-fit: cover; }
.card:hover .art img { opacity: .92; }
.card-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); }
.card.new .art { border: 1px dashed var(--faint); background: transparent; font-size: 13px; color: var(--muted); }
.card.new:hover .art { border-color: var(--muted); color: var(--fg); }

.bar { height: 3px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--fg); border-radius: 3px; }

/* album header */
.album-head { display: grid; grid-template-columns: 168px minmax(0, 1fr); gap: 28px; align-items: end; }
.album-head .art { cursor: pointer; }
.album-head .meta { color: var(--muted); display: flex; gap: 6px 16px; flex-wrap: wrap; margin-top: 6px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 18px; }
.progress-row { display: flex; align-items: center; gap: 12px; margin-top: 18px; max-width: 360px; font-size: 12.5px; color: var(--muted); }
.progress-row .bar { flex: 1; }

.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tab { padding: 0 0 11px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--fg); }
.tab.on { color: var(--fg); border-color: var(--fg); }

.seg { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.chip { height: 28px; padding: 0 10px; border-radius: var(--r); color: var(--muted); border: 1px solid transparent; white-space: nowrap; }
.chip:hover { color: var(--fg); background: var(--soft); }
.chip.on { color: var(--fg); border-color: var(--line); background: var(--raise); font-weight: 500; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* track rows */
.rows { border-top: 1px solid var(--line); }
.row { display: grid; grid-template-columns: 28px minmax(0, 1fr) 128px 48px 92px; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); min-height: 52px; }
.row:hover { background: linear-gradient(90deg, transparent, var(--soft) 2%, var(--soft) 98%, transparent); }
.row.dragging { opacity: .35; }
.row.drop { box-shadow: inset 0 2px 0 var(--fg); }
.idx { font-size: 12.5px; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.idx button { width: 28px; height: 28px; display: none; place-items: center; color: var(--fg); }
.row:hover .idx span { display: none; }
.row:hover .idx button { display: grid; }
.row.playing .idx span, .row.playing .name { color: var(--fg); font-weight: 600; }
.name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; cursor: pointer; text-align: left; max-width: 100%; }
.name:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--faint); }
.row .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-select { height: 28px; padding-block: 0; font-size: 12.5px; border-color: transparent; color: var(--muted); }
.stage-select:hover { border-color: var(--line); }
.stage-select.done { color: var(--fg); font-weight: 500; }
.len { font-size: 12.5px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; justify-content: flex-end; gap: 2px; opacity: 0; }
.more-btn { display: none; }
.row:hover .row-actions, .row-actions:focus-within { opacity: 1; }
.empty { padding: 48px 0; color: var(--muted); text-align: center; }
.empty .btn { margin-top: 14px; }

.drop-hint { border: 1px dashed var(--faint); border-radius: var(--r); padding: 18px; text-align: center; color: var(--muted); cursor: pointer; font-size: 13px; }
.drop-hint:hover, .drop-hint.over { border-color: var(--muted); color: var(--fg); }
.progress-line { height: 2px; background: var(--line); margin: 8px auto 0; max-width: 240px; border-radius: 2px; overflow: hidden; }
.progress-line i { display: block; height: 100%; background: var(--fg); }

/* moodboard */
.board { display: flex; flex-direction: column; gap: 16px; }
.board-head { display: flex; justify-content: space-between; align-items: baseline; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.inspo { columns: 4 180px; column-gap: 12px; }
.inspo .tile { margin-bottom: 12px; break-inside: avoid; }
.tile { position: relative; border-radius: var(--r); overflow: hidden; background: var(--soft); cursor: zoom-in; }
.tiles .tile { aspect-ratio: 1; }
.tiles .tile img { width: 100%; height: 100%; object-fit: cover; }
.tile-actions { position: absolute; inset: auto 6px 6px 6px; display: flex; gap: 4px; justify-content: flex-end; opacity: 0; transition: opacity .15s; }
.tile:hover .tile-actions, .tile-actions:focus-within { opacity: 1; }
.tile-actions button { height: 26px; padding: 0 8px; border-radius: 5px; background: rgb(0 0 0 / .62); color: #fff; font-size: 12px; backdrop-filter: blur(6px); }
.tile-actions button:hover { background: rgb(0 0 0 / .82); }
.badge { position: absolute; top: 6px; left: 6px; font-size: 11px; font-weight: 500; padding: 2px 7px; border-radius: 4px; background: rgb(255 255 255 / .9); color: #111; }
.tile.add { display: grid; place-items: center; border: 1px dashed var(--faint); background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; min-height: 120px; }
.tile.add:hover, .tile.add.over { border-color: var(--muted); color: var(--fg); }

/* song panel */
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .18); z-index: 18; }
.panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100%); background: var(--bg); padding-top: env(safe-area-inset-top, 0px); border-left: 1px solid var(--line); z-index: 19; display: flex; flex-direction: column; box-shadow: -24px 0 60px -30px rgb(0 0 0 / .35); animation: slide .18s ease-out; }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
.panel-head { padding: 18px 24px 0; display: flex; flex-direction: column; gap: 4px; }
.panel-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 0 -6px 6px; }
.panel h1 { font-size: 22px; }
.panel-body { flex: 1; overflow-y: auto; padding: 18px 24px 120px; display: flex; flex-direction: column; gap: 22px; }
.panel-body > * { flex-shrink: 0; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
.stages { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.stages button { padding: 7px 4px; font-size: 12.5px; color: var(--muted); border-right: 1px solid var(--line); }
.stages button:last-child { border-right: 0; }
.stages button:hover { color: var(--fg); background: var(--soft); }
.stages button.on { background: var(--fg); color: var(--bg); font-weight: 500; }
.lyrics { min-height: 46vh; resize: vertical; line-height: 1.75; font-size: 14.5px; padding: 14px; border-color: var(--line); }
.notes { min-height: 30vh; resize: vertical; line-height: 1.65; padding: 14px; }
.save-state { font-size: 12px; color: var(--muted); min-height: 18px; }
.file { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.file:first-child { border-top: 1px solid var(--line); }
.play-sm { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; }
.play-sm:hover { background: var(--soft); }
.file.playing .play-sm { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.file .row-actions { opacity: 1; }

/* dialog */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 22px; width: min(400px, calc(100% - 32px)); background: var(--bg); color: var(--fg); box-shadow: 0 24px 64px -24px rgb(0 0 0 / .35); }
dialog::backdrop { background: rgb(0 0 0 / .25); }
dialog form { display: flex; flex-direction: column; gap: 16px; }
dialog h2 { font-size: 15px; }
.check { display: flex; gap: 8px; align-items: center; color: var(--fg); }
.check input { width: auto; accent-color: var(--fg); }
.btns { display: flex; justify-content: flex-end; gap: 8px; }
.sheet { gap: 2px !important; }
.sheet h2 { padding: 0 4px 10px; color: var(--muted); font-weight: 500; font-size: 13px; }
.sheet-item { text-align: left; padding: 12px 4px; border-radius: var(--r); font-size: 15px; }
.sheet-item:hover { background: var(--soft); }
.sheet-item.danger { color: var(--danger); }
.sheet-item.cancel { color: var(--muted); margin-top: 6px; border-top: 1px solid var(--line); border-radius: 0; }
.lightbox { width: auto; max-width: calc(100vw - 48px); padding: 0; border: 0; background: transparent; box-shadow: none; }
.lightbox img { max-height: calc(100vh - 48px); border-radius: 6px; }

/* transport */
.transport { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(12px); border-top: 1px solid var(--line); }
.transport-in { max-width: 1120px; margin: 0 auto; display: grid; grid-template-columns: 220px 34px minmax(0, 1fr) 90px; gap: 16px; align-items: center; padding: 10px 24px calc(10px + env(safe-area-inset-bottom, 0px)); }
.now { min-width: 0; }
.now div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.play { width: 34px; height: 34px; border-radius: 50%; background: var(--fg); color: var(--bg); display: grid; place-items: center; }
.transport canvas { width: 100%; height: 30px; display: block; cursor: pointer; }
.time { font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: var(--r); font-size: 13px; z-index: 40; max-width: calc(100% - 32px); }

/* login + share page */
.gate { min-height: 100%; padding-top: env(safe-area-inset-top, 0px); display: grid; place-items: center; padding: 24px 16px; }
.gate form { width: min(300px, 100%); display: flex; flex-direction: column; gap: 10px; }
.gate h1 { font-size: 18px; margin-bottom: 14px; }
.gate .error { color: var(--danger); font-size: 12.5px; min-height: 18px; }
.share-page { max-width: 640px; margin: 0 auto; padding: calc(64px + env(safe-area-inset-top, 0px)) 20px 140px; display: flex; flex-direction: column; gap: 32px; }
.share-head { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 24px; align-items: end; }

/* installed on iPhone in light mode: the status bar text is white, so give it a dark strip */
@media (display-mode: standalone) and (prefers-color-scheme: light) {
  .top, .panel, .gate { box-shadow: inset 0 env(safe-area-inset-top, 0px) 0 0 #0c0c0c; }
}

/* touch screens: nothing may depend on hover */
@media (hover: none) {
  .tile-actions { opacity: 1; }
  .row:hover { background: none; }
  [data-rename]:hover { box-shadow: none; background: none; }
}

@media (max-width: 720px) {
  input, select, textarea { font-size: 16px; } /* stops iOS zooming into fields */
  .stage-select { font-size: 13px; }
  .top-in { padding: 0 16px; gap: 16px; height: 48px; }
  .top nav { gap: 16px; }
  .page { padding: 20px 16px 150px; gap: 24px; }
  .page-head h1 { font-size: 22px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 14px; }

  .album-head { display: block; }
  .album-head .art { width: 148px; margin-bottom: 18px; }
  h1 { font-size: 24px; }
  .progress-row { max-width: none; }
  .actions .btn { height: 36px; }

  .row { grid-template-columns: 30px minmax(0, 1fr) 100px 32px; gap: 6px; min-height: 58px; }
  .len, .row-actions { display: none; }
  .more-btn { display: grid; width: 32px; height: 32px; }
  .idx span { display: none; }
  .idx button { display: grid; margin: 0 auto; }
  .row.playing .idx button { color: var(--fg); }
  .stage-select { padding-left: 6px; padding-right: 20px; background-position: calc(100% - 10px) 50%, calc(100% - 6px) 50%; }

  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inspo { columns: 2; }
  .toolbar { align-items: flex-start; }

  .panel { width: 100%; border-left: 0; }
  .panel-head { padding: 12px 16px 0; }
  .panel-body { padding: 14px 16px 140px; gap: 18px; }
  .panel h1 { font-size: 21px; }
  .stages { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stages button { padding: 10px 4px; font-size: 13px; }
  .stages button:nth-child(3) { border-right: 0; }
  .stages button:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
  .lyrics { min-height: 50vh; font-size: 16px; }
  .file .row-actions { display: flex; }
  .file .icon-btn { width: 34px; height: 34px; }

  dialog:not(.lightbox) { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 14px 14px 0 0; border-bottom: 0; padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px)); }

  .transport-in { grid-template-columns: minmax(0, 1fr) 40px; gap: 6px 12px; padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px)); }
  .play { width: 40px; height: 40px; }
  .transport canvas { grid-column: 1 / -1; grid-row: 2; height: 26px; }
  .time { display: none; }
  .toast { bottom: 110px; }
  .share-head { display: block; }
  .share-head .art { width: 160px; margin-bottom: 18px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
