:root {
    --primary: #0277bd;      
    --primary-light: #4fc3f7;
    --accent: #81d4fa;
    --bg-color: #e1f5fe;
    --card-bg: #ffffff;
    --text-main: #333;
    --border-color: #b3e5fc;
    --correct-bg: #e8f5e9;
    --correct-text: #1b5e20;
    --correct-border: #2e7d32;
    --wrong-bg: #ffebee;
    --wrong-border: #c62828;
}

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    margin: 0;
    padding-bottom: 80px;
    line-height: 1.5;
}

/* Sticky Header */
.controls-wrapper {
    position: sticky;
    top: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(5px);
    padding: 15px 20px;
    z-index: 1000;
    border-bottom: 4px solid var(--primary);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 15px;
    transition: margin 0.3s;
}

h1 { margin: 0; color: var(--primary); font-size: 1.5rem; display: flex; align-items: center; gap: 10px; }

.logo-link {
    text-decoration: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: transform 0.2s ease;
}

.logo-link:hover {
    transform: scale(1.1);
}

/* Desktop vs Mobile prvky */
.mobile-only { display: none; }

/* Dropdown styl */
#mode-select {
    padding: 8px 12px;
    border-radius: 20px;
    border: 2px solid var(--primary);
    color: var(--primary);
    font-weight: bold;
    background: white;
    outline: none;
    font-size: 1rem;
}

