:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --text: #e8e8e8;
  --muted: #9aa4b2;
  --accent: #4f9dff;
  --accent-2: #2b6cb0;
  --border: #2a2f3a;
  --danger: #e5484d;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

header.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

header.topbar h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 600;
}

header.topbar .spacer { flex: 1; }

header.topbar nav a {
  margin-left: 14px;
  color: var(--muted);
  text-decoration: none;
}
header.topbar nav a:hover, header.topbar nav a.active { color: var(--text); }

select, button, input {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  cursor: pointer;
  /* room on the left for the text, room on the right for the chevron */
  padding: 6px 34px 6px 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6l5-4.5' fill='none' stroke='%239aa4b2' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
}
select:hover { border-color: var(--accent); }
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
select::-ms-expand { display: none; }

button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent-2); border-color: var(--accent-2); }
button.primary:hover { background: var(--accent); }
button.danger { color: #fff; background: var(--danger); border-color: var(--danger); }

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

/* ---- login ---- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 320px;
  max-width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p.muted { margin: 0 0 6px; color: var(--muted); font-size: 13px; }
.login-card input { text-align: center; padding: 10px; }
.login-card button { padding: 10px; }
.login-err { color: var(--danger); font-size: 13px; }

/* ---- player + subtitle overlay ---- */

.player-area {
  position: relative;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  /* Reserve the 16:9 box always, so switching episode (video briefly has no
     intrinsic size) doesn't collapse the layout and jump the page. */
  aspect-ratio: 16 / 9;
}
.player-area .plyr,
.player-area video {
  width: 100%;
  height: 100%;
}
.player-area .plyr__video-wrapper { height: 100%; }

.subtitle-overlay {
  position: absolute;
  left: 0;
  right: 0;
  /* Fixed spot that always clears the Plyr control bar, in windowed and
     fullscreen alike. Deliberately does NOT react to controls showing/hiding —
     a moving subtitle is impossible to click. */
  bottom: max(56px, 11%);
  display: flex;
  justify-content: center;
  pointer-events: none;      /* only the words capture clicks */
  padding: 0 6%;
  z-index: 20;
  transition: none;          /* never animate position — must stay clickable */
}
.plyr:fullscreen .subtitle-overlay,
.plyr:-webkit-full-screen .subtitle-overlay,
.plyr--fullscreen-active .subtitle-overlay,
.plyr--fullscreen-fallback .subtitle-overlay { bottom: max(90px, 9%); }

.subtitle-box {
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.72);
  border-radius: 8px;
  padding: 8px 14px;
  max-width: 90%;
  text-align: center;
  font-size: clamp(18px, 2.4vw, 28px);
  line-height: 1.35;
  text-shadow: 0 1px 2px #000;
}

.subtitle-box .word {
  cursor: pointer;
  border-radius: 3px;
  padding: 0 1px;
  transition: background .12s, color .12s;
}
.subtitle-box .word:hover { background: var(--accent); color: #fff; }
.subtitle-box .word.active { background: var(--accent-2); color: #fff; }

.plyr:fullscreen .subtitle-box,
.plyr:-webkit-full-screen .subtitle-box,
.plyr--fullscreen-active .subtitle-box,
.plyr--fullscreen-fallback .subtitle-box { font-size: clamp(22px, 2.6vw, 40px); }

.subtitle-overlay.hidden { display: none; }

/* ---- translation popup ---- */

.popup {
  position: absolute;
  z-index: 60;
  min-width: 240px;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
  padding: 14px;
  font-size: 14px;
}
.popup .headword {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 2px;
}
.popup .pos { color: var(--muted); font-size: 12px; }
.popup .row { margin: 8px 0; }
.popup .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.popup .prov { text-transform: none; letter-spacing: 0; opacity: .7; }
.popup .value { margin-top: 2px; }
.popup .value.context { color: var(--muted); font-style: italic; }
.popup .actions { display: flex; gap: 8px; margin-top: 12px; }
.popup .loading { color: var(--muted); }
.popup .err { color: var(--danger); }
.popup .close {
  position: absolute; top: 6px; right: 8px;
  background: none; border: none; color: var(--muted); font-size: 18px; padding: 2px 6px;
}
.popup .saved-badge { color: #3fb950; font-size: 13px; align-self: center; }

/* ---- controls row ---- */

.controls-row {
  display: flex;
  align-items: center;
  gap: 12px 16px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.controls-row + .controls-row { margin-bottom: 14px; }
.controls-row label { color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.sub-sync { color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.sub-sync button { padding: 4px 8px; }
.sub-sync .offset-value { min-width: 58px; color: var(--text); font-variant-numeric: tabular-nums; }
.sub-sync .offset-value.nonzero { color: var(--accent); border-color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; margin-top: 10px; }

/* ---- words table ---- */

#list { overflow-x: auto; }

table.words {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  min-width: 720px;
}
table.words th, table.words td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.words th { color: var(--muted); font-weight: 600; font-size: 13px; }
table.words td.context { color: var(--muted); font-style: italic; max-width: 360px; }
table.words tr:hover { background: var(--panel-2); }
.tc-link { cursor: pointer; color: var(--accent); text-decoration: none; white-space: nowrap; }
.empty { color: var(--muted); padding: 30px 0; text-align: center; }

/* ---- export ---- */

.words-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.words-head h2 { margin: 0; }
.words-head-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
#filter-wrap { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar-label { color: var(--muted); font-size: 13px; }
.toolbar button { padding: 6px 12px; font-size: 14px; }

.export-panel {
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.export-panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.export-panel-head .muted { color: var(--muted); font-size: 12px; flex: 1; min-width: 200px; }
.export-panel-head .close-panel {
  background: none; border: none; color: var(--muted); font-size: 18px; padding: 2px 6px;
}
.export-panel textarea {
  width: 100%;
  resize: vertical;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
}
