:root {
  color-scheme: light;
  --bg: #f3f5f1;
  --surface: #ffffff;
  --surface-soft: #eef3eb;
  --text: #18211d;
  --muted: #647067;
  --line: #dbe2dc;
  --accent: #126b57;
  --accent-strong: #0b4e44;
  --danger: #b93838;
  --shadow: 0 18px 50px rgba(25, 38, 31, 0.12);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121714;
  --surface: #1a211d;
  --surface-soft: #223029;
  --text: #edf4ee;
  --muted: #a8b5ad;
  --line: #334139;
  --accent: #52b89d;
  --accent-strong: #7bd0b8;
  --danger: #ff7b7b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #edf3ea 0%, var(--bg) 42%, #f8f4ee 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] body {
  background: linear-gradient(180deg, #101613 0%, var(--bg) 55%, #181813 100%);
}

button,
input,
textarea {
  font: inherit;
}

button,
.primary-link {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  padding: 12px 18px;
  text-decoration: none;
  transition:
    transform 160ms ease,
    background 160ms ease,
    opacity 160ms ease;
}

button:hover,
.primary-link:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.ghost-button {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}

.ghost-button:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.ghost-button.is-active {
  border-color: var(--accent);
  color: var(--accent);
}

.danger-button {
  background: transparent;
  border: 1px solid #f0c7c7;
  color: var(--danger);
  padding: 10px 14px;
}

.danger-button:hover {
  background: #fff1f1;
  color: var(--danger);
}

.compact {
  padding: 10px 14px;
}

.topbar {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin: 0 auto;
  max-width: 1180px;
  padding: 34px 24px 18px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.topbar h1,
.section-heading h2,
.login-panel h1 {
  letter-spacing: 0;
  margin: 0;
}

.topbar h1 {
  font-size: clamp(32px, 5vw, 56px);
  line-height: 1;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.layout {
  display: grid;
  gap: 24px;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  margin: 0 auto;
  max-width: 1180px;
  padding: 20px 24px 48px;
}

.app-view {
  display: none;
}

.app-view.is-active {
  display: grid;
}

.download-panel,
.history-panel,
.login-panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(219, 226, 220, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.download-panel {
  align-self: start;
  padding: 22px;
  position: sticky;
  top: 18px;
}

.download-form {
  display: grid;
  gap: 16px;
}

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

textarea,
input {
  background: #fbfcfb;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  min-width: 0;
  outline: none;
  padding: 14px;
  resize: vertical;
  width: 100%;
}

.hint-text {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  margin: -8px 0 0;
}

textarea:focus,
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 107, 87, 0.14);
}

.format-row {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.format-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  display: grid;
  gap: 6px;
  min-height: 132px;
  padding: 14px;
}

.format-card input {
  height: 18px;
  margin: 0;
  width: 18px;
}

.format-card span {
  font-size: 24px;
}

.format-card strong {
  font-size: 18px;
}

.format-card small {
  color: var(--muted);
  line-height: 1.35;
}

.format-card:has(input:checked) {
  background: var(--surface-soft);
  border-color: var(--accent);
}

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

.cookie-panel,
.admin-panel {
  border-top: 1px solid var(--line);
  margin-top: 20px;
  padding-top: 16px;
}

.cookie-heading {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.cookie-heading span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.cookie-status {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.cookie-row {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  font-size: 13px;
  justify-content: space-between;
  padding: 9px 10px;
}

.admin-status {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: 10px 0 0;
}

.cookie-row strong {
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  padding: 4px 8px;
}

.cookie-row.is-valid strong {
  background: var(--accent);
}

.cookie-row.is-missing strong {
  background: #8b948e;
}

.form-message,
.error-text {
  color: var(--danger);
  font-size: 14px;
  margin: 0;
}

.history-panel {
  min-width: 0;
  padding: 22px;
}

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

.jobs-list {
  display: grid;
  gap: 14px;
}

.job-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 14px;
  padding: 16px;
}

.job-main {
  display: grid;
  gap: 14px;
  grid-template-columns: 46px minmax(0, 1fr);
}

.job-icon {
  align-items: center;
  background: var(--surface-soft);
  border-radius: 8px;
  display: flex;
  color: var(--accent);
  font-size: 14px;
  font-weight: 900;
  height: 46px;
  justify-content: center;
  width: 46px;
}

.job-title-row {
  align-items: start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.job-title-row h3 {
  font-size: 17px;
  line-height: 1.25;
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.status-pill {
  border-radius: 999px;
  color: #fff;
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 9px;
}

.status-queued .status-pill {
  background: #6d7680;
}

.status-running .status-pill {
  background: #2f6cb3;
}

.status-done .status-pill {
  background: var(--accent);
}

.status-error .status-pill {
  background: var(--danger);
}

.job-url,
.job-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: 7px 0 0;
  overflow-wrap: anywhere;
}

.job-details {
  margin-top: 10px;
}

.job-details summary {
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.job-details pre {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
  margin: 8px 0 0;
  overflow-x: auto;
  padding: 10px;
  white-space: pre-wrap;
}

.media-preview {
  margin-top: 14px;
}

.media-preview audio,
.media-preview video {
  background: #111;
  border-radius: 8px;
  display: block;
  max-height: 420px;
  width: 100%;
}

.media-preview audio {
  background: transparent;
}

.rename-form {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(180px, 1fr) auto;
  margin-top: 12px;
}

.rename-form input {
  padding: 11px 12px;
}

.rename-message {
  color: var(--danger);
  font-size: 13px;
  grid-column: 1 / -1;
  margin: 0;
}

.progress-track {
  background: #e5ebe5;
  border-radius: 999px;
  height: 9px;
  margin-top: 12px;
  overflow: hidden;
}

.progress-fill {
  background: linear-gradient(90deg, var(--accent), #d39a35);
  height: 100%;
  width: 0;
}

.job-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.empty-state {
  background: var(--surface-soft);
  border-radius: 8px;
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.library-view {
  margin: 0 auto;
  max-width: 100%;
  padding: 0 0 48px;
  width: 100%;
}

.video-console {
  background: #050606;
  border-top: 1px solid #151817;
  color: #d8f900;
  min-height: calc(100vh - 132px);
  width: 100%;
}

.preset-bar {
  align-items: center;
  background: #080908;
  border-bottom: 1px solid #171a18;
  display: flex;
  gap: 10px;
  min-height: 44px;
  overflow-x: auto;
  padding: 8px 16px;
}

.preset-bar span {
  color: #44504b;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.preset-button {
  background: #0d0f0e;
  border: 1px solid #222823;
  border-radius: 0;
  color: #66726c;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  min-width: 74px;
  padding: 5px 10px;
}

.preset-button:hover,
.preset-button.is-active {
  background: #151a12;
  border-color: #d8f900;
  color: #d8f900;
  transform: none;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--grid-rows), minmax(150px, 1fr));
  min-height: calc(100vh - 178px);
}

.video-slot {
  background: #0b0d0c;
  border: 3px solid #020303;
  display: grid;
  min-height: 190px;
  overflow: hidden;
  place-items: center;
  position: relative;
}

.video-slot video {
  height: 100%;
  object-fit: contain;
  width: 100%;
}

.video-slot p {
  bottom: 38%;
  color: rgba(216, 249, 0, 0.45);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  left: 16px;
  max-width: calc(100% - 32px);
  overflow: hidden;
  position: absolute;
  right: 16px;
  text-align: center;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.slot-empty {
  align-items: center;
  border: 1px solid #171c19;
  border-radius: 4px;
  color: #121713;
  display: flex;
  height: 30px;
  justify-content: center;
  width: 30px;
}

.slot-number {
  bottom: 10px;
  color: #28312c;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  position: absolute;
  right: 12px;
}

.audio-library {
  margin: 0 auto;
  max-width: 980px;
  padding: 20px 24px 56px;
}

.audio-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.audio-playlist {
  display: grid;
  gap: 12px;
}

.audio-track {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 14px;
  grid-template-columns: 42px minmax(0, 1fr) minmax(240px, 360px);
  padding: 14px;
}

.track-number {
  align-items: center;
  background: var(--surface-soft);
  border-radius: 8px;
  color: var(--accent);
  display: flex;
  font-weight: 900;
  height: 42px;
  justify-content: center;
}

.track-copy h3 {
  font-size: 16px;
  margin: 0;
  overflow-wrap: anywhere;
}

.track-copy p {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 0;
}

.audio-track audio {
  width: 100%;
}

.login-page {
  display: grid;
  place-items: center;
}

.login-shell {
  max-width: 460px;
  padding: 24px;
  width: 100%;
}

.login-panel {
  padding: 28px;
}

.brand-mark {
  align-items: center;
  background: var(--accent);
  border-radius: 8px;
  color: #fff;
  display: flex;
  font-weight: 900;
  height: 52px;
  justify-content: center;
  margin-bottom: 18px;
  width: 52px;
}

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

.password-row {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
}

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

  .download-panel {
    position: static;
  }

  .audio-track {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .audio-track audio {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .topbar,
  .section-heading,
  .actions-row,
  .job-title-row {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions > * {
    width: 100%;
  }

  .format-row,
  .password-row,
  .rename-form {
    grid-template-columns: 1fr;
  }

  .job-main {
    grid-template-columns: 1fr;
  }

  .job-actions {
    justify-content: stretch;
  }

  .job-actions > * {
    text-align: center;
    width: 100%;
  }

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