:root {
    --ink: #131316;
    --ink-soft: #1C1C22;
    --ink-softer: #212127;
    --lime: #D8FF47;
    --cream: #F3F1EC;
    --card: #FFFFFF;
    --border: #E7E3DA;
    --border-soft: #EDEAE1;
    --red: #FF3B23;
    --red-bg: #FFECE9;
    --blue: #2F5BFF;
    --blue-bg: #EEF2FF;
    --purple: #7A3BFF;
    --purple-bg: #F3EEFF;
    --green: #12B76A;
    --green-bg: #E7F8F0;
    --lime-bg: #EFFFB0;
    --text-muted: rgba(19, 19, 22, .55);
    --text-faint: rgba(19, 19, 22, .42);
    --radius-lg: 22px;
    --radius-md: 16px;
    --radius-sm: 10px;
    --shell-width: 440px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--cream);
    color: var(--ink);
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    -webkit-font-smoothing: antialiased;
}

.zh, [lang="zh"] { font-family: 'Noto Sans SC', 'Space Grotesk', sans-serif; }
.mono { font-family: 'JetBrains Mono', monospace; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

img { max-width: 100%; display: block; }

.app-shell {
    max-width: var(--shell-width);
    margin: 0 auto;
    min-height: 100vh;
    background: var(--cream);
    position: relative;
    padding-bottom: 96px;
}

.app-shell.no-nav { padding-bottom: 24px; }

.app-shell.dark { background: var(--ink); color: #fff; }

@media (min-width: 720px) {
    body { background: #E9E6DF; }
    .app-shell {
        margin: 24px auto;
        min-height: calc(100vh - 48px);
        border-radius: 28px;
        box-shadow: 0 30px 60px -20px rgba(19,19,22,.25);
        overflow: hidden;
    }
}

/* Topbar */
.topbar {
    padding: 24px 20px 6px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.topbar .brand { display: flex; align-items: center; gap: 8px; }
.brand-logo { width: 24px; height: 24px; border-radius: 7px; object-fit: cover; flex: none; display: block; }
.topbar .brand span { font-weight: 700; font-size: 12px; letter-spacing: .14em; }
.dark .topbar .brand span { color: #fff; }

.avatar {
    width: 38px; height: 38px; border-radius: 999px; background: var(--ink); color: var(--lime);
    font-weight: 700; font-size: 14px; display: flex; align-items: center; justify-content: center; flex: none;
}
.back-btn {
    width: 32px; height: 32px; border-radius: 10px; background: #fff; border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center; flex: none; cursor: pointer;
}

/* Cards */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}
.card-dark {
    background: var(--ink);
    color: #fff;
    border-radius: var(--radius-lg);
    padding: 20px;
}
.card-tight { padding: 16px 18px; }
.stack { display: flex; flex-direction: column; gap: 12px; padding: 0 20px; }
.stack > * + * { margin-top: 0; }

.eyebrow {
    font: 600 10px/1 'JetBrains Mono', monospace;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--lime);
}
.eyebrow.on-light { color: var(--ink); background: var(--lime); padding: 5px 7px; border-radius: 5px; }

h1.page-title { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 4px; }
.page-sub { color: var(--text-muted); font-size: 13px; margin: 0 0 6px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    font-weight: 600; font-size: 15px; padding: 16px 20px; border-radius: 999px;
    border: none; cursor: pointer; width: 100%; text-align: center;
}
.btn-lime { background: var(--lime); color: var(--ink); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-outline { background: #fff; color: var(--ink); border: 1px solid var(--border); }
.btn-sm { width: auto; padding: 10px 16px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.sticky-cta {
    position: sticky; bottom: 0; padding: 14px 20px 28px;
    background: linear-gradient(to top, var(--cream) 65%, rgba(243,241,236,0));
}
.dark .sticky-cta { background: linear-gradient(to top, var(--ink) 65%, rgba(19,19,22,0)); }

/* Pills / badges */
.pill {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px;
    font-size: 11px; font-weight: 600; background: #fff; border: 1px solid var(--border); color: var(--ink);
}
.pill-dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.badge { display: inline-block; padding: 6px 9px; border-radius: 7px; font-weight: 700; font-size: 12px; }
.badge-lime { background: var(--lime); color: var(--ink); }
.badge-dark { background: var(--ink); color: #fff; }
.badge-muted { background: var(--border-soft); color: var(--ink); }

/* Forms */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.field input[type=text], .field input[type=email], .field input[type=password], .field textarea, .field select {
    width: 100%; padding: 14px 15px; border-radius: 14px; border: 1px solid var(--border);
    font-family: inherit; font-size: 15px; background: #fff; color: var(--ink);
}
.field textarea { min-height: 260px; resize: vertical; line-height: 1.9; }
.error-box {
    background: var(--red-bg); color: #B02713; border-radius: 12px; padding: 12px 14px;
    font-size: 13px; margin: 0 20px 14px;
}
.auth-wrap { padding: 40px 20px; }
.auth-switch { text-align: center; margin-top: 18px; font-size: 13px; color: var(--text-muted); }
.auth-switch a { color: var(--ink); font-weight: 600; }

/* Exam select */
.exam-option {
    display: flex; align-items: center; gap: 13px; background: var(--ink-soft); border: 1px solid #2C2C34;
    border-radius: 16px; padding: 15px 16px; cursor: pointer;
}
.exam-option input { display: none; }
.exam-option .flag {
    font: 600 10px/1 'JetBrains Mono', monospace; color: var(--lime); background: rgba(216,255,71,.12);
    padding: 6px 7px; border-radius: 6px; flex: none;
}
.exam-option .name { font-weight: 600; font-size: 15px; color: #fff; }
.exam-option .tag { font-size: 12px; color: rgba(255,255,255,.45); margin-top: 2px; }
.exam-option.checked { background: var(--lime); border-color: var(--lime); }
.exam-option.checked .flag { color: var(--lime); background: var(--ink); }
.exam-option.checked .name, .exam-option.checked .tag { color: var(--ink); }
.exam-option.checked .tag { color: rgba(19,19,22,.62); }
.exam-option .dot {
    width: 22px; height: 22px; border-radius: 999px; flex: none; border: 1.5px solid rgba(255,255,255,.3);
}
.exam-option.checked .dot { background: var(--ink); border-color: var(--ink); position: relative; }
.exam-option.checked .dot::after {
    content: ""; position: absolute; inset: 6px; background: var(--lime); border-radius: 999px;
}

/* Bottom nav */
.bottom-nav {
    position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: var(--shell-width);
    background: rgba(255,255,255,.92); backdrop-filter: blur(14px); border-top: 1px solid var(--border-soft);
    padding: 10px 10px calc(env(safe-area-inset-bottom, 0px) + 14px);
    display: flex; align-items: center; justify-content: space-between; z-index: 20;
}
@media (min-width: 720px) { .bottom-nav { position: absolute; } }
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 10px; font-weight: 600; color: rgba(19,19,22,.45); }
.nav-item.active { color: var(--ink); }
.nav-item .dot { width: 18px; height: 18px; border-radius: 6px; background: #CFCABE; }
.nav-item.active .dot { background: var(--ink); }
.nav-fab {
    width: 50px; height: 50px; border-radius: 999px; background: var(--lime); margin-top: -24px;
    border: 4px solid #fff; display: flex; align-items: center; justify-content: center; flex: none;
    font-size: 22px; font-weight: 700; color: var(--ink);
}

/* Word count / tabs */
.tabbar { display: flex; gap: 2px; background: var(--border-soft); border-radius: 999px; padding: 3px; }
.tabbar a { flex: 1; text-align: center; padding: 9px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.tabbar a.active { background: var(--ink); color: #fff; }
[data-role-tab] { color: var(--text-muted); }
[data-role-tab].active { background: var(--ink); color: #fff; }
.dark .tabbar { background: var(--ink-soft); }
.dark .tabbar a { color: rgba(255,255,255,.55); }
.dark .tabbar a.active { background: var(--lime); color: var(--ink); }

.progress-track { height: 7px; border-radius: 999px; background: var(--border-soft); overflow: hidden; }
.progress-fill { height: 100%; background: var(--ink); border-radius: 999px; }
.progress-fill.lime { background: var(--lime); }
.progress-fill.red { background: var(--red); }

/* Marking progress */
.ring-wrap { display: flex; justify-content: center; margin-top: 20px; }
.pipeline-step {
    display: flex; align-items: center; gap: 13px; background: var(--ink-soft); border: 1px solid #2C2C34;
    border-radius: 16px; padding: 15px 16px; opacity: .55;
}
.pipeline-step.active { background: #1F2016; border-color: var(--lime); opacity: 1; }
.pipeline-step.done { opacity: 1; }
.pipeline-step .dot-status { width: 24px; height: 24px; border-radius: 999px; flex: none; border: 2px solid #3A3A42; }
.pipeline-step.done .dot-status { background: var(--green); border: none; }
.pipeline-step.active .dot-status { border-color: var(--lime); border-top-color: transparent; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.pipeline-step .step-title { font-weight: 600; font-size: 14px; color: #fff; }
.pipeline-step .step-sub { font-size: 11px; color: rgba(255,255,255,.45); margin-top: 2px; }
.pipeline-step.active .step-title { color: var(--lime); }

/* Score bars */
.dim-row { margin-bottom: 12px; }
.dim-row .dim-label { display: flex; justify-content: space-between; font-size: 12px; font-weight: 500; margin-bottom: 6px; }
.dim-row .track { height: 7px; border-radius: 999px; background: var(--border-soft); overflow: hidden; }
.dim-row .fill { height: 100%; background: var(--ink); }
.dim-row.warn .dim-label { color: var(--red); }
.dim-row.warn .track { background: var(--red-bg); }
.dim-row.warn .fill { background: var(--red); }

.deduction-box { display: flex; align-items: center; gap: 9px; background: var(--red-bg); border-radius: 12px; padding: 11px 13px; margin-top: 14px; }
.deduction-box .amt { font: 700 13px 'JetBrains Mono', monospace; color: var(--red); }
.deduction-box .note { font-size: 12px; color: #B02713; }

/* Annotated text */
.essay-text { font-size: 17px; line-height: 2; }
.essay-text .hl { padding: 1px 0; border-bottom: 2px solid; }
.essay-text .hl-mechanics { background: rgba(255,59,35,.14); border-color: var(--red); }
.essay-text .hl-vocab { background: rgba(47,91,255,.12); border-color: var(--blue); }
.essay-text .hl-structure { background: rgba(122,59,255,.12); border-color: var(--purple); }
.essay-text sup {
    font: 600 9px/1 'JetBrains Mono', monospace; color: #fff; padding: 2px 4px; border-radius: 4px; margin-left: 2px;
}
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border-soft); }
.legend .item { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 500; color: var(--text-muted); }
.legend .swatch { width: 9px; height: 9px; border-radius: 3px; }

/* Coach */
#coach-stack, #drill-stack { color: var(--ink); }
.coach-card { display: none; }
.coach-card.active { display: block; }

/* Micro-drills */
.drill-card { display: none; }
.drill-card.active { display: block; }
.drill-choice.correct { border-color: var(--green) !important; background: var(--green-bg) !important; }
.drill-choice.incorrect { border-color: var(--red) !important; background: var(--red-bg) !important; }
.drill-choice[disabled] { cursor: default; }
.quote-box { background: var(--cream); border-radius: 14px; padding: 14px; font-size: 16px; line-height: 1.8; color: var(--ink); }
.quote-box mark { background: #FFD9D2; border-bottom: 2px solid var(--red); padding: 0; }
.hint-box { border: 1px solid var(--border); border-radius: 14px; padding: 14px; margin-top: 9px; color: var(--ink); }
.hint-box.locked { display: flex; align-items: center; gap: 8px; background: #FBFAF7; cursor: pointer; }
.hint-tag { font: 600 10px/1 'JetBrains Mono', monospace; padding: 5px 6px; border-radius: 5px; background: var(--lime); color: var(--ink); }
.hint-tag.muted { background: var(--border-soft); color: var(--text-muted); }
.rewrite-box {
    border: 1.5px dashed #CFCABE; border-radius: 14px; padding: 14px; font-size: 15px; width: 100%;
    min-height: 90px; font-family: inherit; margin-top: 12px; color: var(--ink); background: #fff;
}
.drill-choice { color: var(--ink); }

/* Radar + heatmap */
.radar-legend { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin-top: 8px; }
.radar-legend .item { display: flex; align-items: center; gap: 7px; font-size: 11px; font-weight: 500; }
.radar-legend .sw { width: 9px; height: 9px; border-radius: 3px; background: var(--ink); flex: none; }
.radar-legend .sw.warn { background: var(--red); }

.heatmap-row { display: flex; align-items: center; gap: 9px; margin-bottom: 7px; }
.heatmap-row .label { width: 96px; font-size: 11px; font-weight: 500; color: rgba(19,19,22,.75); flex: none; }
.heatmap-row .cells { flex: 1; display: grid; gap: 4px; }
.heatmap-row .cell { height: 20px; border-radius: 4px; background: var(--border-soft); }

.callout-lime { background: var(--ink); border-radius: 14px; padding: 14px; display: flex; gap: 11px; align-items: center; color: #fff; }
.callout-lime .num { font: 700 20px/1 'Space Grotesk'; color: var(--lime); }

/* Misc */
.empty-state { text-align: center; padding: 60px 24px; color: var(--text-muted); }
.divider { height: 1px; background: var(--border-soft); margin: 16px 0; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }

.scan-drop {
    margin: 10px 20px 0; border-radius: 20px; overflow: hidden; position: relative; background: #171719;
    height: 340px; display: flex; align-items: center; justify-content: center; border: 1px dashed rgba(255,255,255,.25);
}
.scan-drop input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.scan-drop .hint { color: rgba(255,255,255,.6); font-size: 13px; text-align: center; padding: 0 30px; }
.scan-preview { width: 100%; height: 100%; object-fit: cover; }
