:root {
    --bg: #f6f8fb;
    --surface: #ffffff;
    --surface-strong: #eef3f0;
    --ink: #111827;
    --muted: #667085;
    --line: #e4e7ec;
    --accent: #0f8a6c;
    --accent-2: #2563eb;
    --warn: #c05621;
    --shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
    --shadow-soft: 0 1px 2px rgba(15, 23, 42, 0.06);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, Segoe UI, Arial, sans-serif;
    text-rendering: geometricPrecision;
}

a {
    color: inherit;
    text-decoration: none;
}

input,
select,
textarea,
button {
    font: inherit;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 22px;
    min-height: 72px;
    padding: 0 28px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 1px 0 rgba(17, 24, 39, 0.02);
    backdrop-filter: blur(12px);
}

.brand {
    display: inline-flex;
    align-items: center;
    font-weight: 800;
    min-width: 150px;
    color: #101828;
}

.brand > span:last-child {
    display: grid;
    gap: 2px;
    line-height: 1.05;
}

.brand small {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
}

.topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    min-width: 0;
}

.topnav {
    display: flex;
    gap: 8px;
}

.topnav a,
.admin-tabs a,
.secondary-btn {
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    box-shadow: var(--shadow-soft);
    transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.topnav a:hover,
.admin-tabs a:hover,
.secondary-btn:hover,
.logout-link:hover {
    border-color: #cbd5e1;
    background: #f9fafb;
    transform: translateY(-1px);
}

.user-chip {
    display: grid;
    justify-items: end;
    line-height: 1.2;
    min-width: 160px;
}

.user-chip span {
    font-weight: 700;
}

.user-chip small,
small {
    color: var(--muted);
}

.logout-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 14px;
    border: 1px solid var(--ink);
    border-radius: 8px;
    background: var(--ink);
    color: #fff;
    font-weight: 800;
    box-shadow: var(--shadow-soft);
    transition: background 140ms ease, transform 140ms ease;
}

.flash-stack {
    position: fixed;
    right: 20px;
    top: 78px;
    z-index: 20;
    display: grid;
    gap: 8px;
}

.flash {
    padding: 12px 14px;
    border-radius: 8px;
    background: #fff;
    border-left: 4px solid var(--accent-2);
    box-shadow: var(--shadow);
}

.flash.error {
    border-left-color: var(--warn);
}

.flash.success {
    border-left-color: var(--accent);
}

.login-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at 20% 20%, rgba(15, 138, 108, 0.14), transparent 28%),
        radial-gradient(circle at 82% 78%, rgba(37, 99, 235, 0.12), transparent 30%),
        var(--bg);
}

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

.login-panel {
    width: min(380px, 100%);
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.login-form {
    display: grid;
    align-content: center;
    gap: 16px;
    min-height: 320px;
    padding: 32px;
}

label {
    display: grid;
    gap: 7px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    box-shadow: var(--shadow-soft);
    transition: border-color 140ms ease, box-shadow 140ms ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: rgba(15, 138, 108, 0.75);
    box-shadow: 0 0 0 4px rgba(15, 138, 108, 0.12);
}

textarea {
    resize: vertical;
}

.primary-btn,
.secondary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 800;
}

.primary-btn {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 10px 22px rgba(15, 138, 108, 0.18);
    transition: background 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}

.primary-btn:hover {
    background: #0b7359;
    transform: translateY(-1px);
    box-shadow: 0 14px 26px rgba(15, 138, 108, 0.22);
}

.app-layout {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    min-height: calc(100vh - 72px);
}

.lesson-sidebar {
    min-height: calc(100vh - 72px);
    overflow: visible;
    border-right: 1px solid var(--line);
    background: #101828;
    color: #e9efe9;
    padding-top: 8px;
}

.sidebar-head {
    z-index: 3;
    display: grid;
    gap: 4px;
    padding: 20px 18px;
    background: #101828;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-head span {
    color: #9cac9f;
    font-size: 13px;
}

.sidebar-head strong {
    font-size: 24px;
}

.lesson-group h2 {
    margin: 0;
    padding: 12px 16px 8px;
    background: #172033;
    color: #d0d5dd;
    font-size: 13px;
    letter-spacing: 0;
}

.lesson-link {
    display: grid;
    grid-template-columns: 42px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 14px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    transition: background 140ms ease, box-shadow 140ms ease;
}

.lesson-link:hover,
.lesson-link.active {
    background: #1d2939;
}

.lesson-link.active {
    box-shadow: inset 4px 0 0 #22c55e;
}

.lesson-number {
    color: #98a2b3;
    text-align: right;
    font-size: 13px;
}

.lesson-name {
    display: grid;
    gap: 3px;
    min-width: 0;
    overflow-wrap: anywhere;
}

.lesson-name small {
    color: #98a2b3;
}

.lesson-hours {
    color: #f2f4f7;
    font-weight: 800;
}

.workspace {
    display: grid;
    align-content: start;
    gap: 24px;
    padding: 28px;
}

.empty-workspace {
    min-height: calc(100vh - 72px);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(246, 248, 251, 0.2)),
        var(--bg);
}

