:root {
  --bg: #f4f2ec;
  --card-bg: #ffffff;
  --text: #1f2430;
  --text-muted: #5a5f6b;
  --primary: #2f6fb0;
  --primary-dark: #23578e;
  --success: #2f9e56;
  --success-bg: #e5f6ea;
  --error: #c8433f;
  --error-bg: #fbe7e6;
  --border: #dcd8cc;
  --radius: 18px;
  --focus: #e0a530;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1d23;
    --card-bg: #262932;
    --text: #f1efe9;
    --text-muted: #b7bac2;
    --primary: #5b9bde;
    --primary-dark: #4685c8;
    --success: #4ec97b;
    --success-bg: #163b26;
    --error: #ea7975;
    --error-bg: #3d1f1e;
    --border: #3a3d47;
    --focus: #e0a530;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 23px;
  line-height: 1.5;
  overflow-x: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
}

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

#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.icon-btn {
  background: none;
  border: none;
  font-size: 32px;
  line-height: 1;
  padding: 8px;
  border-radius: 12px;
  color: var(--text);
}
.icon-btn:hover { background: var(--bg); }

.home-brand { display: flex; align-items: center; gap: 8px; }
.brand-name { font-size: 22px; font-weight: 800; color: var(--primary); }

#stats { display: flex; gap: 8px; }

