:root {
  --bg: #0f1115;
  --panel: #161923;
  --panel-2: #1c202c;
  --border: #2a2f3d;
  --text: #e6e8ee;
  --text-dim: #9aa0b0;
  --accent: #6d8dfc;
  --accent-dim: #3b4a7d;
  --green: #4ade80;
  --yellow: #fbbf24;
  --red: #f87171;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.layout {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 15px;
  margin: 0;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.song-list {
  overflow-y: auto;
  flex: 1;
}

.tiktok-panel {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.tiktok-panel .tiktok-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tiktok-panel .tiktok-label {
  color: var(--text-dim);
}

.tiktok-panel .tiktok-connected {
  color: var(--green);
  font-weight: 600;
}

.tiktok-panel .tiktok-hint {
  color: var(--text-dim);
  font-size: 11px;
  margin-top: 6px;
  line-height: 1.5;
}

.song-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.song-item:hover { background: var(--panel-2); }
.song-item.active { background: var(--panel-2); border-left: 3px solid var(--accent); }

.song-item-name {
  font-weight: 600;
  margin-bottom: 4px;
}

.song-item-meta {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  gap: 8px;
  align-items: center;
}

.main {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

.empty-state {
  color: var(--text-dim);
  text-align: center;
  margin-top: 20vh;
}

.spinner-wrap {
  display: flex;
  justify-content: center;
  padding: 40px 0;
}

/* `.spinner-wrap`'s own `display: flex` ties in CSS specificity with the
 * browser default `[hidden] { display: none }` and (being defined later)
 * wins the tie — so without this, setting the `hidden` attribute/property
 * via JS silently has no visual effect and the spinner shows permanently. */
.spinner-wrap[hidden] {
  display: none;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

.detail-header h2 {
  margin: 0 0 6px 0;
}

.run-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.force-realign-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: help;
  white-space: nowrap;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.title-row .btn {
  opacity: 0.6;
}

.title-row .btn:hover {
  opacity: 1;
}

.title-input {
  font-size: 20px;
  font-weight: 600;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 2px 8px;
  margin: 0 0 6px 0;
  font-family: inherit;
}

.meta {
  color: var(--text-dim);
  font-size: 13px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.badge-pending { background: #3a3320; color: var(--yellow); }
.badge-posted { background: #1e3a2b; color: var(--green); }
.badge-failed { background: #3a2020; color: var(--red); }
.badge-running { background: var(--accent-dim); color: var(--accent); }

section { margin-bottom: 32px; }

section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.log-output {
  background: #0a0b0f;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  max-height: 260px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  color: #a8f0c0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.lyrics-output {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  white-space: pre-wrap;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-dim);
  max-height: 300px;
  overflow-y: auto;
}

.plan-line-count {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 12px;
}

.plan-form {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.plan-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}

.plan-form .hint {
  font-weight: 400;
  font-size: 11px;
}

.plan-form input[type="text"],
.plan-form input[type="number"] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}

.plan-target-label input {
  max-width: 160px;
}

.plan-actions {
  display: flex;
  gap: 10px;
}

.plan-status {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-dim);
}

.batch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}

.batch-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.batch-card video {
  width: 100%;
  aspect-ratio: 9 / 16;
  background: #000;
  display: block;
}

.batch-card-body {
  padding: 10px 12px;
}

.batch-card-title {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.batch-card-score {
  font-size: 11px;
  color: var(--accent);
}

.batch-card-empty {
  aspect-ratio: 9 / 16;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 12px;
}

.queue-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.queue-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 500;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.queue-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.queue-table caption-cell {
  color: var(--text-dim);
}

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
}

.btn:hover { border-color: var(--accent-dim); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0d12;
  font-weight: 600;
}

.btn-primary:hover { background: #7f9bff; }

.btn-small {
  padding: 4px 10px;
  font-size: 12px;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  width: 480px;
  max-width: 90vw;
}

.modal h2 { margin-top: 0; }

.modal form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}

.modal .hint { font-weight: 400; font-size: 11px; }

.modal input[type="text"],
.modal textarea,
.modal input[type="file"] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}

.modal textarea {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  resize: vertical;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.form-error {
  color: var(--red);
  font-size: 13px;
}
