:root {
  --bg: #0a0c12;
  --surface: #141826;
  --surface-2: #1c2233;
  --border: #2a3145;
  --text: #e9ecf5;
  --muted: #98a2bd;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --ok: #34d399;
  --warn: #fbbf24;
  --error: #f87171;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 600px at 20% -10%, #171b2e 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

body { display: flex; flex-direction: column; min-height: 100vh; }

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

button {
  cursor: pointer;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.85rem;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
}
button:hover { border-color: var(--accent); }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.danger { border-color: #7f1d1d; color: #fca5a5; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.topbar {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.7rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(20, 24, 38, 0.85);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 700; letter-spacing: -0.02em; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--error); }
.brand .dot.online { background: var(--ok); box-shadow: 0 0 12px var(--ok); }
.brand small { color: var(--muted); font-weight: 500; }
.brand .logo {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: inline-block;
}
.spacer { flex: 1; }
.badge {
  font-size: 0.75rem; color: var(--muted); text-decoration: none;
  border: 1px solid var(--border); border-radius: 999px;
  padding: 0.25rem 0.7rem; white-space: nowrap;
}

.tabs {
  display: flex; gap: 0.5rem; padding: 0.6rem 1.25rem;
  overflow-x: auto; border-bottom: 1px solid var(--border);
}
.tab {
  display: flex; align-items: center; gap: 0.5rem; white-space: nowrap;
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 0.45rem 0.9rem; border-radius: 999px;
}
.tab.active { background: var(--surface); border-color: var(--accent); color: var(--text); }
.tab .state { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.tab .state.running { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.tab .state.starting { background: var(--warn); }
.tab .state.error { background: var(--error); }
.tab .state.finished { background: var(--accent-2); }
.tab .state.idle { background: #556; }

.layout {
  flex: 1; display: grid; gap: 1.1rem;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  padding: 1.1rem clamp(1rem, 3vw, 2rem);
  align-content: start;
}
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
}

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

[hidden] { display: none !important; }

.video-box {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
}
.video-box video, .video-box iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #000;
}
.video-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  padding: 2rem;
  font-size: 0.95rem;
}

.video-bar {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.75rem 0.9rem; border-top: 1px solid var(--border);
}
#run {
  min-width: 130px; font-size: 0.98rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
}
#run.playing { background: #3a2030; border-color: #7f1d1d; color: #fca5a5; }
.video-bar .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.video-bar .sub { color: var(--muted); font-size: 0.8rem; }

.captions-card { display: flex; flex-direction: column; height: 100%; min-height: 320px; }
.captions-head {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
  color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em;
}
.captions {
  flex: 1; overflow-y: auto; padding: 0.75rem 1.1rem 1.1rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  max-height: 62vh; scroll-behavior: smooth;
}
.block { padding: 0.55rem 0; border-bottom: 1px dashed rgba(42, 49, 69, 0.55); }
.block .original { color: var(--muted); font-size: 1.02rem; line-height: 1.4; }
.block .translation { font-size: 1.3rem; line-height: 1.35; margin-top: 0.15rem; }

.live {
  border-left: 3px solid var(--accent);
  padding: 0.4rem 0 0.4rem 0.85rem;
  background: linear-gradient(90deg, rgba(124, 92, 255, 0.10), transparent 70%);
  border-radius: 0 8px 8px 0;
  margin-top: 0.4rem;
}
.live .original { color: #c3cbe3; font-size: clamp(1rem, 1.5vw, 1.2rem); min-height: 1.4em; }
.live .translation {
  font-size: clamp(1.5rem, 2.8vw, 2.4rem); font-weight: 650;
  line-height: 1.25; min-height: 1.2em; letter-spacing: -0.01em;
}
.live .translation:empty::after { content: "…"; color: var(--muted); }

.statsbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.7rem 1.3rem;
  padding: 0.6rem clamp(1rem, 3vw, 2rem);
  border-top: 1px solid var(--border); color: var(--muted); font-size: 0.82rem;
}
.statsbar strong { color: var(--text); }
.statsbar a { color: var(--muted); }

.pill { padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.75rem; border: 1px solid var(--border); }
.pill.running { color: var(--ok); border-color: rgba(52, 211, 153, 0.5); }
.pill.idle, .pill.stopped { color: var(--muted); }
.pill.starting { color: var(--warn); border-color: rgba(251, 191, 36, 0.5); }
.pill.error { color: var(--error); border-color: rgba(248, 113, 113, 0.5); }
.pill.finished { color: var(--accent-2); }

.empty { color: var(--muted); text-align: center; margin: auto; font-size: 0.95rem; }

dialog {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.5rem; width: min(520px, 92vw);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin-top: 0; }
.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.9rem; }
.field label { font-size: 0.8rem; color: var(--muted); }
.field input, .field select {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.55rem 0.7rem;
}
.row { display: flex; gap: 0.75rem; }
.row .field { flex: 1; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 0.5rem; }

.page { padding: 1.25rem; max-width: 1100px; margin: 0 auto; width: 100%; }
.page h1 { margin-top: 0; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }

body[data-lang="translation"] .original { display: none; }
body[data-lang="original"] .translation { display: none; }
