:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2026;
  --muted: #5f6b7a;
  --border: #d8dde4;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --good: #1a7f37;
  --good-bg: #e6f4ea;
  --warn: #9a6700;
  --warn-bg: #fff4d6;
  --bad: #cf222e;
  --bad-bg: #fde8ea;
  --idle-bg: #eef1f4;
  --code-bg: #f0f2f5;
  --rule: #e9edf1;
  --shadow: 0 4px 14px rgba(15, 23, 42, 0.18);
  --font-scale: 1;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "D2Coding", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1f25;
    --text: #e6e9ee;
    --muted: #98a3b1;
    --border: #2e3640;
    --accent: #4c8dff;
    --accent-text: #0b1220;
    --good: #4ac26b;
    --good-bg: #13301d;
    --warn: #d6a838;
    --warn-bg: #352a10;
    --bad: #ff6b6b;
    --bad-bg: #3a1a1d;
    --idle-bg: #232a32;
    --code-bg: #232a32;
    --rule: #222931;
    --shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

h1,
h2,
h3 {
  line-height: 1.3;
  margin: 0 0 0.6em;
}

h1 {
  font-size: 1.5rem;
}

h2 {
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.5em;
  flex-wrap: wrap;
}

h3 {
  font-size: 1rem;
  margin-top: 1.2em;
}

a {
  color: var(--accent);
}

code,
.mono {
  font-family: var(--mono);
  font-size: 0.92em;
}

code {
  background: var(--code-bg);
  padding: 0.05em 0.35em;
  border-radius: 4px;
}

.muted,
.hint {
  color: var(--muted);
}

.hint {
  font-size: 0.93rem;
  margin: 0 0 0.8em;
}

ol.hint {
  padding-left: 1.3em;
}

/* Controls */

button,
.button {
  font: inherit;
  font-size: 0.95rem;
  padding: 0.5em 1em;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  line-height: 1.3;
}

button:hover:not(:disabled),
.button:hover {
  border-color: var(--accent);
}

button:focus-visible,
.button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.primary,
.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

button.secondary {
  background: transparent;
}

button.small {
  font-size: 0.85rem;
  padding: 0.3em 0.7em;
}

button.wide {
  width: 100%;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input[type="text"],
input[type="password"],
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5em 0.65em;
  max-width: 100%;
}

textarea {
  width: 100%;
  font-family: var(--mono);
  font-size: 0.85rem;
  resize: vertical;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  align-items: center;
  margin: 0.6em 0;
}

label.inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
}

label.stacked {
  display: flex;
  flex-direction: column;
  gap: 0.3em;
  margin-top: 0.6em;
}

.actions {
  display: flex;
  gap: 0.6em;
  flex-wrap: wrap;
  margin-top: 1.2em;
}

/* Layout */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.6em;
  max-width: 560px;
  margin: 10vh auto 0;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 2em 1em;
}

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

/* Login */

.login-card {
  max-width: 400px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3em;
  margin-bottom: 1em;
}

.field input {
  width: 100%;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
}

.error {
  color: var(--bad);
  background: var(--bad-bg);
  border-radius: 8px;
  padding: 0.6em 0.8em;
  margin: 0 0 1em;
}

/* Probe page */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.8em 1.2em;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6em 1.5em;
  align-items: center;
  justify-content: space-between;
}

.topbar h1 {
  font-size: 1.2rem;
  margin: 0;
}

.topbar-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6em;
  align-items: center;
  font-size: 0.9rem;
}

.steps {
  max-width: 920px;
  margin: 0 auto;
  padding: 1.2em;
}

.step {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2em 1.4em;
  margin-bottom: 1.2em;
}

.num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7em;
  height: 1.7em;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.85rem;
}

.badge {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.15em 0.65em;
  border-radius: 999px;
  background: var(--idle-bg);
  color: var(--muted);
}

.badge[data-state="pass"],
.badge[data-state="done"] {
  background: var(--good-bg);
  color: var(--good);
}

