:root {
    --ink: #243447;
    --muted: #627488;
    --accent: #d89a72;
    --accent-dark: #c28258;
    --teal: #6d8ea8;
    --lavender: #eff4f8;
    --sand: #f6f9fc;
    --card: #ffffff;
    --border: #dbe5ef;
    --shadow: 0 12px 28px rgba(73, 98, 121, 0.12);
    --radius: 18px;
    --sidebar-width: 260px;
    --topbar-height: 70px;
    --focus: #4f46e5;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Manrope', sans-serif;
    background: linear-gradient(180deg, #f8fbfe 0%, #f2f7fb 100%);
    color: var(--ink);
    min-height: 100vh;
}

body::before {
    content: none;
}

h1, h2, h3, h4 {
    font-family: 'Manrope', sans-serif;
    font-weight: 700;
}

p {
    line-height: 1.7;
    color: var(--muted);
}

#app {
    min-height: 100vh;
}

.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    background: rgba(248, 252, 255, 0.94);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    z-index: 1000;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: linear-gradient(150deg, var(--teal), #8eabc3);
    display: grid;
    place-items: center;
    font-weight: 700;
    color: white;
    letter-spacing: 1px;
}

.brand-title {
    font-weight: 700;
    font-size: 1.05rem;
}

.brand-subtitle {
    font-size: 0.85rem;
    color: var(--muted);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.lang-toggle {
    display: inline-flex;
    gap: 6px;
    padding: 4px;
    background: #fff;
    border-radius: 14px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.lang-btn {
    border: none;
    background: transparent;
    padding: 6px 12px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--muted);
}

.lang-btn.active {
    background: #cf936f;
    color: white;
}

.ghost-btn {
    border: 1px solid var(--border);
    background: #f8fbff;
    padding: 8px 14px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
}

#menu-toggle {
    display: none;
}

.layout {
    display: flex;
    padding-top: var(--topbar-height);
}

.sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--topbar-height));
    background: #f9fcff;
    border-right: 1px solid var(--border);
    padding: 24px 18px;
    z-index: 900;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.sidebar-header h2 {
    font-size: 1.1rem;
    margin-bottom: 6px;
}

.sidebar-header p {
    font-size: 0.85rem;
}

.nav-links {
    list-style: none;
    margin-top: 18px;
}

.nav-links a {
    display: block;
    padding: 10px 14px;
    border-radius: 12px;
    text-decoration: none;
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 6px;
    transition: all 0.2s ease;
}

.nav-links a.active,
.nav-links a:hover {
    background: #eaf2f9;
    color: var(--ink);
    transform: translateX(4px);
}

.sidebar-note {
    margin-top: 18px;
    font-size: 0.8rem;
    color: var(--muted);
}

#content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    padding: 32px 40px 80px;
}

.catalog-section {
    display: none;
    animation: fadeUp 0.4s ease;
}

.catalog-section.active {
    display: block;
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.section-hero {
    background: linear-gradient(135deg, #ffffff, #f1f7fc);
    border-radius: 24px;
    padding: 28px 32px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 24px;
}

.hero-label {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 999px;
    background: #7f9cb6;
    color: white;
    font-size: 0.78rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 10px;
}

.section-hero h1 {
    font-size: 2.1rem;
    margin-bottom: 12px;
    color: var(--ink);
}

.catalog-shell {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.catalog-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
    gap: 14px;
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: 0 8px 20px rgba(95, 121, 145, 0.1);
    border: 1px solid var(--border);
}

.control label {
    display: block;
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 6px;
    font-weight: 600;
}

.control select,
.control input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #fff;
    font-family: inherit;
    font-size: 0.9rem;
}

.control-reset {
    display: flex;
    align-items: flex-end;
}

.control-reset .ghost-btn {
    width: 100%;
}

.catalog-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 6px;
    color: var(--muted);
    font-size: 0.9rem;
}

.catalog-list {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.qa-card {
    background: var(--card);
    border-radius: 20px;
    padding: 22px 24px;
    border: 1px solid var(--border);
    box-shadow: 0 10px 24px rgba(95, 121, 145, 0.12);
}

.catalog-notice {
    margin-bottom: 16px;
    padding: 13px 16px;
    border-radius: 14px;
    border: 1px solid #c7d8e8;
    background: #eef6fc;
    color: #405a70;
    font-size: 0.9rem;
    line-height: 1.65;
}

.catalog-notice strong {
    color: var(--ink);
}

.pill.neutral {
    background: #e9f0f6;
    color: #405a70;
}

.topic-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.topic-tags span {
    padding: 4px 9px;
    border-radius: 999px;
    background: #f2f0fb;
    color: #574f82;
    font-size: 0.72rem;
    font-weight: 600;
}

.question-block {
    margin-top: 0;
}

.prompt-text {
    white-space: normal;
}

.answer-disclosure {
    margin-top: 18px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.answer-disclosure > summary,
.study-panel > summary {
    min-height: 44px;
    display: flex;
    align-items: center;
    cursor: pointer;
    color: #3b5770;
    font-weight: 700;
    list-style: none;
}

.answer-disclosure > summary::-webkit-details-marker,
.study-panel > summary::-webkit-details-marker {
    display: none;
}

.answer-disclosure > summary::after,
.study-panel > summary::after {
    content: "+";
    margin-left: auto;
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #edf4fa;
    color: #4b6780;
}

.answer-disclosure[open] > summary::after,
.study-panel[open] > summary::after {
    content: "−";
}

.answer-content {
    padding-top: 4px;
}

.block-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.block-heading span {
    color: var(--muted);
    font-size: 0.8rem;
}

.study-panel {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: #fbfdff;
    overflow: hidden;
}

.study-panel > summary {
    padding: 4px 14px;
}

.study-panel-body {
    padding: 4px 14px 16px;
}

.structure-list {
    list-style: none;
    display: grid;
    gap: 10px;
}

.structure-list li {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
}

.step-number {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: #dfeaf4;
    color: #3b5770;
    font-size: 0.8rem;
    font-weight: 700;
}

.analysis-description,
.vocab-meaning {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.65;
}

.analysis-grid,
.vocab-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 10px;
}

.analysis-card,
.vocab-card {
    padding: 13px 14px;
    border-radius: 13px;
    border: 1px solid #e0e9f1;
    background: white;
}

.analysis-card h5,
.vocab-card h5 {
    color: #344f68;
    font-size: 0.95rem;
}

.analysis-card blockquote,
.vocab-example {
    margin-top: 8px;
    padding-left: 10px;
    border-left: 3px solid #bdccda;
    color: var(--ink);
    font-family: 'Source Serif 4', serif;
    font-size: 0.92rem;
    line-height: 1.65;
}

.source-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
}

