:root {
  color-scheme: light;
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-muted: #f0eee8;
  --ink: #1f2523;
  --muted: #64706d;
  --line: #d8d3c8;
  --accent: #1f7a6b;
  --accent-dark: #15594f;
  --warm: #b8573f;
  --focus: #173b66;
  --shadow: 0 18px 50px rgba(32, 37, 35, 0.12);
  --app-gradient: rgba(31, 122, 107, 0.08);
  --panel-red: #fffaf6;
  --panel-yellow: #fffdf2;
  --panel-blue: #f9fbff;
  --tile-hover: rgba(255, 246, 176, 0.48);
  --folder-hover: #fff1ed;
  --track-bg: #f8f7f3;
  --modal-backdrop: rgba(31, 37, 35, 0.48);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111412;
  --surface: #1b211f;
  --surface-muted: #242b28;
  --ink: #f4f0e8;
  --muted: #a8b4af;
  --line: #3c4541;
  --accent: #58b7a4;
  --accent-dark: #3e927f;
  --warm: #d3856e;
  --focus: #8db7e8;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
  --app-gradient: rgba(88, 183, 164, 0.08);
  --panel-red: #1e1715;
  --panel-yellow: #1e1d14;
  --panel-blue: #151b22;
  --tile-hover: rgba(88, 183, 164, 0.14);
  --folder-hover: rgba(211, 133, 110, 0.14);
  --track-bg: #222825;
  --modal-backdrop: rgba(0, 0, 0, 0.68);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(120deg, var(--app-gradient), transparent 36%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-topbar {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 10;
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand {
  margin-bottom: 22px;
}

.login-brand h1,
.login-brand p {
  margin: 0;
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-error {
  margin: 0 0 16px;
  border: 1px solid rgba(216, 71, 61, 0.4);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(216, 71, 61, 0.1);
  color: var(--warm);
  font-weight: 700;
}

.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 28px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 26px;
  font-weight: 700;
}

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

.brand h1 {
  font-size: 25px;
  line-height: 1.1;
}

.brand p,
.empty-state p,
.eyebrow {
  margin: 4px 0 0;
  color: var(--muted);
}

.panel-form,
label,
.section-title {
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
}

#track-form .input-row {
  grid-template-columns: minmax(120px, 1fr) 42px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(23, 59, 102, 0.14);
}

.icon-button {
  display: grid;
  place-items: center;
  min-width: 42px;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.icon-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 750;
  text-decoration: none;
}

.secondary-button:hover {
  border-color: var(--accent);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: inherit;
}

.section-title strong {
  color: var(--accent);
}

.campaign-list {
  display: grid;
  gap: 8px;
  max-height: min(360px, 45vh);
  overflow: auto;
}

.campaign-button {
  display: grid;
  gap: 3px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.campaign-button:hover,
.campaign-button.active {
  border-color: var(--accent);
  background: rgba(31, 122, 107, 0.1);
}

.campaign-button strong {
  font-size: 15px;
}

.campaign-button span {
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  min-width: 0;
  padding: 28px 36px 36px;
}

.hidden {
  display: none !important;
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: calc(100vh - 140px);
  text-align: center;
}

.campaign-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--modal-backdrop);
}

.campaign-modal-panel {
  display: grid;
  gap: 20px;
  width: min(560px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.campaign-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.campaign-modal-header h2 {
  margin: 0;
  font-size: 28px;
}

.modal-close-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.modal-close-button:hover {
  border-color: var(--accent);
}

.empty-state h2 {
  margin-top: 20px;
  font-size: 36px;
}

.empty-state p {
  max-width: 560px;
  color: var(--muted);
  font-size: 17px;
}

.record-visual {
  display: grid;
  place-items: center;
  width: 190px;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle, #f5f3ee 0 12%, #262b29 13% 24%, #111 25% 31%, #333 32% 42%, #111 43% 51%, #3d3d3d 52% 60%, #111 61%);
  box-shadow: var(--shadow);
}

.record-visual span {
  width: 44px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--warm);
}

.campaign-view {
  display: grid;
  gap: 26px;
}

.workspace-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  color: var(--warm);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.workspace-header h2 {
  margin-top: 4px;
  font-size: 38px;
  line-height: 1.05;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 1fr));
  gap: 10px;
}

