/* Barvy a rozměry na jednom místě – tmavý režim jen přepíše tokeny */
:root {
  --bg: #f7f3ee;
  --surface: #ffffff;
  --surface-muted: #f1ebe4;
  --text: #221b18;
  --text-muted: #6f6560;
  --border: #e3dad2;
  --accent: #7a1f3d;
  --accent-hover: #611731;
  --accent-soft: #f4e4e9;
  --accent-text: #ffffff;
  --winner: #b07d12;
  --danger: #b3261e;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(34 27 24 / 6%), 0 4px 16px rgb(34 27 24 / 5%);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171312;
    --surface: #211b1a;
    --surface-muted: #2a2322;
    --text: #efe8e3;
    --text-muted: #a89d97;
    --border: #3a3130;
    --accent: #d0678b;
    --accent-hover: #e07fa1;
    --accent-soft: #3b2029;
    --accent-text: #1a0d12;
    --winner: #e0b24a;
    --danger: #f08a82;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

/* Atribut hidden musí vyhrát i nad display: flex – jinak by se předčasně ukázalo jméno modelu */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 40px 16px 80px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.muted { color: var(--text-muted); }

/* Hlavička */
.masthead { max-width: 720px; margin-bottom: 28px; }

.masthead h1 {
  margin: 0 0 6px;
  font-family: var(--font-serif);
  font-size: clamp(2rem, 5vw, 2.8rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--accent);
}

.lede { margin: 0; color: var(--text-muted); font-size: 1.05rem; }

/* Tlačítka */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.button:disabled { opacity: 0.45; cursor: not-allowed; }

.button-primary { background: var(--accent); color: var(--accent-text); }
.button-primary:not(:disabled):hover { background: var(--accent-hover); }

.button-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.button-secondary:hover { background: var(--surface-muted); }

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.9rem;
  text-decoration: underline;
  cursor: pointer;
}
.link-button.danger { color: var(--danger); }

/* Zadání */
.composer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  max-width: 820px;
}

.composer textarea {
  display: block;
  width: 100%;
  min-height: 120px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

.composer textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.image-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.image-preview img {
  max-width: 120px;
  max-height: 90px;
  border-radius: 6px;
  border: 1px solid var(--border);
  object-fit: cover;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.composer-actions .hint {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Karty s odpověďmi */
.round { margin-top: 36px; }

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card.is-winner { border-color: var(--winner); box-shadow: 0 0 0 2px var(--winner); }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.card-label {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 700;
}

.card-status { color: var(--text-muted); font-size: 0.85rem; }
.card-status.is-error { color: var(--danger); }

.card-status.is-busy::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse { 50% { opacity: 0.25; } }

.card-reveal {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  padding: 10px 16px;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
}

.card-model { font-size: 1.05rem; }
.card-meta { color: var(--text-muted); font-size: 0.85rem; }

.card-body {
  padding: 4px 16px 12px;
  min-height: 120px;
  overflow-wrap: anywhere;
}

.card-body.is-error { color: var(--danger); padding-top: 16px; }

.card-rating {
  display: flex;
  gap: 6px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
}

.card-rating button {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.card-rating button:not(:disabled):hover { border-color: var(--accent); }

.card-rating button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.card-rating button:disabled:not([aria-pressed="true"]) { opacity: 0.4; cursor: default; }

/* Formátovaná odpověď z markdownu */
.answer h1, .answer h2, .answer h3, .answer h4 { line-height: 1.3; margin: 1.2em 0 0.4em; }
.answer h1 { font-size: 1.3rem; }
.answer h2 { font-size: 1.15rem; }
.answer h3, .answer h4 { font-size: 1rem; }
.answer p, .answer ul, .answer ol { margin: 0.7em 0; }
.answer ul, .answer ol { padding-left: 1.3em; }
.answer code {
  padding: 0.1em 0.3em;
  border-radius: 4px;
  background: var(--surface-muted);
  font-size: 0.9em;
}
.answer pre {
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-muted);
  overflow-x: auto;
}
.answer pre code { padding: 0; background: none; }
.answer blockquote {
  margin: 0.7em 0;
  padding-left: 12px;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}
.answer table { border-collapse: collapse; display: block; overflow-x: auto; }
.answer th, .answer td { padding: 4px 8px; border: 1px solid var(--border); }
.answer img { max-width: 100%; }

/* Lišta s vyhodnocením */
.reveal-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  margin-top: 16px;
}

.reveal-status { margin: 0; color: var(--text-muted); text-align: right; }
.reveal-status strong { color: var(--text); }

/* Žebříček */
.leaderboard { margin-top: 56px; max-width: 820px; }

.leaderboard h2 {
  margin: 0 0 12px;
  font-family: var(--font-serif);
  font-size: 1.6rem;
  font-weight: 600;
}

.leaderboard table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}

.leaderboard th, .leaderboard td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.leaderboard th {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.leaderboard tbody tr:last-child td { border-bottom: 0; }
.leaderboard .num { text-align: right; }

.model-maker { display: block; color: var(--text-muted); font-size: 0.8rem; }

.score {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.score-bar {
  flex: 1;
  min-width: 48px;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-muted);
  overflow: hidden;
}

.score-bar span { display: block; height: 100%; background: var(--accent); }

/* Historie kol */
.history { margin-top: 20px; }
.history summary { cursor: pointer; color: var(--text-muted); }

.history-list {
  margin: 12px 0 16px;
  padding-left: 0;
  list-style: none;
}

.history-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.history-prompt { display: block; }
.history-meta { color: var(--text-muted); font-size: 0.85rem; }

/* Mobil a tablet */
@media (max-width: 900px) {
  .cards { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 600px) {
  .page { padding-top: 24px; }
  .composer-actions .hint { display: none; }
  .composer-actions .button-primary { margin-left: auto; }
  .reveal-bar { flex-direction: column; align-items: stretch; }
  .reveal-status { text-align: left; }
  /* Na úzkém displeji schováme méně důležité sloupce žebříčku a zhustíme zbytek */
  .leaderboard th:nth-child(5), .leaderboard td:nth-child(5),
  .leaderboard th:nth-child(6), .leaderboard td:nth-child(6) { display: none; }
  .leaderboard th, .leaderboard td { padding: 8px 6px; }
  .leaderboard th { font-size: 0.7rem; letter-spacing: 0; }
  .score-bar { display: none; }
}
