:root {
    --blue: #1559d6;
    --blue-dark: #0f3f9a;
    --ink: #182235;
    --muted: #637083;
    --line: #d9e1ec;
    --panel: #ffffff;
    --page: #f4f7fb;
    --success-bg: #edfdf5;
    --success-border: #9be0bd;
    --success-text: #146c43;
    --error-bg: #fff1f1;
    --error-border: #f4b4b4;
    --error-text: #a42424;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    background: var(--page);
    color: var(--ink);
    font-family: "Segoe UI", Arial, sans-serif;
    line-height: 1.5;
}

a {
    color: var(--blue);
}

.top-bar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    min-height: 64px;
    padding: 14px 28px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
}

.top-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

.brand {
    color: var(--blue);
    font-size: 0.98rem;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}

.external-button,
.secondary-button,
.form-panel button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 16px;
    border: 0;
    border-radius: 8px;
    background: var(--blue);
    color: #ffffff;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    transition: background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.external-button:hover,
.secondary-button:hover,
.form-panel button:hover {
    background: var(--blue-dark);
    box-shadow: 0 10px 24px rgba(21, 89, 214, 0.18);
    transform: translateY(-1px);
}

.secondary-button {
    background: #20324d;
}

.secondary-button:hover {
    background: #142238;
}

.page-content {
    width: min(1040px, calc(100% - 40px));
    margin: 0 auto;
    padding: 40px 0 64px;
}

.home-page {
    padding-top: 56px;
}

.home-intro {
    max-width: 700px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--line);
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--blue);
    font-size: 0.84rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.home-intro h1,
.course-header h1 {
    margin: 0 0 12px;
    font-size: 2.45rem;
    line-height: 1.12;
    letter-spacing: 0;
}

.home-intro p,
.course-header p,
.empty-state p,
.muted {
    color: var(--muted);
}

.levels-grid,
.terms-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-top: 28px;
}

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

.level-card,
.term-card {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 112px;
    padding: 18px;
    border: 1px solid var(--line);
    border-left: 5px solid var(--blue);
    border-radius: 8px;
    background: var(--panel);
    color: var(--ink);
    font-size: 1.08rem;
    font-weight: 800;
    text-align: center;
    text-decoration: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.term-card {
    min-height: 132px;
}

.level-card:hover,
.term-card:hover {
    border-color: #b6c5d9;
    box-shadow: 0 16px 34px rgba(24, 34, 53, 0.08);
    transform: translateY(-2px);
}

.course-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 28px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--line);
}

.back-link {
    display: inline-flex;
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 0.94rem;
    font-weight: 700;
    text-decoration: none;
}

.posts-stack {
    display: grid;
    gap: 14px;
}

.wiki-post,
.empty-state,
.form-panel,
.recent-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.empty-state {
    padding: 24px;
}

.empty-state h2,
.form-panel h2,
.recent-panel h2 {
    margin: 0 0 12px;
    font-size: 1.25rem;
}

.wiki-post {
    overflow: hidden;
}

.wiki-post summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 64px;
    padding: 18px 20px;
    cursor: pointer;
    font-weight: 800;
    list-style: none;
    overflow-wrap: anywhere;
}

.wiki-post summary::-webkit-details-marker {
    display: none;
}

.wiki-post summary::after {
    content: "+";
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: #eaf1ff;
    color: var(--blue);
    font-weight: 900;
}

.post-summary-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.post-summary-title {
    overflow-wrap: anywhere;
}

.wiki-post[open] summary {
    border-bottom: 1px solid var(--line);
}

.wiki-post[open] summary::after {
    content: "-";
}

.wiki-body {
    padding: 18px 20px 20px;
}

.post-date {
    margin: 0 0 14px;
    color: var(--muted);
    font-size: 0.9rem;
}

.subject-badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-height: 28px;
    padding: 5px 9px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 800;
    line-height: 1.2;
}

.subject-badge--blue {
    border-color: #b8cdf8;
    background: #eaf1ff;
    color: #1559d6;
}

.subject-badge--teal {
    border-color: #a9ded5;
    background: #e8faf5;
    color: #047064;
}

