:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-2: #f3f4f6;
    --border: #d1d5db;
    --text: #111827;
    --muted: #6b7280;
    --active: #e0f2fe;
    --active-border: #7dd3fc;
    --topbar-h: 60px;
    --sidebar-w: 220px;
    --hsk1: #dbeafe;
    --hsk2: #dcfce7;
    --hsk3: #fef3c7;
    --hsk4: #fae8ff;
    --hsk5: #ffe4e6;
    --hsk6: #e0e7ff;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, sans-serif;
}

body {
    overflow-x: hidden;
}

.app-shell {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 16px 12px;
    overflow-y: auto;
}

.brand {
    margin: 0 0 18px;
    font-size: 18px;
    line-height: 1.2;
}

.nav-group {
    padding-top: 12px;
}

.nav-group + .nav-group {
    margin-top: 12px;
    border-top: 1px solid var(--border);
}

.nav-group-title {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.nav-list {
    display: grid;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
}

.nav-item:hover {
    background: var(--surface-2);
}

.nav-item.active {
    background: var(--active);
    border-color: var(--active-border);
}

.main {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    min-height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    white-space: nowrap;
}

.hsk-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.hsk-filter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    user-select: none;
}

.hsk-filter input {
    margin: 0;
}

.hsk-filter.active {
    border-color: #93c5fd;
    background: #eff6ff;
}

.content-wrap {
    padding: 16px;
}

.toolbar {
    display: grid;
    grid-template-columns: 1fr 220px;
    gap: 12px;
    margin-bottom: 12px;
}

.pill-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.choice-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    cursor: pointer;
    user-select: none;
    font-size: 13px;
}

.choice-pill input {
    margin: 0;
}

.choice-pill.active {
    background: var(--active);
    border-color: var(--active-border);
}

.field {
    display: grid;
    gap: 6px;
}

.field-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
}

.field input,
.field select {
    width: 100%;
    min-height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.module-summary {
    margin: 8px 0 12px;
    font-size: 13px;
    color: var(--muted);
}

.vocab-results {
    display: grid;
    gap: 10px;
}

.vocab-card {
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.vocab-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.vocab-hanzi {
    font-size: 28px;
    line-height: 1;
    font-weight: 700;
}

.vocab-pinyin {
    margin-top: 6px;
    font-size: 14px;
    color: var(--muted);
}

.vocab-meaning {
    margin-top: 10px;
    font-size: 15px;
    line-height: 1.6;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.page-btn {
    min-width: 38px;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
}

.page-btn.active {
    background: var(--active);
    border-color: var(--active-border);
}

#module-content > .module-panel {
    display: none;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}

#module-content > .module-panel.active {
    display: block;
}

.hidden {
    display: none !important;
}

.module-title {
    margin: 0 0 12px;
    font-size: 20px;
}

.module-note {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.flashcard-shell {
    display: flex;
    justify-content: center;
}

.flashcard-stage {
    width: min(100%, 720px);
    display: grid;
    gap: 14px;
    justify-items: center;
}

.flashcard-counter {
    font-size: 13px;
    color: var(--muted);
}

.flashcard-card {
    width: min(100%, 520px);
    aspect-ratio: 3 / 2;
    perspective: 1200px;
    cursor: pointer;
}

.flashcard-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.55s ease;
    transform-style: preserve-3d;
}

.flashcard-card.is-flipped .flashcard-inner {
    transform: rotateY(180deg);
}

.flashcard-face {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    backface-visibility: hidden;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
}

.flashcard-back {
    transform: rotateY(180deg);
}

.flashcard-hanzi {
    font-size: clamp(48px, 10vw, 92px);
    font-weight: 700;
    line-height: 1;
}

.flashcard-pinyin {
    font-size: clamp(24px, 4vw, 36px);
    font-weight: 700;
    margin-bottom: 10px;
}

.flashcard-meaning {
    font-size: clamp(16px, 2.8vw, 22px);
    line-height: 1.6;
    text-align: center;
}

.flashcard-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.flashcard-actions .page-btn {
    min-width: 92px;
}

.listen-setup,
.listen-session,
.listen-review {
    display: grid;
    gap: 14px;
}

.listen-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.listen-session {
    margin-top: 10px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}

.listen-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.listen-label {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 6px;
}

.listen-pinyin {
    font-size: 24px;
    font-weight: 700;
}

.listen-meaning {
    margin-top: 8px;
    color: var(--text);
}

.listen-timer {
    min-width: 88px;
    text-align: center;
    font-size: 36px;
    font-weight: 700;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
}

.listen-input-wrap input {
    font-size: 18px;
}

.listen-feedback {
    min-height: 24px;
    font-size: 14px;
    font-weight: 700;
}

.listen-feedback.correct {
    color: #15803d;
}

.listen-feedback.wrong {
    color: #b91c1c;
}

.listen-feedback.skip {
    color: #9a3412;
}

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

.stat-box {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    font-size: 13px;
}

.module-subtitle {
    margin: 0;
    font-size: 16px;
}

.review-list {
    display: grid;
    gap: 10px;
}

.review-item {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}

.review-item strong {
    display: block;
    margin-bottom: 4px;
    font-size: 18px;
}

.radical-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.radical-current {
    font-size: 42px;
    font-weight: 700;
    line-height: 1;
}

.radical-entry-list {
    display: grid;
    gap: 8px;
}

.radical-entry {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}

.radical-entry.ok {
    border-color: #86efac;
    background: #f0fdf4;
}

.radical-entry.bad {
    border-color: #fca5a5;
    background: #fef2f2;
}

.radical-entry.dupe {
    border-color: #fdba74;
    background: #fff7ed;
}

.radical-entry-code {
    min-width: 34px;
    font-size: 14px;
    font-weight: 700;
}

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

.radical-chip {
    padding: 10px 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    display: grid;
    justify-items: center;
    gap: 4px;
    text-align: center;
}

.radical-chip strong {
    font-size: 20px;
}

.radical-chip span {
    font-size: 12px;
    color: var(--muted);
}

.guess-session,
.guess-review,
.guess-setup {
    display: grid;
    gap: 14px;
}

.guess-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    min-height: 120px;
}

