:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card2: #24324a;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #d4a24c;
  --accent-dark: #b3873a;
  --claude: #c96f4a;
  --gpt: #4aa88c;
  --kimi: #5b7fd4;
  --danger: #dc6a6a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 40px;
}

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

.brand { display: flex; align-items: center; gap: 10px; }

.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  background: var(--accent);
  color: #1a1205;
  font-weight: 700;
  font-size: 22px;
  border-radius: 8px;
}

.brand h1 { font-size: 18px; font-weight: 600; }

.topbar-actions { display: flex; gap: 6px; }

.icon-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--text);
}
.icon-btn:hover { background: var(--card2); }

main { max-width: 860px; margin: 0 auto; padding: 16px; }

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

.ask-label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 8px; }

/* Přepínač režimu */
.mode-switch { display: flex; gap: 10px; margin-bottom: 14px; }
.mode-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--text);
  text-align: left;
}
.mode-btn:hover { border-color: var(--muted); }
.mode-btn.active { border-color: var(--accent); background: var(--card2); outline: 1px solid var(--accent); }
.mode-title { font-size: 14px; font-weight: 600; }
.mode-desc { font-size: 12px; color: var(--muted); }
@media (max-width: 480px) {
  .mode-switch { flex-direction: column; }
}

textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  padding: 12px;
  resize: vertical;
  font-family: inherit;
}
textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }

.ask-actions { display: flex; gap: 10px; margin-top: 12px; }

.mic-btn {
  font-size: 20px;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
}
.mic-btn.recording { background: var(--danger); animation: pulse 1s infinite; }

.attach-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  max-width: 100%;
  background: var(--card2);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}
.attach-chip .attach-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#attachChips { display: flex; flex-direction: column; gap: 6px; }
#attachChips .attach-chip { margin-top: 6px; }
.attach-chip button {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
}
@keyframes pulse { 50% { opacity: .6; } }

.primary-btn {
  flex: 1;
  background: var(--accent);
  color: #1a1205;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  padding: 12px 20px;
  cursor: pointer;
}
.primary-btn:hover { background: var(--accent-dark); }
.primary-btn:disabled { opacity: .5; cursor: default; }

.secondary-btn, .danger-btn {
  background: var(--card2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  padding: 10px 16px;
  cursor: pointer;
}
.danger-btn { color: var(--danger); border-color: var(--danger); background: none; }

.hint { font-size: 13px; color: var(--muted); margin-top: 12px; }

.hidden { display: none !important; }

/* Pipeline */
.pipeline { margin-top: 18px; display: flex; flex-direction: column; gap: 12px; }

.stage {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  transition: opacity .3s, border-color .3s, box-shadow .3s;
}
.stage-final { border-color: var(--kimi); }

/* čekající fáze potlačená, běžící výrazně zvýrazněná */
.stage.dim { opacity: .45; }
.stage.working {
  opacity: 1;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 22px rgba(212, 162, 76, .35);
  animation: workingGlow 1.4s ease-in-out infinite;
}
@keyframes workingGlow {
  50% { box-shadow: 0 0 0 1px var(--accent), 0 0 34px rgba(212, 162, 76, .6); }
}

.stage-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
}
.stage-head:hover { background: var(--card2); }

.stage-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}
.stage-badge.claude { background: var(--claude); }
.stage-badge.gpt { background: var(--gpt); }
.stage-badge.kimi { background: var(--kimi); }

.stage-title { flex: 1; font-weight: 600; font-size: 15px; }

.stage-status { font-size: 13px; color: var(--muted); }
.stage-status.working {
  color: #1a1205;
  background: var(--accent);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: .8px;
  padding: 4px 12px;
  border-radius: 12px;
  animation: pulse 1.2s infinite;
}
.stage-status.done { color: var(--gpt); }
.stage-status.error { color: var(--danger); }

.stage-body { padding: 0 16px 16px; }
.stage-body.collapsed { display: none; }