.workspace-head,
.admin-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.workspace-head h1,
.admin-head h1 {
    margin: 0;
    font-size: clamp(28px, 3.5vw, 44px);
    line-height: 1.02;
}

.eyebrow {
    margin: 0 0 7px;
    color: var(--accent);
    font-weight: 900;
    text-transform: uppercase;
    font-size: 12px;
}

.term-pill,
.type-badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-height: 30px;
    padding: 6px 10px;
    border-radius: 8px;
    background: #e7f6f1;
    color: #0b7359;
    font-weight: 800;
    font-size: 12px;
}

.type-badge.large {
    min-height: 40px;
    font-size: 14px;
}

.focus-panel,
.submission-panel,
.lesson-content,
.table-wrap,
.admin-form,
.edit-form,
.stats-grid > div {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.focus-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 24px;
}

.focus-panel h2,
.lesson-card h3,
.submission-panel h2,
.lesson-content h2,
.table-wrap h2 {
    margin: 0 0 8px;
}

.focus-panel p,
.lesson-card p,
.submission-panel p,
.lesson-content p {
    margin: 0;
    color: var(--muted);
}

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

.lesson-card {
    display: grid;
    gap: 12px;
    min-height: 164px;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.lesson-card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}

.lesson-workspace {
    padding-bottom: 48px;
}

.lesson-workspace .workspace-head h1 {
    font-size: clamp(24px, 2.6vw, 34px);
    line-height: 1.14;
}

.lesson-content {
    display: grid;
    gap: 24px;
    padding: 28px;
}

.lead {
    font-size: 18px;
}

.recipe-steps {
    display: grid;
    gap: 18px;
}

.step-row {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 16px;
    padding: 18px 0;
    border-top: 1px solid var(--line);
}

.step-number {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    background: #101828;
    color: #fff;
    border-radius: 50%;
    font-weight: 900;
}

