:root {
  --ground: #15181b;
  --panel: #1c2024;
  --line: #2b3136;
  --ink: #e9eef0;
  --muted: #8c989e;
  --faint: #5f6b70;
  --accent: #3fb6ae;
  --accent-ink: #24302f;
  --hover: #272d32;
  --danger: #e07a6e;
  --playlist-width: 270px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--ground);
  color: var(--ink);
  font: 13px/1.5 "Segoe UI", "Yu Gothic UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  overflow: hidden;
}
[hidden] { display: none !important; }
.for-touch { display: none; }
@media (hover: none) and (pointer: coarse) { .for-pointer { display: none; } .for-touch { display: inline; } }
button { font: inherit; color: inherit; }

.icon { display: inline-flex; width: 18px; height: 18px; flex: none; }
.icon svg { width: 100%; height: 100%; }
.icon-lg { width: 34px; height: 34px; }
.icon-xl { width: 46px; height: 46px; }
.accent { color: var(--accent); }
.muted { color: var(--muted); }

/* Layout: stage and playlist on top, the transport across the full width. */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--playlist-width);
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100vh;
}
.app.no-playlist { grid-template-columns: minmax(0, 1fr) 0; }
.app.no-playlist .playlist { display: none; }

.stage { position: relative; background: #000; overflow: hidden; }
.deck { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: transparent; opacity: 0; visibility: hidden; z-index: 0; }
.deck.is-front { z-index: 1; }
.audio-card, .empty-state { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; z-index: 2; pointer-events: none; }
.empty-state { pointer-events: auto; }
.audio-title { margin: 16px 0 0; font-size: 18px; font-weight: 600; max-width: 520px; overflow-wrap: anywhere; }
.audio-meta { margin: 6px 0 0; color: var(--muted); }
.empty-title { margin: 14px 0 0; font-size: 17px; font-weight: 600; }
.empty-sub { margin: 6px 0 18px; color: var(--muted); }
.empty-note { margin: 22px 0 0; color: var(--faint); font-size: 11px; }
.drop-hint { position: absolute; inset: 16px; z-index: 5; display: grid; place-items: center; border: 2px solid var(--accent); border-radius: 10px; background: rgba(21, 24, 27, 0.7); pointer-events: none; }
.drop-hint p { font-size: 17px; font-weight: 600; }

/* Playlist */
.playlist { grid-column: 2; grid-row: 1; display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-left: 1px solid var(--line); }
.playlist-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 6px 14px; }
.playlist-head p { margin: 0; }
.count { margin-left: 8px; color: var(--muted); }
.playlist-items { flex: 1; min-height: 0; overflow-y: auto; margin: 0 6px; padding: 0; list-style: none; outline: none; }
.playlist-items li { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; align-items: center; margin: 1px 0; padding: 6px 8px; border-radius: 6px; cursor: default; }
.playlist-items li:hover { background: var(--hover); }
.playlist-items li.is-selected { background: #2a3337; }
.playlist-items li .icon { width: 13px; height: 13px; color: var(--muted); }
.playlist-items li .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.playlist-items li .detail { display: block; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.playlist-items li.is-current .icon, .playlist-items li.is-current .name { color: var(--accent); }
.playlist-items li.is-current .name { font-weight: 600; }
.playlist-items li.is-failed .name { color: var(--danger); }
.row-remove { display: inline-grid; place-items: center; width: 24px; height: 24px; margin-left: 4px; padding: 0; border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; visibility: hidden; }
.row-remove svg { width: 13px; height: 13px; }
.row-remove:hover { background: #343c41; color: var(--ink); }
.playlist-items li:hover .row-remove, .playlist-items li.is-selected .row-remove { visibility: visible; }
@media (hover: none) { .row-remove { visibility: visible; } }
.playlist-foot { margin: 6px 14px 10px; color: var(--muted); font-size: 11px; }

/* Transport */
.controls { grid-column: 1 / -1; grid-row: 2; padding: 8px 14px 10px; background: var(--panel); border-top: 1px solid var(--line); }
.seek-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; }
.time { min-width: 44px; color: var(--muted); font-variant-numeric: tabular-nums; }
.time.right { text-align: right; }
.seek-area { position: relative; margin: 0 8px; height: 18px; }
.range-band { position: absolute; top: 4px; height: 10px; border-radius: 3px; background: rgba(63, 182, 174, 0.3); pointer-events: none; }

.slider { -webkit-appearance: none; appearance: none; position: relative; width: 100%; height: 18px; margin: 0; background: transparent; --pct: 0%; }
.slider::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--accent) var(--pct), #33393e var(--pct)); }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; margin-top: -4px; border-radius: 50%; background: var(--ink); }
.slider:disabled::-webkit-slider-thumb { background: #4a5257; }
.slider.volume { width: 96px; }

.button-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; margin-top: 6px; }
.group { display: flex; align-items: center; gap: 2px; }
.status { margin: 0 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-button, .flat-button, .small-button, .text-button, .accent-button { border: 0; background: transparent; cursor: pointer; border-radius: 6px; }
.icon-button { display: inline-grid; place-items: center; width: 36px; height: 32px; padding: 0; }
.icon-button.play { width: 42px; height: 36px; margin: 0 6px; background: var(--accent-ink); color: var(--accent); }
.icon-button.small { width: 28px; height: 28px; }
.icon-button.small .icon { width: 14px; height: 14px; }
.flat-button { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; }
.flat-button .icon { width: 16px; height: 16px; }
#loopButton { margin-left: 10px; }
.small-button { margin-left: 6px; padding: 4px 9px; font-size: 12px; background: #23292d; }
.small-button.ghost { background: transparent; color: var(--muted); }
.text-button { padding: 4px 8px; color: var(--muted); font-size: 12px; }
.accent-button { padding: 8px 16px; background: var(--accent-ink); color: var(--accent); font-weight: 600; }
:is(.icon-button, .flat-button, .small-button, .text-button, .accent-button):hover:not(:disabled) { background-color: var(--hover); }
.icon-button.play:hover { background: #2c3a39; }
:is(button, input):disabled { opacity: 0.35; cursor: default; }

/* Loop range and transition panel */
.options { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; background: #171b1e; }
.option-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 0; min-height: 30px; }
.option-label { width: 76px; flex: none; color: var(--muted); font-size: 12px; }
.time-box { width: 78px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: #101315; color: var(--ink); font: inherit; font-variant-numeric: tabular-nums; text-align: center; outline: none; user-select: text; }
.time-box::placeholder { color: var(--muted); }
.time-box:focus { border-color: var(--accent); }
.time-box.narrow { width: 50px; margin-left: 6px; }
.dash { margin: 0 10px; color: var(--muted); }
.unit { margin-left: 4px; color: var(--muted); }

/* Automatic loop range button in the panel */
.small-button.auto { display: inline-flex; align-items: center; gap: 5px; color: var(--accent); }
.small-button.auto .icon { width: 13px; height: 13px; }
#openTrim { margin-left: auto; }

/* Trimming, in the manner of QuickTime Player: a strip of the whole file with a yellow frame. */
.trim { position: absolute; left: 16px; right: 16px; bottom: 16px; z-index: 4; padding: 10px 12px 12px; border-radius: 12px; background: rgba(28, 32, 36, 0.94); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.trim-top { display: flex; align-items: center; gap: 8px; min-height: 26px; margin: 0 0 8px 60px; }
.trim-auto { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border: 0; border-radius: 6px; background: #23292d; color: var(--accent); font-size: 12px; cursor: pointer; }
.trim-auto .icon { width: 13px; height: 13px; }
.trim-auto.is-busy { color: var(--muted); cursor: progress; }
.trim-auto:hover:not(:disabled) { background: var(--hover); }
.trim-candidates { display: flex; flex-wrap: wrap; gap: 4px; }
.trim-candidate { padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--ink); font-size: 12px; cursor: pointer; }
.trim-candidate .quality { margin-left: 2px; color: var(--muted); font-size: 11px; }
.trim-candidate .quality.great { color: var(--accent); }
.trim-candidate:hover { background: var(--hover); }
.trim-candidate.is-selected { border-color: #f5c400; }
.trim-info { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.trim-bar { display: flex; align-items: center; gap: 20px; }
.trim-play { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border: 0; border-radius: 8px; background: transparent; color: var(--ink); cursor: pointer; }
.trim-play .icon { width: 22px; height: 22px; }
.trim-play:hover { background: var(--hover); }
.trim-strip { position: relative; flex: 1; min-width: 0; height: 56px; border-radius: 6px; background: #0d0f11; overflow: visible; touch-action: none; user-select: none; }
.trim-strip canvas { display: block; width: 100%; height: 100%; border-radius: 6px; }
.trim-note { position: absolute; inset: 0; display: grid; place-items: center; padding: 0 12px; color: var(--muted); font-size: 12px; text-align: center; pointer-events: none; }
.trim-note:empty { display: none; }
.trim-shade { position: absolute; top: 0; bottom: 0; left: 0; background: rgba(0, 0, 0, 0.62); border-radius: 6px 0 0 6px; pointer-events: none; }
.trim-shade.end { left: auto; right: 0; border-radius: 0 6px 6px 0; }
.trim-frame { position: absolute; top: -3px; bottom: -3px; border: 3px solid #f5c400; border-left-width: 12px; border-right-width: 12px; border-radius: 6px; margin: 0 -12px; pointer-events: none; box-sizing: content-box; }
.trim-handle { position: absolute; top: 50%; left: -8px; width: 4px; height: 18px; margin-top: -9px; border-radius: 2px; background: rgba(0, 0, 0, 0.45); }
.trim-handle.end { left: auto; right: -8px; }
.trim-overlap { position: absolute; top: 0; bottom: 0; left: 0; background: repeating-linear-gradient(135deg, rgba(245, 196, 0, 0.28) 0 4px, rgba(245, 196, 0, 0.08) 4px 8px); }
.trim-overlap.end { left: auto; right: 0; }
.trim-playhead { position: absolute; top: -6px; bottom: -6px; width: 2px; margin-left: -1px; border-radius: 1px; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4); pointer-events: none; }
.trim-actions { display: flex; flex-direction: column; gap: 6px; flex: none; }
.trim-apply, .trim-cancel { min-width: 92px; padding: 6px 12px; border: 0; border-radius: 7px; font-size: 12px; font-weight: 600; cursor: pointer; }
.trim-apply { background: var(--accent); color: #0f1d1c; }
.trim-apply:hover { background: #52c4bc; }
.trim-cancel { background: #2f363b; color: var(--ink); }
.trim-cancel:hover { background: #394146; }
.app.is-trimming .empty-state, .app.is-trimming .drop-hint { display: none; }

/* Cut / crossfade: one choice, shown as two segments of one control. */
.segmented { display: inline-flex; padding: 2px; border-radius: 7px; background: #101315; border: 1px solid var(--line); }
.segment { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; }
.segment .icon { width: 15px; height: 15px; }
.segment:hover:not(.is-selected) { color: var(--ink); }
.segment.is-selected { background: var(--accent-ink); color: var(--accent); font-weight: 600; }

.fade-length { display: inline-flex; align-items: center; margin-left: 16px; }
.chips { display: inline-flex; gap: 2px; }
.chip { min-width: 30px; padding: 4px 6px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; cursor: pointer; }
.chip:hover { background: var(--hover); color: var(--ink); }
.chip.is-selected { background: #23292d; color: var(--accent); font-weight: 600; }

/* Two lanes: this pass ends on top, the next starts below; the tinted part is where both play. */
.seam { position: relative; width: 112px; height: 16px; margin-left: 18px; flex: none; }
.seam .lane { position: absolute; height: 6px; border-radius: 2px; background: #3a4247; }
.seam .lane-a { top: 0; left: 0; }
.seam .lane-b { bottom: 0; right: 0; }
.seam .overlap { position: absolute; top: 0; bottom: 0; border-radius: 2px; background: rgba(63, 182, 174, 0.45); }
.seam-note { margin-left: 10px; color: var(--muted); font-size: 11px; }
.small-button.try { display: inline-flex; align-items: center; gap: 5px; margin-left: auto; }
.small-button.try .icon { width: 11px; height: 11px; color: var(--accent); }

.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); padding: 8px 14px; border-radius: 8px; background: #2b3136; color: var(--ink); z-index: 10; }

/* Full screen: the picture fills the window and the playlist steps aside. */
.app.is-fullscreen { grid-template-columns: minmax(0, 1fr) 0; }
.app.is-fullscreen .playlist { display: none; }

/* Phones and narrow windows: picture on top, then the controls, then the list. */
@media (max-width: 720px) {
  body { overflow: auto; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(240px, 1fr); height: auto; min-height: 100vh; min-height: 100dvh; }
  .app.no-playlist, .app.is-fullscreen { grid-template-columns: minmax(0, 1fr); }
  .stage { height: 42vh; min-height: 220px; }
  .app.is-fullscreen .stage { height: 100vh; height: 100dvh; }
  .controls { grid-row: 2; padding: 8px 12px 12px; }
  .playlist { grid-column: 1; grid-row: 3; min-height: 240px; border-left: 0; border-top: 1px solid var(--line); }
  .button-row { grid-template-columns: minmax(0, 1fr) auto; row-gap: 4px; }
  .button-row > .group:first-child { grid-column: 1 / -1; flex-wrap: wrap; }
  .status { grid-column: 1; margin: 0 4px; font-size: 12px; }
  #loopButton { margin-left: 4px; }
  .slider.volume { width: 72px; }
  #fullscreenButton { display: none; }
  .options { padding: 10px; }
  .option-label { width: 100%; margin-bottom: 2px; }
  .option-label:empty { display: none; }
  #openTrim { margin-left: 0; }
  .small-button.auto { margin-top: 6px; }
  .trim { left: 8px; right: 8px; bottom: 8px; padding: 8px; }
  .trim-top { margin-left: 0; flex-wrap: wrap; }
  .trim-info { width: 100%; margin-left: 0; order: 3; }
  .trim-bar { gap: 16px; }
  .trim-play { width: 32px; }
  .trim-apply, .trim-cancel { min-width: 76px; padding: 6px 8px; }
  #trimButton span:last-child { display: none; }
  .fade-length { margin-left: 0; margin-top: 6px; }
  .seam { margin-left: 12px; margin-top: 6px; }
  .small-button.try { margin-left: 0; margin-top: 6px; }
  .empty-note { margin-top: 16px; }
}
@media (max-width: 720px) and (hover: none) {
  .slider.volume { display: none; }
}