.md { font-size: 15px; line-height: 1.65; overflow-wrap: break-word; }
.md h1, .md h2, .md h3 { margin: 14px 0 6px; color: var(--accent); }
.md h1 { font-size: 19px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15px; }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 8px 0 8px 22px; }
.md li { margin: 4px 0; }
.md strong { color: #fff; }
.md code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.md blockquote { border-left: 3px solid var(--accent); padding-left: 10px; color: var(--muted); margin: 8px 0; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

.pipeline-actions { display: flex; gap: 10px; justify-content: center; margin-top: 4px; flex-wrap: wrap; }

.disclaimer {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin-top: 24px;
  padding: 0 10px;
  line-height: 1.8;
}
.disclaimer a { color: var(--muted); text-decoration: underline; }
.disclaimer a:hover { color: var(--accent); }

/* Přihlášení / PIN */
.view { }

.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px 22px;
  max-width: 400px;
  margin: 8vh auto 0;
}
.auth-card h2 { font-size: 20px; margin-bottom: 14px; text-align: center; }
.auth-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.auth-card input[type=email], .auth-card input[type=password] {
  width: 100%;
  margin-top: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  padding: 10px 12px;
}
.auth-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.auth-card .primary-btn { width: 100%; margin-top: 6px; }

.pin-input {
  display: block;
  width: 100%;
  text-align: center;
  font-size: 28px !important;
  letter-spacing: 12px;
  padding: 12px !important;
  margin: 10px 0 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
}
.pin-input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.auth-switch { text-align: center; font-size: 13px; color: var(--muted); margin-top: 14px; }
.auth-switch a { color: var(--accent); text-decoration: none; }

.form-error { color: var(--danger); font-size: 13px; margin: 8px 0; }
.muted-line { color: var(--muted); font-size: 13px; text-align: center; margin-bottom: 10px; }

/* Zůstatek v liště */
.balance-chip {
  background: var(--card2);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  cursor: pointer;
}
.balance-chip:hover { background: var(--bg); }

/* Balíčky kreditů */
.pkg-grid { display: flex; flex-direction: column; gap: 8px; margin-bottom: 6px; }
.pkg-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
  width: 100%;
}
.pkg-btn:hover { border-color: var(--accent); }
.pkg-btn .pkg-name { font-weight: 600; text-align: left; }
.pkg-btn .pkg-price { color: var(--accent); font-weight: 700; white-space: nowrap; }
.pkg-btn.pkg-sub { border-color: var(--kimi); }

/* Účet */
.account-line { font-size: 14px; margin-bottom: 8px; }
.account-credits b { color: var(--accent); font-size: 16px; }
.usage-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 8px; }
.usage-table th, .usage-table td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--border); }
.usage-table th:first-child, .usage-table td:first-child { text-align: left; }
.usage-table th { color: var(--muted); font-weight: 600; }

/* Modaly */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 17px; }

.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-body h3 { font-size: 14px; margin: 14px 0 8px; color: var(--accent); }
.modal-body h3:first-child { margin-top: 0; }
.modal-body label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.modal-body input[type=text], .modal-body input[type=password] {
  width: 100%;
  margin-top: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 9px 11px;
}
.check-label { display: flex !important; align-items: flex-start; gap: 8px; font-size: 13px; line-height: 1.5; }
.check-label input { margin-top: 3px; }
.muted { color: var(--muted); font-weight: 400; font-size: 12px; }
.modal-actions { margin-top: 14px; }
.modal-actions .primary-btn { width: 100%; }

/* Aplikační dialog */
.dialog-card { max-width: 400px; }
.dialog-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 15px;
  color: var(--accent);
}
.dialog-msg { padding: 18px 20px; font-size: 15px; line-height: 1.6; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; padding: 0 20px 18px; }
.dialog-actions .primary-btn { flex: 0 0 auto; padding: 10px 26px; }

/* Historie */
.history-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  cursor: pointer;
}
.history-item:hover { background: var(--card2); }
.history-q { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.history-date { font-size: 12px; color: var(--muted); }
.history-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 20px 0; }

@media (max-width: 600px) {
  .brand h1 { font-size: 16px; }
  main { padding: 10px; }
  .ask-card { padding: 14px; }
}

/* Fakturační údaje — dvousloupcové řádky */
.field-row { display: flex; gap: 10px; }
.field-row label { flex: 1; min-width: 0; }