.stat-pill {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 700;
  font-size: 18px;
  white-space: nowrap;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

h1 { font-size: 34px; margin: 8px 0 4px; }
h2 { font-size: 27px; margin: 4px 0; }
p.subtitle { color: var(--text-muted); margin-top: 0; font-size: 20px; }

.name-row { display: flex; align-items: center; gap: 10px; }
.icon-btn.small { font-size: 24px; padding: 6px; }
.name-card input { margin-bottom: 0; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.back-btn {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}
.back-btn:hover { background: var(--bg); }

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

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.topic-card, .list-row {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  text-align: left;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  font-size: 22px;
  color: var(--text);
}
.topic-card:hover, .list-row:hover { border-color: var(--primary); }

.topic-icon {
  font-size: 40px;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  flex-shrink: 0;
}

.list-row { margin-bottom: 12px; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 700; font-size: 23px; }
.row-sub { color: var(--text-muted); font-size: 18px; margin-top: 2px; }
.row-arrow { font-size: 26px; color: var(--text-muted); flex-shrink: 0; }

.progress-track {
  height: 10px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width .3s ease;
}

.stars { font-size: 22px; letter-spacing: 2px; white-space: nowrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 16px 24px;
  font-size: 23px;
  font-weight: 700;
  min-height: 60px;
  width: 100%;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary {
  background: var(--card-bg);
  color: var(--text);
  border: 2px solid var(--border);
}
.btn.secondary:hover { border-color: var(--primary); }
.btn.wide { max-width: 420px; }

.quick-play {
  background: linear-gradient(135deg, var(--primary), #7b4fbf);
  color: #fff;
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  text-align: center;
}
.quick-play h2 { margin-top: 0; color: #fff; }
.quick-play button {
  margin-top: 10px;
  background: #fff;
  color: var(--primary-dark);
  border: none;
  border-radius: 14px;
  padding: 14px 26px;
  font-size: 22px;
  font-weight: 700;
  min-height: 58px;
}

.multiplayer-card {
  background: linear-gradient(135deg, #e0a530, #c4863b);
  color: #fff;
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  text-align: center;
}
.multiplayer-card h2 { margin-top: 0; color: #fff; }
.multiplayer-card button {
  margin-top: 10px;
  background: #fff;
  color: #a35a1a;
  border: none;
  border-radius: 14px;
  padding: 14px 26px;
  font-size: 22px;
  font-weight: 700;
  min-height: 58px;
}

/* Exercise player */
.player-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  font-size: 19px;
  font-weight: 600;
  color: var(--text-muted);
}

.question-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 18px;
}
.question-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.question-text {
  font-size: 29px;
  font-weight: 700;
  flex: 1;
}
.question-image {
  font-size: 90px;
  text-align: center;
  line-height: 1;
  margin-bottom: 6px;
}
.question-image img {
  display: block;
  width: 100%;
  max-height: 340px;
  object-fit: contain;
  border-radius: 12px;
  cursor: zoom-in;
}
.listen-play-btn {
  margin-top: 10px;
  font-size: 20px;
}
.image-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
  margin: 0 0 14px;
}

.image-lightbox {
  cursor: zoom-out;
  padding: 16px;
  align-items: center;
}
.image-lightbox img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: 12px;
  object-fit: contain;
  background: #fff;
  padding: 16px;
}
.speak-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 24px;
  padding: 8px 12px;
  flex-shrink: 0;
}
.speak-btn:hover { border-color: var(--primary); }

.options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.option-btn {
  text-align: left;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  font-size: 23px;
  min-height: 60px;
  color: var(--text);
}
.option-btn:hover:not(:disabled) { border-color: var(--primary); }
.option-btn.selected { border-color: var(--primary); background: var(--bg); }
.option-btn.correct { border-color: var(--success); background: var(--success-bg); }
.option-btn.wrong { border-color: var(--error); background: var(--error-bg); }
.option-btn:disabled { cursor: default; }

.text-input {
  width: 100%;
  font-size: 24px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
}
.text-input:disabled { opacity: .7; }

.sentence-built {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 64px;
  padding: 10px;
  border: 2px dashed var(--border);
  border-radius: 14px;
  margin-bottom: 14px;
}
.sentence-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.word-chip {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 22px;
  font-weight: 600;
}
.word-chip.bank {
  background: var(--card-bg);
  color: var(--text);
  border: 2px solid var(--border);
}
.word-chip:disabled { opacity: .4; }

.mic-area { text-align: center; padding: 10px 0; }
.mic-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  width: 96px;
  height: 96px;
  font-size: 40px;
  margin: 10px auto;
}
.mic-btn.listening { background: var(--error); }
.mic-status { color: var(--text-muted); font-size: 20px; min-height: 26px; }
.transcript { font-size: 24px; font-weight: 700; margin-top: 6px; }

.feedback {
  border-radius: 14px;
  padding: 16px 18px;
  margin-bottom: 16px;
  font-size: 22px;
  font-weight: 600;
}
.feedback.correct { background: var(--success-bg); color: var(--success); }
.feedback.wrong { background: var(--error-bg); color: var(--error); }
.feedback .answer-hint { display: block; font-weight: 400; margin-top: 6px; color: var(--text); font-size: 19px; }

.summary {
  text-align: center;
  padding: 30px 20px;
}
.summary .big-emoji { font-size: 64px; }
.summary .points-earned { font-size: 28px; font-weight: 800; color: var(--primary); margin: 10px 0; }
.summary .stars-big { font-size: 40px; letter-spacing: 6px; margin: 10px 0; }
.summary-actions { display: flex; flex-direction: column; gap: 12px; align-items: center; margin-top: 20px; }

.note {
  font-size: 16px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Soutěžní (multiplayer) režim */
.room-code-card { text-align: center; }
.room-code {
  font-size: 56px;
  font-weight: 800;
  letter-spacing: 10px;
  color: var(--primary);
  margin: 6px 0;
}
.player-row {
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 20px;
}
.player-row:last-child { border-bottom: none; }

.mp-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.mp-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 110px;
  border: none;
  border-radius: 14px;
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  padding: 12px;
  text-align: center;
}
.mp-opt span { line-height: 1.2; }
.mp-opt.mp-red { background: #c8433f; }
.mp-opt.mp-blue { background: #2f6fb0; }
.mp-opt.mp-yellow { background: #d9a02c; }
.mp-opt.mp-green { background: #2f9e56; }
.mp-opt:disabled { opacity: .55; }
.mp-opt.selected { outline: 4px solid #fff; outline-offset: -8px; }

.mp-options-host {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}
.mp-opt-host {
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 20px;
}
.mp-opt-host.is-correct { border-color: var(--success); background: var(--success-bg); }

.leaderboard { padding: 18px; }
.leaderboard.big .leaderboard-row { font-size: 24px; padding: 14px 6px; }
.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 20px;
}
.leaderboard-row:last-child { border-bottom: none; }
.leaderboard-row.me { background: var(--success-bg); border-radius: 10px; font-weight: 700; }
.lb-rank { width: 42px; flex-shrink: 0; font-weight: 700; }
.lb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 800; color: var(--primary); }

.badge-custom {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  vertical-align: middle;
}

.editor-card {
  background: linear-gradient(135deg, #3ba35a, #2f6fb0);
  color: #fff;
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  text-align: center;
}
.editor-card h2 { margin-top: 0; color: #fff; }
.editor-card button {
  margin-top: 10px;
  background: #fff;
  color: #23578e;
  border: none;
  border-radius: 14px;
  padding: 14px 26px;
  font-size: 22px;
  font-weight: 700;
  min-height: 58px;
}

/* Formulářové prvky editoru */
.field-label { display: block; font-weight: 700; font-size: 17px; margin: 12px 0 6px; }
.field-label:first-child { margin-top: 0; }
.field-row { display: flex; gap: 20px; align-items: flex-end; margin-top: 4px; }
.color-input { width: 70px; height: 52px; padding: 4px; border-radius: 12px; border: 2px solid var(--border); background: var(--card-bg); }
textarea.text-input { resize: vertical; min-height: 64px; font-family: inherit; }

.editor-block { border: 2px solid var(--border); }
.editor-block-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.editor-block-header .text-input { flex: 1; }
.editor-sub-list { display: flex; flex-direction: column; gap: 14px; }
.editor-sub-block { background: var(--bg); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }

.exercise-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.exercise-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}
.exercise-row-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.exercise-type-badge {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}
.exercise-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.add-exercise-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.type-select {
  font-size: 18px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  flex: 1;
  min-width: 180px;
}

.option-edit-legend {
  display: flex;
  gap: 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-bottom: 6px;
}
.option-edit-legend span:first-child { width: 118px; flex-shrink: 0; }
.option-edit-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.option-edit-row .text-input { flex: 1; }
.correct-checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 118px;
  flex-shrink: 0;
  padding: 10px 8px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--bg);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}
.correct-checkbox-label input[type="checkbox"] { width: 24px; height: 24px; flex-shrink: 0; }
.correct-checkbox-label:has(input:checked) {
  background: var(--success-bg);
  border-color: var(--success);
  color: var(--success);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 14px;
  overflow-y: auto;
  z-index: 100;
}
.modal-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 560px;
  width: 100%;
  margin: 20px 0;
}

/* Výběr zdroje otázek pro místnost */
.radio-row { display: flex; align-items: center; gap: 12px; font-size: 21px; font-weight: 700; padding: 8px 0; }
.radio-row input[type="radio"] { width: 26px; height: 26px; }
.indent-block { padding: 10px 0 4px 38px; }
.indent-block .count-input { max-width: 110px; }
.checkbox-row { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; font-size: 19px; }
.checkbox-row input[type="checkbox"] { width: 24px; height: 24px; flex-shrink: 0; }
.picker-topic { border-bottom: 1px solid var(--border); padding: 10px 0; }
.picker-topic:last-child { border-bottom: none; }
.picker-row { display: flex; align-items: center; gap: 10px; }
.picker-row.sub { padding-left: 34px; margin-top: 8px; }
.expand-btn { background: none; border: none; font-size: 20px; width: 28px; flex-shrink: 0; color: var(--text-muted); }
.picker-subs { margin-top: 4px; }
.count-input { max-width: 90px; flex-shrink: 0; }

/* Nápovědy (lifelines) v soutěžním režimu */
.lifelines-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.lifeline-btn {
  flex: 1;
  min-width: 100px;
  background: var(--card-bg);
  border: 2px solid var(--primary);
  color: var(--primary);
  border-radius: 12px;
  padding: 12px 10px;
  font-size: 16px;
  font-weight: 700;
}
.lifeline-btn:disabled { opacity: .4; border-color: var(--border); color: var(--text-muted); }
.lifeline-bubble {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 14px;
  font-size: 18px;
}
.mp-opt-hidden { display: none; }

/* Statistiky odpovědí (kdo jak odpověděl) */
.stat-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.stat-label { width: 40%; flex-shrink: 0; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-bar-track { flex: 1; height: 20px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.stat-bar-fill { height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s ease; }
.stat-count { width: 28px; text-align: right; font-weight: 700; flex-shrink: 0; }

/* Osobní statistiky hráče po kole */
.personal-stats .personal-rank { font-size: 22px; margin-bottom: 10px; }
.rank-delta { display: block; font-size: 16px; color: var(--text-muted); margin-top: 2px; }
.personal-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 18px;
}
.personal-row:last-child { border-bottom: none; }

/* Přehled otázek na konci hry */
.recap-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.recap-row:last-child { border-bottom: none; }
.recap-q { font-weight: 700; font-size: 17px; }
.recap-a { color: var(--success); font-size: 16px; margin-top: 2px; }

/* Historie her */
.history-row { padding: 16px; }
.history-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; flex-wrap: wrap; gap: 6px; }

@media (max-width: 400px) {
  .brand-name { display: none; }
}

@media (max-width: 480px) {
  body { font-size: 20px; }
  .question-text { font-size: 25px; }
  .topic-icon { width: 50px; height: 50px; font-size: 32px; }
  .room-code { font-size: 42px; letter-spacing: 6px; }
  .mp-opt { min-height: 96px; font-size: 18px; }
  .field-row { flex-direction: column; align-items: flex-start; gap: 10px; }
  .indent-block { padding-left: 16px; }
  .modal-card { padding: 16px; }
  .lifeline-btn { font-size: 14px; padding: 10px 6px; }
  .stat-label { width: 34%; }
}
