:root {
  --bg: #0f0f0f;
  --surface: #181818;
  --surface-hover: #272727;
  --line: #303030;
  --text: #f1f1f1;
  --muted: #aaa;
  --quiet: #717171;
  --youtube-red: #ff0033;
  --ready: #2ecc71;
  --processing: #f2b84b;
  --failed: #ff5c68;
  --manual: #3ea6ff;
  --youtube-source: #ff4e68;
  --whisper: #b17cff;
  --unknown: #777;
  --subtitle-font-family: Arial, Helvetica, sans-serif;
  --subtitle-font-size: 26px;
  --subtitle-fullscreen-font-size: 38px;
  --subtitle-font-weight: 700;
  --subtitle-font-style: normal;
  --subtitle-text-color: #ffffff;
  --subtitle-background: rgba(0, 0, 0, 0.44);
  --subtitle-border-radius: 5px;
  --subtitle-bottom-position: 11%;
  --subtitle-max-width: 86%;
  --subtitle-line-height: 1.25;
  --subtitle-text-align: center;
  --subtitle-text-shadow: 0 1px 3px #000, 0 0 8px rgba(0, 0, 0, 0.9);
  --subtitle-background-blur: 0px;
  --subtitle-padding-x: 13px;
  --subtitle-padding-y: 7px;
  color: var(--text);
  background: var(--bg);
  font-family: Roboto, Arial, Helvetica, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
}

button,
input { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--manual);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  height: 72px;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(360px, 680px) minmax(190px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 0 28px;
  background: rgba(15, 15, 15, 0.96);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 8px;
  color: #fff;
  text-decoration: none;
}

.brand-mark {
  position: relative;
  width: 39px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--youtube-red);
}

.brand-mark span {
  width: 0;
  height: 0;
  margin-left: 2px;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 10px solid #fff;
}

.brand-name {
  font-size: 20px;
  font-weight: 750;
  letter-spacing: -0.055em;
  white-space: nowrap;
}

.brand-name strong {
  margin-left: 3px;
  color: var(--youtube-red);
  font-size: 11px;
  letter-spacing: 0.05em;
  vertical-align: top;
}

.search-area {
  position: relative;
  width: 100%;
}

.url-form {
  width: 100%;
  display: flex;
}

.url-form input {
  min-width: 0;
  flex: 1;
  height: 42px;
  padding: 0 18px;
  border: 1px solid #383838;
  border-right: 0;
  border-radius: 24px 0 0 24px;
  color: var(--text);
  background: #121212;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5);
}

.url-form input:focus {
  z-index: 1;
  border-color: #1c62b9;
  outline: 0;
  box-shadow: inset 1px 0 0 #1c62b9;
}

.url-form #submit-button {
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 20px;
  border: 1px solid #383838;
  border-radius: 0 24px 24px 0;
  color: #fff;
  background: #272727;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.url-form #submit-button:hover { background: #353535; }
.url-form #submit-button:disabled { opacity: 0.55; cursor: wait; }
.button-icon { color: var(--youtube-red); font-size: 21px; font-weight: 400; line-height: 1; }

.header-settings-button {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  margin-left: 12px;
  border: 1px solid #383838;
  border-radius: 50%;
  color: #fff;
  background: #272727;
  opacity: 0.38;
  cursor: pointer;
  font-size: 20px;
  transition: opacity 150ms ease, background-color 150ms ease;
}

.header-settings-button:hover,
.header-settings-button:focus-visible,
.header-settings-button.active {
  opacity: 1;
  background: #3b3b3b;
}

