:root {
    --ink: #183126;
    --muted: #63766b;
    --line: #dce8df;
    --paper: #ffffff;
    --canvas: #f4f8f4;
    --forest: #166534;
    --forest-dark: #0f4f29;
    --leaf: #35a35d;
    --sun: #f4a23a;
    --danger: #c63838;
    --radius-sm: 12px;
    --radius: 20px;
    --radius-lg: 28px;
    --shadow: 0 14px 40px rgba(24, 49, 38, .10);
    --font-ui: "Plus Jakarta Sans", system-ui, sans-serif;
    --font-arabic: "Amiri", serif;
}

* { box-sizing: border-box; }

html { background: var(--canvas); }

body {
    margin: 0;
    min-width: 320px;
    color: var(--ink);
    background: var(--canvas);
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.55;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .52; }

.skip-link {
    position: fixed;
    z-index: 20;
    top: -4rem;
    left: 1rem;
    border-radius: 8px;
    padding: .75rem 1rem;
    color: #fff;
    background: var(--forest);
}
.skip-link:focus { top: 1rem; }

.app-shell {
    width: min(100%, 760px);
    min-height: 100dvh;
    margin: 0 auto;
    padding: 16px;
}

.page {
    min-height: calc(100dvh - 32px);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--forest);
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .12em;
}
.brand-mark {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    color: #fff;
    background: var(--forest);
    font-family: var(--font-arabic);
    font-size: 1.55rem;
    line-height: 1;
}

.hero {
    padding: 12px 4px 4px;
}
.hero h1, .page-title {
    margin: 14px 0 8px;
    color: var(--ink);
    font-size: clamp(1.75rem, 7vw, 2.5rem);
    line-height: 1.15;
    letter-spacing: -.045em;
}
.hero p, .page-subtitle { margin: 0; color: var(--muted); }

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

.field { display: grid; gap: 8px; margin-bottom: 16px; }
.field label { font-size: .87rem; font-weight: 700; }
.field input, .field select {
    width: 100%;
    min-height: 52px;
    border: 1px solid #bed1c3;
    border-radius: var(--radius-sm);
    outline: none;
    padding: 0 14px;
    color: var(--ink);
    background: #fff;
}
.field input:focus, .field select:focus { border-color: var(--forest); box-shadow: 0 0 0 3px rgba(22,101,52,.14); }
.field-error { min-height: 1.2em; margin: 0; color: var(--danger); font-size: .8rem; }