.stats div {
  min-width: 88px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
}

.stats strong,
.stats span {
  display: block;
}

.stats strong {
  font-size: 24px;
}

.stats span {
  color: var(--muted);
  font-size: 12px;
}

.library {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  box-shadow: 0 10px 24px rgba(32, 37, 35, 0.05);
}

.library {
  display: grid;
  gap: 14px;
  padding: 18px;
  overflow: visible;
}

.library-tree {
  display: grid;
  gap: 12px;
}

.library-interface {
  display: grid;
  grid-template-columns: minmax(180px, 250px) minmax(320px, 1fr) minmax(320px, 440px);
  min-height: 560px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: visible;
}

.folder-panel,
.playlist-panel,
.playlist-detail-stack {
  min-width: 0;
  padding: 18px;
}

.folder-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-right: 2px solid #d8473d;
  background: var(--panel-red);
}

.playlist-panel {
  border-right: 2px solid #d9be18;
  background: var(--panel-yellow);
}

.playlist-detail-stack {
  position: relative;
  z-index: 5;
  display: grid;
  gap: 14px;
  align-content: start;
  background: var(--panel-blue);
  overflow: visible;
}

.playlist-detail-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--surface);
}

.folder-panel h3,
.playlist-panel h3,
.playlist-detail-stack h3,
.playlist-detail-panel h3 {
  margin: 0 0 14px;
  font-size: 16px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-heading h3 {
  margin: 0;
}

.panel-add-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.panel-add-button:hover {
  background: var(--accent-dark);
}

.folder-button {
  display: grid;
  gap: 3px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

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

.folder-actions {
  position: relative;
  flex: 0 0 auto;
}

.folder-menu-button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  color: var(--ink);
  cursor: pointer;
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
}

.folder-menu-button:hover {
  border-color: var(--accent);
}

.folder-button:hover,
.folder-button.active {
  border-color: var(--warm);
  background: var(--folder-hover);
}

.folder-button[draggable="true"] {
  cursor: grab;
}

.folder-button.dragging {
  opacity: 0.48;
  border-style: dashed;
}

.folder-button.drop-before {
  box-shadow: inset 0 3px 0 var(--accent);
}

.folder-button.drop-after {
  box-shadow: inset 0 -3px 0 var(--accent);
}

.folder-button.drop-target {
  border-color: var(--accent);
  background: rgba(31, 122, 107, 0.12);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.folder-button span {
  font-weight: 800;
}

.folder-button small,
.playlist-tile small,
.playlist-detail-header p,
.detail-empty p {
  color: var(--muted);
}

.playlist-button-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 18px;
  align-content: start;
}

.playlist-tile {
  position: relative;
  display: grid;
  justify-items: center;
  align-items: start;
  gap: 9px;
  min-height: 164px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 12px 14px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: center;
}

.playlist-actions {
  position: relative;
}

.playlist-tile-top {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 100%;
  min-height: 30px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.playlist-menu-button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 68%, transparent);
  color: var(--ink);
  cursor: pointer;
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
}

.playlist-menu-button:hover {
  border-color: var(--accent);
}

.folder-action-panel,
.playlist-action-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  display: grid;
  gap: 8px;
  width: min(280px, calc(100vw - 48px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
}

.folder-action-panel button,
.playlist-action-panel button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--track-bg);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.folder-action-panel button:hover:not(:disabled),
.playlist-action-panel button:hover:not(:disabled) {
  border-color: var(--accent);
}

.folder-action-panel button:disabled,
.playlist-action-panel button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.folder-action-panel label,
.playlist-action-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.playlist-tile:hover,
.playlist-tile.active {
  border-color: #c6b21f;
  background: var(--tile-hover);
}

.playlist-tile.dragging {
  opacity: 0.48;
  border-style: dashed;
}

