/* AI Historik – rozhraní pro žáky (optimalizováno pro tablety)
   Paleta: muzejní stěna, inkoust, měděná patina, mosaz */
:root {
  --wall: #e9eee8;
  --wall-deep: #dde5de;
  --paper: #fafbf8;
  --ink: #1e2b32;
  --ink-2: #51606a;
  --line: #cdd6ce;
  --patina: #2c6e66;
  --patina-deep: #1f524c;
  --patina-soft: #d6e6e2;
  --brass: #b8892b;
  --brass-soft: #f1e6cc;
  --alert: #a33a2b;
  --alert-soft: #f6e1dc;

  --font-display: "Bitter", "Rockwell", Georgia, serif;
  --font-body: "Atkinson Hyperlegible", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --r-lg: 22px;
  --r-md: 14px;
  --r-sm: 10px;
  --tap: 56px;
  --pad: clamp(16px, 3vw, 32px);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 19px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--wall);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--patina-deep); }
:focus-visible { outline: 3px solid var(--brass); outline-offset: 3px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Tlačítka ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 26px;
  border: 2px solid transparent; border-radius: 999px;
  font: 700 18px/1 var(--font-body); text-decoration: none; cursor: pointer;
  transition: background-color .15s, border-color .15s, transform .1s;
  touch-action: manipulation; user-select: none;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--patina); color: #fff; }
.btn-primary:hover { background: var(--patina-deep); }
.btn-secondary { background: var(--paper); color: var(--patina-deep); border-color: var(--patina); }
.btn-secondary:hover { background: var(--patina-soft); }
.btn-quiet { background: transparent; color: var(--ink-2); border-color: var(--line); }
.btn-quiet:hover { background: var(--paper); color: var(--ink); }
.btn-done { background: var(--patina-soft); color: var(--patina-deep); cursor: default; }
.btn-locked { background: transparent; color: var(--ink-2); border: 2px dashed var(--line); cursor: not-allowed; }
.btn-small { min-height: 44px; padding: 0 18px; font-size: 16px; }
.btn-large { min-height: 64px; padding: 0 40px; font-size: 20px; }
.btn-block { width: 100%; }

