/* ============================================================
   Ôn Tập MT — mobile-app design system
   Palette: industrial emerald + safety amber, eco-tinted neutrals
   Type: Be Vietnam Pro (full Vietnamese diacritic support)
   ============================================================ */

:root {
    --primary: #0f7a5c;
    --primary-strong: #0b5c45;
    --primary-soft: #e3f3ec;
    --accent: #f5a524;
    --accent-soft: #fef3dd;
    --good: #17a34a;
    --good-soft: #e3f8ea;
    --bad: #e0483f;
    --bad-soft: #fdeae8;

    --bg: #f1f6f3;
    --surface: #ffffff;
    --surface-2: #eaf2ed;
    --ink: #10241a;
    --ink-muted: #5c7469;
    --border: #dbe7df;

    --radius-lg: 22px;
    --radius-md: 16px;
    --radius-sm: 12px;
    --radius-pill: 999px;

    --shadow-card: 0 1px 2px rgba(16, 36, 26, 0.04), 0 8px 24px -12px rgba(16, 36, 26, 0.14);
    --shadow-float: 0 10px 30px -8px rgba(11, 92, 69, 0.35);

    --topbar-h: 60px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html { -webkit-tap-highlight-color: transparent; }

body {
    margin: 0;
    font-family: "Be Vietnam Pro", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    background-image:
        radial-gradient(circle at 12% 0%, rgba(15, 122, 92, 0.08), transparent 40%),
        radial-gradient(circle at 100% 8%, rgba(245, 165, 36, 0.10), transparent 35%);
    background-attachment: fixed;
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
}

a { color: inherit; }

/* ---------- App shell ---------- */

.app-shell {
    max-width: 520px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 10px;
    height: calc(var(--topbar-h) + var(--safe-t));
    padding: var(--safe-t) 16px 0;
    background: rgba(241, 246, 243, 0.82);
    backdrop-filter: blur(14px) saturate(1.4);
    -webkit-backdrop-filter: blur(14px) saturate(1.4);
    border-bottom: 1px solid rgba(219, 231, 223, 0.7);
}

.topbar-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-pill);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--ink);
    flex-shrink: 0;
    text-decoration: none;
    box-shadow: var(--shadow-card);
}
.topbar-back:active { transform: scale(0.94); }

.topbar-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 10px -4px rgba(11, 92, 69, 0.5);
}
.topbar-icon svg { width: 19px; height: 19px; }

.topbar-titles {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    min-width: 0;
}
.topbar-title {
    font-weight: 700;
    font-size: 0.98rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar-subtitle {
    font-size: 0.76rem;
    color: var(--ink-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-link {
    margin-left: auto;
    flex-shrink: 0;
}

/* ---------- Main content ---------- */

main {
    flex: 1;
    padding: 18px 16px calc(96px + var(--safe-b));
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ---------- Bottom tab bar ---------- */

.tabbar {
    position: fixed;
    left: 50%;
    bottom: calc(14px + var(--safe-b));
    transform: translateX(-50%);
    width: calc(100% - 32px);
    max-width: 488px;
    display: flex;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border: 1px solid rgba(219, 231, 223, 0.9);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-float);
    padding: 6px;
    z-index: 30;
}

.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 9px 4px 8px;
    border-radius: var(--radius-pill);
    text-decoration: none;
    color: var(--ink-muted);
    font-size: 0.7rem;
    font-weight: 600;
    transition: background 0.18s ease, color 0.18s ease;
}
.tab svg { width: 21px; height: 21px; }
.tab.is-active {
    background: var(--primary-soft);
    color: var(--primary-strong);
}
.tab:active { transform: scale(0.96); }

/* ---------- Cards ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px 20px;
    box-shadow: var(--shadow-card);
}

.card-flat {
    background: var(--surface-2);
    border-radius: var(--radius-md);
    padding: 16px 18px;
}

h1 { font-size: 1.32rem; margin: 0 0 2px; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 0 0 2px; letter-spacing: -0.01em; }
h3 { font-size: 0.92rem; margin: 0 0 8px; }

.subtitle { color: var(--ink-muted); margin: 4px 0 0; font-size: 0.92rem; }

/* ---------- Hero / progress ring ---------- */

.hero-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 14px;
    padding-top: 26px;
}

.ring-wrap {
    position: relative;
    width: 156px;
    height: 156px;
}
.ring-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--surface-2); stroke-width: 12; }
.ring-fill {
    fill: none;
    stroke: var(--primary);
    stroke-width: 12;
    stroke-linecap: round;
    stroke-dasharray: 402;
    stroke-dashoffset: 402;
    transition: stroke-dashoffset 1s cubic-bezier(0.22, 1, 0.36, 1);
}
.ring-wrap.animate .ring-fill { stroke-dashoffset: var(--ring-offset, 402); }
.ring-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.ring-percent { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; }
.ring-label { font-size: 0.72rem; color: var(--ink-muted); font-weight: 600; }