.btn {
    min-height: 52px;
    border: 0;
    border-radius: var(--radius-sm);
    padding: .7rem 1rem;
    font-weight: 800;
    transition: transform .16s ease, background .16s ease;
}
.btn:not(:disabled):active { transform: scale(.98); }
.btn-primary { color: #fff; background: var(--forest); }
.btn-primary:hover { background: var(--forest-dark); }
.btn-secondary { color: var(--forest); background: #e8f4eb; }
.btn-outline { border: 1px solid #b6ccb9; color: var(--forest); background: #fff; }
.btn-block { width: 100%; }
.btn-disabled, .btn:disabled { opacity: .45; pointer-events: none; cursor: not-allowed; }

.helper { margin: 14px 0 0; color: var(--muted); font-size: .8rem; text-align: center; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.profile { display: flex; align-items: center; gap: 10px; text-align: right; }
.profile strong, .profile span { display: block; }
.profile strong { font-size: .82rem; }
.profile span { color: var(--muted); font-size: .72rem; }
.avatar { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: var(--forest); background: #dff0e4; font-weight: 800; }
.icon-btn { width: 44px; min-height: 44px; border: 0; border-radius: 12px; color: var(--forest); background: transparent; font-size: 1.1rem; }

.welcome { padding: 6px 4px; }
.welcome h1 { margin: 8px 0; font-size: 1.7rem; line-height: 1.2; letter-spacing: -.04em; }
.welcome p { margin: 0; color: var(--muted); }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; }
.section-heading h2 { margin: 0; font-size: 1.05rem; }
.section-heading span { color: var(--muted); font-size: .78rem; }

.category-list { display: grid; gap: 12px; }
.category-card {
    width: 100%;
    display: grid;
    grid-template-columns: 54px 1fr 24px;
    align-items: center;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    color: inherit;
    text-align: left;
    background: var(--paper);
    box-shadow: 0 6px 18px rgba(24,49,38,.05);
}
.category-card:hover { border-color: var(--leaf); }
.category-icon { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 17px; color: #fff; font-family: var(--font-arabic); font-size: 1.8rem; }
.category-card h3 { margin: 0 0 3px; font-size: .98rem; }
.category-card p { margin: 0; color: var(--muted); font-size: .78rem; }
.category-arrow { color: var(--muted); font-size: 1.4rem; }

.empty, .loading, .error-card { display: grid; place-items: center; min-height: 180px; border-radius: var(--radius); padding: 22px; color: var(--muted); text-align: center; background: #fff; }
.error-card { color: var(--danger); border: 1px solid #f0c5c5; }

.quiz-header { display: grid; gap: 12px; }
.quiz-meta { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .8rem; }
.progress { height: 8px; overflow: hidden; border-radius: 99px; background: #dceade; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--forest); transition: width .25s ease; }
.question-card { display: grid; gap: 20px; }
.question-card h1 { margin: 0; font-size: 1.35rem; line-height: 1.4; }
.arabic { font-family: var(--font-arabic); font-size: 1.55rem; line-height: 1.7; direction: rtl; }

.word-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.word-choice, .placeholder, .answer-choice {
    min-height: 54px;
    border: 1px solid #bdd1c2;
    border-radius: 14px;
    color: var(--ink);
    background: #fff;
    font-weight: 700;
    transition: transform .15s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.word-choice { padding: 6px; font-family: var(--font-arabic); font-size: 1.35rem; }
.word-choice:not(:disabled):hover { transform: translateY(-2px); border-color: var(--leaf); box-shadow: 0 4px 12px rgba(22,101,52,.12); }
.word-choice.is-selected {
    border-color: var(--forest);
    color: #fff;
    background: var(--forest);
    box-shadow: 0 0 0 4px rgba(22,101,52,.15);
    animation: pop .25s ease;
}
.word-choice.is-paired { background: #e8f5eb; color: var(--forest-dark); border-color: var(--leaf); opacity: .85; }
.pair-indicator { display: block; font-size: .75rem; line-height: 1; margin-top: 2px; opacity: .7; }

@keyframes pop {
    0% { transform: scale(.92); }
    60% { transform: scale(1.04); }
    100% { transform: scale(1); }
}

.fill-sentence { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--ink); }
.placeholder { min-width: 92px; padding: 6px 10px; border-style: dashed; font-family: var(--font-arabic); font-size: 1.25rem; transition: transform .15s ease, background .15s ease, border-color .15s ease; }
.placeholder.is-selected { border-color: var(--forest); background: #e9f5eb; transform: scale(1.03); }
.placeholder.is-filled { border-style: solid; color: var(--forest); background: #e9f5eb; animation: pop .25s ease; }
.word-pool { display: flex; flex-wrap: wrap; gap: 10px; }
.word-pool .word-choice { min-width: 92px; padding: 4px 12px; }

.sentence-list { display: grid; gap: 14px; }
.sentence-item { display: grid; gap: 10px; border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.sentence-item p { margin: 0; }
.answer-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.answer-choice { min-height: 48px; color: var(--muted); }
.answer-choice.is-selected { border-color: var(--forest); color: #fff; background: var(--forest); }

.quiz-actions { display: grid; gap: 10px; margin-top: auto; }
.inline-error { margin: 0; color: var(--danger); font-size: .82rem; text-align: center; }

.score-card { text-align: center; }
.score-orb { width: 140px; height: 140px; display: grid; place-items: center; margin: 0 auto 18px; border: 10px solid #cdebd3; border-radius: 50%; color: var(--forest); font-size: 2.1rem; font-weight: 800; }
.score-card h1 { margin: 0; font-size: 1.55rem; }
.score-card p { color: var(--muted); }
.score-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 20px 0; }
.score-stat { border-radius: 14px; padding: 12px; background: #f1f8f2; }
.score-stat strong, .score-stat span { display: block; }
.score-stat span { color: var(--muted); font-size: .75rem; }

@media (min-width: 600px) {
    .app-shell { padding: 28px; }
    .page { min-height: calc(100dvh - 56px); }
    .card { padding: 28px; }
    .category-list { grid-template-columns: 1fr 1fr; }
    .quiz-actions { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

/* Rekap jawaban di akhir kuis */
.recap-item {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 14px;
    margin: 8px 0;
}
.recap-item-header {
    margin-bottom: 4px;
}
.recap-q {
    font-weight: 600;
    font-size: 0.88rem;
    line-height: 1.4;
    word-break: break-word;
}
.recap-item-score {
    margin-bottom: 8px;
}
.recap-item-body {
    display: grid;
    gap: 4px;
}
.recap-line {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 4px 6px;
    font-size: 0.82rem;
    line-height: 1.5;
}
.recap-label {
    color: var(--muted);
    font-size: 0.76rem;
    flex-shrink: 0;
}
.recap-mark {
    font-weight: 800;
    flex-shrink: 0;
}
.recap-right .recap-mark {
    color: #2e7d32;
}
.recap-wrong .recap-mark {
    color: #c62828;
}
.recap-ar {
    font-family: var(--font-arabic);
    font-size: 0.88rem;
}
.recap-note {
    color: var(--muted);
    font-size: 0.74rem;
}
.recap-lock {
    border: none;
    background: #f0f4f1;
    color: var(--muted);
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 8px;
    cursor: pointer;
}
.recap-hint-answer {
    display: none;
}
.recap-hint.show-hint .recap-lock {
    display: none;
}
.recap-hint.show-hint .recap-hint-answer {
    display: inline;
}
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}
.badge-success { background: #e9f5eb; color: #2e7d32; }
.badge-error { background: #fdecea; color: #c62828; }
.badge-warning { background: #fff4e5; color: #e65100; }

/* Pair and placeholder counters */
.inline-meta { color: var(--muted); font-size: 0.78rem; }

/* Vocabulary overlay (bottom sheet) */
.vocabulary-overlay {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(0,0,0,.35);
    display: flex; align-items: flex-end; justify-content: center;
    animation: fadeIn .2s ease;
}
.vocabulary-sheet {
    width: 100%; max-width: 600px; max-height: 65vh;
    background: #fff; border-radius: 20px 20px 0 0;
    display: flex; flex-direction: column;
    animation: slideUp .3s ease;
    box-shadow: 0 -4px 24px rgba(0,0,0,.1);
}
.vocabulary-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px 8px;
    border-bottom: 1px solid var(--line);
}
.vocabulary-header h3 { margin: 0; font-size: 1.1rem; }
.vocabulary-body {
    overflow-y: auto; padding: 12px 20px 24px;
}
.vocabulary-table {
    width: 100%; border-collapse: collapse; font-size: .88rem;
}
.vocabulary-table th {
    text-align: left; padding: 8px 6px;
    border-bottom: 2px solid var(--line);
    color: var(--muted); font-weight: 600; font-size: .78rem;
    white-space: nowrap;
}
.vocabulary-table td {
    padding: 8px 6px; border-bottom: 1px solid var(--line);
    vertical-align: top;
}
.vocabulary-table td[lang="ar"] { font-family: var(--font-arabic); font-size: 1.1rem; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
