/* === Modern Minimalist Educational App === */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --secondary: #10b981;
    --accent: #f59e0b;
    --error: #ef4444;
    --success: #22c55e;

    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-hover: #334155;

    --text: #f8fafc;
    --text-muted: #94a3b8;
    --text-dim: #64748b;

    --radius: 10px;
    --radius-sm: 6px;
    --transition: 0.2s ease;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
}

/* === Main Container === */
.app {
    width: 100%;
    max-width: 360px;
    height: 100%;
    max-height: 640px;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* === Header === */
.header {
    text-align: center;
    padding: 12px 0;
    flex-shrink: 0;
}

.header h1 {
    font-size: 1.3rem;
    font-weight: 700;
}

.header p {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* === Visitor Counter === */
.visitor-count {
    font-size: 0.65rem;
    color: var(--text-dim);
    text-align: center;
    margin-top: auto;
    padding: 8px;
    opacity: 0.5;
}

/* === Screens === */
.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.screen.hidden {
    display: none !important;
}

/* === Category List === */
.category-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 0;
}

.category-item {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: all var(--transition);
    border: 2px solid transparent;
    display: flex;
    flex-direction: column;
}

.category-item:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
}

.category-item.quiz {
    border-color: var(--accent);
    border-style: dashed;
}

.category-item span {
    font-size: 1rem;
    font-weight: 600;
}

.category-item small {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* === Topic List === */
.topic-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 4px 0;
}

.topic-item {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    cursor: pointer;
    transition: all var(--transition);
    font-size: 0.9rem;
    font-weight: 500;
    border: 2px solid transparent;
}

.topic-item:hover {
    background: var(--bg-hover);
    border-color: var(--primary-light);
}

/* === Screen Header (for topics) === */
.screen-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    flex-shrink: 0;
}

.screen-header h1 {
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0;
}

/* === Inline Home Button === */
.home-btn-inline {
    background: var(--bg-card);
    border: none;
    border-radius: var(--radius-sm);
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.home-btn-inline:hover {
    background: var(--bg-hover);
    color: var(--text);
}

/* === Exercise Screen === */
.exercise-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 12px;
}

/* Progress */
.progress-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.progress-bar {
    flex: 1;
    height: 4px;
    background: var(--bg-card);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 2px;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.7rem;
    color: var(--text-muted);
    min-width: 32px;
}

/* Question Card */
.question-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    flex-shrink: 0;
}

.question-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.question-text {
    font-size: 1.2rem;
    font-weight: 600;
    line-height: 1.4;
}

.question-text .highlight {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* Fraction Display */
.fraction-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 1.1rem;
    font-weight: 600;
}

.fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
    vertical-align: middle;
}

.fraction .num {
    padding-bottom: 2px;
}

.fraction .line {
    width: 100%;
    height: 2px;
    background: var(--text);
    min-width: 14px;
}

.fraction .den {
    padding-top: 2px;
}

.fraction.small {
    font-size: 0.85em;
}

.fraction.small .line {
    height: 1px;
}

.fraction-op {
    font-size: 1.3rem;
}

/* Answer Grid - adaptive */
.answers-grid {
    display: grid;
    gap: 8px;
    flex: 1;
    width: 100%;
    max-width: 320px;
    /* Omezení šířky */
    margin: 0 auto;
    /* Centrování */
    align-content: center;
}

.answers-grid.cols-2 {
    grid-template-columns: 1fr 1fr;
    max-height: none;
    align-content: start;
}

.answers-grid.cols-4 {
    grid-template-columns: 1fr 1fr;
}

.answer-btn {
    background: var(--bg-card);
    border: 1px solid var(--bg-hover);
    /* Jemnější border */
    border-radius: var(--radius-sm);
    padding: 16px 8px;
    /* Menší padding na výšku */
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 60px;
    /* Fixní minimální výška */
}

.answer-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--primary);
    transform: translateY(-1px);
}

.answer-btn.correct {
    background: var(--success);
    border-color: var(--success);
}

.answer-btn.wrong {
    background: var(--error);
    border-color: var(--error);
}

.answer-btn:disabled {
    cursor: default;
}

/* === Numpad === */
.numpad-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    flex: 1;
    justify-content: center;
}

.numpad-display {
    background: var(--bg-card);
    border: 2px solid var(--primary);
    border-radius: var(--radius-sm);
    padding: 10px 20px;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
    min-width: 100px;
    text-align: center;
}

.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    width: 100%;
    max-width: 180px;
}

.numpad-btn {
    background: var(--bg-card);
    border: none;
    border-radius: var(--radius-sm);
    padding: 12px;
    font-family: inherit;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition);
}

.numpad-btn:hover {
    background: var(--bg-hover);
}

.numpad-btn:active {
    transform: scale(0.95);
}

.numpad-btn.action {
    background: var(--primary);
}

.numpad-btn.action:hover {
    background: var(--primary-light);
}

.numpad-btn.delete {
    background: var(--error);
    color: white;
}

/* === Modal Popup === */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 320px;
    width: 100%;
    text-align: center;
    animation: modalPop 0.3s ease;
}

@keyframes modalPop {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

.modal-text {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text);
    margin-bottom: 16px;
}

/* === Results Screen === */
.results-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.score-display {
    text-align: center;
    padding: 16px;
    background: var(--bg-card);
    border-radius: var(--radius);
}

.score-display .score {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.score-display .label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 10px;
    text-align: center;
}

.stat-card .value {
    font-size: 1.2rem;
    font-weight: 600;
}

.stat-card .label {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.stat-card.success .value {
    color: var(--success);
}

.stat-card.error .value {
    color: var(--error);
}

.stat-card.accent .value {
    color: var(--accent);
}

/* Error Section */
.error-header {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.error-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 100px;
    overflow-y: auto;
}

.error-item {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: 0.75rem;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.error-item .q {
    color: var(--text-muted);
}

.error-item .a {
    color: var(--success);
    font-weight: 500;
}

/* === Buttons === */
.btn {
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-light);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-accent {
    background: var(--accent);
    color: var(--bg);
}

.btn-block {
    width: 100%;
}

.btn-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

/* === Feedback Animation === */
.feedback {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    z-index: 999;
    pointer-events: none;
    animation: pop 0.5s ease forwards;
}

@keyframes pop {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }

    50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }
}

.shake {
    animation: shake 0.4s ease;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-6px);
    }

    75% {
        transform: translateX(6px);
    }
}

/* === Responsive === */
@media (max-width: 380px) {
    body {
        padding: 8px;
    }

    .header h1 {
        font-size: 1.2rem;
    }

    .question-text {
        font-size: 1.1rem;
    }

    .numpad-btn {
        padding: 10px;
        font-size: 1rem;
    }
}

@media (min-height: 700px) {
    .app {
        max-height: 680px;
    }
}