/* ---------- Horní lišta ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px var(--pad);
  background: rgba(233, 238, 232, .92);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-brand, .topbar-back {
  display: inline-flex; align-items: center; gap: 10px; min-height: 48px;
  color: var(--ink); text-decoration: none; font: 600 19px/1.2 var(--font-display);
}
.topbar-mark { width: 30px; height: 30px; color: var(--patina); }
.topbar-back svg { width: 26px; height: 26px; }
.topbar-back span { font-family: var(--font-body); font-weight: 700; font-size: 18px; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.code-chip {
  font-weight: 700; font-size: 15px; letter-spacing: .12em;
  padding: 6px 12px; border-radius: 8px;
  background: var(--brass-soft); color: #6e5116;
}

/* ---------- Hlášky ---------- */
.flash {
  padding: 14px 18px; border-radius: var(--r-md); margin-bottom: 20px;
  background: var(--patina-soft); color: var(--patina-deep); font-weight: 700;
}
.flash-info { background: var(--brass-soft); color: #6e5116; }
.flash-error { background: var(--alert-soft); color: var(--alert); }
.form-error { color: var(--alert); font-weight: 700; margin-top: 10px; font-size: 17px; }
.empty-state { background: var(--paper); border-radius: var(--r-lg); padding: 40px; text-align: center; color: var(--ink-2); display: grid; gap: 20px; justify-items: center; }

/* ---------- Přihlášení ---------- */
.page-login { display: grid; place-items: center; padding: var(--pad); }
.login {
  width: 100%; max-width: 1040px;
  display: grid; gap: clamp(28px, 5vw, 72px); align-items: center;
  grid-template-columns: 1fr;
}
@media (min-width: 900px) and (orientation: landscape) {
  .login { grid-template-columns: 1.1fr 1fr; }
}
.login-intro { text-align: center; }
@media (min-width: 900px) and (orientation: landscape) { .login-intro { text-align: left; } }
.login-portrait {
  display: block; width: min(300px, 58vw); height: auto; margin: 0 auto 26px;
  filter: drop-shadow(0 10px 24px rgba(30, 43, 50, .14));
}
@media (min-width: 900px) and (orientation: landscape) {
  .login-portrait { width: min(340px, 30vw); margin: 0 0 28px; }
}
@media (orientation: landscape) and (max-height: 620px) {
  .login-portrait { width: min(190px, 26vw); margin-bottom: 18px; }
}
.login-intro h1 { font-size: clamp(38px, 5.5vw, 60px); font-weight: 700; margin-bottom: 14px; }
.login-intro p { font-size: 21px; color: var(--ink-2); max-width: 30ch; margin: 0 auto; }
@media (min-width: 900px) and (orientation: landscape) { .login-intro p { margin: 0; } }

.login-card {
  background: var(--paper); border-radius: var(--r-lg); padding: clamp(24px, 4vw, 40px);
  border: 1px solid var(--line);
  width: 100%; max-width: 480px; justify-self: center;
}
.login-label { display: block; font: 600 22px/1.2 var(--font-display); margin-bottom: 14px; }
.code-input {
  width: 100%; min-height: 76px; padding: 0 20px;
  font: 700 32px/1 var(--font-body); letter-spacing: .08em; text-align: center;
  color: var(--ink); background: var(--wall);
  border: 2px solid var(--line); border-radius: var(--r-md);
  -webkit-appearance: none; appearance: none;
}
.code-input::placeholder { color: #9aa7a0; letter-spacing: .04em; font-size: 22px; font-weight: 400; }
.code-input:focus { outline: none; border-color: var(--patina); background: #fff; }
.login-help { color: var(--ink-2); font-size: 16px; margin: 12px 0 22px; }
.login-card .btn { margin-top: 6px; }

/* ---------- Přehled: tři kroky jako časová osa ---------- */
.home { max-width: 1160px; margin: 0 auto; padding: clamp(24px, 4vw, 48px) var(--pad) 48px; }
.home-head { margin-bottom: clamp(28px, 4vw, 48px); max-width: 60ch; }
.home-head h1 { font-size: clamp(32px, 4.5vw, 46px); margin-bottom: 10px; }
.home-head p { color: var(--ink-2); font-size: 20px; }

.steps { list-style: none; margin: 0; padding: 0; position: relative; display: grid; gap: 20px; }
/* svislá osa (na výšku) */
.steps::before {
  content: ""; position: absolute; left: 31px; top: 36px; bottom: 36px;
  border-left: 3px dotted var(--brass);
}
.step { position: relative; display: grid; grid-template-columns: 64px 1fr; gap: 20px; align-items: start; }
.step-marker {
  position: relative; z-index: 1;
  width: 64px; height: 64px; border-radius: 50%;
  display: grid; place-items: center;
  font: 700 26px/1 var(--font-display);
  background: var(--paper); color: var(--patina-deep);
  box-shadow: 0 0 0 5px var(--wall), inset 0 0 0 3px var(--brass);
}
.step-marker svg { width: 30px; height: 30px; }
.step-done .step-marker { background: var(--patina); color: #fff; box-shadow: 0 0 0 5px var(--wall); }
.step-locked .step-marker { color: #9aa7a0; box-shadow: 0 0 0 5px var(--wall), inset 0 0 0 3px var(--line); }
.step-body {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 24px 26px; display: grid; gap: 8px; justify-items: start;
}
.step-body h2 { font-size: 26px; }
.step-desc { color: var(--ink-2); }
.step-status { font-size: 16px; font-weight: 700; color: var(--patina-deep); margin-bottom: 10px; }
.step-locked .step-status { color: #6e5116; }
.step-locked .step-body { background: transparent; }
.step-active .step-body, .step-ready:first-child .step-body { border-color: var(--patina); box-shadow: inset 0 0 0 1px var(--patina); }

/* vodorovná osa (tablet na šířku) */
@media (min-width: 900px) and (orientation: landscape) {
  .steps { grid-template-columns: repeat(var(--steps, 3), 1fr); gap: 24px; }
  .steps::before { left: 10%; right: 10%; top: 31px; bottom: auto; border-left: 0; border-top: 3px dotted var(--brass); }
  .step { grid-template-columns: 1fr; justify-items: center; gap: 18px; }
  .step-body { width: 100%; height: 100%; align-content: start; }
  .step-body .btn { margin-top: auto; }
}

/* ---------- Dotazníky ---------- */
.questions { max-width: 820px; margin: 0 auto; padding: clamp(24px, 4vw, 44px) var(--pad) 64px; }
.page-head { margin-bottom: 28px; }
.page-head h1 { font-size: clamp(30px, 4vw, 40px); margin-bottom: 8px; }
.page-head p { color: var(--ink-2); }
.q-form { display: grid; gap: 18px; }
.q-card {
  margin: 0; min-width: 0;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 22px clamp(18px, 3vw, 28px) 26px;
}
.q-card.has-error { border-color: var(--alert); box-shadow: inset 0 0 0 1px var(--alert); }
.q-card legend { display: contents; }
.q-num { display: block; font-size: 15px; font-weight: 700; color: var(--brass); margin-bottom: 4px; }
.q-text { display: block; font: 600 22px/1.3 var(--font-display); margin-bottom: 16px; }
.q-optional { display: inline-block; font-size: 14px; color: var(--ink-2); margin: -8px 0 14px; }
textarea {
  width: 100%; padding: 14px 16px; min-height: 110px; resize: vertical;
  font: 400 19px/1.5 var(--font-body); color: var(--ink);
  background: #fff; border: 2px solid var(--line); border-radius: var(--r-md);
}
textarea:focus { outline: none; border-color: var(--patina); }

.choices { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.choice, .scale-item { position: relative; cursor: pointer; }
.choice input, .scale-item input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.choice span {
  display: flex; align-items: center; min-height: var(--tap); padding: 10px 18px;
  border: 2px solid var(--line); border-radius: var(--r-md); background: #fff; font-weight: 700;
}
.choice input:checked + span { border-color: var(--patina); background: var(--patina-soft); color: var(--patina-deep); }
.choice input:focus-visible + span, .scale-item input:focus-visible + span { outline: 3px solid var(--brass); outline-offset: 2px; }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.scale-item span {
  display: grid; place-items: center; height: 64px;
  border: 2px solid var(--line); border-radius: var(--r-md); background: #fff;
  font: 700 24px/1 var(--font-display);
}
.scale-item input:checked + span { background: var(--patina); border-color: var(--patina); color: #fff; }
.scale-labels { display: flex; justify-content: space-between; gap: 16px; margin-top: 8px; font-size: 15px; color: var(--ink-2); }
.scale-labels span:last-child { text-align: right; }
.q-submit { display: grid; justify-items: center; gap: 10px; margin-top: 12px; text-align: center; }
.q-submit p { color: var(--ink-2); font-size: 16px; }

/* ---------- Chat ---------- */
.page-chat {
  height: 100vh; height: var(--app-h, 100dvh);
  display: flex; flex-direction: column; overflow: hidden;
}
.chat {
  flex: 1; min-height: 0; width: 100%; max-width: 920px; margin: 0 auto;
  display: flex; flex-direction: column;
}
.chat-head { display: flex; align-items: center; gap: 16px; padding: 16px var(--pad) 12px; }
.chat-head h1 { font-size: 24px; }
.chat-head p { font-size: 15px; color: var(--ink-2); }

.seal {
  flex: none; width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--patina); color: #fff;
  box-shadow: 0 0 0 2px var(--wall), 0 0 0 4px var(--brass);
}
.seal svg { width: 24px; height: 24px; }
.seal-large { width: 56px; height: 56px; }
.msg-portrait { flex: none; width: 42px; height: 42px; border-radius: 50%; box-shadow: 0 0 0 2px var(--brass); background: var(--paper); }
.chat-portrait { flex: none; width: 62px; height: 62px; border-radius: 50%; box-shadow: 0 0 0 2px var(--brass); background: var(--paper); }
.seal-large svg { width: 32px; height: 32px; }

.messages {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 12px var(--pad) 20px;
  display: flex; flex-direction: column; gap: 16px;
}
.msg { display: flex; gap: 12px; align-items: flex-end; max-width: 100%; flex-wrap: wrap; }
.msg .bubble {
  max-width: min(640px, 82%);
  padding: 14px 18px; border-radius: 20px;
  overflow-wrap: anywhere;
}
.msg-assistant .bubble {
  background: var(--paper); border: 1px solid var(--line); border-bottom-left-radius: 6px;
}
.msg-user { justify-content: flex-end; }
.msg-user .bubble {
  background: var(--patina-deep); color: #fff; border-bottom-right-radius: 6px; white-space: pre-wrap;
}
.bubble p + p, .bubble p + ul, .bubble p + ol, .bubble ul + p, .bubble ol + p { margin-top: 10px; }
.bubble ul, .bubble ol { margin: 0; padding-left: 1.3em; }
.bubble li + li { margin-top: 4px; }
.msg-new { animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.msg-failed .bubble { background: #7d8a86; }
.msg-error {
  flex-basis: 100%; display: flex; justify-content: flex-end; align-items: center; gap: 12px; flex-wrap: wrap;
  font-size: 16px; color: var(--alert); font-weight: 700; text-align: right;
}

.msg-typing .bubble { display: inline-flex; align-items: center; gap: 12px; color: var(--ink-2); font-size: 16px; }
.dots { display: inline-flex; gap: 5px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--patina); opacity: .3; animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.composer-wrap {
  padding: 10px var(--pad) calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--wall);
}
.starters { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.starters::-webkit-scrollbar { display: none; }
.starter {
  flex: none; min-height: 48px; padding: 8px 18px; max-width: 360px; text-align: left;
  border: 2px solid var(--patina); border-radius: 999px; background: var(--paper); color: var(--patina-deep);
  font: 700 16px/1.25 var(--font-body); cursor: pointer;
}
.starter:hover { background: var(--patina-soft); }
.composer-notice { font-size: 16px; font-weight: 700; color: #6e5116; margin-bottom: 8px; }
.composer {
  display: flex; align-items: flex-end; gap: 10px;
  background: #fff; border: 2px solid var(--line); border-radius: 28px; padding: 6px 6px 6px 20px;
}
.composer:focus-within { border-color: var(--patina); }
.composer textarea {
  flex: 1; min-height: 44px; max-height: 160px; padding: 10px 0; border: 0; border-radius: 0; background: transparent; resize: none;
}
.composer textarea:focus { outline: none; }
.send-btn {
  flex: none; width: 52px; height: 52px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--patina); color: #fff; display: grid; place-items: center;
  transition: background-color .15s, opacity .15s;
}
.send-btn svg { width: 24px; height: 24px; }
.send-btn:disabled { background: var(--line); cursor: default; }
.composer.is-busy .send-btn { opacity: .6; }
.composer-meta { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; color: var(--ink-2); margin-top: 8px; padding: 0 8px; }
#char-counter.over { color: var(--alert); font-weight: 700; }

@media (max-width: 600px) {
  body { font-size: 17px; }
  .code-chip { display: none; }
  .msg .bubble { max-width: 88%; }
  .chat-head h1 { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Obrázky u zadání a otázek */
.q-media { display: block; margin: 0 0 18px; }
.q-media img {
  display: block; max-width: 100%; max-height: 46vh; width: auto; border-radius: var(--r-md);
  border: 1px solid var(--line); background: #fff;
}
.page-head .q-media { margin-top: 16px; }
@media (orientation: landscape) and (max-height: 720px) { .q-media img { max-height: 40vh; } }

/* Lišta náhledu pro učitele */
.preview-bar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 12px clamp(16px, 4vw, 32px); background: var(--brass-soft, #f4e7cc);
  color: var(--ink); font-size: 16px;
}
.preview-bar .btn { white-space: nowrap; }

/* ---------- Mřížka a volba „Jiné“ ---------- */
.choice-other { margin-top: 2px; }
.other-input {
  width: 100%; grid-column: 1 / -1; min-height: 56px; padding: 0 16px; margin-top: 6px;
  font: 400 18px/1.4 var(--font-body); color: var(--ink);
  background: #fff; border: 2px solid var(--line); border-radius: var(--r-md);
}
.other-input:focus { outline: none; border-color: var(--patina); }

.grid-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.q-grid { width: 100%; border-collapse: collapse; min-width: 420px; }
.q-grid th, .q-grid td { padding: 10px 6px; text-align: center; }
.q-grid thead th { font: 600 15px/1.25 var(--font-body); color: var(--ink-2); vertical-align: bottom; }
.q-grid tbody th {
  text-align: left; font: 400 17px/1.3 var(--font-body); color: var(--ink);
  padding-right: 12px; min-width: 110px;
}
.q-grid tbody tr + tr { border-top: 1px solid var(--line); }
.q-grid tbody tr:nth-child(odd) { background: rgba(44, 110, 102, .04); }
.grid-cell { display: flex; align-items: center; justify-content: center; min-height: 52px; cursor: pointer; }
.grid-cell input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.grid-mark {
  width: 28px; height: 28px; border: 2px solid #aebcb4; background: #fff;
  display: block; transition: border-color .12s, background .12s;
}
.grid-cell input[type="radio"] + .visually-hidden + .grid-mark { border-radius: 50%; }
.grid-cell input[type="checkbox"] + .visually-hidden + .grid-mark { border-radius: 7px; }
.grid-cell input:checked + .visually-hidden + .grid-mark { border-color: var(--patina); background: var(--patina); box-shadow: inset 0 0 0 4px #fff; }
.grid-cell input:focus-visible + .visually-hidden + .grid-mark { outline: 3px solid var(--brass); outline-offset: 3px; }
@media (max-width: 560px) {
  .q-grid { min-width: 360px; }
  .q-grid tbody th { font-size: 16px; min-width: 92px; }
}

/* Formátovaný text zadání a otázek */
.rich-text p { margin: 0 0 12px; }
.rich-text p:last-child { margin-bottom: 0; }
.rich-text ul, .rich-text ol { margin: 0 0 12px; padding-left: 24px; }
.rich-text li { margin-bottom: 6px; }
.rich-text h3, .rich-text h4 { margin: 0 0 8px; font-size: 1.05em; }
.rich-text blockquote { margin: 0 0 12px; padding-left: 14px; border-left: 3px solid var(--line-2); color: var(--ink-2); }
.q-text.rich-text { display: block; }
