:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --page:           #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --series-1:       #2a78d6; /* blue */
  --series-2:       #eb6834; /* orange */
  --good:           #0ca30c;
  --critical:       #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page:           #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);
    --series-1:       #3987e5;
    --series-2:       #d95926;
    --good:           #0ca30c;
    --critical:       #e66767;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
}

.topbar {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { margin: 0; font-size: 1.1rem; color: var(--text-secondary); font-weight: 600; }
.topbar-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.topbar-row form { margin: 0; }
.logout-btn { padding: 4px 12px; font-size: 0.8rem; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}
.tab-btn.active { background: var(--series-1); color: #fff; border-color: var(--series-1); }

main { max-width: 760px; margin: 0 auto; padding: 24px; }
main:has(#tab-text.active) { max-width: 1100px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.subtabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.subtab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  padding: 8px 4px;
  margin-right: 18px;
  cursor: pointer;
  font-size: 0.92rem;
}
.subtab-btn.active { color: var(--text-primary); border-bottom-color: var(--series-1); font-weight: 600; }
.subtab-panel { display: none; }
.subtab-panel.active { display: block; }

.detail-tabs { display: flex; gap: 4px; margin: 4px 0 14px; border-bottom: 1px solid var(--border); }
.detail-tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  padding: 7px 4px;
  margin-right: 16px;
  cursor: pointer;
  font-size: 0.9rem;
}
.detail-tab-btn.active { color: var(--text-primary); border-bottom-color: var(--series-1); font-weight: 600; }
.detail-tab-panel { display: none; }
.detail-tab-panel.active { display: block; }

.history-list { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; }
.history-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--gridline);
  font-size: 0.9rem;
}
.history-list li:first-child { font-weight: 600; }
.history-list .h-word { color: var(--text-primary); }
.history-list .h-meta { color: var(--text-muted); font-size: 0.8rem; }
.history-list .h-mark.correct { color: var(--good); }
.history-list .h-mark.incorrect { color: var(--critical); }

.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.choice-btn {
  padding: 14px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1rem;
  text-align: left;
}
.choice-btn:disabled { cursor: default; opacity: 0.85; }
.choice-btn.correct { background: var(--good); color: #fff; border-color: var(--good); }
.choice-btn.incorrect { background: var(--critical); color: #fff; border-color: var(--critical); }
@media (max-width: 560px) {
  .choice-grid { grid-template-columns: 1fr; }
}

.permission-checks { display: flex; flex-wrap: wrap; gap: 14px; margin: 10px 0; }
.permission-checks label { display: flex; align-items: center; gap: 6px; font-size: 0.88rem; color: var(--text-secondary); }
.permission-checks input { width: auto; }

.filter-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.filter-row input[type=text] { flex: 1; min-width: 200px; width: auto; }
.filter-row .checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 0.88rem; color: var(--text-secondary); white-space: nowrap; }
.filter-row .checkbox-label input { width: auto; }

.login-main { max-width: 340px; margin: 15vh auto 0; padding: 0 20px; }
.login-box { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 24px; }
.login-box h1 { margin: 0 0 18px; font-size: 1.2rem; text-align: center; }
.login-box form { display: flex; flex-direction: column; gap: 14px; }
.login-box label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--text-secondary); }
.login-box button { width: 100%; }

h2 { margin-top: 0; }
.hint { color: var(--text-muted); font-size: 0.88rem; }
.warning { color: var(--critical); font-size: 0.88rem; }

textarea, input[type=text], input[type=password], input[type=number], select {
  width: 100%;
  font-size: 1rem;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-1);
  color: var(--text-primary);
  font-family: inherit;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--text-secondary); }
.form-grid label.checkbox-label { flex-direction: row; align-items: center; gap: 8px; justify-content: flex-start; margin-top: auto; }
.form-grid label.checkbox-label input { width: auto; }

.quiz-example { font-style: italic; margin-top: -6px; }

.progress-bar-outer { background: var(--gridline); border-radius: 6px; height: 10px; overflow: hidden; margin-top: 8px; }
.progress-bar-inner { background: var(--series-1); height: 100%; width: 0%; transition: width 0.25s ease; }

