:root {
  --bg: #0b1020;
  --bg-elev: #11182c;
  --bg-card: #16203a;
  --bg-input: #0e1528;
  --border: rgba(148, 163, 184, 0.18);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent: #a855f7;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #f43f5e;
  --shadow: 0 12px 32px rgba(2, 6, 23, 0.45);
  --radius: 14px;
}

html[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f8fafc;
  --border: rgba(15, 23, 42, 0.12);
  --text: #0f172a;
  --text-muted: #475569;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --accent: #7c3aed;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 0.9rem; }

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Topbar - Ultra-compact single row + collapsible drawer */
.topbar {
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  z-index: 40;
}
.topbar-main {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  min-height: 46px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}
.brand-logo { width: 28px; height: 28px; border-radius: 8px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 800; font-size: 0.96rem; letter-spacing: -0.02em; }
.brand-tag { font-size: 0.66rem; color: var(--accent); font-weight: 600; }

.omnibox {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 4px;
  min-width: 0;
}
.omnibox:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.22);
}
.omnibox-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.88rem;
  padding: 4px 6px;
  outline: none;
}

.topbar-quick-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.topbar-drawer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 8px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
}

.btn-go {
  padding: 5px 12px;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.go-arrow { display: none; }

/* Immersive Full-Screen Mode */
.app-shell.immersive .topbar,
.app-shell.immersive .status-bar {
  display: none !important;
}
.floating-restore-btn {
  position: fixed;
  top: 10px;
  right: 12px;
  z-index: 95;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(15, 23, 42, 0.78);
  color: #f8fafc;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

/* Buttons & Inputs */
.btn-primary, .btn-ghost, .btn-accent, .icon-btn, .select-pill, .chip {
  font-family: inherit;
  border-radius: 999px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s ease;
  font-weight: 600;
  font-size: 0.85rem;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  border-color: transparent;
  padding: 8px 16px;
}
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-accent {
  background: rgba(168, 85, 247, 0.18);
  color: var(--text);
  border-color: rgba(168, 85, 247, 0.45);
  padding: 7px 12px;
}
.btn-ghost {
  background: var(--bg-card);
  color: var(--text);
  padding: 7px 12px;
}
.btn-ghost:hover { border-color: var(--primary); }
.btn-compact { padding: 6px 11px; font-size: 0.82rem; }
.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  background: var(--bg-card);
  color: var(--text);
  padding: 0;
}
.icon-btn-sm {
  width: 30px;
  height: 30px;
  font-size: 0.85rem;
}
.icon-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn:not(:disabled):hover { border-color: var(--primary); }

.select-pill {
  background: var(--bg-input);
  color: var(--text);
  padding: 6px 12px;
  max-width: 170px;
}

.segmented {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.seg-btn.active {
  background: var(--primary);
  color: #fff;
}

/* Status Bar - Slim single-line strip */
.status-bar {
  position: relative;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  padding: 3px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.76rem;
  height: 24px;
}
.status-inner {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}
.status-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}
.status-dot.busy { background: var(--warning); box-shadow: 0 0 6px var(--warning); animation: pulse 1s infinite; }
.status-dot.error { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.progress-track { width: 96px; height: 4px; border-radius: 999px; background: var(--bg-input); overflow: hidden; flex-shrink: 0; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width 0.25s ease; }

/* Workspace */
.workspace {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  position: relative;
}

/* Home View */
.home-view {
  max-width: 1060px;
  margin: 0 auto;
  padding: 26px 18px 60px;
}
.hero-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.14);
  border: 1px solid rgba(99, 102, 241, 0.35);
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 12px;
}
.hero-card h1 {
  margin: 0 0 10px;
  font-size: clamp(1.45rem, 2.7vw, 2.15rem);
  line-height: 1.24;
  letter-spacing: -0.02em;
}
.hero-sub {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.55;
}

.home-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.home-tab {
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
}
.home-tab.active { background: var(--primary); color: #fff; border-color: transparent; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.drop-zone {
  border: 2px dashed rgba(99, 102, 241, 0.45);
  border-radius: 18px;
  padding: 32px 18px;
  text-align: center;
  background: rgba(99, 102, 241, 0.05);
  transition: all 0.2s ease;
}
.drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(168, 85, 247, 0.14);
  transform: scale(1.01);
}
.drop-icon { font-size: 2.2rem; margin-bottom: 8px; }
.drop-title { font-size: 1.12rem; font-weight: 700; margin-bottom: 6px; }
.drop-meta { color: var(--text-muted); font-size: 0.88rem; margin-bottom: 18px; line-height: 1.5; }
.drop-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

.quick-examples {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.chip {
  background: var(--bg-input);
  color: var(--text);
  padding: 6px 12px;
  font-size: 0.82rem;
}
.chip:hover { border-color: var(--primary); }

.quick-text-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.qt-col { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 0.84rem; font-weight: 700; color: var(--text-muted); }
.textarea, .input {
  width: 100%;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.94rem;
  line-height: 1.55;
  outline: none;
}
.textarea:focus, .input:focus { border-color: var(--primary); }
.qt-actions { display: flex; gap: 8px; }
.qt-out-head { display: flex; justify-content: space-between; align-items: center; }
.qt-out-tools { display: flex; gap: 6px; }
.qt-output {
  min-height: 196px;
  max-height: 380px;
  overflow-y: auto;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  white-space: pre-wrap;
  line-height: 1.65;
}
.qt-context-note {
  font-size: 0.83rem;
  color: var(--text-muted);
  background: rgba(99, 102, 241, 0.1);
  border-radius: 10px;
  padding: 8px 12px;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 22px;
}
.feature-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
}
.f-icon { font-size: 1.5rem; margin-bottom: 8px; }
.feature-card h3 { margin: 0 0 6px; font-size: 1rem; }
.feature-card p { margin: 0; color: var(--text-muted); font-size: 0.87rem; line-height: 1.5; }