.source-grid > div {
    padding: 11px;
    border-radius: 11px;
    background: #f2f6fa;
}

.source-grid span,
.source-grid strong {
    display: block;
}

.source-grid span {
    color: var(--muted);
    font-size: 0.75rem;
}

.source-grid strong {
    margin-top: 2px;
    color: var(--ink);
    font-size: 0.9rem;
}

.related-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.related-links button {
    border: 0;
    color: #425f78;
    background: #e8f1f8;
    border-radius: 9px;
    padding: 7px 10px;
    font-size: 0.82rem;
    cursor: pointer;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 8px;
}

.page-btn {
    min-height: 44px;
    padding: 9px 16px;
    border-radius: 11px;
    border: 1px solid var(--border);
    background: white;
    color: var(--ink);
    font-weight: 700;
    cursor: pointer;
}

.page-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

button:focus-visible,
a:focus-visible,
summary:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--focus) 55%, transparent);
    outline-offset: 2px;
}

[hidden] {
    display: none !important;
}

.qa-header {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.qa-tags {
    display: flex;
    gap: 8px;
    align-items: center;
}

.pill {
    background: #cb9574;
    color: white;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.pill.outline {
    background: transparent;
    border: 1px solid var(--accent);
    color: #a97352;
}

.qa-months {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    background: #edf4fa;
    color: var(--ink);
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
}

.qa-block {
    margin-top: 18px;
}

.qa-block h3 {
    font-size: 1.1rem;
    margin-bottom: 10px;
    color: #3c5770;
    letter-spacing: 0.2px;
}

.sub-block h4 {
    font-size: 0.95rem;
    margin-top: 12px;
    margin-bottom: 6px;
}

.answer-title {
    font-family: 'Manrope', sans-serif;
    font-size: 1rem;
    color: #6f8da8;
    margin-bottom: 8px;
}

.fr-sample {
    color: var(--ink);
    font-family: 'Source Serif 4', serif;
    font-size: 1.05rem;
    line-height: 1.85;
}

.qa-block:first-of-type .fr-sample {
    font-size: 1.08rem;
    line-height: 1.9;
    background: #f4f8fc;
    border: 1px solid #dbe6f0;
    border-left: 4px solid #9ab2c7;
    border-radius: 12px;
    padding: 14px 16px;
}

.qa-block:nth-of-type(2) .fr-sample {
    background: #fff;
    border: 1px solid #e3ebf3;
    border-radius: 12px;
    padding: 14px 16px;
}

.translation {
    color: var(--muted);
    background: #f1f6fb;
    border-radius: 12px;
    padding: 10px 12px;
    border: 1px solid #dce8f2;
    font-size: 0.95rem;
}

.pairs-table {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pair-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 14px;
    padding: 12px 14px;
    border-radius: 14px;
    background: #f9fbfe;
    border: 1px solid #e2ebf4;
}

.pair-fr {
    font-weight: 600;
    color: var(--ink);
    font-family: 'Source Serif 4', serif;
    font-size: 1rem;
    line-height: 1.75;
}

.pair-tr {
    color: var(--muted);
    font-size: 0.93rem;
    line-height: 1.7;
}

.grammar-list {
    padding-left: 18px;
    color: var(--muted);
    font-size: 0.95rem;
    line-height: 1.75;
}

.loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px;
    color: var(--muted);
}

.spinner {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 3px solid #f0e5d8;
    border-top-color: var(--accent);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.empty {
    padding: 12px 14px;
    border-radius: 12px;
    background: #f1f6fb;
    color: var(--muted);
    font-size: 0.9rem;
}

.load-error {
    padding: 12px 14px;
    border-radius: 12px;
    background: #ffe9e2;
    color: #8f2a1d;
}

@media (max-width: 900px) {
    #menu-toggle {
        display: inline-flex;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    #content {
        margin-left: 0;
        width: 100%;
        padding: 28px 20px 60px;
    }

    .topbar {
        padding: 0 16px;
    }
}

@media (max-width: 700px) {
    .pair-row {
        grid-template-columns: 1fr;
    }

    .section-hero h1 {
        font-size: 1.7rem;
    }

    .qa-card {
        padding: 18px 16px;
    }

    .analysis-grid,
    .vocab-grid {
        grid-template-columns: 1fr;
    }

    .pagination {
        justify-content: space-between;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
