:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #eef2f7;
  --text: #111827;
  --muted: #667085;
  --line: rgba(15, 23, 42, 0.12);
  --accent: #dc2626;
  --accent-2: #991b1b;
  --button: #111827;
  --button-text: #ffffff;
  --danger: #b42318;
  --shadow: 0 20px 60px rgba(15, 23, 42, 0.10);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg: #090c12;
  --panel: #111827;
  --panel-2: #1f2937;
  --text: #f8fafc;
  --muted: #aab4c3;
  --line: rgba(255, 255, 255, 0.12);
  --accent: #ef4444;
  --accent-2: #f87171;
  --button: #f8fafc;
  --button-text: #111827;
  --danger: #f87171;
  --shadow: 0 20px 70px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(220, 38, 38, 0.14), transparent 32rem),
    radial-gradient(circle at bottom right, rgba(59, 130, 246, 0.10), transparent 30rem),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
.file-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 16px;
  color: var(--text);
  background: var(--panel);
  cursor: pointer;
  touch-action: manipulation;
}

button:hover,
.file-button:hover {
  border-color: rgba(220, 38, 38, 0.5);
}

button:active,
.file-button:active {
  transform: translateY(1px);
}

button.primary {
  border-color: transparent;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  background: var(--panel-2);
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus,
button:focus-visible,
.file-button:focus-visible {
  outline: 3px solid rgba(220, 38, 38, 0.28);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  padding: calc(14px + var(--safe-top)) 14px calc(14px + var(--safe-bottom));
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: center;
  max-width: 1500px;
  margin: 0 auto 14px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 4px;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(135deg, #ef4444, #991b1b);
  font-weight: 900;
}

.brand strong,
.brand span {
  display: block;
  line-height: 1.1;
}

.brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.search {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.search input {
  min-height: 44px;
  border-radius: 999px;
  background: var(--panel-2);
}

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 1.2rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 14px;
  max-width: 1500px;
  margin: 0 auto;
}

.player-column,
.library-panel,
.player-card,
.notice-card,
.results-section {
  min-width: 0;
}

.player-card,
.notice-card,
.results-section,
.library-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.player-card {
  padding: 12px;
}

.player-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 20px;
  background: #05070b;
}

.player-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.empty-player {
  display: grid;
  height: 100%;
  place-content: center;
  padding: 28px;
  color: #fff;
  text-align: center;
}

.empty-player h1 {
  max-width: 720px;
  margin: 0 auto 8px;
  font-size: clamp(1.35rem, 3vw, 2.4rem);
  letter-spacing: -0.04em;
}

.empty-player p {
  max-width: 560px;
  margin: 0 auto;
  color: #cbd5e1;
}

.now-playing {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px 4px 2px;
}

.now-playing h2 {
  margin: 0 0 4px;
  font-size: 1.1rem;
}

.now-playing p,
.notice-card,
.section-heading p,
.muted {
  color: var(--muted);
}

.status-error {
  color: var(--danger) !important;
}

.now-playing p {
  margin: 0;
}

.player-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.player-actions select {
  min-width: 140px;
  border-radius: 999px;
}

.notice-card {
  display: flex;
  gap: 8px;
  margin: 14px 0;
  padding: 14px 16px;
  line-height: 1.45;
}

.results-section,
.library-panel {
  padding: 14px;
}

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

.section-heading h2 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.section-heading p {
  margin: 3px 0 0;
  font-size: 0.92rem;
}

.section-heading.compact {
  margin-bottom: 12px;
}

.section-heading.split {
  align-items: center;
}

.inline-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  white-space: nowrap;
}

.switch input {
  width: 18px;
  height: 18px;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.video-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel);
}

.thumbnail-button {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #05070b;
}

.thumbnail-button img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.duration-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: none;
  padding: 3px 7px;
  border-radius: 999px;
  color: #fff;
  background: rgba(0, 0, 0, 0.72);
  font-size: 0.8rem;
  font-weight: 700;
}

.duration-badge:not(:empty) {
  display: inline-block;
}

.video-info {
  padding: 12px;
}

.video-info h3 {
  display: -webkit-box;
  min-height: 2.7em;
  margin: 0 0 6px;
  overflow: hidden;
  font-size: 0.98rem;
  line-height: 1.35;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.video-info p {
  margin: 0;
}

.channel {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.description {
  display: -webkit-box;
  min-height: 2.6em;
  margin-top: 8px !important;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.3;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.card-actions,
.button-row,
.row-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.card-actions {
  margin-top: 12px;
}

.card-actions button {
  min-height: 38px;
  padding: 0 12px;
  font-size: 0.9rem;
}

.library-panel {
  position: sticky;
  top: 84px;
  align-self: start;
  max-height: calc(100vh - 98px - var(--safe-bottom));
  overflow: auto;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
}

.tab {
  min-height: 38px;
  padding: 0 8px;
  border-color: transparent;
  background: transparent;
  font-size: 0.86rem;
}

.tab.active {
  color: var(--button-text);
  background: var(--button);
}

.tab-panel {
  display: none;
  padding-top: 16px;
}

.tab-panel.active {
  display: block;
}

.stack-form {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.stack-form label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.row-form {
  display: grid;
  grid-template-columns: 1fr auto;
}

.compact-list,
.lists-container {
  display: grid;
  gap: 8px;
}

.compact-item,
.list-box {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel);
}

.compact-item {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 10px;
  padding: 8px;
}

.compact-item img {
  width: 74px;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  object-fit: cover;
  background: #05070b;
}

.compact-item h3 {
  margin: 0 0 2px;
  overflow: hidden;
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-item p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.compact-actions {
  display: flex;
  gap: 6px;
}

.compact-actions button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.8rem;
}

.list-box {
  padding: 10px;
}

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

.list-header h3 {
  margin: 0;
  font-size: 0.95rem;
}

.empty-state {
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  color: var(--muted);
  text-align: center;
}

.danger-soft {
  color: var(--danger);
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#importData {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.details-note {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel);
}

.details-note p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .library-panel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    border-radius: 24px;
  }

  .brand {
    min-width: 0;
  }

  .search {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .now-playing,
  .notice-card,
  .section-heading {
    display: grid;
    grid-template-columns: 1fr;
  }

  .player-actions,
  .inline-controls {
    justify-content: stretch;
  }

  .player-actions button,
  .player-actions select,
  .inline-controls button {
    width: 100%;
  }

  .tabs {
    grid-template-columns: repeat(2, 1fr);
    border-radius: 20px;
  }

  .tab {
    border-radius: 999px;
  }
}