.playlist-tile.drop-before {
  box-shadow: inset 4px 0 0 var(--accent);
}

.playlist-tile.drop-after {
  box-shadow: inset -4px 0 0 var(--accent);
}

.playlist-disc {
  display: block;
  width: 62px;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--panel-yellow) 0 15%, #262b29 16% 28%, #111 29% 40%, #3d3d3d 41% 58%, #111 59%);
  box-shadow: 0 8px 18px rgba(32, 37, 35, 0.12);
}

.playlist-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.playlist-detail-header h3,
.playlist-detail-header p {
  margin: 0;
}

.playlist-open-options {
  display: grid;
  gap: 10px;
  margin: 0 0 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 68%, transparent);
}

.playlist-detail-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.detail-track {
  position: relative;
  grid-template-columns: 1fr !important;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 12px !important;
  background: var(--surface);
  cursor: grab;
  overflow: visible;
}

.detail-track:active {
  cursor: grabbing;
}

.detail-track:hover {
  border-color: rgba(31, 122, 107, 0.42);
  box-shadow: 0 8px 18px rgba(32, 37, 35, 0.08);
}

.detail-track.is-playing {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  box-shadow: inset 4px 0 0 var(--accent);
}

.detail-track.dragging {
  opacity: 0.48;
  border-style: dashed;
}

.detail-track.drop-before {
  box-shadow: inset 0 3px 0 var(--accent);
}

.detail-track.drop-after {
  box-shadow: inset 0 -3px 0 var(--accent);
}

.track-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.folder-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: visible;
}

.folder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface-muted);
}

.folder-header strong {
  font-size: 16px;
}

.folder-header span,
.playlist-empty {
  color: var(--muted);
  font-size: 13px;
}

.playlist-list {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.playlist-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

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

.playlist-card h3 {
  margin: 0;
  font-size: 15px;
}

.playlist-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.loop-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.loop-toggle input {
  width: 16px;
  min-height: auto;
  height: 16px;
  accent-color: var(--accent);
}

.playlist-play-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
}

.playlist-play-button:hover {
  background: var(--accent-dark);
}

.playlist-stop-button {
  min-height: 34px;
  border: 0;
  border-radius: 8px;
  padding: 0 10px;
  background: var(--warm);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

.playlist-stop-button:hover {
  filter: brightness(0.92);
}

.playlist-close-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
}

.playlist-close-button:hover {
  border-color: var(--warm);
}

.track-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.track-list li {
  display: grid;
  grid-template-columns: minmax(120px, 220px) minmax(220px, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 34px;
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--track-bg);
}

.track-title {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.track-player {
  width: 100%;
  min-width: 180px;
  height: 36px;
}

.track-missing {
  color: var(--warm);
  font-size: 13px;
}

.track-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  z-index: 30;
}

.track-menu-button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  line-height: 1;
}

.track-menu-button:hover {
  border-color: var(--accent);
}

.track-action-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 1000;
  display: grid;
  gap: 8px;
  width: min(320px, calc(100vw - 48px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.track-action-panel button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--track-bg);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.track-action-panel button:hover:not(:disabled) {
  border-color: var(--accent);
}

.track-action-panel button:disabled,
.track-action-panel select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.track-action-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.empty-note {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 980px) {
  .workspace {
    padding: 24px;
  }

  .workspace-header {
    align-items: stretch;
    flex-direction: column;
  }

  .library-interface {
    grid-template-columns: 1fr;
  }

  .folder-panel,
  .playlist-panel,
  .playlist-detail-stack {
    border-right: 0;
    border-bottom: 2px solid var(--line);
  }
}

@media (max-width: 620px) {
  .workspace {
    padding: 18px;
  }

  .app-topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .secondary-button {
    width: 100%;
  }

  .empty-state h2,
  .workspace-header h2 {
    font-size: 29px;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  #track-form .input-row,
  .stacked-mobile {
    grid-template-columns: 1fr;
  }

  .track-list li {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .detail-track {
    grid-template-columns: 1fr !important;
  }

  .icon-button {
    width: 100%;
  }
}