.history-section { margin-top: 26px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.section-head h2 { margin: 0; font-size: 1.1rem; }
.history-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.history-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.history-item:hover { border-color: var(--primary); }
.history-title { font-weight: 700; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-sub { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Proxy View */
.proxy-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}
.proxy-video-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 14px;
  background: rgba(99, 102, 241, 0.14);
  border-bottom: 1px solid var(--border);
  font-size: 0.86rem;
}
.proxy-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #ffffff;
}

/* Reader View */
.reader-view {
  max-width: 920px;
  margin: 0 auto;
  padding: 24px 18px 80px;
}
.reader-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}
.reader-context-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 20px;
}
.reader-article {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  line-height: 1.75;
  box-shadow: var(--shadow);
}
.reader-block { margin-bottom: 16px; }
.reader-orig-sub {
  margin-top: 4px;
  font-size: 0.88rem;
  color: var(--text-muted);
  font-style: italic;
  border-left: 3px solid var(--primary);
  padding-left: 10px;
}
.reader-quote {
  border-left: 4px solid var(--accent);
  padding: 10px 16px;
  background: rgba(168, 85, 247, 0.08);
  border-radius: 0 10px 10px 0;
}
.reader-table-wrap { overflow-x: auto; }
.reader-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.reader-table th, .reader-table td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: top; }
.reader-table th { background: var(--bg-input); }
.reader-img-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  text-align: center;
}
.reader-img-card img { max-width: 100%; max-height: 620px; border-radius: 10px; }
.reader-img-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

/* Studio Views (Image & Video) */
.studio-view {
  max-width: 1320px;
  margin: 0 auto;
  padding: 18px;
}
.studio-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.studio-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 1fr);
  gap: 16px;
  align-items: start;
}
@media (max-width: 920px) {
  .studio-grid { grid-template-columns: 1fr; }
}
.studio-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}

/* Image Slider */
.img-stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  border-radius: 12px;
  background: #050814;
  user-select: none;
}
.img-stage img { display: block; max-width: 100%; max-height: 74vh; width: auto; height: auto; }
.compare-wrap { position: relative; display: inline-block; max-width: 100%; overflow: hidden; border-radius: 12px; }
.compare-top {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.compare-divider {
  position: absolute;
  top: 0; bottom: 0;
  width: 3px;
  background: #ffffff;
  box-shadow: 0 0 10px rgba(0,0,0,0.6);
  cursor: ew-resize;
  z-index: 5;
}
.compare-handle {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: grid; place-items: center;
  font-size: 0.8rem; font-weight: 800;
  border: 2px solid #fff;
}
.overlay-box {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3px 5px;
  border-radius: 6px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.region-list { display: flex; flex-direction: column; gap: 10px; max-height: 68vh; overflow-y: auto; }
.region-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}
.region-orig { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 6px; }

/* Video Studio */
.video-player-box {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
}
.video-player-box video, .video-player-box iframe, #ytPlayerHost {
  width: 100%;
  height: 100%;
  border: none;
}
.subtitle-stage {
  margin-top: 10px;
  min-height: 62px;
  background: #060914;
  color: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}
.sub-main { font-size: 1.08rem; font-weight: 700; line-height: 1.4; }
.sub-orig { font-size: 0.86rem; color: #cbd5e1; opacity: 0.82; }
.dub-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
}
.transcript-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 62vh;
  overflow-y: auto;
  margin-top: 10px;
}
.cue-row {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.cue-row.active {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.15);
}
.cue-time { font-size: 0.76rem; font-weight: 700; color: var(--accent); margin-bottom: 3px; }
.cue-trans { font-size: 0.92rem; font-weight: 600; line-height: 1.45; }
.cue-orig { font-size: 0.8rem; color: var(--text-muted); margin-top: 3px; }

/* Modals & Toasts */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(2, 6, 23, 0.72); backdrop-filter: blur(4px); }
.modal-card {
  position: relative;
  width: min(620px, 100%);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-wide { width: min(740px, 100%); }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 1.08rem; }
.modal-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }

.toast-container {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.toast {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.88rem;
  box-shadow: var(--shadow);
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

@media (max-width: 768px) {
  .topbar-main { padding: 5px 8px; gap: 5px; min-height: 44px; }
  .brand-text { display: none; }
  .go-label { display: none; }
  .go-arrow { display: inline; }
  .btn-go { width: 30px; height: 30px; padding: 0; display: inline-grid; place-items: center; }
  .select-pill { max-width: 140px; font-size: 0.78rem; padding: 5px 9px; }
  .reader-article { padding: 16px; }
  .hero-card { padding: 18px; }
}