.image-slot {
    display: grid;
    place-items: center;
    min-height: 190px;
    margin-top: 14px;
    background:
        linear-gradient(45deg, #f2f4f7 25%, transparent 25%),
        linear-gradient(-45deg, #f2f4f7 25%, transparent 25%),
        #fff;
    background-size: 22px 22px;
    border: 1px dashed #b7c7b9;
    border-radius: 8px;
    color: var(--muted);
    font-weight: 800;
}

.simulation {
    display: grid;
    grid-template-columns: minmax(260px, 520px) 220px;
    gap: 22px;
}

.pc-case {
    position: relative;
    aspect-ratio: 4 / 3;
    background: #253044;
    border: 12px solid #111827;
    border-radius: 8px;
}

.slot {
    position: absolute;
    display: grid;
    place-items: center;
    border: 2px dashed #7f9185;
    border-radius: 8px;
    color: #dbe5dd;
    font-weight: 800;
    text-align: center;
}

.slot.done {
    background: rgba(29, 211, 133, 0.22);
    border-style: solid;
    border-color: #1dd385;
}

.slot-board { left: 22%; top: 15%; width: 46%; height: 54%; }
.slot-ram { left: 72%; top: 18%; width: 16%; height: 42%; }
.slot-disk { left: 12%; bottom: 12%; width: 28%; height: 18%; }
.slot-psu { right: 9%; bottom: 10%; width: 24%; height: 22%; }
.slot-fan { left: 9%; top: 12%; width: 16%; height: 20%; border-radius: 50%; }

.component-tray {
    display: grid;
    align-content: start;
    gap: 10px;
}

.component {
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    font-weight: 800;
    box-shadow: var(--shadow-soft);
}

.component.selected {
    border-color: var(--accent-2);
    background: #eff6ff;
}

.component.used {
    opacity: 0.45;
}

pre {
    overflow: auto;
    padding: 14px;
    background: #101828;
    color: #dce7df;
    border-radius: 8px;
}

.submission-panel {
    display: grid;
    grid-template-columns: 1fr minmax(280px, 440px);
    gap: 20px;
    padding: 22px;
}

.upload-form {
    display: grid;
    gap: 10px;
}

.admin-shell {
    display: grid;
    gap: 22px;
    width: min(1180px, calc(100% - 40px));
    margin: 28px auto 56px;
}

.admin-shell.narrow {
    width: min(820px, calc(100% - 40px));
}

.admin-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.admin-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

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

.stats-grid > div {
    display: grid;
    gap: 4px;
    padding: 20px;
}

.stats-grid span {
    font-size: 34px;
    font-weight: 900;
}

.admin-form,
.edit-form {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    padding: 18px;
}

.admin-form.compact {
    grid-template-columns: 2fr 1fr 1fr auto;
}

.lesson-form {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.lesson-form textarea,
.lesson-form input[name="allowed_extensions"],
.edit-form label,
.edit-form .checkbox-row {
    grid-column: 1 / -1;
}

.edit-form {
    grid-template-columns: 1fr;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-row input {
    width: auto;
    min-height: auto;
}

.table-wrap {
    overflow: auto;
    padding: 8px;
}

.table-wrap h2 {
    padding: 12px 14px 4px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

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

th {
    color: var(--muted);
    font-size: 13px;
    background: #f8fafc;
    font-weight: 900;
}

tbody tr {
    transition: background 120ms ease;
}

tbody tr:hover {
    background: #fbfcfd;
}

td small {
    display: block;
}

.row-title-link {
    color: var(--accent);
    font-weight: 900;
}

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

.table-actions a {
    color: var(--accent);
    font-weight: 800;
}

.lesson-status-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.lesson-status-strip span,
.status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 900;
}

.lesson-status-strip span {
    background: #eef2f6;
    color: var(--ink);
}

.status-badge.submitted {
    background: #e7f6f1;
    color: #0b7359;
}

.status-badge.missing {
    background: #fff1f0;
    color: #b42318;
}

.custom-lesson {
    display: grid;
    gap: 24px;
}

.lesson-hero {
    display: grid;
    gap: 8px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.lesson-hero h2 {
    margin: 0;
    font-size: 24px;
}

.lesson-hero p,
.lesson-card-list p {
    margin: 0;
    color: var(--muted);
}

.lesson-kicker {
    color: var(--accent);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

.lesson-card-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 12px;
}

.lesson-card-list article,
.ui-shot,
.code-task,
.pc-builder-game,
.pixel-admin-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow-soft);
}

.lesson-card-list article {
    display: grid;
    gap: 6px;
    padding: 16px;
}

.lesson-card-list h3 {
    margin: 0;
    font-size: 16px;
}

.ui-shot {
    margin-top: 12px;
    overflow: hidden;
}

.ui-shot figcaption {
    padding: 9px 12px;
    border-bottom: 1px solid var(--line);
    background: #f8fafc;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.fake-ribbon {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
    border-bottom: 1px solid var(--line);
    background: #eef2f6;
}

.fake-ribbon span,
.fake-menu span {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 5px 9px;
    border: 1px solid #cfd8e3;
    border-radius: 6px;
    background: #fff;
    color: #344054;
    font-size: 12px;
    font-weight: 800;
}

.fake-menu {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 14px;
}

.fake-document,
.fake-slide,
.fake-sheet {
    min-height: 180px;
    margin: 14px;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    background: linear-gradient(#fff, #fbfcfd);
}

.fake-document {
    padding: 22px;
}

.fake-line {
    height: 10px;
    margin-bottom: 10px;
    border-radius: 999px;
    background: #d0d5dd;
}

.fake-line.short {
    width: 48%;
}

.fake-slide {
    display: grid;
    grid-template-columns: 1fr 120px;
    gap: 18px;
    padding: 24px;
}

.fake-slide::before,
.fake-slide::after {
    content: "";
    border-radius: 8px;
    background: #dbeafe;
}

.fake-slide::after {
    background: #dcfce7;
}

.fake-sheet {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-auto-rows: 34px;
}

.fake-sheet span {
    border-right: 1px solid #e4e7ec;
    border-bottom: 1px solid #e4e7ec;
}

.code-task {
    display: grid;
    gap: 12px;
    padding: 16px;
}

.code-task pre {
    margin: 0;
}

.pc-builder-game {
    display: grid;
    gap: 16px;
    padding: 18px;
}

.pc-builder-grid {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(220px, 300px);
    gap: 18px;
}

.pc-builder-game .pc-case {
    min-height: 300px;
}

.pc-builder-score {
    color: var(--accent);
    font-weight: 900;
}

.pixel-admin-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 420px);
    gap: 18px;
    padding: 18px;
}

.pixel-admin-panel h2 {
    margin: 0 0 10px;
}

.pixel-result {
    min-height: 22px;
    color: var(--muted);
    font-weight: 800;
}

.pipeline-list {
    display: grid;
    gap: 10px;
    margin: 0;
}

.pipeline-list div {
    display: grid;
    gap: 4px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.pipeline-list dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

.pipeline-list dd {
    margin: 0;
    overflow-wrap: anywhere;
    font-family: Consolas, ui-monospace, monospace;
    font-size: 13px;
}

.inline-eval {
    display: grid;
    grid-template-columns: 1fr 90px auto;
    gap: 8px;
}

.inline-eval textarea {
    grid-column: 1 / -1;
}

@media (max-width: 900px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
        padding: 12px 16px;
    }

    .topbar-actions {
        align-items: flex-start;
        flex-direction: column;
        width: 100%;
    }

    .topnav {
        flex-wrap: wrap;
    }

    .user-chip {
        justify-items: start;
    }

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

    .simulation,
    .submission-panel,
    .pc-builder-grid,
    .pixel-admin-panel {
        grid-template-columns: 1fr;
    }

    .lesson-sidebar {
        min-height: auto;
        max-height: none;
    }

    .workspace {
        padding: 18px;
    }

    .workspace-head,
    .admin-head,
    .focus-panel {
        align-items: flex-start;
        flex-direction: column;
    }

    .admin-actions {
        justify-content: flex-start;
    }

    .stats-grid,
    .admin-form,
    .admin-form.compact,
    .lesson-form {
        grid-template-columns: 1fr;
    }

    .login-form {
        min-height: auto;
        padding: 28px;
    }
}
