:root {
    --bg: #0f1419;
    --bg-card: #1a2332;
    --bg-elevated: #243044;
    --text: #f4f7fb;
    --text-muted: #9aa8bc;
    --primary: #4f8cff;
    --primary-dark: #3a6fd6;
    --accent: #ff8f4f;
    --success: #3ecf8e;
    --danger: #ff6b6b;
    --warning: #ffd166;
    --border: rgba(255, 255, 255, 0.08);
    --radius: 16px;
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    --max-width: 480px;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    background: radial-gradient(circle at top, #1b2840 0%, var(--bg) 55%);
    color: var(--text);
}

body {
    -webkit-font-smoothing: antialiased;
    touch-action: manipulation;
}

a {
    color: var(--primary);
    text-decoration: none;
}

.app-shell {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    max-width: var(--max-width);
    margin: 0 auto;
}

.app-main {
    flex: 1;
    padding: 1rem 1rem 5.5rem;
}

.bottom-nav {
    position: fixed;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: min(100%, var(--max-width));
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
    background: rgba(15, 20, 25, 0.92);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
}

.nav-link {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.85rem 1rem;
    border-radius: 12px;
    color: var(--text-muted);
    font-weight: 600;
}

.nav-link.active {
    background: var(--bg-elevated);
    color: var(--text);
}

.page {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.hero {
    padding: 0.5rem 0 0.25rem;
}

.hero.compact h1 {
    margin-bottom: 0.25rem;
}

.eyebrow {
    margin: 0;
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

h1 {
    margin: 0.25rem 0 0.5rem;
    font-size: clamp(1.8rem, 6vw, 2.4rem);
    line-height: 1.1;
}

.subtitle, .player-tag {
    margin: 0;
    color: var(--text-muted);
    line-height: 1.5;
}

.mode-grid {
    display: grid;
    gap: 0.85rem;
}

.mode-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    width: 100%;
    padding: 1.1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text);
    text-align: left;
    box-shadow: var(--shadow);
    cursor: pointer;
}

.mode-card.primary {
    border-color: rgba(79, 140, 255, 0.35);
}

.mode-card.accent {
    border-color: rgba(255, 143, 79, 0.35);
}

.mode-card.theory {
    border-color: rgba(79, 140, 255, 0.35);
}

.mode-card.exercise {
    border-color: rgba(62, 207, 142, 0.35);
}

.mode-card.simulation {
    border-color: rgba(255, 143, 79, 0.4);
}

.mode-card.all {
    border-color: rgba(180, 140, 255, 0.35);
}

.mode-card.theory .mode-icon { color: #9ec0ff; }
.mode-card.exercise .mode-icon { color: #8ce8b8; }
.mode-card.simulation .mode-icon { color: #ffc49a; }
.mode-card.all .mode-icon { color: #d4b8ff; }

.mode-section {
    margin-top: 1.25rem;
}

.section-title {
    margin: 0 0 0.65rem;
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.mode-grid.compact {
    gap: 0.65rem;
}

.mode-card.compact {
    padding: 0.95rem 1rem;
}

.mode-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 3rem;
    height: 3rem;
    border-radius: 12px;
    background: var(--bg-elevated);
    font-weight: 800;
}

.mode-title {
    font-size: 1.15rem;
    font-weight: 700;
}

.mode-desc {
    color: var(--text-muted);
    line-height: 1.45;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
}

.question-card.correct {
    border-color: rgba(62, 207, 142, 0.5);
}

.question-card.wrong {
    border-color: rgba(255, 107, 107, 0.5);
}

.question-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.badge {
    background: rgba(79, 140, 255, 0.15);
    color: #b8d0ff;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
}

.badge.content-badge {
    background: rgba(180, 140, 255, 0.15);
    color: #dcc8ff;
}

.topic {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.question-body {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
    font-size: 1.15rem;
    line-height: 1.5;
}

.math-text, .math-plain {
    word-break: break-word;
}

.math-text .katex {
    font-size: 1.05em;
}

.math-text .katex-display {
    margin: 0.35rem 0;
}

.answers {
    display: grid;
    gap: 0.65rem;
}

.answers.disabled {
    opacity: 1;
    pointer-events: none;
}

.answer-btn.answer-wrong {
    border-color: rgba(255, 107, 107, 0.85);
    background: rgba(255, 107, 107, 0.2);
    box-shadow: 0 0 0 2px rgba(255, 107, 107, 0.35);
}

.answer-btn.answer-correct {
    border-color: rgba(62, 207, 142, 0.85);
    background: rgba(62, 207, 142, 0.18);
    box-shadow: 0 0 0 2px rgba(62, 207, 142, 0.35);
}

.answer-btn {
    width: 100%;
    min-height: 3.25rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-elevated);
    color: var(--text);
    font-size: 1rem;
    text-align: left;
    cursor: pointer;
}

.answer-btn:active {
    transform: scale(0.98);
}

.feedback-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 1.5rem;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    cursor: pointer;
    opacity: 1;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    overscroll-behavior: contain;
}

.feedback-overlay.wrong {
    color: #ffe0e0;
}

.feedback-overlay-backdrop {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.feedback-overlay.correct .feedback-overlay-backdrop {
    -webkit-backdrop-filter: blur(16px) saturate(0.75) brightness(0.7);
    backdrop-filter: blur(16px) saturate(0.75) brightness(0.7);
    background:
        radial-gradient(circle at 50% 35%, rgba(62, 207, 142, 0.18) 0%, transparent 55%),
        rgba(8, 12, 18, 0.55);
}

.feedback-overlay.wrong .feedback-overlay-backdrop {
    -webkit-backdrop-filter: blur(6px) saturate(0.9) brightness(0.82);
    backdrop-filter: blur(6px) saturate(0.9) brightness(0.82);
    background:
        radial-gradient(circle at 50% 40%, rgba(255, 107, 107, 0.14) 0%, transparent 50%),
        rgba(8, 12, 18, 0.38);
}

.feedback-overlay.visible {
    opacity: 1;
}

.feedback-overlay.correct {
    color: #d8ffe9;
}

.feedback-overlay-panel {
    position: relative;
    z-index: 1;
    width: min(100%, 22rem);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.85rem;
    padding: 1.25rem;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}

.feedback-overlay.wrong .feedback-overlay-panel {
    width: min(100%, 26rem);
    padding: 1.15rem 1.25rem;
    gap: 0.75rem;
}

.feedback-overlay-icon {
    width: 5.5rem;
    height: 5.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.75rem;
    font-weight: 800;
    line-height: 1;
    border: 3px solid currentColor;
    background: rgba(0, 0, 0, 0.2);
}

.feedback-overlay-title {
    margin: 0;
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: 0.02em;
}

.feedback-overlay.wrong .feedback-overlay-title {
    font-size: 2.15rem;
}

.feedback-overlay-detail {
    width: 100%;
    padding: 0.95rem 1.1rem;
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.22);
    font-size: 1.05rem;
    line-height: 1.55;
    text-align: center;
}

.feedback-overlay.wrong .feedback-overlay-detail {
    font-size: 1.15rem;
    line-height: 1.6;
}

.feedback-overlay.wrong .feedback-overlay-detail .math-text {
    font-size: 1.05em;
}

.feedback-overlay-detail-label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    opacity: 0.75;
}

.feedback-overlay-hint {
    margin: 0.5rem 0 0;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.55);
}

.feedback-overlay.wrong .feedback-overlay-hint {
    font-size: 0.95rem;
}

.feedback-overlay-progress {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 6px;
    z-index: 2;
    background: rgba(0, 0, 0, 0.55);
    overflow: hidden;
}

.feedback-overlay-progress-bar {
    display: block;
    height: 100%;
    width: 100%;
    transform-origin: left center;
    background: var(--success);
    animation-name: feedback-progress-shrink;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
    will-change: transform;
}

.feedback-overlay.correct .feedback-overlay-progress-bar {
    background: var(--success);
}

@keyframes feedback-progress-shrink {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

.hud {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.hud-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.hud-stat {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.65rem 0.75rem;
}

.hud-label {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.hud-value {
    font-size: 1.25rem;
    font-weight: 800;
}

.hud-stat.correct .hud-value { color: var(--success); }
.hud-stat.wrong .hud-value { color: var(--danger); }
.hud-stat.streak .hud-value { color: var(--warning); }

.timer-bar, .progress-bar {
    height: 8px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    overflow: hidden;
}

.timer-fill, .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #7aa8ff);
    transition: width 0.2s linear;
}

.timer-text, .progress-text {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
}

.results-hero {
    text-align: center;
}

.results-card {
    text-align: center;
}

.score-ring {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 9rem;
    height: 9rem;
    margin: 0 auto 1rem;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(79, 140, 255, 0.2), transparent 70%);
    border: 3px solid rgba(79, 140, 255, 0.35);
}

.score-value {
    font-size: 2.2rem;
    font-weight: 800;
}

.score-label {
    color: var(--text-muted);
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.result-stat .value {
    display: block;
    font-size: 1.5rem;
    font-weight: 800;
}

.result-stat .value.correct { color: var(--success); }
.result-stat .value.wrong { color: var(--danger); }
.result-stat .value.xp { color: var(--warning); }

.result-stat .label, .elapsed, .mode-label {
    color: var(--text-muted);
}

.actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 3rem;
    padding: 0.85rem 1rem;
    border-radius: 14px;
    border: none;
    font-weight: 700;
    cursor: pointer;
}

.btn.primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
}

.btn.secondary {
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
}

.text-link, .back-link {
    display: inline-block;
    text-align: center;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.quick-links {
    text-align: center;
}

.stats-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.65rem;
}

.summary-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0.85rem 0.5rem;
    text-align: center;
}

.summary-value {
    display: block;
    font-size: 1.35rem;
    font-weight: 800;
}

.summary-value.correct { color: var(--success); }

.summary-label {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.daily-list, .subcategory-list {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.daily-row, .subcategory-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 0.65rem;
    align-items: center;
}

.daily-bar {
    height: 8px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    overflow: hidden;
}

.daily-fill {
    height: 100%;
    background: var(--success);
}

.daily-date, .daily-score, .subcategory-info span {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-left:5px;
}

.subcategory-row {
    grid-template-columns: 1fr auto;
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--border);
}

.subcategory-accuracy {
    font-weight: 800;
}

.subcategory-accuracy.high { color: var(--success); }
.subcategory-accuracy.mid { color: var(--warning); }
.subcategory-accuracy.low { color: var(--danger); }

.loading-card, .empty-card, .error-card {
    text-align: center;
}

.spinner {
    width: 2rem;
    height: 2rem;
    margin: 0 auto 0.75rem;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.mode-card {
    text-decoration: none;
}

.mode-card.custom {
    border-color: rgba(79, 200, 255, 0.35);
}

.mode-card.custom .mode-icon { color: #9ee8ff; }

.custom-badge {
    background: rgba(79, 200, 255, 0.15);
    color: #9ee8ff;
}

.preset-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.preset-card {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.85rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-elevated);
}

.preset-name {
    margin: 0;
    font-size: 1rem;
}

.preset-desc {
    margin: 0.25rem 0 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.preset-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.btn.compact {
    min-height: 2.5rem;
    padding: 0.55rem 0.85rem;
    font-size: 0.9rem;
}

.btn.ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.custom-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.field-label {
    font-weight: 700;
    font-size: 0.9rem;
}

.field-hint, .empty-hint {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.field-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.field-actions {
    display: flex;
    gap: 0.5rem;
}

.text-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    padding: 0;
}

.field input[type="text"],
.field input[type="number"],
.field select {
    width: 100%;
    min-height: 2.75rem;
    padding: 0.65rem 0.85rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    font: inherit;
}

.subcategory-groups {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    max-height: 18rem;
    overflow: auto;
    padding-right: 0.25rem;
}

.subcategory-group {
    margin: 0;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.subcategory-group legend {
    padding: 0 0.35rem;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.checkbox-grid {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    cursor: pointer;
}

.checkbox-item input {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--primary);
}

.form-actions {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.preset-list.compact {
    gap: 0.55rem;
}

.preset-link {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

.preset-play {
    color: var(--primary);
    font-weight: 700;
    white-space: nowrap;
}

h2 {
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
}
