/* shared.css — common foundation for all authenticated pages */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --blue: #2196F3;
    --blue-dark: #1976D2;
    --bg: #F2F2F7;
    --white: #FFFFFF;
    --text: #1C1C1E;
    --text-secondary: #6B7280;
    --red: #FF3B30;
    --green: #34C759;
    --gold: #FF9500;
    --radius: 16px;
    --shadow: 0 2px 8px rgba(0,0,0,0.06);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Loading */
.auth-loading {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--bg);
    gap: 16px;
}
.auth-loading-ring {
    width: 88px;
    height: 88px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: loaderPulse 2s ease-in-out infinite;
}
.auth-loading-ring svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
.auth-loading-ring .ring-bg {
    fill: none;
    stroke: rgba(33,150,243,0.12);
    stroke-width: 3;
}
.auth-loading-ring .ring-fill {
    fill: none;
    stroke: var(--blue);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-dasharray: 80 165.04;
    animation: loadRingSpin 1.2s linear infinite;
    transform-origin: center;
}
.auth-loading-emoji {
    font-size: 36px;
    position: relative;
    z-index: 1;
}
@keyframes loadRingSpin {
    0%   { stroke-dasharray: 10 235.04; stroke-dashoffset: 0; }
    50%  { stroke-dasharray: 120 125.04; stroke-dashoffset: -40; }
    100% { stroke-dasharray: 10 235.04; stroke-dashoffset: -245.04; }
}
@keyframes loaderPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

/* Language toggle (light style — sub-pages; app.html overrides for blue header) */
.lang-toggle {
    position: fixed;
    top: 14px;
    right: 16px;
    display: flex;
    background: rgba(0,0,0,0.05);
    border-radius: 20px;
    padding: 2px;
    z-index: 10;
}
.lang-btn {
    padding: 6px 14px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 18px;
    font-weight: 600;
    font-size: 0.8rem;
    transition: all 0.2s;
    text-decoration: none;
}
.lang-btn.active {
    background: var(--white);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Sub-page layout (chapters, exams, etc.) */
.page-wrapper {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px 16px 32px;
}
.back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    color: var(--text);
    text-decoration: none;
    margin-bottom: 20px;
    transition: background 0.2s;
}
.back-btn:hover {
    background: rgba(0,0,0,0.05);
}
.page-title {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 24px;
}

/* Base card */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 12px;
}

/* ── Practice page ── */

.practice-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    background: var(--white);
}

/* Header */
.practice-header {
    display: flex;
    align-items: center;
    padding: 12px 16px 0;
    gap: 12px;
    position: sticky;
    top: 0;
    background: var(--white);
    z-index: 5;
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
}
.practice-close {
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    font-size: 1.2rem;
    border-radius: 50%;
    flex-shrink: 0;
    transition: background 0.2s;
}
.practice-close:hover { background: var(--bg); }
.practice-title {
    flex: 1;
    font-size: 0.95rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
}
.practice-bookmark {
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    border-radius: 50%;
    flex-shrink: 0;
    transition: background 0.2s;
    color: var(--text-secondary);
}
.practice-bookmark:hover { background: var(--bg); }
.practice-bookmark.active { color: var(--blue); }

/* Timer (exam mode) */
.practice-timer {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 12px;
    background: var(--bg);
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
    color: var(--text);
    transition: background 0.3s, color 0.3s;
}
.practice-timer.urgent {
    background: #FFE5E5;
    color: var(--red);
}
.practice-timer svg { flex-shrink: 0; }

/* Progress bar */
.practice-progress {
    height: 3px;
    background: #E8E8ED;
    margin: 10px auto 0;
    max-width: 600px;
    width: calc(100% - 32px);
}
.practice-progress-fill {
    height: 100%;
    background: var(--blue);
    border-radius: 2px;
    transition: width 0.4s ease;
}

/* Scrollable content */
.practice-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 16px 0;
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
}

/* Question image */
.practice-image {
    width: 100%;
    border-radius: 12px;
    background: #fff;
    overflow: hidden;
    margin-bottom: 16px;
}
.practice-image img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    margin: 0 auto;
    opacity: 0;
}

