:root {
    --bg: #eef3f5;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --ink: #17202a;
    --muted: #667085;
    --line: #d9dee7;
    --line-strong: #c4ccd8;
    --teal: #0f766e;
    --teal-dark: #115e59;
    --blue: #1d4ed8;
    --amber: #b45309;
    --red: #be123c;
    --nav: #101828;
    --shadow: 0 14px 34px rgba(15, 23, 42, .08);
    --touch: 44px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-width: 320px;
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at 0 0, rgba(15, 118, 110, .08), transparent 28rem),
        linear-gradient(180deg, #f7fafc 0%, var(--bg) 46%, #eaf0f4 100%);
    color: var(--ink);
    text-rendering: optimizeLegibility;
}

[v-cloak] {
    display: none;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

button:disabled {
    cursor: not-allowed;
    opacity: .55;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-panel {
    width: min(420px, 100%);
    background: var(--surface);
    border: 1px solid rgba(217, 222, 231, .9);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 32px;
}

.brand-mark {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    background: var(--teal);
    color: #fff;
    border-radius: 8px;
    font-weight: 900;
    letter-spacing: 0;
}

.brand-mark.small {
    width: 44px;
    height: 44px;
    font-size: 13px;
}

.login-panel h1 {
    margin: 18px 0 24px;
    font-size: 28px;
    line-height: 1.15;
}

.login-form {
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

input,
select {
    width: 100%;
    min-height: var(--touch);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 0 12px;
    color: var(--ink);
    outline: 0;
}

input:focus,
select:focus {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, .12);
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: var(--nav);
    color: #fff;
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    box-shadow: 10px 0 30px rgba(15, 23, 42, .08);
}

.side-brand {
    display: flex;
    gap: 12px;
    align-items: center;
}

.side-brand small {
    display: block;
    color: #aab2c0;
    margin-top: 2px;
}

.side-nav {
    display: grid;
    gap: 6px;
}

.side-nav button,
.logout {
    min-height: var(--touch);
    display: flex;
    align-items: center;
    gap: 10px;
    border: 0;
    border-radius: 8px;
    padding: 0 12px;
    background: transparent;
    color: #d8dee9;
    text-align: left;
    font-weight: 800;
}

.side-nav button.active {
    background: #243244;
    color: #fff;
}

.side-nav button:hover,
.logout:hover {
    background: rgba(255, 255, 255, .08);
    color: #fff;
}

.nav-label-mobile,
.top-action-label-mobile,
.mobile-logout {
    display: none;
}

.logout {
    margin-top: auto;
}

.workspace {
    min-width: 0;
    padding: 24px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

.topbar h1 {
    margin-bottom: 5px;
    font-size: 26px;
    line-height: 1.15;
}

.topbar p,
.detail-head p,
.section-head p {
    color: var(--muted);
    margin-bottom: 0;
}

.top-actions,
.section-head,
.list-head,
.sim-head,
.detail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.primary-btn,
.ghost-btn {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 8px;
    padding: 0 14px;
    border: 1px solid transparent;
    font-weight: 900;
    line-height: 1;
    white-space: nowrap;
}

.primary-btn {
    background: var(--teal);
    color: #fff;
}

.primary-btn:hover {
    background: var(--teal-dark);
}

.ghost-btn {
    background: #fff;
    color: var(--ink);
    border-color: var(--line);
}

.ghost-btn:hover {
    border-color: var(--line-strong);
    background: #f8fafc;
}

.small-btn {
    min-height: 34px;
    padding: 0 10px;
    font-size: 13px;
}

.icon-only {
    width: 42px;
    padding: 0;
}

.icon-only.active {
    color: var(--amber);
    border-color: #f2c777;
    background: #fff8eb;
}

.view-stack {
    display: grid;
    gap: 18px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.stats-grid.compact {
    grid-template-columns: repeat(4, minmax(120px, 1fr));
}

.stat-card,
.panel,
.flash-card {
    background: rgba(255, 255, 255, .96);
    border: 1px solid rgba(217, 222, 231, .92);
    border-radius: 8px;
    box-shadow: 0 8px 22px rgba(15, 23, 42, .04);
}

.stat-card {
    min-height: 92px;
    padding: 18px;
    display: grid;
    align-content: center;
    gap: 4px;
}

.stat-card span,
.flash-card span,
.question-row span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
}

.stat-card strong {
    font-size: 28px;
    line-height: 1;
}

.panel {
    padding: 18px;
}

.panel h2 {
    font-size: 18px;
    margin-bottom: 14px;
}

.content-grid.two {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr);
    gap: 18px;
}

.bar-list {
    display: grid;
    gap: 9px;
}

.bar-list button {
    display: grid;
    grid-template-columns: 60px 1fr 42px;
    gap: 12px;
    align-items: center;
    border: 0;
    background: transparent;
    padding: 6px 0;
    color: var(--ink);
    text-align: left;
}

meter {
    width: 100%;
    height: 12px;
}

.subject-pills,
.filter-row,
.sim-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.filter-row select {
    flex: 1 1 160px;
}

.filter-row input {
    flex: 2 1 220px;
}

.sim-controls select {
    flex: 1 1 160px;
}

.subject-pills button {
    min-height: 40px;
    border: 1px solid var(--line);
    background: #f8fafc;
    border-radius: 8px;
    padding: 0 12px;
    color: var(--ink);
    font-weight: 800;
}

.subject-pills strong {
    margin-left: 8px;
    color: var(--teal);
}

.plan-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.plan-strip div,
.plan-list div,
.insight-grid article {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: var(--surface-soft);
}

.plan-strip span,
.plan-list span {
    display: block;
    margin: 6px 0;
    font-weight: 900;
}

.plan-strip small,
.plan-list p {
    color: var(--muted);
}

.question-layout {
    display: grid;
    grid-template-columns: 330px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.question-list {
    max-height: calc(100vh - 175px);
    overflow: auto;
    display: grid;
    gap: 8px;
    align-content: start;
    scrollbar-width: thin;
}

.question-row {
    min-height: 72px;
    display: grid;
    gap: 3px;
    text-align: left;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 10px;
    color: var(--ink);
}

.question-row.active {
    border-color: var(--teal);
    background: #eefaf7;
    box-shadow: inset 3px 0 0 var(--teal);
}

.question-row small {
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pager {
    display: flex;
    gap: 8px;
    justify-content: space-between;
    margin-top: 8px;
}

.question-detail {
    min-width: 0;
}

.detail-head h2 {
    margin-bottom: 6px;
    line-height: 1.2;
}

.image-stack {
    display: grid;
    gap: 12px;
    margin: 16px 0;
    justify-items: start;
}

.image-stack.narrow {
    max-width: 760px;
}

.question-image {
    width: min(100%, 1080px);
    max-width: 100%;
    max-height: none;
    object-fit: contain;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.source-toggle {
    display: flex;
    justify-content: flex-start;
    margin: 6px 0 12px;
}

.source-pages {
    padding-top: 8px;
    border-top: 1px solid var(--line);
}

.source-page-image {
    width: min(100%, 980px);
}

.question-text {
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 14px;
    overflow-wrap: anywhere;
}

.question-text p {
    margin-bottom: 10px;
}

.option-texts {
    display: grid;
    gap: 6px;
}

.option-texts p {
    margin: 0;
}

.answer-grid {
    display: grid;
    grid-template-columns: repeat(5, 58px);
    gap: 8px;
    margin: 12px 0;
}

.answer-grid button,
.sim-nav button {
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    font-weight: 900;
}

.answer-grid button.chosen,
.sim-nav button.done {
    border-color: var(--blue);
    background: #eff6ff;
    color: var(--blue);
}

.answer-grid button.correct {
    border-color: var(--teal);
    background: #ecfdf5;
    color: var(--teal);
}

.answer-status {
    display: flex;
    gap: 12px;
    align-items: center;
    color: var(--muted);
    min-height: 34px;
}

.ok-text {
    color: var(--teal);
}

.bad-text,
.error-line {
    color: var(--red);
}

.insight-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 18px 0;
}

.insight-grid h3,
.ai-box h3 {
    font-size: 15px;
    margin-bottom: 7px;
}

.insight-grid p,
.solution-view {
    color: #344054;
    line-height: 1.58;
}

.ai-box {
    border-top: 1px solid var(--line);
    padding-top: 16px;
}

.solution-view {
    margin-top: 12px;
    padding: 14px;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow-wrap: anywhere;
}

.solution-view p:last-child {
    margin-bottom: 0;
}

.empty-solution {
    margin-top: 12px;
    color: var(--muted);
}

.sim-panel {
    display: grid;
    gap: 16px;
}

.sim-question {
    display: grid;
    gap: 12px;
}

.sim-question > p {
    margin-bottom: 0;
    line-height: 1.55;
}

.sim-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.sim-nav button {
    width: 38px;
    height: 34px;
}

.sim-nav button.active {
    border-color: var(--teal);
    color: var(--teal);
}

.card-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 18px;
    align-items: end;
    background: linear-gradient(135deg, #ffffff 0%, #f5fbfa 54%, #fff8ef 100%);
}

.eyebrow {
    display: inline-flex;
    margin-bottom: 8px;
    color: var(--teal-dark);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0;
}

.card-hero h2 {
    margin-bottom: 8px;
    font-size: 26px;
}

.card-hero p {
    max-width: 720px;
    margin-bottom: 0;
    color: var(--muted);
    line-height: 1.55;
}

.card-metrics {
    display: grid;
    grid-template-columns: repeat(3, 112px);
    gap: 10px;
}

.card-metrics article {
    min-height: 76px;
    display: grid;
    align-content: center;
    gap: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .78);
    padding: 12px;
}

.card-metrics strong {
    font-size: 24px;
    line-height: 1;
}

.card-metrics span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.card-tools {
    display: grid;
    grid-template-columns: minmax(240px, 1.4fr) minmax(160px, .7fr) minmax(180px, .8fr) auto;
    gap: 10px;
    align-items: center;
}

.card-search {
    position: relative;
}

.card-search svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
}

.card-search input {
    padding-left: 40px;
}

.card-subject-strip {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 2px 0 4px;
    scrollbar-width: thin;
}

.card-subject-strip button {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    padding: 0 12px;
    font-weight: 900;
}

.card-subject-strip button.active {
    border-color: var(--teal);
    background: #e8f7f4;
    color: var(--teal-dark);
}

.card-subject-strip strong {
    color: var(--teal);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

.flash-card {
    min-height: 236px;
    padding: 18px;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 10px;
    text-align: left;
    color: var(--ink);
}

.qa-card {
    position: relative;
    overflow: hidden;
    border-top: 4px solid var(--blue);
}

.qa-card.flipped {
    border-top-color: var(--amber);
    background: #fffdf8;
}

.card-face {
    width: max-content;
    border-radius: 8px;
    background: #eff6ff;
    color: var(--blue);
    padding: 5px 9px;
    font-size: 12px;
    font-weight: 900;
}

.qa-card.flipped .card-face {
    background: #fff3df;
    color: var(--amber);
}

.card-topic {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.flash-card strong {
    font-size: 16px;
    line-height: 1.45;
    overflow: hidden;
}

.flash-card small {
    color: var(--muted);
    line-height: 1.45;
}

.load-more-cards {
    justify-self: center;
    min-width: 220px;
}

.empty-state {
    text-align: center;
}

.empty-state p {
    color: var(--muted);
    margin-bottom: 0;
}

.plan-list {
    display: grid;
    gap: 12px;
}

.json-box {
    white-space: pre-wrap;
    background: #101828;
    color: #edf2f7;
    border-radius: 8px;
    padding: 16px;
}

@media (max-width: 1120px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        height: auto;
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        align-items: center;
        overflow: hidden;
    }

    .side-nav {
        display: flex;
        min-width: 0;
        overflow-x: auto;
        padding-bottom: 2px;
    }

    .side-nav button,
    .logout {
        white-space: nowrap;
    }

    .logout {
        margin-top: 0;
    }

    .question-layout,
    .content-grid.two {
        grid-template-columns: 1fr;
    }

    .question-list {
        max-height: 360px;
    }
}

@media (max-width: 760px) {
    body {
        background: #eef3f5;
    }

    .login-screen {
        align-items: stretch;
        padding: 16px;
    }

    .login-panel {
        align-self: center;
        padding: 24px;
    }

    .app-shell {
        display: block;
        min-height: 100dvh;
        padding-bottom: calc(76px + env(safe-area-inset-bottom));
    }

    .sidebar {
        position: fixed;
        inset: auto 0 0 0;
        z-index: 20;
        height: calc(66px + env(safe-area-inset-bottom));
        display: block;
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
        background: rgba(16, 24, 40, .96);
        border-top: 1px solid rgba(255, 255, 255, .12);
        box-shadow: 0 -12px 28px rgba(15, 23, 42, .16);
    }

    .side-brand,
    .logout {
        display: none;
    }

    .side-nav {
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 4px;
        overflow: visible;
        padding: 0;
        height: 100%;
    }

    .side-nav button {
        min-width: 0;
        min-height: 52px;
        height: 52px;
        justify-content: center;
        flex-direction: column;
        gap: 4px;
        padding: 5px 2px;
        border-radius: 8px;
        color: #cbd5e1;
        font-size: 11px;
        line-height: 1.05;
        text-align: center;
    }

    .side-nav button svg {
        width: 20px;
        height: 20px;
    }

    .side-nav button.active {
        background: #e8f7f4;
        color: var(--teal-dark);
    }

    .nav-label {
        display: none;
    }

    .nav-label-mobile {
        display: block;
        width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .workspace {
        padding: 12px 12px 18px;
    }

    .topbar {
        position: sticky;
        top: 0;
        z-index: 12;
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
        margin: -12px -12px 14px;
        padding: 14px 12px 12px;
        background: rgba(238, 243, 245, .94);
        backdrop-filter: blur(14px);
        border-bottom: 1px solid rgba(217, 222, 231, .75);
    }

    .topbar h1 {
        font-size: 22px;
        margin-bottom: 4px;
    }

    .topbar p {
        font-size: 13px;
    }

    .top-actions {
        width: 100%;
        display: grid;
        grid-template-columns: minmax(0, .9fr) 44px minmax(0, 1.35fr);
        gap: 8px;
    }

    .top-actions .ghost-btn,
    .top-actions .primary-btn {
        width: 100%;
        min-height: 42px;
        padding: 0 10px;
        font-size: 13px;
    }

    .mobile-logout {
        display: inline-flex;
    }

    .top-action-label {
        display: none;
    }

    .top-action-label-mobile {
        display: inline;
    }

    .view-stack {
        gap: 14px;
    }

    .panel,
    .stat-card,
    .flash-card {
        border-color: rgba(217, 222, 231, .85);
        box-shadow: 0 5px 16px rgba(15, 23, 42, .035);
    }

    .panel {
        padding: 14px;
    }

    .stats-grid,
    .stats-grid.compact {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .stat-card {
        min-height: 86px;
        padding: 14px;
    }

    .stat-card strong {
        font-size: 25px;
    }

    .content-grid.two,
    .plan-strip,
    .insight-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .bar-list button {
        grid-template-columns: 54px minmax(0, 1fr) 36px;
        gap: 8px;
    }

    .subject-pills {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .subject-pills button {
        justify-content: space-between;
        min-width: 0;
        padding: 0 10px;
    }

    .filter-row,
    .sim-controls {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .filter-row input,
    .filter-row button,
    .sim-controls button {
        grid-column: 1 / -1;
    }

    .filter-row select,
    .filter-row input,
    .sim-controls select {
        min-width: 0;
    }

    .question-layout {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .question-list {
        max-height: 292px;
        padding: 12px;
    }

    .list-head {
        position: sticky;
        top: 0;
        z-index: 1;
        padding-bottom: 8px;
        background: rgba(255, 255, 255, .96);
    }

    .question-row {
        min-height: 66px;
        padding: 10px 11px;
    }

    .question-row.active {
        box-shadow: inset 4px 0 0 var(--teal);
    }

    .pager .ghost-btn {
        flex: 1;
    }

    .detail-head {
        align-items: flex-start;
        gap: 10px;
    }

    .detail-head .icon-only {
        position: absolute;
        right: 14px;
        top: 14px;
    }

    .question-detail {
        position: relative;
    }

    .detail-head h2 {
        max-width: calc(100% - 54px);
        font-size: 20px;
    }

    .image-stack {
        gap: 10px;
        margin: 14px 0;
    }

    .question-image {
        width: 100%;
        border-radius: 8px;
    }

    .question-text,
    .solution-view,
    .plan-strip div,
    .plan-list div,
    .insight-grid article {
        padding: 12px;
    }

    .answer-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 7px;
        margin: 14px 0;
    }

    .answer-grid button {
        min-height: 46px;
        height: 46px;
    }

    .answer-status {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }

    .sim-head {
        align-items: stretch;
        flex-direction: column;
    }

    .sim-head .primary-btn {
        width: 100%;
    }

    .sim-nav {
        display: grid;
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 6px;
    }

    .sim-nav button {
        width: auto;
        min-width: 0;
        height: 38px;
    }

    .card-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .card-hero,
    .card-tools {
        grid-template-columns: 1fr;
    }

    .card-metrics {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        width: 100%;
    }

    .card-metrics article {
        min-height: 68px;
        padding: 10px;
    }

    .card-metrics strong {
        font-size: 21px;
    }

    .card-tools .ghost-btn {
        width: 100%;
    }

    .card-subject-strip {
        margin-right: -12px;
        padding-right: 12px;
    }

    .flash-card {
        min-height: 210px;
        padding: 16px;
    }
}

@media (max-width: 420px) {
    .workspace {
        padding-left: 10px;
        padding-right: 10px;
    }

    .topbar {
        margin-left: -10px;
        margin-right: -10px;
        padding-left: 10px;
        padding-right: 10px;
    }

    .top-actions {
        grid-template-columns: minmax(0, .82fr) 42px minmax(0, 1.28fr);
    }

    .top-actions .ghost-btn,
    .top-actions .primary-btn {
        font-size: 12px;
        gap: 6px;
    }

    .subject-pills,
    .filter-row,
    .sim-controls {
        grid-template-columns: 1fr;
    }

    .card-metrics {
        grid-template-columns: 1fr;
    }

    .side-nav button {
        font-size: 10px;
    }

    .sim-nav {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}