.badge[data-state="warn"],
.badge[data-state="todo"],
.badge[data-state="running"] {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge[data-state="fail"] {
  background: var(--bad-bg);
  color: var(--bad);
}

.notice {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 0.7em 1em;
  margin: 0 0 1.2em;
}

.notice.warn {
  border-left-color: var(--warn);
  background: var(--warn-bg);
}

.notice.info {
  border-left-color: var(--good);
}

.status {
  min-height: 1.4em;
  margin: 0.4em 0;
  font-size: 0.93rem;
}

[data-tone="ok"],
[data-tone="good"] {
  color: var(--good);
}

[data-tone="warn"] {
  color: var(--warn);
}

[data-tone="error"],
[data-tone="bad"] {
  color: var(--bad);
}

fieldset.question {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6em 1em 0.8em;
  margin: 0.8em 0;
}

fieldset.question legend {
  padding: 0 0.3em;
  font-weight: 600;
  font-size: 0.95rem;
}

fieldset.question > label {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  margin: 0.2em 1.2em 0.2em 0;
}

fieldset.question > label.stacked {
  display: flex;
}

table.kv,
table.grid {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.92rem;
  margin: 0.6em 0;
}

table.kv th,
table.kv td,
table.grid th,
table.grid td {
  border-bottom: 1px solid var(--border);
  padding: 0.4em 0.6em;
  text-align: left;
  vertical-align: top;
}

table.kv th {
  width: 38%;
  font-weight: 500;
  color: var(--muted);
}

table.kv td {
  font-family: var(--mono);
  font-size: 0.88rem;
}

table.grid th {
  white-space: nowrap;
  font-weight: 600;
}

.table-wrap {
  overflow-x: auto;
}

.level {
  display: flex;
  align-items: center;
  gap: 0.8em;
  margin: 0.6em 0;
}

meter {
  flex: 1;
  max-width: 420px;
  height: 1.1em;
}

.live-box {
  border: 1px dashed var(--accent);
  border-radius: 8px;
  padding: 0.6em 1em;
  margin: 0.8em 0;
}

ul.verdict {
  list-style: none;
  padding: 0;
  margin: 0.6em 0;
}

ul.verdict li {
  padding: 0.35em 0.7em;
  border-radius: 6px;
  margin-bottom: 0.3em;
  background: var(--idle-bg);
}

ul.verdict li[data-state="pass"] {
  background: var(--good-bg);
  color: var(--good);
}

ul.verdict li[data-state="warn"] {
  background: var(--warn-bg);
  color: var(--warn);
}

ul.verdict li[data-state="fail"] {
  background: var(--bad-bg);
  color: var(--bad);
}

details summary {
  cursor: pointer;
  color: var(--muted);
  margin: 0.6em 0;
}

pre.preview {
  background: var(--code-bg);
  border-radius: 8px;
  padding: 0.8em;
  max-height: 360px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.8rem;
  white-space: pre-wrap;
}

/* Document Picture-in-Picture test window */

body.pip {
  background: #0d1117;
  color: #f0f3f6;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1em;
}

.pip-text {
  font-size: 1.4rem;
  text-align: center;
  margin: 0;
}

@media (max-width: 640px) {
  .card {
    margin-top: 4vh;
    padding: 1.2em;
  }

  .steps {
    padding: 0.8em;
  }

  .step {
    padding: 1em;
  }

  table.kv th {
    width: 45%;
  }
}

/* Caption page (index.html) */

body.page-captions {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.cap-header {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  padding: 0.55em 1em 0.6em;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.statusbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3em 1.2em;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
}

.stat,
.stat[data-tone] {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  white-space: nowrap;
  color: var(--text);
}

.stat-name {
  color: var(--muted);
  font-size: 0.8rem;
}

.stat .dot {
  flex: none;
  width: 0.62em;
  height: 0.62em;
  border-radius: 50%;
  background: var(--border);
}

.stat[data-tone="ok"] .dot {
  background: var(--good);
}

.stat[data-tone="warn"] .dot {
  background: var(--warn);
}

.stat[data-tone="bad"] .dot {
  background: var(--bad);
}

.stat[data-tone="warn"] .stat-text {
  color: var(--warn);
}

.stat[data-tone="bad"] .stat-text {
  color: var(--bad);
  font-weight: 600;
}

.level-bar {
  position: relative;
  width: 84px;
  height: 8px;
  border-radius: 4px;
  background: var(--idle-bg);
  overflow: hidden;
}

.level-fill {
  position: absolute;
  inset: 0;
  background: var(--good);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 90ms linear;
}

.stat-db {
  min-width: 4.6em;
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45em;
}

.toolbar select {
  max-width: 17em;
  font-size: 0.95rem;
  padding: 0.42em 0.5em;
}

.toolbar-gap {
  flex: 1 1 0.5em;
}

.hints {
  display: flex;
  flex-direction: column;
  gap: 0.3em;
  margin: 0;
  padding: 0;
  list-style: none;
}

.hints li {
  padding: 0.45em 0.85em;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--idle-bg);
  color: var(--text);
  font-size: 0.95rem;
}

.hints li[data-tone="ok"] {
  border-left-color: var(--good);
  background: var(--good-bg);
}

.hints li[data-tone="warn"] {
  border-left-color: var(--warn);
  background: var(--warn-bg);
}

.hints li[data-tone="bad"] {
  border-left-color: var(--bad);
  background: var(--bad-bg);
}

.cap-main {
  position: relative;
  flex: 1;
  min-height: 0;
}

.transcript {
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.6em 1.2em 4.5em;
}

.transcript:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.items {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0;
  list-style: none;
}

.item {
  display: grid;
  grid-template-columns: 3.3em minmax(0, 1fr);
  align-items: baseline;
  column-gap: 0.85em;
  padding: 0.55em 0;
  border-bottom: 1px solid var(--rule);
}

.item p {
  margin: 0;
}

.item .time {
  text-align: right;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.item.late .time {
  text-decoration: underline dotted;
}

.item .body {
  min-width: 0;
}

.item .orig {
  color: var(--muted);
  font-size: calc(15px * var(--font-scale));
  line-height: 1.45;
}

.item .ko {
  color: var(--text);
  font-size: calc(26px * var(--font-scale));
  font-weight: 500;
  line-height: 1.42;
}

.item-en .ko {
  margin-top: 0.1em;
}

.item-ko .body {
  border-left: 3px solid var(--accent);
  padding-left: 0.65em;
}

.item .ko.tr-pending {
  color: var(--muted);
}

.item .ko.tr-error {
  color: var(--muted);
  font-size: calc(15px * var(--font-scale));
  font-weight: 400;
}

.item .ko .cut-mark {
  color: var(--muted);
  font-size: calc(15px * var(--font-scale));
  font-weight: 400;
}

.item.tr-failed .orig {
  color: var(--text);
  font-size: calc(21px * var(--font-scale));
}

.item-partial {
  border-bottom: 0;
}

.item-partial .partial-text {
  color: var(--muted);
  font-size: calc(20px * var(--font-scale));
  font-style: italic;
  line-height: 1.45;
}

.empty-note {
  max-width: 640px;
  margin: 12vh auto 0;
  text-align: center;
  font-size: 1.05rem;
}

.empty-note p {
  margin: 0 0 0.6em;
}

.jump-live {
  position: absolute;
  left: 50%;
  bottom: 1.1em;
  transform: translateX(-50%);
  padding: 0.55em 1.3em;
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.cap-footer {
  flex: none;
  padding: 0.35em 1em 0.5em;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

@media (max-width: 640px) {
  .cap-header {
    padding: 0.5em 0.7em;
  }

  .transcript {
    padding: 0.5em 0.7em 4.5em;
  }

  .item {
    grid-template-columns: 2.9em minmax(0, 1fr);
    column-gap: 0.6em;
  }

  .toolbar-gap {
    display: none;
  }
}

/* Document Picture-in-Picture caption window (pip.js) */

html.pip-doc {
  color-scheme: dark;
}

body.pip-captions {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #0b0f14;
  color: #f2f4f7;
}

.pip-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-bottom: 1px solid #1d2530;
  color: #a7b1bf;
  font-size: 12px;
}

.pip-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #5d6878;
}

.pip-dot[data-tone="ok"] {
  background: #3fb950;
}

.pip-dot[data-tone="warn"] {
  background: #d29922;
}

.pip-dot[data-tone="bad"] {
  background: #f85149;
}

.pip-status {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pip-bar .pip-button {
  padding: 3px 9px;
  border: 1px solid #2c3642;
  border-radius: 6px;
  background: #161c24;
  color: #e8ebf0;
  font-size: 12px;
  line-height: 1.2;
}

.pip-bar .pip-button:hover {
  border-color: #4c8dff;
}

.pip-items {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  margin: 0;
  padding: 4px 12px 8px;
  overflow: hidden;
  list-style: none;
  mask-image: linear-gradient(to bottom, transparent 0, #000 22px);
}

.pip-items .item {
  display: block;
  padding: 3px 0;
  border-bottom: 0;
}

.pip-items .item .time {
  display: none;
}

.pip-items .item .orig {
  color: #9ba6b5;
  font-size: calc(13px * var(--pip-scale, 1));
  line-height: 1.35;
}

.pip-items .item .ko {
  color: #ffffff;
  font-size: calc(28px * var(--pip-scale, 1));
  font-weight: 600;
  line-height: 1.3;
}

.pip-items .item-ko .body {
  border-left: 3px solid #4c8dff;
  padding-left: 8px;
}

.pip-items .item .ko.tr-pending,
.pip-items .item .ko.tr-error,
.pip-items .item .ko .cut-mark {
  color: #8d98a8;
  font-size: calc(15px * var(--pip-scale, 1));
  font-weight: 400;
}

.pip-items .item.tr-failed .orig {
  color: #e8ebf0;
  font-size: calc(20px * var(--pip-scale, 1));
}

.pip-items .item-partial .partial-text {
  color: #8d98a8;
  font-size: calc(18px * var(--pip-scale, 1));
  font-style: italic;
}

.pip-empty {
  color: #8d98a8;
  font-size: 15px;
}