.subject-badge--green {
    border-color: #b9dcae;
    background: #edf8e9;
    color: #2f6b1f;
}

.subject-badge--amber {
    border-color: #ead38a;
    background: #fff7df;
    color: #946200;
}

.subject-badge--rose {
    border-color: #f2b5c7;
    background: #fff0f4;
    color: #b42350;
}

.subject-badge--violet {
    border-color: #cfc4ff;
    background: #f3f0ff;
    color: #6941c6;
}

.subject-badge--cyan {
    border-color: #abdff3;
    background: #e8f8ff;
    color: #006c9c;
}

.subject-badge--orange {
    border-color: #f5c198;
    background: #fff4e8;
    color: #a44900;
}

.subject-badge--neutral {
    border-color: #cdd6e2;
    background: #f5f7fb;
    color: #4e5f74;
}

.wiki-content {
    max-width: 760px;
    overflow-wrap: anywhere;
}

.preview-card {
    margin-top: 18px;
    padding: 16px;
    border: 1px solid #c7d4e6;
    border-radius: 8px;
    background: #f8fbff;
}

.preview-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-weight: 800;
}

.preview-title a {
    flex: 0 0 auto;
    font-size: 0.94rem;
    text-decoration: none;
}

.file-name {
    margin: 8px 0 12px;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.preview-image {
    display: block;
    max-width: 100%;
    max-height: 540px;
    border: 1px solid var(--line);
    border-radius: 8px;
    object-fit: contain;
}

.preview-frame {
    width: 100%;
    min-height: 500px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
}

.admin-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
    gap: 20px;
    align-items: start;
}

.form-panel,
.recent-panel {
    padding: 24px;
}

.login-panel {
    max-width: 460px;
}

.form-panel label {
    display: block;
    margin: 16px 0 8px;
    font-weight: 750;
}

.form-panel input,
.form-panel textarea,
.form-panel select {
    width: 100%;
    padding: 12px 13px;
    border: 1px solid #b9c7d8;
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink);
    font: inherit;
}

.form-panel textarea {
    min-height: 180px;
    resize: vertical;
}

.form-panel input:focus,
.form-panel textarea:focus,
.form-panel select:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(21, 89, 214, 0.14);
    outline: none;
}

.form-panel button {
    margin-top: 18px;
}

.message {
    margin-bottom: 18px;
    padding: 13px 16px;
    border-radius: 8px;
    font-weight: 700;
}

.message.success {
    border: 1px solid var(--success-border);
    background: var(--success-bg);
    color: var(--success-text);
}

.message.error {
    border: 1px solid var(--error-border);
    background: var(--error-bg);
    color: var(--error-text);
}

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

.recent-item {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcff;
}

.recent-item h3 {
    margin: 0 0 6px;
    font-size: 1rem;
    overflow-wrap: anywhere;
}

.recent-item p {
    margin: 0 0 8px;
    color: var(--muted);
}

.recent-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 0.94rem;
}

.recent-item a {
    font-weight: 700;
    text-decoration: none;
}

.recent-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.recent-actions form {
    margin: 0;
}

.delete-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 7px 11px;
    border: 1px solid var(--error-border);
    border-radius: 8px;
    background: var(--error-bg);
    color: var(--error-text);
    cursor: pointer;
    font: inherit;
    font-weight: 800;
}

.delete-button:hover {
    background: #ffe4e4;
}

@media (max-width: 840px) {
    .levels-grid,
    .terms-grid,
    .admin-layout {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .top-bar {
        padding: 12px 16px;
    }

    .top-actions {
        width: 100%;
    }

    .brand {
        margin-right: auto;
    }

    .page-content {
        width: min(100% - 28px, 1040px);
        padding-top: 28px;
    }

    .home-intro h1,
    .course-header h1 {
        font-size: 2rem;
    }

    .levels-grid,
    .terms-grid,
    .admin-layout {
        grid-template-columns: 1fr;
    }

    .course-header {
        display: block;
    }

    .secondary-button {
        margin-top: 14px;
    }

    .preview-frame {
        min-height: 360px;
    }
}
