:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --card-bg: #ffffff;
  --text: #1f2937;
  --accent: #2563eb;
  --border: #e2e8f0;
  --error: #dc2626;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  /* pojistka - kdyby nekde uvnitr neco preteklo, at se hybe jen ten konkretni
   * prvek (.table-scroll apod.), ne cela stranka vodorovne */
  overflow-x: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.topbar .brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--accent);
  text-decoration: none;
}

.topbar nav { display: flex; align-items: center; gap: 1rem; }
.user-tag { color: #64748b; }

.content {
  max-width: 1300px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.auth-card { max-width: 360px; margin: 3rem auto; }
.settings-card { max-width: 560px; margin: 2rem auto; }
.settings-group {
  padding-bottom: 1.25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.settings-group:last-of-type { border-bottom: none; }
.settings-group label:not(.checkbox-label) { font-weight: 600; }
.settings-label { display: block; font-weight: 600; margin-bottom: 0.5rem; }
.checkbox-label { display: block; font-weight: 400 !important; margin-bottom: 0.4rem; }
.checkbox-label input { width: auto; display: inline; margin: 0 0.4rem 0 0; }

.set-picker {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem 1rem;
  margin-bottom: 0.75rem;
}
.set-picker legend { padding: 0 0.4rem; font-weight: 600; font-size: 0.9rem; }
.set-picker-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.35rem 1rem;
  max-height: 260px;
  overflow-y: auto;
}
.set-picker-option { display: flex; align-items: center; gap: 0.4rem; font-weight: 400; font-size: 0.85rem; margin-bottom: 0; }
.set-picker-option input { width: auto; margin: 0; }
.set-picker .hint { margin-top: 0.6rem; }
.settings-group .hint { margin: 0.4rem 0 0; }
.settings-section {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin: 1.75rem 0 0.75rem;
}
.settings-section:first-of-type { margin-top: 0; }

form label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

input, select, button {
  font: inherit;
}

input, select {
  display: block;
  width: 100%;
  padding: 0.5rem;
  margin-top: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  cursor: pointer;
}

button:hover { opacity: 0.9; }

.danger-btn { background: var(--error); }

.inline-form {
  display: inline-flex;
  gap: 0.5rem;
  margin: 0;
  align-items: center;
}

.password-field { position: relative; }
.password-field input { padding-right: 2.4rem; margin-top: 0.25rem; }
.password-toggle {
  position: absolute;
  right: 0.3rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  padding: 0.2rem 0.4rem;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.password-toggle:hover { background: var(--border); border-radius: 6px; }

.error { color: var(--error); }
.success { color: #16a34a; }
.hint { color: #64748b; font-size: 0.85rem; }
.summary-box { margin-bottom: 1rem; }
.summary-line { font-weight: 600; margin: 0; display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.summary-submodes { margin: 0.25rem 0 0; }

.grade-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 6px;
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
}
.grade-1 { background: #16a34a; }
.grade-2 { background: #65a30d; }
.grade-3 { background: #d97706; }
.grade-4 { background: #ea580c; }
.grade-5 { background: #dc2626; }

.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table .actions { display: flex; flex-direction: column; gap: 0.4rem; }
.table .progress-cell { text-align: center; color: #64748b; font-variant-numeric: tabular-nums; }

/* barevne odliseni radku slovicek podle stavu (umi/uci se/nove) */
#words-table tr.row-mature { background: #f0fdf4; }
#words-table tr.row-learning { background: #eff6ff; }

.legend-line { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; margin: 0 0 0.75rem; }
.legend-item { display: inline-flex; align-items: center; gap: 0.35rem; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.legend-mature { background: #16a34a; }
.legend-learning { background: var(--accent); }
.legend-plain { background: var(--border); border: 1px solid #c3c2b7; }

.mastery-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 0.25rem; min-width: 90px; }
.mastery-pct { font-weight: 700; font-variant-numeric: tabular-nums; }
.stage-dots { display: flex; gap: 0.2rem; }
.stage-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid var(--border);
  display: inline-block;
}

.set-progress-bar {
  display: flex;
  height: 8px;
  min-width: 80px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--border);
}
.set-progress-bar span { display: block; }
.bar-mature { background: #16a34a; }
.bar-learning { background: var(--accent); }
.bar-new { background: var(--border); }

.tag-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.75rem;
  padding: 0 0.9rem;
}
.tag-group summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  padding: 0.7rem 0;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.tag-group summary::-webkit-details-marker { display: none; }
.tag-group-title::before {
  content: "▸ ";
  color: var(--accent);
  display: inline-block;
  transition: transform 0.15s;
}
.tag-group[open] .tag-group-title::before { transform: rotate(90deg); display: inline-block; }
.tag-group .table-scroll { padding-bottom: 0.9rem; }
.tag-group-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 400;
  color: #64748b;
}
.tag-group-stats strong { color: var(--text); }
.tag-group-stats .set-progress-bar { flex: 0 0 80px; }

.user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.user-actions .inline-form { flex-wrap: nowrap; }
.user-actions input[type="password"] {
  width: 10rem;
  margin-top: 0;
}
.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
  border-radius: 6px;
  white-space: nowrap;
}
.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.btn-outline:hover { border-color: var(--accent); background: var(--bg); }
#admin-users-table td { vertical-align: top; padding-top: 0.85rem; padding-bottom: 0.85rem; }

.child-cards { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: 1rem; }
.child-card {
  flex: 1;
  min-width: 240px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  background: #fff;
}
.child-card h2 { margin: 0 0 0.75rem; }
.child-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem 1rem; margin: 0 0 1rem; }
.child-stats div { display: flex; flex-direction: column; }
.child-stats dt { font-size: 0.78rem; color: #64748b; }
.child-stats dd { margin: 0; font-size: 1.15rem; font-weight: 700; }

.streak-tile {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  background: linear-gradient(135deg, #fb923c, #f97316);
  color: #fff;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  margin-bottom: 1rem;
}
.streak-flame { font-size: 1.7rem; line-height: 1; }
.streak-days { font-size: 1.25rem; font-weight: 700; line-height: 1.2; }
.streak-label { font-size: 0.75rem; opacity: 0.9; }
.streak-freeze-badge {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-weight: 700;
  font-size: 1rem;
}
.streak-freeze-badge .streak-freeze-icon { font-size: 1.1rem; }
.streak-freeze-countdown { font-weight: 400; font-size: 0.75rem; opacity: 0.9; white-space: nowrap; }

.week-chart { margin-bottom: 1rem; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; margin-bottom: 0.35rem; font-size: 0.8rem; color: #64748b; }
.legend-item { display: inline-flex; align-items: center; gap: 0.35rem; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.legend-good { background: #16a34a; }
.legend-critical { background: var(--error); }

.week-chart-svg { width: 100%; height: auto; display: block; }
.chart-baseline { stroke: var(--border); stroke-width: 1; }
.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-line-good { stroke: #16a34a; }
.chart-line-critical { stroke: var(--error); }
.chart-dot { stroke: var(--card-bg); stroke-width: 2; }
.chart-dot-good { fill: #16a34a; }
.chart-dot-critical { fill: var(--error); }
.chart-day-label { font-size: 8px; fill: #64748b; }
.chart-value-label { font-size: 8px; font-weight: 700; }
.chart-value-label-good { fill: #15803d; }
.chart-value-label-critical { fill: #b91c1c; }
.chart-grade-badge text { fill: #fff; font-size: 8px; font-weight: 700; }
.chart-grade-1 rect { fill: #16a34a; }
.chart-grade-2 rect { fill: #65a30d; }
.chart-grade-3 rect { fill: #d97706; }
.chart-grade-4 rect { fill: #ea580c; }
.chart-grade-5 rect { fill: #dc2626; }
.chart-summary { margin: 0.4rem 0 0; }

.pronounce-btn {
  background: transparent;
  color: var(--accent);
  border: none;
  padding: 0.2rem 0.4rem;
  font-size: 1rem;
  line-height: 1;
  border-radius: 6px;
  cursor: pointer;
}
.pronounce-btn:hover { background: var(--border); }
.pronounce-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.priority-badge {
  background: transparent;
  border: none;
  color: #d97706;
  font-size: 1rem;
  line-height: 1;
  padding: 0.1rem 0.3rem;
  cursor: pointer;
  border-radius: 6px;
}
.priority-badge:hover { background: var(--border); }
.priority-badge-hidden { display: none; }

.jump-links { margin: 0.25rem 0; }
.back-to-top-btn {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  display: none;
  z-index: 20;
}
.back-to-top-btn.visible { display: block; }
.back-to-top-btn:hover { filter: brightness(1.1); }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.card-header h1, .card-header h2 { margin: 0; }
.header-actions { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; }

.filter-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.filter-bar input, .filter-bar select {
  width: auto;
  margin-top: 0;
}
.progress-window-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: #64748b;
  margin-bottom: 0;
}
.progress-window-label select { margin-top: 0; }
.filter-bar input[type="search"] { flex: 1; min-width: 180px; }
.mastery-manual {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: #64748b;
  margin-bottom: 0;
}
.mastery-manual input[type="number"] { width: 4.5rem; margin-top: 0; }

.table th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.table th.sortable:hover { color: var(--accent); }
.table th.sortable.sort-asc::after { content: " \25B2"; font-size: 0.7em; }
.table th.sortable.sort-desc::after { content: " \25BC"; font-size: 0.7em; }

textarea {
  display: block;
  width: 100%;
  padding: 0.5rem;
  margin-top: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}

.choice-options { display: flex; flex-direction: column; gap: 0.5rem; margin: 1rem 0; }
.choice-options button {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  text-align: left;
  padding: 0.75rem 1rem;
}
.choice-options button:hover { border-color: var(--accent); }
.choice-options button.correct { background: #dcfce7; border-color: #16a34a; }
.choice-options button.wrong { background: #fee2e2; border-color: var(--error); }

.stage-badges { display: flex; gap: 0.4rem; margin: 0.5rem 0; }
.stage-badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--border);
  color: #64748b;
}
.stage-badge.active { background: var(--accent); color: #fff; }
.stage-badge.done { background: #16a34a; color: #fff; }

.learn-card { text-align: center; max-width: 480px; margin: 2rem auto; }
.learn-card .term { font-size: 2rem; margin: 0.5rem 0; }
.learn-card .pronunciation { color: #64748b; margin-top: -0.5rem; }
.learn-card .choice-options button { width: 100%; }
.feedback { font-size: 1.5rem; font-weight: 700; }
.feedback.correct { color: #16a34a; }
.feedback.wrong { color: var(--error); }
#speak-btn { font-size: 1.5rem; padding: 1rem 2rem; }
.typo-notice { color: #b45309; }
.typo-diff { font-size: 1.2rem; letter-spacing: 0.03em; }
.typo-diff .typo-bad { color: var(--error); text-decoration: underline; text-decoration-thickness: 2px; font-weight: 700; }

.mode-picker {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}
.mode-tile {
  flex: 1;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 1.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  text-decoration: none;
  color: var(--text);
}
.mode-tile:hover { border-color: var(--accent); }
.mode-tile-label { font-size: 1.25rem; font-weight: 700; }
.mode-tile-count { color: #64748b; font-size: 0.85rem; }
.mode-tile-empty { opacity: 0.55; }

.pairing-card { max-width: 560px; margin: 2rem auto; text-align: center; }
.pairing-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem 1rem; }
.pair-tile {
  padding: 0.9rem 1rem;
  border: 2px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  font-weight: 600;
  font-size: 1.1rem;
  cursor: pointer;
}
.pair-left { font-size: 1.4rem; }
.pair-tile:hover { border-color: var(--accent); }
.pair-tile.selected { border-color: var(--accent); background: #eff6ff; }
.pair-tile.matched { border-color: #16a34a; background: #dcfce7; color: #16a34a; cursor: default; opacity: 0.7; }
.pair-tile.shake { animation: pair-shake 0.4s; border-color: var(--error); }
@keyframes pair-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ── Responzivita pro mobil ── */
@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
  }
  .topbar nav {
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    width: 100%;
  }
  .content { padding: 0 0.5rem; margin: 1rem auto; }
  .card { padding: 1rem; }
  .card-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar input, .filter-bar select { width: 100%; }
  .mode-picker { flex-direction: column; }
  .child-cards { flex-direction: column; }
  .user-actions input[type="password"] { width: 100%; }

  /* tabulka slovicek se na mobilu prekresli na karty mist vodorovneho scrollu -
   * #words-table/#admin-users-table se prekresli na bloky (display:block), takze
   * uz nepotrebuji ani nechteji horizontalni scroll od .table-scroll (viz nize).
   * DULEZITE: neresetovat .table-scroll globalne (byval tu bug - overflow-x:visible
   * platilo pro VSECHNY tabulky na strance, ne jen tyhle dve, takze ostatni tabulky
   * (Sady, Kos...) ztratily jediny zpusob, jak se na mobilu vubec dalo dostat k
   * prekryvajicim se sloupcum - zustavaly proste oriznute) */
  #words-table thead { display: none; }
  #words-table, #words-table tbody, #words-table tr, #words-table td { display: block; width: 100%; }
  #words-table tr {
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.4rem 0.75rem;
    background: #fff;
  }
  #words-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.45rem 0;
    border: none;
    border-bottom: 1px solid var(--bg);
    text-align: right;
  }
  #words-table td:last-child { border-bottom: none; }
  #words-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #64748b;
    text-align: left;
  }
  #words-table td:not([data-label]),
  #words-table td[data-label=""] {
    justify-content: flex-end;
  }
  #words-table td.actions { justify-content: flex-end; }

  /* tabulka uzivatelu v adminu - stejny princip prekresleni na karty jako u slovicek,
   * ale sloupec Akce ma vic radku obsahu (tlacitka + reset hesla), takze misto
   * vodorovneho radku (label vlevo, obsah vpravo) je blokovy layout (label nahore) */
  #admin-users-table thead { display: none; }
  #admin-users-table, #admin-users-table tbody, #admin-users-table tr, #admin-users-table td { display: block; width: 100%; }
  #admin-users-table tr {
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.4rem 0.75rem;
    background: #fff;
  }
  #admin-users-table td {
    padding: 0.45rem 0;
    border: none;
    border-bottom: 1px solid var(--bg);
  }
  #admin-users-table td:last-child { border-bottom: none; }
  #admin-users-table td::before {
    content: attr(data-label);
    display: block;
    font-weight: 600;
    color: #64748b;
    font-size: 0.8rem;
  }
  #admin-users-table td.actions { padding-top: 0.6rem; }
  #admin-users-table td.actions .user-actions { margin-top: 0.4rem; }
}