/* Přepínač role: právník / občan */
.role-switch { display: flex; gap: 8px; margin-bottom: 12px; }
.role-btn {
  flex: 1; padding: 8px 10px; border-radius: 999px; cursor: pointer;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted);
  font-size: 13px; font-weight: 600; font-family: inherit;
}
.role-btn:hover { border-color: var(--muted); }
.role-btn.active { border-color: var(--accent); color: var(--text); background: var(--card2); }

/* Dlaždice životních situací (režim Občan) */
.topic-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.topic-btn {
  padding: 10px 6px; border-radius: 10px; cursor: pointer; text-align: center;
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  font-size: 12.5px; font-family: inherit; line-height: 1.3;
}
.topic-btn:hover { border-color: var(--muted); }
.topic-btn.active { border-color: var(--accent); background: var(--card2); outline: 1px solid var(--accent); }
@media (max-width: 480px) { .topic-grid { grid-template-columns: repeat(2, 1fr); } }

/* ===================== Jazyky AI ===================== */

:root { --accent: #4fb0a5; --accent-dark: #3b8f86; }

.lang-row { margin-bottom: 12px; }
.lang-row label { display: block; font-size: 12px; color: var(--muted); }
.ask-card select {
  width: 100%; margin-top: 4px; padding: 10px 12px; border-radius: 10px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  font-size: 15px; font-family: inherit;
}
.ask-card select:focus { outline: none; border-color: var(--accent); }
.quality-select { flex: 1; margin-top: 0 !important; }
.tab-pane textarea { width: 100%; }
.task-switch { flex-wrap: wrap; }
.task-switch .mode-btn { flex: 1 1 calc(50% - 5px); }

/* Hlasová lekce */
.voice-btn { width: 100%; margin-top: 12px; padding: 16px; font-size: 17px; }
.voice-btn.danger { background: var(--danger); color: #fff; }
.voice-status {
  display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600;
  padding: 10px 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border);
}
.voice-meta { margin-left: auto; color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.voice-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.voice-dot.listen { background: var(--gpt); animation: pulse 1.2s infinite; }
.voice-dot.speak  { background: var(--accent); }
.voice-dot.think  { background: var(--kimi); animation: pulse 0.8s infinite; }

.phrase-card {
  margin-top: 12px; padding: 18px 16px; border-radius: 14px; text-align: center;
  background: var(--card2); border: 1px solid var(--accent);
}
.phrase-main { font-size: 26px; font-weight: 700; line-height: 1.25; }
.phrase-pron { font-size: 17px; color: var(--accent); margin-top: 6px; font-style: italic; }
.phrase-mean { font-size: 14px; color: var(--muted); margin-top: 6px; }

.voice-log {
  margin-top: 12px; max-height: 38vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px;
}
.bubble { max-width: 88%; padding: 8px 12px; border-radius: 12px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.bubble.tutor { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); }
.bubble.me { align-self: flex-end; background: var(--accent-dark); color: #fff; }

/* Moje fráze */
.phrase-row { display: flex; align-items: center; gap: 6px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.phrase-row-text { flex: 1; min-width: 0; }
.phrase-row-main { font-size: 16px; font-weight: 600; }
.phrase-row .phrase-pron { font-size: 14px; margin-top: 2px; }
.phrase-row .phrase-mean { font-size: 13px; margin-top: 2px; }

/* Klepnutím přehratelné fráze ve výsledku */
.md strong.speakable { cursor: pointer; border-bottom: 1px dotted var(--accent); }
.md strong.speakable:hover { color: var(--accent); }
.md del { color: var(--danger); }

/* ===== v2: větší ovládání na mobilu, A−/A+, stále viditelné ukončení lekce ===== */

.zoom-btn { font-size: 15px; font-weight: 700; min-width: 40px; min-height: 40px; color: var(--muted); }
.zoom-btn:disabled { opacity: .35; cursor: default; }
.icon-btn { min-width: 40px; min-height: 40px; }
.topbar-actions { display: flex; align-items: center; gap: 2px; }

.role-btn { padding: 12px 10px; font-size: 15px; }
.topic-btn { padding: 14px 8px; font-size: 14.5px; }
.mode-btn .mode-title { font-size: 16px; }
.mode-btn .mode-desc { font-size: 13.5px; }
.ask-card select { padding: 13px 12px; font-size: 16px; }
.tab-pane textarea { font-size: 16px; }
.mic-btn { min-width: 56px; min-height: 52px; font-size: 22px; }
.primary-btn { padding: 15px 20px; font-size: 17px; }
.secondary-btn, .danger-btn { padding: 12px 16px; font-size: 15px; }
.hint { font-size: 14px; line-height: 1.5; }
.bubble { font-size: 16px; }
.md { font-size: 16px; }
.voice-status { font-size: 15px; }

/* Ukončení lekce: malé tlačítko přímo ve stavovém řádku + velké přilepené ke spodku obrazovky */
.voice-stop-top {
  margin-left: 8px; padding: 8px 12px; border-radius: 8px; border: none; cursor: pointer;
  background: var(--danger); color: #fff; font-size: 14px; font-weight: 700; font-family: inherit; white-space: nowrap;
}
.voice-btn.danger { position: sticky; bottom: 12px; z-index: 5; box-shadow: 0 6px 18px rgba(0,0,0,.45); }

@media (max-width: 480px) {
  .brand h1 { display: none; }
  .balance-chip { font-size: 14px; padding: 8px 10px; }
  .voice-meta { font-size: 13px; }
}

/* Velké zvětšení na úzkém displeji: řádky se zalamují místo vodorovného posunu */
body { overflow-x: hidden; }
.topbar, .role-switch, .voice-status, .lang-row, .ask-actions { flex-wrap: wrap; }
.role-btn { flex: 1 1 auto; padding: 12px 6px; font-size: 14.5px; white-space: nowrap; }
.lang-row label { flex: 1 1 130px; }
.voice-meta { white-space: nowrap; }
.balance-chip { white-space: nowrap; }

/* v5: pořadí bloků v záložce Mluvení — „Spustit lekci" je vždy hned pod zadáním; přepis minulé lekce až pod ním.
   Během lekce (.live) je nahoře stav + karta + přepis a tlačítko Ukončit drží u spodku obrazovky. */
#tabVoice:not(.hidden) { display: flex; flex-direction: column; }
#voiceSetup { order: 1; }
#btnVoice { order: 2; flex: 0 0 auto; }
#btnVoiceMute { order: 3; }
#voiceHint { order: 4; }
#voiceLive { order: 5; margin-top: 16px; }
#tabVoice.live #voiceLive { order: 1; margin-top: 0; }
#tabVoice.live #voiceHint { display: none; }
.voice-btn { padding: 18px; font-size: 19px; font-weight: 700; }
.mic-labeled { display: flex; align-items: center; gap: 6px; }
.mic-labeled span { font-size: 14px; color: var(--muted); font-weight: 600; }
.ask-actions .quality-select { flex: 1 1 160px; }

/* víceřádkové zprávy v dialogu (návod k mikrofonu) */
.dialog-msg { white-space: pre-line; }


/* ===================== Čtečka ===================== */
.reader-bar {
  position: sticky; top: 64px; z-index: 4; display: flex; gap: 8px; padding: 8px 0;
  background: var(--card);
}
.reader-bar .primary-btn { flex: 1; padding: 16px; font-size: 18px; font-weight: 700; }
.reader-bar .secondary-btn { flex: 0 0 auto; min-width: 58px; font-size: 20px; }
.reader-info { font-size: 14px; color: var(--muted); margin: 2px 0 10px; font-variant-numeric: tabular-nums; }
.reader-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 4px; }
.reader-actions .secondary-btn { width: 100%; }
.reader-learn { margin: 10px 0 14px; padding: 14px; border-radius: 12px; background: var(--bg); border: 1px solid var(--border); }
.reader-blocks { margin-top: 10px; }
.reader-block {
  padding: 10px 12px; margin: 0 0 6px; border-radius: 10px; font-size: 17px; line-height: 1.6; cursor: pointer;
  border-left: 3px solid transparent;
}
.reader-block:hover { background: var(--bg); }
.reader-block.current { background: var(--card2); border-left-color: var(--accent); }
