:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: #191c22;
  --panel-2: #20242b;
  --text: #f4f0e9;
  --muted: #a7aeb8;
  --line: #303640;
  --accent: #f0b35a;
  --accent-2: #54b5a9;
  --danger: #e07171;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
  --radius: 8px;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  touch-action: manipulation;
}

body {
  overflow: hidden;
}

.app-shell {
  -webkit-user-select: none;
  user-select: none;
}

input,
textarea {
  -webkit-user-select: text;
  user-select: text;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  min-height: 100dvh;
  background:
    radial-gradient(
      circle at 50% -20%,
      rgba(84, 181, 169, 0.18),
      transparent 36rem
    ),
    linear-gradient(180deg, #151820 0%, var(--bg) 42%);
  padding: max(env(safe-area-inset-top), 10px) 12px
    max(env(safe-area-inset-bottom), 10px);
  gap: 10px;
}

.topbar,
.player,
.library-pane,
.queue-pane {
  background: rgba(25, 28, 34, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 10px 12px;
  gap: 12px;
}

.topbar h1,
.queue-header h2,
.empty-state h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 1.2rem;
  line-height: 1.1;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  max-width: min(68vw, 32rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-grid {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
  gap: 10px;
}

.library-pane,
.queue-pane {
  min-height: 0;
  overflow: hidden;
}

.library-pane {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.queue-pane {
  display: none;
}

.queue-pane[hidden] {
  display: none;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 12px;
}

.search-box {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #11141a;
}

.search-box svg,
.icon-button svg,
.mini-button svg,
.text-button svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.search-box svg {
  color: var(--muted);
}

.search-box input,
.playlist-form input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.search-box input::placeholder,
.playlist-form input::placeholder {
  color: #7f8791;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 0 10px 10px;
}

.tab,
.text-button,
.wide-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #171a20;
  color: var(--text);
}

.tab {
  color: var(--muted);
}

.tab.active,
.text-button:active,
.wide-button:active {
  background: #252b33;
  color: var(--text);
}

.text-button:disabled {
  color: #656d78;
  cursor: not-allowed;
}

.wide-button {
  width: 100%;
  background: var(--accent);
  border-color: var(--accent);
  color: #15120c;
  font-weight: 700;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #171a20;
  color: var(--text);
}

.icon-button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #15120c;
}

.icon-button.toggle.active {
  border-color: var(--accent-2);
  color: var(--accent-2);
}

.icon-button.toggle[data-repeat="one"] {
  position: relative;
}

.icon-button.toggle[data-repeat="one"]::after {
  content: "1";
  position: absolute;
  right: 7px;
  bottom: 6px;
  display: grid;
  place-items: center;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent-2);
  color: #111318;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1;
}

.icon-button.play {
  width: 52px;
  height: 52px;
  background: var(--text);
  color: #14161c;
  border-color: var(--text);
}

.icon-button svg {
  width: 22px;
  height: 22px;
}

.view {
  display: none;
  grid-row: 3;
  min-height: 0;
  overflow: auto;
  overflow-x: hidden;
  padding: 0 12px 12px;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.view.active {
  display: block;
}

.track-list,
.playlist-list,
.queue-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.track-row,
.playlist-row,
.queue-row {
  display: grid;
  align-items: center;
  gap: 10px;
  min-width: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.track-row {
  grid-template-columns: 42px minmax(0, 1fr);
  min-height: 64px;
  padding: 8px 10px;
}

.track-row.current {
  border-radius: var(--radius);
  background: rgba(84, 181, 169, 0.14);
  box-shadow: inset 3px 0 0 var(--accent-2);
}

.track-row.current .row-title {
  color: #ffffff;
}

.playlist-row {
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 56px;
  padding: 8px 10px;
}

.playlist-row.selected {
  border-radius: var(--radius);
  background: rgba(240, 179, 90, 0.1);
  box-shadow: inset 3px 0 0 var(--accent);
}

.queue-row {
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 48px;
  padding: 6px 10px;
}

.thumb,
.artwork {
  background:
    radial-gradient(circle at 50% 50%, #111318 0 18%, transparent 19%),
    conic-gradient(from 90deg, #f0b35a, #54b5a9, #d85f6b, #f0b35a);
}

.thumb {
  width: 42px;
  height: 42px;
  border-radius: 6px;
  background-size: cover;
  background-position: center;
}

.row-copy {
  min-width: 0;
}

.row-title,
.row-subtitle {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-title {
  color: var(--text);
  font-weight: 700;
  line-height: 1.25;
}

.row-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mini-button {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #171a20;
  color: var(--muted);
}

.mini-button svg {
  width: 19px;
  height: 19px;
}

.mini-button.danger {
  color: var(--danger);
}

.plain-row-button {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  color: inherit;
}

.empty-state {
  display: grid;
  grid-row: 3;
  place-items: center;
  align-content: center;
  gap: clamp(8px, 2dvh, 14px);
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 8px 16px 16px;
  text-align: center;
  color: var(--muted);
}

.empty-state[hidden] {
  display: none;
}

.empty-state:not([hidden]) ~ .view {
  display: none;
}

.empty-state h2 {
  color: var(--text);
  font-size: clamp(1.05rem, 4.6vw, 1.35rem);
  line-height: 1.15;
}

.empty-state p {
  margin: 0;
  max-width: 26rem;
  line-height: 1.35;
  font-size: 0.9rem;
}

.empty-visual {
  width: min(58vw, 260px, 28dvh);
  aspect-ratio: 1 / 1;
  height: auto;
  object-fit: cover;
  border-radius: var(--radius);
  background: #11141a;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.32);
}

.empty-backup,
.empty-state.video-fallback .empty-visual:not(.empty-backup) {
  display: none;
}

.empty-backup {
  aspect-ratio: 992 / 681;
  object-fit: contain;
  background: transparent;
}

.empty-state.video-fallback .empty-backup {
  display: block;
  width: auto;
  height: min(28dvh, 220px);
  max-width: 100%;
}

@media (max-height: 700px) {
  .empty-state p {
    display: none;
  }

  .empty-visual {
    width: min(48vw, 190px, 24dvh);
  }
}

@media (max-height: 650px) {
  .empty-state {
    gap: 8px;
    padding-block: 6px 10px;
  }

  .empty-state .empty-visual:not(.empty-backup) {
    display: none;
  }

  .empty-state .empty-backup {
    display: block;
    width: auto;
    height: min(18dvh, 120px);
    max-width: 100%;
  }

  .empty-state .wide-button {
    min-height: 34px;
  }
}

.playlist-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 0 0 12px;
}

.playlist-form input {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #11141a;
  color: var(--text);
  padding: 0 12px;
}

.playlist-track-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 2px solid var(--line);
}

.playlist-detail {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  margin: 2px 0 8px;
  padding: 0 0 0 12px;
}

.playlist-add-button {
  justify-self: start;
  display: inline-grid;
  grid-template-columns: 18px auto;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
}

.playlist-add-button svg {
  width: 18px;
  height: 18px;
}

.playlist-track-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  padding: 4px 0 4px 10px;
}

.empty-playlist {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.58);
}

.modal[hidden] {
  display: none;
}

.modal-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  width: min(720px, 100%);
  max-height: min(720px, 86dvh);
  min-height: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-header h2 {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1rem;
}

.modal-track-list {
  overflow: auto;
}

.modal-track-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.modal-track-row input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.queue-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
}

.queue-header h2 {
  font-size: 1rem;
}

.queue-list {
  overflow: auto;
  max-height: calc(100% - 62px);
  padding: 0 10px 10px;
}

.player {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 10px;
}

.player[hidden] {
  display: none;
}

.now-playing {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.artwork {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  background-size: cover;
  background-position: center;
}

.track-copy {
  min-width: 0;
}

.track-copy strong,
.track-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track-copy span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.86rem;
}

.transport {
  display: grid;
  grid-template-columns: repeat(5, auto);
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.timeline {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.timeline span:last-child {
  text-align: right;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.hidden-input {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

@media (min-width: 860px) {
  .app-shell {
    padding: 18px;
  }

  .main-grid {
    grid-template-columns: minmax(0, 1fr) 340px;
  }

  .main-grid:has(.queue-pane[hidden]) {
    grid-template-columns: minmax(0, 1fr);
  }

  .queue-pane {
    display: block;
  }

  .view {
    padding-bottom: 14px;
  }

  .player {
    grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
    align-items: center;
  }
}

@media (hover: hover) {
  button:hover {
    border-color: #596270;
  }
}