.round-tags { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }

.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.74rem;
    font-weight: 700;
    padding: 5px 11px;
    border-radius: var(--radius-pill);
}
.tag-blue { background: var(--primary-soft); color: var(--primary-strong); }
.tag-purple { background: var(--accent-soft); color: #92620a; }

.hint { color: var(--ink-muted); font-size: 0.85rem; margin: 0; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 15px 24px;
    border-radius: var(--radius-pill);
    text-decoration: none;
    font-weight: 700;
    font-size: 0.98rem;
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 10px 22px -10px rgba(11, 92, 69, 0.65);
}
.btn-primary:hover { background: var(--primary-strong); }
.btn-primary:disabled {
    background: var(--border);
    color: var(--ink-muted);
    box-shadow: none;
    cursor: not-allowed;
}

.btn-ghost {
    background: var(--surface);
    color: var(--ink-muted);
    border: 1.5px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-block { width: 100%; }
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.actions.col { flex-direction: column; }

.restart-form { width: 100%; }

/* ---------- Stat chips ---------- */

.stat-row {
    display: flex;
    gap: 10px;
}
.stat-chip {
    flex: 1;
    background: var(--surface-2);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    text-align: left;
}
.stat-chip-value { font-size: 1.28rem; font-weight: 800; letter-spacing: -0.02em; }
.stat-chip-label { font-size: 0.72rem; color: var(--ink-muted); font-weight: 600; }

/* ---------- Accordion (native details/summary) ---------- */

.accordion {
    border-top: 1px solid var(--border);
    padding-top: 4px;
}
.accordion summary {
    cursor: pointer;
    font-weight: 700;
    font-size: 0.92rem;
    padding: 12px 2px;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.accordion summary::-webkit-details-marker { display: none; }
.accordion summary .chevron { transition: transform 0.2s ease; color: var(--ink-muted); }
.accordion[open] summary .chevron { transform: rotate(180deg); }
.accordion ul {
    margin: 4px 0 12px;
    padding-left: 18px;
    color: var(--ink-muted);
    font-size: 0.88rem;
    line-height: 1.55;
}
.accordion li { margin-bottom: 6px; }

/* ---------- Quiz: segmented dot progress ---------- */

.quiz-progress {
    display: flex;
    gap: 4px;
    flex: 1;
    align-items: center;
}
.quiz-progress .dot {
    flex: 1;
    height: 5px;
    border-radius: 3px;
    background: var(--border);
    transition: background 0.2s ease;
}
.quiz-progress .dot.is-filled { background: var(--primary); }

.quiz-meta {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 2px 2px 4px;
}
.quiz-meta .count { font-size: 0.8rem; font-weight: 700; color: var(--primary-strong); }

/* ---------- Question cards ---------- */

.question-block {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 16px 16px;
    background: var(--surface);
    box-shadow: var(--shadow-card);
    min-width: 0;
}

.q-index {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 22px;
    padding: 0 8px;
    border-radius: var(--radius-pill);
    background: var(--primary-soft);
    color: var(--primary-strong);
    font-size: 0.74rem;
    font-weight: 800;
    margin-bottom: 8px;
}

.question-block .q-text {
    font-weight: 700;
    font-size: 0.98rem;
    line-height: 1.42;
    margin: 0 0 12px;
    display: block;
    width: 100%;
    overflow-wrap: break-word;
    word-break: break-word;
}

.option {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    border: 1.5px solid var(--border);
    margin-bottom: 8px;
    cursor: pointer;
    background: var(--surface);
    transition: border-color 0.15s ease, background 0.15s ease;
}
.option:last-child { margin-bottom: 0; }
.option:active { transform: scale(0.99); }

.option-input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    pointer-events: none;
}

.option-letter {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-pill);
    border: 1.5px solid var(--border);
    font-size: 0.82rem;
    font-weight: 800;
    color: var(--ink-muted);
    flex-shrink: 0;
    background: var(--surface-2);
    transition: all 0.15s ease;
}

.option-text { font-size: 0.92rem; line-height: 1.4; }

.option-input:checked ~ .option-letter {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.option-input:checked ~ .option-text { color: var(--primary-strong); font-weight: 600; }
.option:has(.option-input:checked) {
    border-color: var(--primary);
    background: var(--primary-soft);
}
.option.is-selected {
    border-color: var(--primary);
    background: var(--primary-soft);
}
.option.is-selected .option-letter {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.option.is-selected .option-text { color: var(--primary-strong); font-weight: 600; }

.question-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ---------- Sticky bottom submit bar ---------- */

.sticky-cta {
    position: fixed;
    left: 50%;
    bottom: calc(88px + var(--safe-b));
    transform: translateX(-50%);
    width: calc(100% - 32px);
    max-width: 488px;
    z-index: 25;
}
.sticky-cta .btn {
    width: 100%;
    padding: 16px 20px;
}

/* ---------- Review options (result page) ---------- */

.review-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 11px 13px;
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    border: 1.5px solid var(--border);
    font-size: 0.9rem;
}
.review-option:last-child { margin-bottom: 0; }
.review-option.is-correct { background: var(--good-soft); border-color: #bfe9cd; }
.review-option.is-wrong-choice { background: var(--bad-soft); border-color: #f6c9c5; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.68rem;
    font-weight: 800;
    padding: 3px 9px;
    border-radius: var(--radius-pill);
    white-space: nowrap;
    flex-shrink: 0;
}
.badge-correct { background: var(--good); color: #fff; }
.badge-wrong { background: var(--bad); color: #fff; }

.question-block.review { padding-left: 15px; border-left: 4px solid var(--border); }
.question-block.review.correct { border-left-color: var(--good); }
.question-block.review.incorrect { border-left-color: var(--bad); }

.q-index.correct { background: var(--good-soft); color: var(--good); }
.q-index.incorrect { background: var(--bad-soft); color: var(--bad); }

/* ---------- Score summary ---------- */

.score-card {
    display: flex;
    align-items: center;
    gap: 16px;
    text-align: left;
    padding-top: 20px;
}
.score-badge {
    width: 74px;
    height: 74px;
    border-radius: var(--radius-pill);
    background: var(--primary-soft);
    color: var(--primary-strong);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 800;
}
.score-badge.perfect { background: var(--good-soft); color: var(--good); }
.score-badge .num { font-size: 1.32rem; line-height: 1; }
.score-badge .den { font-size: 0.65rem; opacity: 0.8; }
.score-pct { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.score-note { color: var(--ink-muted); font-size: 0.86rem; margin-top: 2px; }

/* ---------- History list ---------- */

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.history-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface);
}
.history-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-pill);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.82rem;
    flex-shrink: 0;
    background: var(--primary-soft);
    color: var(--primary-strong);
}
.history-icon.low { background: var(--bad-soft); color: var(--bad); }
.history-icon.mid { background: var(--accent-soft); color: #92620a; }
.history-icon.high { background: var(--good-soft); color: var(--good); }
.history-main { flex: 1; min-width: 0; }
.history-title { font-weight: 700; font-size: 0.9rem; }
.history-sub { font-size: 0.76rem; color: var(--ink-muted); }
.history-score { font-weight: 800; font-size: 0.95rem; text-align: right; }

.empty-state {
    text-align: center;
    padding: 30px 10px;
    color: var(--ink-muted);
}
.empty-state .emoji { font-size: 2.2rem; display: block; margin-bottom: 8px; }

/* ---------- Misc ---------- */

.center-card { text-align: center; }

@media (min-width: 560px) {
    .app-shell { max-width: 560px; }
}