.text-log-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; gap: 10px; flex-wrap: wrap; }
.text-source-edit { display: inline-flex; align-items: center; gap: 6px; }
.text-source-edit input { width: 160px; padding: 4px 8px; font-size: 0.85rem; }
.badge { background: var(--series-2); color: #fff; border-radius: 10px; padding: 1px 9px; font-size: 0.75rem; white-space: nowrap; }
.badge-ready { background: var(--good); }
.badge-pending { background: var(--surface-1); color: var(--text-secondary); border: 1px solid var(--border); }
.badge-source { background: hsl(var(--source-hue, 210) 70% 92%); color: hsl(var(--source-hue, 210) 70% 30%); border: 1px solid hsl(var(--source-hue, 210) 60% 60%); }
@media (prefers-color-scheme: dark) {
  .badge-source { background: hsl(var(--source-hue, 210) 40% 20%); color: hsl(var(--source-hue, 210) 70% 78%); border-color: hsl(var(--source-hue, 210) 40% 45%); }
}
.text-log-snippet { white-space: pre-wrap; }

#text-audio-player { position: sticky; top: 0; z-index: 3; background: var(--surface-1); }
.subtitle-list { border: 1px solid var(--border); border-radius: 8px; margin-top: 8px; }
.subtitle-row { padding: 8px 12px; border-bottom: 1px solid var(--gridline); cursor: pointer; }
.subtitle-row:hover { background: color-mix(in srgb, var(--series-1) 6%, transparent); }
.subtitle-row.active { background: color-mix(in srgb, var(--series-1) 16%, transparent); border-left: 3px solid var(--series-1); }
.subtitle-en { margin: 0; font-size: 0.92rem; }
.subtitle-cs { margin: 2px 0 0; font-size: 0.85rem; color: var(--text-secondary); }

.subtitle-mode-label { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 0.85rem; color: var(--text-secondary); }
.subtitle-mode-label select { width: auto; }
.subtitle-list[data-mode="none"] { display: none; }
.subtitle-list[data-mode="en"] .subtitle-cs { display: none; }
.subtitle-list[data-mode="cs"] .subtitle-en { display: none; }

#text-log-table tbody tr { cursor: pointer; }
#text-log-table tbody tr:hover { background: color-mix(in srgb, var(--series-1) 8%, transparent); }
.sortable-th { cursor: pointer; user-select: none; white-space: nowrap; }
.sortable-th:hover { color: var(--text-primary); }
.sortable-th::after { content: "↕"; opacity: 0.35; margin-left: 4px; font-size: 0.75em; }
.sortable-th.sort-asc::after { content: "↑"; opacity: 1; }
.sortable-th.sort-desc::after { content: "↓"; opacity: 1; }

.btn-primary, .btn-secondary {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.95rem;
  cursor: pointer;
  margin-top: 10px;
}
.btn-primary { background: var(--series-1); color: #fff; }
.btn-secondary { background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border); }
a.btn-secondary, a.btn-primary { display: inline-block; text-decoration: none; margin-right: 10px; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.result-box {
  margin-top: 20px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.result-box h3 { margin-top: 0; font-size: 0.85rem; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.03em; }

mark.new-word { background: color-mix(in srgb, var(--series-2) 30%, transparent); color: var(--text-primary); border-radius: 3px; padding: 0 2px; }

.en-render { font-size: 1.05rem; line-height: 1.6; }

.prompt-word { font-size: 1.6rem; font-weight: 600; margin: 12px 0; }

#quiz-feedback.correct { color: var(--good); font-weight: 600; }
#quiz-feedback.incorrect { color: var(--critical); font-weight: 600; }

.goal-row { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; font-size: 0.85rem; color: var(--text-secondary); }
.goal-row input { width: 90px; }

.tiles-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 24px; }
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  min-width: 130px;
  flex: 1;
}
.tile .value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .label { color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }

.chart-box { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 20px; overflow-x: auto; }
.chart-box svg { display: block; }
.chart-legend { display: flex; gap: 16px; margin-top: 6px; font-size: 0.8rem; color: var(--text-secondary); }
.chart-legend .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.chart-tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--surface-1);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  z-index: 100;
  display: none;
  white-space: nowrap;
}

/* Wraps every .data-table so a too-wide table scrolls within itself on
   narrow screens instead of forcing the whole page wider (was pushing the
   mobile viewport out to 900px+ for the wider tables). */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--gridline); }
.data-table .cell-example { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); }
.data-table .row-actions { white-space: nowrap; }
.data-table .row-actions button { padding: 4px 10px; font-size: 0.78rem; margin: 0 4px 0 0; }
.data-table input, .data-table select { padding: 4px 6px; font-size: 0.85rem; width: auto; min-width: 90px; }
.data-table th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }
.data-table td:nth-child(3), .data-table td:nth-child(4) { font-variant-numeric: tabular-nums; }

@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
}