.guess-meaning {
    font-size: 26px;
    line-height: 1.5;
    font-weight: 700;
}

.guess-audio {
    min-width: 52px;
    height: 52px;
    border-radius: 999px;
}

.guess-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}

.guess-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.guess-table th,
.guess-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.guess-table th {
    background: var(--surface-2);
    font-size: 13px;
}

.guess-result.ok {
    color: #15803d;
    font-weight: 700;
}

.guess-result.bad {
    color: #b91c1c;
    font-weight: 700;
}

.guess-result.skip {
    color: #9a3412;
    font-weight: 700;
}

.writing-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 16px;
    min-height: calc(100vh - 180px);
}

.writing-sidebar,
.writing-main {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    padding: 16px;
}

.writing-main {
    display: grid;
    gap: 14px;
    align-content: start;
}

.writing-top {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
}

.writing-stage {
    min-height: 440px;
    display: grid;
    gap: 12px;
    justify-items: center;
    align-content: center;
}

.writing-target {
    font-size: clamp(56px, 12vw, 120px);
    font-weight: 700;
    line-height: 1;
    text-align: center;
}

.writing-container {
    width: min(100%, 520px);
    min-height: 360px;
    border: 1px dashed var(--border);
    border-radius: 14px;
    background: #fff;
}

.writing-status {
    min-height: 24px;
    color: var(--muted);
    font-size: 14px;
}

.writing-missing {
    font-size: 13px;
    color: #b91c1c;
    padding: 10px 12px;
    border: 1px solid #fca5a5;
    background: #fef2f2;
    border-radius: 10px;
}

.writing-compact .sidebar {
    width: 72px;
    padding: 16px 8px;
}

.writing-compact .brand,
.writing-compact .nav-group-title,
.writing-compact .nav-item span {
    display: none;
}

.writing-compact .main {
    margin-left: 72px;
}

.writing-compact .nav-item {
    justify-content: center;
}

.writing-compact .nav-item i {
    margin: 0;
}

body.writing-mode .sidebar {
    width: 72px;
    padding: 16px 8px;
}

body.writing-mode .brand,
body.writing-mode .nav-group-title,
body.writing-mode .nav-item span {
    display: none;
}

body.writing-mode .main {
    margin-left: 72px;
}

body.writing-mode .nav-item {
    justify-content: center;
}

body.writing-mode .nav-item i {
    margin: 0;
}

.hsk-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.hsk-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.hsk-1 { background: var(--hsk1); }
.hsk-2 { background: var(--hsk2); }
.hsk-3 { background: var(--hsk3); }
.hsk-4 { background: var(--hsk4); }
.hsk-5 { background: var(--hsk5); }
.hsk-6 { background: var(--hsk6); }

@media (max-width: 767px) {
    .sidebar {
        position: sticky;
        top: 0;
        width: 100%;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        display: flex;
        gap: 16px;
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
    }

    .brand {
        flex: 0 0 auto;
        margin: 0 12px 0 0;
        padding-right: 12px;
        border-right: 1px solid var(--border);
    }

    .nav-group {
        padding-top: 0;
        margin-top: 0;
        border-top: 0;
        flex: 0 0 auto;
    }

    .nav-group-title {
        display: none;
    }

    .nav-list {
        display: flex;
        gap: 8px;
    }

    .nav-item {
        flex: 0 0 auto;
    }

    .main {
        margin-left: 0;
    }

    .topbar {
        top: 0;
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .topbar-label {
        width: 100%;
    }

    .toolbar {
        grid-template-columns: 1fr;
    }

    .listen-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .radical-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .guess-card {
        flex-direction: column;
        align-items: flex-start;
    }

    .writing-layout {
        grid-template-columns: 1fr;
    }

    body.writing-mode .sidebar {
        width: 100%;
    }

    body.writing-mode .main {
        margin-left: 0;
    }
}
