:root {
  color-scheme: dark light;
  --bg: #0f172a;
  --bg-panel: #111827;
  --bg-alt: rgba(255, 255, 255, 0.04);
  --text: #f8fafc;
  --text-muted: #cbd5f5;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --warning: #fbbf24;
  --error: #f87171;
  --success: #34d399;
  --font-stack: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-stack);
  background: linear-gradient(160deg, #0f172a 0%, #1e293b 60%, #0f172a 100%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  padding: 2rem clamp(1rem, 4vw, 3rem);
  text-align: center;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.app-header h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  letter-spacing: 0.04em;
}

.tagline {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: clamp(1rem, 3vw, 2rem);
  padding: clamp(1rem, 3vw, 2.5rem);
  flex: 1;
}

.panel {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 16px;
  padding: clamp(1rem, 3vw, 1.75rem);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.35);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.25);
  color: var(--text-muted);
  position: relative;
}

.status-badge::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
  box-shadow: 0 0 0 rgba(56, 189, 248, 0.4);
  transition: 0.3s ease;
}

.status-live {
  color: var(--success);
  border-color: rgba(52, 211, 153, 0.5);
}

.status-live::before {
  background: var(--success);
  box-shadow: 0 0 0 6px rgba(52, 211, 153, 0.15);
}

.status-error {
  color: var(--error);
  border-color: rgba(248, 113, 113, 0.5);
}

.status-error::before {
  background: var(--error);
  box-shadow: 0 0 0 6px rgba(248, 113, 113, 0.12);
}

.status-disconnected {
  color: var(--text-muted);
}

.status-idle {
  color: var(--warning);
  border-color: rgba(251, 191, 36, 0.4);
}

.form-grid {
  display: grid;
  gap: 1rem;
}

.advanced-toggle {
  margin-top: 0.35rem;
}

.advanced-settings {
  display: grid;
  gap: 1rem;
  padding: 0.85rem;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 12px;
}

.advanced-settings[hidden] {
  display: none !important;
}

.advanced-settings label {
  margin: 0;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.95rem;
  color: var(--text-muted);
}

input,
select,
textarea {
  background: rgba(148, 163, 184, 0.1);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  color: var(--text);
  font-size: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.25);
}

textarea {
  resize: vertical;
}

.form-actions {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.75rem;
}

button {
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.4rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  font-size: 1rem;
}

.viewer-link {
  margin-top: 0.5rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(148, 163, 184, 0.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.viewer-link-info {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.viewer-link-label {
  margin: 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.viewer-link-url {
  color: var(--accent);
  font-weight: 600;
  word-break: break-word;
  text-decoration: none;
}

.viewer-link-url:hover,
.viewer-link-url:focus {
  text-decoration: underline;
}

button.primary {
  background: linear-gradient(140deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #0f172a;
  box-shadow: 0 12px 30px rgba(14, 165, 233, 0.25);
}

button.secondary {
  background: rgba(148, 163, 184, 0.18);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.28);
}

button.small {
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
  padding: 1rem;
  border-radius: 12px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.15);
}

.metric-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.65);
}

.metric-value {
  display: block;
  margin-top: 0.35rem;
  font-size: 1.4rem;
  font-weight: 600;
}

.console {
  background: rgba(15, 23, 42, 0.6);
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 1;
}

.console header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.88rem;
}

.log-line {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 1rem;
  padding: 0.55rem 0.6rem;
  border-radius: 10px;
  background: rgba(148, 163, 184, 0.05);
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.log-time {
  font-family: "JetBrains Mono", "SFMono-Regular", monospace;
  color: rgba(255, 255, 255, 0.5);
}

.log-line.info {
  border-color: rgba(56, 189, 248, 0.25);
}

.log-line.success {
  border-color: rgba(52, 211, 153, 0.35);
}

.log-line.warning {
  border-color: rgba(251, 191, 36, 0.35);
}

.log-line.error {
  border-color: rgba(248, 113, 113, 0.35);
}

.viewer-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: rgba(148, 163, 184, 0.16);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.toggle input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.caption-stream {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-right: 0.4rem;
  max-height: clamp(240px, 50vh, 420px);
}

.caption-line {
  background: rgba(15, 23, 42, 0.6);
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  padding: 0.9rem 1rem;
  line-height: 1.45;
}

.caption-line .english {
  margin: 0;
  font-weight: 600;
  color: var(--text);
}

.caption-line .translation {
  margin: 0.2rem 0 0;
  color: var(--text-muted);
}

.partial-caption {
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  background: rgba(59, 130, 246, 0.12);
  border-radius: 12px;
  border: 1px solid rgba(59, 130, 246, 0.35);
  display: grid;
  gap: 0.4rem;
}

.partial-caption .label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.68);
}

.partial-caption .english {
  font-weight: 600;
}

.partial-caption .translation {
  color: var(--text-muted);
}

@media (max-width: 720px) {
  .panel {
    padding: 1.25rem;
  }

  .caption-line {
    padding: 0.75rem 0.85rem;
  }

  .viewer-toolbar {
    gap: 0.5rem;
  }
}