.form-message {
  position: absolute;
  top: 45px;
  left: 18px;
  min-height: 15px;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.form-message.error { color: var(--failed); }

.system-state {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.state-dot,
.indicator-dot,
.legend-item i {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  display: inline-block;
  border-radius: 50%;
  background: var(--processing);
}

.system-state.ok .state-dot {
  background: var(--ready);
  box-shadow: 0 0 0 4px rgba(46, 204, 113, 0.1);
}

.system-state.error .state-dot { background: var(--failed); }

.watch-shell {
  max-width: 1840px;
  margin: 0 auto;
  padding: 22px 28px 48px;
}

.watch-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(350px, 420px);
  align-items: start;
  gap: 28px;
}

.primary-column { min-width: 0; }

.player-stage {
  position: relative;
  width: 100%;
  overflow: hidden;
  border-radius: 12px;
  aspect-ratio: 16 / 9;
  background: #000;
}

#youtube-player,
#youtube-player iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.player-placeholder {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 28px;
  color: var(--text);
  text-align: center;
  background: radial-gradient(circle at 50% 45%, #242424, #090909 55%);
}

.player-placeholder.hidden { display: none; }
.player-placeholder strong { font-size: 16px; }
.player-placeholder small { max-width: 460px; color: var(--muted); line-height: 1.5; }

.play-symbol {
  width: 66px;
  height: 46px;
  display: grid;
  place-items: center;
  padding-left: 4px;
  margin-bottom: 9px;
  border-radius: 14px;
  color: #fff;
  background: var(--youtube-red);
  font-size: 19px;
}

.fullscreen-button {
  position: absolute;
  z-index: 6;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  color: #fff;
  background: rgba(15, 15, 15, 0.7);
  backdrop-filter: blur(7px);
  cursor: pointer;
  font-size: 21px;
}

.fullscreen-button { right: 14px; bottom: 56px; }

.fullscreen-button:hover,
.fullscreen-button.active { background: rgba(45, 45, 45, 0.94); }
.fullscreen-button[hidden] { display: none; }

.subtitle-layer {
  position: absolute;
  z-index: 3;
  left: 2%;
  right: 2%;
  bottom: var(--subtitle-bottom-position);
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.subtitle-layer p {
  display: none;
  max-width: var(--subtitle-max-width);
  margin: 0;
  padding: var(--subtitle-padding-y) var(--subtitle-padding-x);
  border-radius: var(--subtitle-border-radius);
  color: var(--subtitle-text-color);
  background: var(--subtitle-background);
  -webkit-backdrop-filter: blur(var(--subtitle-background-blur));
  backdrop-filter: blur(var(--subtitle-background-blur));
  box-decoration-break: clone;
  text-align: var(--subtitle-text-align);
  font-family: var(--subtitle-font-family);
  font-size: var(--subtitle-font-size);
  font-style: var(--subtitle-font-style);
  font-weight: var(--subtitle-font-weight);
  line-height: var(--subtitle-line-height);
  text-shadow: var(--subtitle-text-shadow);
  white-space: pre-line;
  overflow-wrap: break-word;
}

.subtitle-layer p.visible { display: block; }
.subtitle-layer p.subtitle-reflow { white-space: normal; max-width: 98%; }

.translation-limit {
  position: absolute;
  z-index: 5;
  top: 15px;
  left: 50%;
  max-width: min(560px, 88%);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 14px;
  border: 1px solid rgba(242, 184, 75, 0.7);
  border-radius: 9px;
  color: #fff4d6;
  background: rgba(72, 49, 8, 0.78);
  box-shadow: 0 5px 22px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.translation-limit[hidden] { display: none; }
.translation-limit strong { font-size: 13px; }
.translation-limit span { color: #f5dba4; font-size: 11px; line-height: 1.35; }

.player-stage:fullscreen,
.player-stage:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  min-height: 0;
  border-radius: 0;
  aspect-ratio: auto;
  background: #000;
}

.player-stage:fullscreen .subtitle-layer p,
.player-stage:-webkit-full-screen .subtitle-layer p {
  max-width: min(1120px, var(--subtitle-max-width));
  font-size: var(--subtitle-fullscreen-font-size);
}

.player-stage:fullscreen .translation-limit,
.player-stage:-webkit-full-screen .translation-limit {
  top: 28px;
  padding: 13px 20px;
}

.player-stage:fullscreen .translation-limit strong,
.player-stage:-webkit-full-screen .translation-limit strong { font-size: 18px; }

.player-stage:fullscreen .translation-limit span,
.player-stage:-webkit-full-screen .translation-limit span { font-size: 14px; }

.video-detail { padding: 18px 2px 6px; }

.video-detail h1 {
  margin: 0 0 11px;
  color: var(--text);
  font-size: clamp(19px, 1.6vw, 24px);
  font-weight: 700;
  line-height: 1.3;
}

.video-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  min-height: 24px;
}

.state-label {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.state-label.translation.ready .indicator-dot { background: var(--ready); }
.state-label.translation.processing .indicator-dot { background: var(--processing); }
.state-label.translation.failed .indicator-dot { background: var(--failed); }
.state-label.translation.waiting .indicator-dot { background: #65a5ff; }
.state-label.translation.pending .indicator-dot { background: var(--unknown); }
.state-label.source.manual .indicator-dot { background: var(--manual); }
.state-label.source.youtube .indicator-dot { background: var(--youtube-source); }
.state-label.source.whisper .indicator-dot { background: var(--whisper); }
.state-label.source.unknown .indicator-dot { background: var(--unknown); }

.video-date { color: var(--quiet); font-size: 11px; }

.detail-message {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.detail-actions[hidden],
.action-button[hidden] { display: none; }

.action-button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 0;
  border-radius: 18px;
  color: var(--text);
  background: var(--surface-hover);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.action-button:hover { background: #3f3f3f; }
.primary-action { color: #07150d; background: var(--ready); }
.primary-action:hover { background: #54dc8d; }
.retry-action { color: #1a1200; background: var(--processing); }
.danger-action { color: #ff9ba3; }

.settings-dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: min(860px, calc(100dvh - 28px));
  padding: 0;
  overflow: hidden;
  border: 1px solid #3a3a3a;
  border-radius: 16px;
  color: var(--text);
  background: #191919;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.7);
}

.settings-dialog::backdrop {
  background: rgba(0, 0, 0, 0.76);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}

.settings-panel {
  max-height: min(860px, calc(100dvh - 28px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.settings-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 22px 15px;
  border-bottom: 1px solid var(--line);
}

.settings-header p {
  margin: 0 0 3px;
  color: var(--youtube-red);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.settings-header h2 { margin: 0; font-size: 22px; }

.settings-close {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--text);
  background: #292929;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.settings-close:hover { background: #3b3b3b; }

.settings-preview {
  min-height: 118px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  overflow: hidden;
  background:
    linear-gradient(rgba(0, 0, 0, 0.16), rgba(0, 0, 0, 0.44)),
    radial-gradient(circle at 25% 20%, #405269, #1b242d 48%, #101010);
}

.settings-preview p {
  max-width: var(--subtitle-max-width);
  margin: 0;
  padding: var(--subtitle-padding-y) var(--subtitle-padding-x);
  border-radius: var(--subtitle-border-radius);
  color: var(--subtitle-text-color);
  background: var(--subtitle-background);
  -webkit-backdrop-filter: blur(var(--subtitle-background-blur));
  backdrop-filter: blur(var(--subtitle-background-blur));
  text-align: var(--subtitle-text-align);
  font-family: var(--subtitle-font-family);
  font-size: min(var(--subtitle-font-size), 34px);
  font-style: var(--subtitle-font-style);
  font-weight: var(--subtitle-font-weight);
  line-height: var(--subtitle-line-height);
  text-shadow: var(--subtitle-text-shadow);
}

.settings-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 17px 22px;
  padding: 20px 22px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #555 transparent;
}

.setting-field {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.setting-field > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setting-field output { color: #ddd; font-size: 11px; font-weight: 500; }
.setting-wide { grid-column: 1 / -1; }

.setting-field select {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  border: 1px solid #414141;
  border-radius: 9px;
  color: var(--text);
  background: #242424;
}

.setting-field input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: var(--youtube-red);
}

.setting-color { flex-direction: row; align-items: center; justify-content: space-between; }

.setting-color input[type="color"] {
  width: 48px;
  height: 34px;
  padding: 2px;
  border: 1px solid #414141;
  border-radius: 8px;
  background: #242424;
  cursor: pointer;
}

.setting-toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.setting-toggle input { width: 18px; height: 18px; accent-color: var(--youtube-red); }

.settings-footer {
  flex: 0 0 auto;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px 8px;
  border-top: 1px solid var(--line);
}

.settings-footer button {
  min-height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 19px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
}

.settings-reset { color: var(--text); background: #303030; }
.settings-save { color: #fff; background: var(--youtube-red); }
.settings-footer button:hover { filter: brightness(1.15); }

.settings-note {
  flex: 0 0 auto;
  margin: 0;
  padding: 3px 22px 15px;
  color: var(--quiet);
  font-size: 10px;
  text-align: right;
}

.translated-rail {
  min-width: 0;
  max-height: calc(100vh - 100px);
  overflow: hidden;
}

.rail-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 2px 10px;
}

.rail-kicker {
  margin: 0 0 3px;
  color: var(--youtube-red);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.rail-heading h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.icon-button {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border: 0;
  border-radius: 50%;
  color: var(--text);
  background: var(--surface-hover);
  cursor: pointer;
  font-size: 19px;
}

.icon-button:hover { background: #3a3a3a; }

.source-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 12px;
  padding: 6px 2px 14px;
  border-bottom: 1px solid var(--line);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--quiet);
  font-size: 10px;
  white-space: nowrap;
}

.legend-item.ready i { background: var(--ready); }
.legend-item.manual i { background: var(--manual); }
.legend-item.youtube i { background: var(--youtube-source); }
.legend-item.whisper i { background: var(--whisper); }

.jobs-list {
  max-height: calc(100vh - 210px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 0 24px;
  scrollbar-width: thin;
  scrollbar-color: #555 transparent;
}

.empty-state {
  padding: 60px 20px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  line-height: 1.55;
}

.job-card {
  position: relative;
  width: 100%;
  margin: 0 0 5px;
  border-radius: 10px;
  background: transparent;
  transition: background 120ms ease;
}

.job-card-select {
  width: 100%;
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  gap: 11px;
  padding: 8px 36px 8px 8px;
  border: 0;
  border-radius: inherit;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 120ms ease;
}

.job-card:hover { background: #1d1d1d; }
.job-card.active { background: var(--surface-hover); }

.job-card-delete {
  position: absolute;
  z-index: 2;
  top: 7px;
  right: 7px;
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #b8b8b8;
  background: rgba(15, 15, 15, 0.82);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.job-card-delete:hover { color: #fff; background: var(--failed); }
.job-card-delete[hidden] { display: none; }

.thumbnail-wrap {
  position: relative;
  width: 168px;
  overflow: hidden;
  border-radius: 8px;
  aspect-ratio: 16 / 9;
  background: #252525;
}

.job-thumbnail {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.thumbnail-progress {
  position: absolute;
  right: 5px;
  bottom: 5px;
  padding: 3px 5px;
  border-radius: 4px;
  color: #fff;
  background: rgba(0, 0, 0, 0.82);
  font-size: 10px;
  font-weight: 700;
}

.watch-progress-badge,
.watch-complete-badge {
  position: absolute;
  z-index: 2;
  left: 7px;
  top: 7px;
  min-width: 48px;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  color: #fff;
  background: rgba(8, 8, 8, 0.82);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(7px);
}

.watch-progress-badge {
  flex-direction: column;
  gap: 0;
  padding: 3px 7px;
  line-height: 1;
}

.watch-progress-badge strong { font-size: 12px; }
.watch-progress-badge small { margin-top: 3px; color: #d0d0d0; font-size: 7px; text-transform: uppercase; }

.watch-complete-badge {
  width: 38px;
  min-width: 38px;
  height: 38px;
  min-height: 38px;
  border-color: rgba(133, 255, 181, 0.8);
  border-radius: 50%;
  background: rgba(25, 174, 91, 0.94);
  box-shadow: 0 3px 16px rgba(31, 214, 111, 0.38);
  font-size: 24px;
  font-weight: 900;
}

.watch-progress-badge[hidden],
.watch-complete-badge[hidden] { display: none; }

.watch-progress-track {
  position: absolute;
  z-index: 2;
  right: 0;
  bottom: 0;
  left: 0;
  height: 4px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.22);
}

.watch-progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--youtube-red);
  box-shadow: 0 0 7px rgba(255, 0, 51, 0.7);
}

.job-card.watched-complete .watch-progress-track span {
  background: var(--ready);
  box-shadow: 0 0 7px rgba(46, 204, 113, 0.72);
}

.job-card-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  padding: 2px 0;
}

.job-title {
  width: 100%;
  display: -webkit-box;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.job-card .state-label {
  width: 100%;
  overflow: hidden;
  font-size: 10px;
  white-space: nowrap;
}

.job-card .state-label span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.job-message {
  width: 100%;
  overflow: hidden;
  color: var(--quiet);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-track {
  width: 100%;
  height: 3px;
  overflow: hidden;
  border-radius: 3px;
  background: #333;
}

.progress-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--youtube-red);
  transition: width 250ms ease;
}

.job-card.ready .progress-fill { background: var(--ready); }
.job-card.failed .progress-fill { background: var(--failed); }
.job-date { color: #606060; font-size: 9px; }

/* On a normal desktop display, the watch page stays inside the viewport.
   The rail scrolls independently; the primary column scrolls only as a
   safety fallback for unusually short windows or very long metadata. */
@media (min-width: 941px) and (min-height: 700px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .watch-shell {
    height: calc(100dvh - 72px);
    padding-top: 10px;
    padding-bottom: 10px;
    overflow: hidden;
  }

  .watch-layout,
  .primary-column {
    height: 100%;
    min-height: 0;
  }

  .primary-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #555 transparent;
  }

  /* Reserve enough vertical space for title, status, message and every action.
     The width remains capped by the column, so the player keeps 16:9 without
     pushing the desktop controls below the viewport. */
  .player-stage {
    width: min(100%, calc((100dvh - 282px) * 16 / 9));
    flex: 0 0 auto;
  }

  .video-detail {
    width: 100%;
    flex: 0 0 auto;
  }
  .video-detail { padding-top: 12px; }
  .detail-actions { margin-top: 12px; }

  .translated-rail {
    height: 100%;
    max-height: none;
    display: flex;
    flex-direction: column;
  }

  .rail-heading,
  .source-legend { flex: 0 0 auto; }

  .jobs-list {
    min-height: 0;
    max-height: none;
    flex: 1 1 auto;
    overflow-y: auto;
  }
}

@media (max-width: 1250px) {
  .topbar { grid-template-columns: 180px minmax(320px, 1fr) 170px; }
  .watch-layout { grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; }
  .job-card-select { grid-template-columns: 144px minmax(0, 1fr); }
  .thumbnail-wrap { width: 144px; }
}

@media (max-width: 940px) {
  .topbar { grid-template-columns: auto minmax(0, 1fr) auto; gap: 14px; padding: 0 18px; }
  .brand-name { display: none; }
  .watch-shell { padding: 18px 16px 40px; }
  .watch-layout { grid-template-columns: 1fr; }
  .translated-rail { max-height: none; margin-top: 14px; }
  .jobs-list { max-height: none; overflow: visible; }
  .job-card-select { grid-template-columns: minmax(150px, 230px) minmax(0, 1fr); }
  .thumbnail-wrap { width: 100%; }
}

@media (max-width: 620px) {
  .topbar { height: auto; min-height: 66px; padding: 10px 12px; }
  .brand-mark { width: 34px; height: 24px; border-radius: 7px; }
  .system-state span:last-child { display: none; }
  .url-form input { height: 40px; padding: 0 13px; }
  .url-form #submit-button { width: 44px; height: 40px; padding: 0; }
  .url-form #submit-button span:last-child { display: none; }
  .header-settings-button {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
    margin-left: 8px;
  }
  .form-message { display: none; }
  .watch-shell { padding: 8px 0 30px; }
  .player-stage { border-radius: 0; }
  .video-detail { padding: 15px 13px 5px; }
  .translated-rail { padding: 0 6px; }
  .rail-heading,
  .source-legend { padding-left: 7px; padding-right: 7px; }
  .job-card-select { grid-template-columns: 148px minmax(0, 1fr); gap: 9px; padding: 7px 34px 7px 7px; }
  .job-message,
  .job-date { display: none; }
  .fullscreen-button { right: 10px; bottom: 50px; }
  .subtitle-layer { left: 2%; right: 2%; }
  .settings-dialog {
    width: 100vw;
    max-width: none;
    max-height: calc(100dvh - 8px);
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: 18px 18px 0 0;
  }
  .settings-panel { max-height: calc(100dvh - 8px); }
  .settings-header { padding: 16px 16px 12px; }
  .settings-preview { min-height: 94px; padding: 16px; }
  .settings-grid { grid-template-columns: 1fr; gap: 15px; padding: 17px 16px 20px; }
  .setting-wide { grid-column: auto; }
  .settings-footer { padding: 12px 16px 7px; }
  .settings-note { padding: 3px 16px 12px; text-align: left; }
}

@media (max-width: 420px) {
  .job-card-select { grid-template-columns: 132px minmax(0, 1fr); }
  .job-card .state-label { font-size: 9px; }
}