.mode-switch { display: flex; gap: 8px; flex-wrap: wrap; }
.mode-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 20px;
    background: #e0e0e0;
    cursor: pointer;
    font-weight: 600;
    transition: 0.3s;
    font-size: 0.9rem;
}
.mode-btn.active { background: var(--primary); color: white; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; transition: all 0.3s; }
.control-group { display: flex; gap: 5px; }
.btn-icon { background: var(--primary); color: white; border: none; padding: 0; border-radius: 50%; cursor: pointer; width: 36px; height: 36px; font-size: 14px; }
.btn-icon:hover { background: #01579b; }

.search-input { flex-grow: 1; padding: 10px 15px; border: 1px solid var(--primary-light); border-radius: 20px; outline: none; }
.search-input:focus { border-color: var(--primary); box-shadow: 0 0 5px rgba(2, 119, 189, 0.3); }

.btn-reset { background: #ff9800; color: white; border: none; padding: 8px 15px; border-radius: 5px; cursor: pointer; margin-left: auto; }
#status-bar { margin-top: 5px; font-size: 0.85rem; color: #666; }

/* --- RESPONSIVITA PRO MOBILY --- */
@media (max-width: 600px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: block; width: 100%; margin-top: 10px; }
    .btn-play, .btn-pause { display: none; }
    
    h1 { font-size: 1.3rem; width: 100%; }
    .top-row { flex-direction: column; align-items: flex-start; gap: 5px; }
    .toolbar { width: 100%; margin-top: 5px; }

    .controls-wrapper.scrolled { padding: 10px 15px; }
    .controls-wrapper.scrolled .top-row { flex-direction: row; align-items: center; width: 100%; margin-bottom: 8px; gap: 15px; }
    .controls-wrapper.scrolled .site-title { display: none; }
    .controls-wrapper.scrolled h1 { width: auto; margin: 0; }
    .controls-wrapper.scrolled #mode-select { margin-top: 0; width: auto; flex-grow: 1; }
    .controls-wrapper.scrolled .toolbar { flex-wrap: nowrap; }
    .controls-wrapper.scrolled .search-input { width: auto; }
}

/* Karty */
.container { max-width: 900px; margin: 20px auto; padding: 0 15px; }
.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    border-left: 6px solid var(--primary-light);
    transition: transform 0.2s;
    position: relative;
    cursor: pointer; 
}
.card:hover { transform: translateY(-2px); }
.card.reading-active { border-left-color: #ff9800; background-color: #fffde7; }
.mode-test .card { cursor: default; }

.question-text { font-size: 1.2rem; font-weight: 700; margin-bottom: 15px; color: #01579b; }
.answer-hint { font-size: 0.95rem; color: var(--primary); margin-bottom: 15px; font-style: italic; font-weight: 500; display: flex; align-items: center; gap: 6px; }

.question-img { max-width: 100%; height: auto; border-radius: 8px; margin: 10px 0 20px 0; border: 1px solid #ddd; display: block; }

.options-container { display: flex; flex-direction: column; gap: 8px; }
.option-box { padding: 12px; border-radius: 8px; border: 1px solid #eee; background: #fcfcfc; transition: all 0.2s; }
.mode-study-strict .option-box { display: none; }
.mode-study-strict .option-box.is-correct { display: block; background-color: var(--correct-bg); color: var(--correct-text); border-color: var(--correct-border); font-weight: normal; }
.mode-study-full .option-box.is-correct { background-color: var(--correct-bg); border: 2px solid var(--correct-border); color: var(--correct-text); }
.mode-test .option-box { cursor: pointer; }
.mode-test .option-box:hover:not(.checked) { background-color: #e3f2fd; }
.mode-test .option-box.selected-correct { background-color: var(--correct-bg); border-color: var(--correct-border); color: var(--correct-text); }
.mode-test .option-box.selected-wrong { background-color: var(--wrong-bg); border-color: var(--wrong-border); color: #b71c1c; }

/* OTEVŘENÉ OTÁZKY - OBECNÉ */
.open-answer-box {
    line-height: 1.6;
    text-align: left;
    white-space: normal;
    font-size: 0.95rem;
}

.open-answer-box strong {
    color: #2e7d32;
    font-weight: 700;
    display: inline-block;
    margin-top: 8px;
}
.open-answer-box strong:first-child { margin-top: 0; }

/* OTEVŘENÉ OTÁZKY - INPUT FORMULÁŘE */
.open-answer-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.open-answer-container textarea {
    width: 100%;
    /* OPRAVA PŘETÉKÁNÍ */
    box-sizing: border-box; 
    height: 100px;
    padding: 12px;
    margin: 0;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-family: inherit;
    resize: vertical;
}

.open-answer-container textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(2, 119, 189, 0.1);
}

.btn-check { 
    background: var(--primary); 
    color: white; 
    border: none; 
    padding: 10px 16px; 
    border-radius: 5px; 
    cursor: pointer; 
    font-weight: bold;
    align-self: flex-start;
}
.btn-check:hover { background: #01579b; }

/* HODNOCENÍ ODPOVĚDÍ */
.evaluation-result {
    padding: 15px;
    border-radius: 8px;
    margin-top: 5px;
    display: none;
    animation: fadeIn 0.3s ease;
    font-size: 0.95rem;
}

.eval-success {
    background-color: var(--correct-bg);
    border: 1px solid var(--correct-border);
    color: var(--correct-text);
}

.eval-partial {
    background-color: #fff3e0;
    border: 1px solid #ffb74d;
    color: #e65100;
}

.eval-fail {
    background-color: var(--wrong-bg);
    border: 1px solid var(--wrong-border);
    color: #c62828;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Matching */
.matching-container { display: flex; gap: 20px; margin-top: 15px; }
.match-col { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.match-item { padding: 15px; background: #fff; border: 2px solid #ddd; border-radius: 8px; cursor: pointer; transition: all 0.2s; user-select: none; font-size: 0.95rem; display: flex; align-items: center; min-height: 40px; }
.match-item:hover { border-color: var(--primary-light); background: #f0faff; }
.match-item.selected { border-color: var(--primary); background: #e1f5fe; box-shadow: 0 0 5px var(--primary); font-weight: bold; }
.match-item.matched-correct { background-color: var(--pair-bg, var(--correct-bg)); border-color: var(--pair-color, var(--correct-border)); color: var(--pair-color, var(--correct-text)); cursor: default; pointer-events: none; opacity: 1; }
.match-item.matched-wrong { animation: shake 0.4s; border-color: var(--wrong-border); background-color: var(--wrong-bg); color: #c62828; }
@keyframes shake { 0% { transform: translateX(0); } 25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-5px); } 100% { transform: translateX(0); } }

.pair-0 { --pair-color: #1976D2; --pair-bg: #E3F2FD; }
.pair-1 { --pair-color: #388E3C; --pair-bg: #E8F5E9; }
.pair-2 { --pair-color: #F57C00; --pair-bg: #FFF3E0; }
.pair-3 { --pair-color: #7B1FA2; --pair-bg: #F3E5F5; }
.pair-4 { --pair-color: #00796B; --pair-bg: #E0F2F1; }
.pair-5 { --pair-color: #C2185B; --pair-bg: #FCE4EC; }

.study-pair { background: #fff; border: 1px solid #eee; border-left: 5px solid var(--pair-color); border-radius: 8px; padding: 12px 15px; margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; transition: transform 0.2s; }
.study-pair:hover { transform: translateX(5px); box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.pair-content { display: flex; align-items: center; flex: 1; }
.pair-badge { background-color: var(--pair-color); color: white; width: 24px; height: 24px; border-radius: 50%; display: inline-flex; justify-content: center; align-items: center; font-size: 0.8rem; font-weight: bold; margin-right: 12px; flex-shrink: 0; }
.pair-answer { background-color: var(--pair-bg); color: var(--pair-color); padding: 6px 12px; border-radius: 20px; font-weight: normal; display: flex; align-items: center; font-size: 0.95rem; }
.pair-arrow { color: #ccc; margin: 0 15px; font-size: 0.9rem; }
@media (max-width: 600px) { .matching-container { flex-direction: column; } .study-pair { flex-direction: column; align-items: flex-start; gap: 8px; } .pair-arrow { transform: rotate(90deg); align-self: center; margin: 5px 0; } .pair-answer { width: 100%; box-sizing: border-box; } }

/* --- PODPORA HTML FORMÁTOVÁNÍ V TEXTU --- */

/* Základní reset pro vložené HTML elementy, aby dědily font */
.card b, .card strong { font-weight: 700; color: inherit; }
.card i, .card em { font-style: italic; }
.card u { text-decoration: underline; }

/* Horní a dolní indexy - úprava, aby nerozhazovaly line-height */
sub, sup {
  font-size: 75%;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}
sup { top: -0.5em; }
sub { bottom: -0.25em; }

/* Seznamy v textu otázky/odpovědi */
.card ul, .card ol {
    margin: 5px 0 10px 20px;
    padding: 0;
}
.card li {
    margin-bottom: 4px;
}

/* Chemické vzorce a matematika často potřebují trochu více místa */
.match-item sub, .match-item sup,
.option-box sub, .option-box sup {
    font-size: 70%; 
}

/* Pokud je v otázce <br>, zvětšíme mírně rozestup */
.question-text br {
    display: block;
    margin-bottom: 5px;
    content: "";
}