/* Question text */
.practice-question {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.45;
    margin-bottom: 20px;
    color: var(--text);
}

/* Options */
.practice-options { display: flex; flex-direction: column; gap: 8px; }
.option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border: 2px solid #E5E7EB;
    border-radius: 14px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.option:active:not(.disabled) { border-color: var(--blue); background: #F0F7FF; }
.option.disabled { pointer-events: none; }

.option-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
    background: var(--bg);
    color: var(--text-secondary);
    transition: background 0.2s, color 0.2s;
}
.option-text {
    flex: 1;
    font-size: 0.95rem;
    line-height: 1.4;
}

/* Option states */
.option.pressed { border-color: var(--blue); background: #F0F7FF; }
.option.pressed .option-icon { background: var(--blue); color: #fff; }

.option.loading { border-color: var(--blue); background: #F0F7FF; }
.option.loading .option-icon { background: var(--blue); color: #fff; }

.option.correct { border-color: var(--green); background: #F0FFF4; }
.option.correct .option-icon { background: var(--green); color: #fff; }

.option.incorrect { border-color: var(--red); background: #FFF5F5; }
.option.incorrect .option-icon { background: var(--red); color: #fff; }

.option.reveal { border-color: var(--green); }
.option.reveal .option-icon { background: var(--green); color: #fff; }

/* Spinner inside option-icon */
.option.loading .option-icon::after {
    content: '';
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
.option.loading .option-letter { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Feedback box */
.practice-feedback {
    margin-top: 16px;
    padding: 16px;
    background: #F0F7FF;
    border-radius: 12px;
    font-size: 0.92rem;
    line-height: 1.55;
    color: var(--text);
}

/* Footer */
.practice-footer {
    position: sticky;
    bottom: 0;
    background: var(--white);
    border-top: 1px solid #E8E8ED;
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
}
.footer-hint {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
}
.hint-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
    padding: 8px 0;
}
.next-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    transition: background 0.2s;
    background: var(--bg);
    color: var(--text-secondary);
}
.next-btn.enabled {
    background: var(--text);
    color: #fff;
}

/* Result banner */
.footer-result {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
}
.footer-result-text {
    font-weight: 700;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 8px;
}
.footer-correct { background: #F0FFF4; }
.footer-correct .footer-result-text { color: var(--green); }
.footer-incorrect { background: #FFF5F5; }
.footer-incorrect .footer-result-text { color: var(--red); }

/* ── Empty state ── */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 32px 24px;
    text-align: center;
    background: var(--white);
}
.empty-state-icon {
    font-size: 3.5rem;
    margin-bottom: 16px;
    animation: resultsPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.empty-state-title {
    font-size: 1.4rem;
    font-weight: 800;
    margin-bottom: 8px;
    color: var(--text);
    animation: resultsFadeUp 0.4s ease-out 0.2s both;
}
.empty-state-desc {
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-secondary);
    max-width: 320px;
    margin-bottom: 32px;
    animation: resultsFadeUp 0.4s ease-out 0.35s both;
}
.empty-state .btn-primary {
    animation: resultsFadeUp 0.4s ease-out 0.5s both;
}

/* ── Results screen ── */

@keyframes resultsPop {
    from { opacity: 0; transform: scale(0.6); }
    to { opacity: 1; transform: scale(1); }
}
@keyframes resultsFadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.results-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 32px 24px;
    text-align: center;
    background: var(--white);
}
.results-circle {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.4rem;
    font-weight: 800;
    margin-bottom: 16px;
    animation: resultsPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.results-circle.passed { background: #E8F9EE; color: var(--green); }
.results-circle.failed { background: #FFE5E5; color: var(--red); }
.results-status {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 24px;
    animation: resultsFadeUp 0.4s ease-out 0.3s both;
}
.results-stats {
    display: flex;
    gap: 32px;
    margin-bottom: 32px;
    animation: resultsFadeUp 0.4s ease-out 0.5s both;
}
.results-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.results-stat-value {
    font-size: 1.4rem;
    font-weight: 700;
}
.results-stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.results-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 300px;
    animation: resultsFadeUp 0.4s ease-out 0.7s both;
}
.btn-primary {
    padding: 14px 24px;
    border-radius: 14px;
    border: none;
    background: var(--blue);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
    text-align: center;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary {
    padding: 14px 24px;
    border-radius: 14px;
    border: 2px solid #E5E7EB;
    background: none;
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.2s;
    text-decoration: none;
    text-align: center;
}
.btn-secondary:hover { border-color: var(--text-secondary); }

/* Practice animations (matching app motion) */
@keyframes optionFadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.option.animate {
    animation: optionFadeIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.option.shake {
    animation: shake 0.2s ease;
}
.practice-image img.fade-in {
    animation: fadeIn 0.5s ease-out both;
}
.practice-feedback.animate {
    animation: slideUp 0.3s ease-out both;
}
.footer-result.animate {
    animation: slideUp 0.25s ease-out both;
}

/* ── Paywall modal ── */

.paywall-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeIn 0.25s ease-out;
}
.paywall-modal {
    background: var(--white);
    border-radius: 20px;
    max-width: 820px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    animation: slideUp 0.35s ease-out;
}
.paywall-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.06);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: background 0.2s;
}
.paywall-close:hover { background: rgba(0,0,0,0.12); }

.paywall-header {
    background: linear-gradient(135deg, #E3F2FD, #BBDEFB);
    padding: 24px 20px 16px;
    text-align: center;
    border-radius: 20px 20px 0 0;
}
.paywall-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1565C0;
    margin-bottom: 6px;
}
.paywall-subtitle {
    font-size: 0.88rem;
    color: #1976D2;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.paywall-features {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 20px 24px 8px;
    justify-content: center;
}
.paywall-feature {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.88rem;
    color: var(--text);
    font-weight: 500;
}
.paywall-feature svg { flex-shrink: 0; color: var(--green); }

.paywall-cards {
    display: flex;
    align-items: stretch;
    gap: 12px;
    padding: 24px 24px 24px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}
.paywall-card {
    flex: 1;
    min-width: 160px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--white);
}
.paywall-card.popular {
    overflow: visible;
    box-shadow: 0 4px 24px rgba(156,39,176,0.25);
    border: 2px solid #9C27B0;
    z-index: 1;
}
.paywall-card.popular .paywall-card-header {
    border-radius: 14px 14px 0 0;
}
.paywall-badge {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: #FF6F00;
    color: #fff;
    font-size: 0.68rem;
    font-weight: 800;
    padding: 3px 12px;
    border-radius: 10px;
    letter-spacing: 0.05em;
    white-space: nowrap;
    z-index: 2;
}
.paywall-save {
    display: inline-block;
    background: #E8F5E9;
    color: #2E7D32;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 8px;
    margin-top: 4px;
}
.paywall-card-header {
    padding: 14px 12px;
    text-align: center;
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}
.paywall-card-header.color-dark   { background: #37474F; }
.paywall-card-header.color-blue   { background: #42A5F5; }
.paywall-card-header.color-purple { background: #9C27B0; }
.paywall-card-header.color-green  { background: #4CAF50; }

.paywall-card-body {
    padding: 20px 14px;
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.paywall-price {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
}
.paywall-price sup {
    font-size: 0.5em;
    vertical-align: super;
    font-weight: 700;
}
.paywall-period {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}
.paywall-cta {
    display: block;
    padding: 10px 20px;
    margin: auto auto 0;
    border-radius: 24px;
    border: none;
    background: var(--green);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 0.03em;
    transition: background 0.2s;
    text-decoration: none;
    text-align: center;
}
.paywall-cta:hover { background: #43A047; }
.paywall-perday {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 2px;
}
.paywall-guarantee {
    text-align: center;
    padding: 0 24px 20px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.paywall-guarantee svg { flex-shrink: 0; }

/* Responsive */
@media (max-width: 600px) {
    .paywall-cards {
        flex-direction: column;
        padding: 16px 16px 24px;
        overflow-x: visible;
        scroll-snap-type: none;
    }
    .paywall-card {
        min-width: unset;
        width: 100%;
    }
    .paywall-card.popular {
        order: -1;
    }
}

/* Responsive */
@media (min-width: 768px) {
    .page-wrapper { padding: 24px 24px 40px; }
}
