:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f0f1f4;
    --text: #17181b;
    --muted: #6b7078;
    --line: #dedfe4;
    --accent: #6546d7;
    --accent-strong: #4e34b8;
    --success: #1f7a4f;
    --danger: #b23838;
    --warning: #946200;
    --code: #16171a;
    --code-text: #edf0f5;
    --radius: 8px;
    --max: 1180px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.55; }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

.shell { min-height: 100vh; }
.site-header { height: 64px; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.site-header .inner { width: min(var(--max), calc(100% - 40px)); margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.brand { font-weight: 760; letter-spacing: -0.03em; font-size: 21px; display: inline-flex; gap: 7px; align-items: baseline; }
.brand small { color: var(--muted); font-weight: 600; letter-spacing: 0; font-size: 12px; }
.nav { display: flex; align-items: center; gap: 22px; font-size: 14px; }
.nav form { margin: 0; }
.nav-button { border: 0; background: transparent; color: var(--muted); padding: 0; }
.nav-button:hover { color: var(--text); }

.page { width: min(var(--max), calc(100% - 40px)); margin: 0 auto; padding: 40px 0 72px; }
.page-narrow { width: min(720px, calc(100% - 40px)); }
.eyebrow { color: var(--accent); text-transform: uppercase; letter-spacing: .09em; font-size: 11px; font-weight: 750; margin: 0 0 8px; }
h1, h2, h3 { letter-spacing: -0.025em; line-height: 1.15; }
h1 { font-size: clamp(32px, 5vw, 54px); margin: 0 0 16px; }
h2 { font-size: 26px; margin: 0 0 14px; }
h3 { font-size: 18px; margin: 0 0 8px; }
p { margin: 0 0 16px; }
.muted { color: var(--muted); }

.hero { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(300px, .85fr); gap: 72px; align-items: center; min-height: 520px; }
.hero-copy { max-width: 700px; }
.hero-copy p { color: var(--muted); font-size: 19px; max-width: 620px; }
.hero-panel { border-left: 1px solid var(--line); padding-left: 38px; }
.hero-panel dl { margin: 0; display: grid; gap: 24px; }
.hero-panel dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.hero-panel dd { margin: 3px 0 0; font-size: 18px; font-weight: 650; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 24px; }
.btn { border: 1px solid var(--text); background: var(--text); color: #fff; border-radius: 6px; padding: 10px 15px; font-weight: 650; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.btn:hover { background: #303136; color: #fff; }
.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-secondary { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: #fff; border-color: #e6bcbc; color: var(--danger); }
.btn-small { padding: 7px 10px; font-size: 12px; }

.flash { margin-bottom: 22px; border: 1px solid #bfdcca; background: #f0faf4; color: #185e3d; padding: 12px 14px; border-radius: 6px; }
.errors { margin-bottom: 22px; border: 1px solid #e8c0c0; background: #fff5f5; color: #8d2929; padding: 12px 14px; border-radius: 6px; }
.errors ul { margin: 0; padding-left: 20px; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.card-flat { border-top: 1px solid var(--line); padding: 22px 0; }
.card-meta { display: flex; gap: 10px; color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.course-title { font-size: 20px; font-weight: 720; letter-spacing: -0.02em; }

.progress { height: 6px; background: #e8e9ec; overflow: hidden; border-radius: 99px; }
.progress > span { display: block; height: 100%; background: var(--accent); }
.progress-row { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 7px; }

.section-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin: 40px 0 16px; }
.section-head:first-child { margin-top: 0; }

.form { display: grid; gap: 18px; }
.field { display: grid; gap: 7px; }
.field label { font-size: 13px; font-weight: 650; }
.field small { color: var(--muted); }
.input, .textarea, .select { width: 100%; border: 1px solid #cfd1d6; border-radius: 6px; background: #fff; color: var(--text); padding: 10px 11px; outline: none; }
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(101,70,215,.08); }
.textarea { min-height: 140px; resize: vertical; }
.textarea-code { font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; min-height: 280px; tab-size: 2; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; }

.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) 460px; }
.auth-side { padding: 64px; display: flex; flex-direction: column; justify-content: space-between; background: #17181b; color: #f5f5f6; }
.auth-side p { color: #b9bbc1; max-width: 520px; }
.auth-box { background: #fff; padding: 60px; display: flex; align-items: center; }
.auth-box-inner { width: 100%; }
.auth-box h1 { font-size: 34px; }

.module-list { border-top: 1px solid var(--line); }
.module { border-bottom: 1px solid var(--line); padding: 20px 0; }
.module-head { display: flex; justify-content: space-between; gap: 20px; align-items: center; }
.lesson-list { margin-top: 14px; display: grid; }
.lesson-row { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center; padding: 11px 0; border-top: 1px solid #ececef; }
.lesson-index { color: var(--muted); font-size: 12px; }
.lesson-state { font-size: 12px; color: var(--muted); }
.lesson-state.done { color: var(--success); font-weight: 650; }

.lesson-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: calc(100vh - 64px); }
.lesson-sidebar { border-right: 1px solid var(--line); padding: 28px 24px; background: #fbfbfc; }
.lesson-sidebar a { display: block; padding: 8px 0; font-size: 13px; }
.lesson-main { padding: 38px clamp(24px, 5vw, 72px) 72px; min-width: 0; }
.lesson-content { max-width: 760px; }
.prose { font-size: 16px; }
.prose h2 { margin-top: 34px; }
.prose h3 { margin-top: 26px; }
.prose code { background: #eeeef2; padding: 2px 5px; border-radius: 4px; font: 13px ui-monospace, monospace; }
.prose pre { background: var(--code); color: var(--code-text); padding: 18px; overflow: auto; border-radius: 6px; }
.prose pre code { background: transparent; padding: 0; color: inherit; }

.lab { margin-top: 30px; border-top: 1px solid var(--line); padding-top: 28px; }
.lab-grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(320px, .95fr); gap: 16px; }
.editor-panel, .preview-panel { background: #fff; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.panel-head { height: 46px; padding: 0 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 700; }
.code-editor { display: block; width: 100%; min-height: 440px; border: 0; resize: vertical; outline: 0; padding: 16px; background: var(--code); color: var(--code-text); font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; tab-size: 2; }
.preview-frame { display: block; width: 100%; min-height: 270px; border: 0; background: #fff; }
.test-list { border-top: 1px solid var(--line); padding: 12px 14px; display: grid; gap: 8px; }
.test-item { font-size: 13px; display: flex; align-items: center; gap: 8px; }
.test-item::before { content: '○'; color: var(--muted); }
.test-item.pass::before { content: '✓'; color: var(--success); font-weight: 800; }
.test-item.fail::before { content: '×'; color: var(--danger); font-weight: 800; }

.admin-shell { min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.admin-nav { background: #17181b; color: #e8e8eb; padding: 26px 18px; position: sticky; top: 0; height: 100vh; }
.admin-nav .brand { color: #fff; padding: 0 8px 24px; }
.admin-nav nav { display: grid; gap: 3px; }
.admin-nav nav a { padding: 9px 10px; border-radius: 5px; color: #bfc1c7; font-size: 13px; }
.admin-nav nav a:hover, .admin-nav nav a.active { background: #26272c; color: #fff; }
.admin-user { position: absolute; left: 18px; right: 18px; bottom: 20px; border-top: 1px solid #33343a; padding-top: 15px; color: #a8abb3; font-size: 12px; }
.admin-main { min-width: 0; }
.admin-top { height: 64px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: #fff; padding: 0 32px; }
.admin-page { padding: 32px; max-width: 1400px; }
.admin-title { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 24px; }
.admin-title h1 { font-size: 30px; margin: 0; }
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border: 1px solid var(--line); background: #fff; }
.stat { padding: 18px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat strong { display: block; font-size: 25px; }
.stat span { color: var(--muted); font-size: 12px; }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid #ececef; font-size: 13px; vertical-align: top; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; background: #fafafb; }
tr:last-child td { border-bottom: 0; }
.badge { display: inline-flex; padding: 2px 7px; border: 1px solid var(--line); border-radius: 99px; font-size: 11px; color: var(--muted); background: #fff; }
.badge-published { border-color: #b9d8c6; color: var(--success); background: #f2faf5; }
.badge-draft { color: var(--warning); background: #fffaf0; border-color: #ead7a9; }
.admin-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 22px; align-items: start; }
.stack { display: grid; gap: 18px; }
.module-admin { background: #fff; border: 1px solid var(--line); }
.module-admin-head { padding: 14px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr 90px 120px auto; gap: 9px; align-items: center; }
.module-admin-lessons { padding: 0 14px; }
.test-row { display: grid; grid-template-columns: 1.2fr 1fr .9fr .8fr 1.2fr 70px 85px 40px; gap: 7px; align-items: center; margin-bottom: 8px; }
.test-row input, .test-row select { min-width: 0; }

.pagination { display: flex; gap: 6px; margin-top: 18px; }
.pagination a, .pagination span { border: 1px solid var(--line); padding: 6px 9px; border-radius: 4px; font-size: 12px; background: #fff; }

@media (max-width: 980px) {
    .hero, .auth-shell, .lesson-layout, .admin-shell, .admin-grid, .lab-grid { grid-template-columns: 1fr; }
    .hero { gap: 32px; min-height: auto; }
    .hero-panel { border-left: 0; border-top: 1px solid var(--line); padding: 28px 0 0; }
    .auth-side { min-height: 240px; padding: 34px; }
    .auth-box { padding: 34px; }
    .lesson-sidebar { display: none; }
    .admin-nav { height: auto; position: static; }
    .admin-user { position: static; margin-top: 20px; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .stat { border-bottom: 1px solid var(--line); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
    .test-row { grid-template-columns: 1fr 1fr; border: 1px solid var(--line); padding: 10px; }
}

@media (max-width: 640px) {
    .site-header .inner, .page { width: min(100% - 24px, var(--max)); }
    .nav a:not(.keep-mobile) { display: none; }
    .grid-2, .grid-3, .form-row, .form-row-3, .stats { grid-template-columns: 1fr; }
    .page { padding-top: 26px; }
    .admin-page, .admin-top { padding-left: 18px; padding-right: 18px; }
    .module-admin-head { grid-template-columns: 1fr; }
}

/* PHP Lab v1.2 */
.lab-output {
    margin: 0;
    min-height: 338px;
    padding: 22px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    background: #111318;
    color: #f7f7f8;
    border: 0;
    border-bottom: 1px solid var(--line);
    font: 14px/1.65 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.solution-reveal { margin-top: 18px; }
.solution-reveal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.solution-reveal-head p { margin: 6px 0 0; }
.solution-reveal .lab-output { margin-top: 16px; white-space: pre-wrap; }
@media (max-width: 720px) {
  .solution-reveal-head { flex-direction: column; }
}


/* Lab configuration warnings v1.4 */
.warning-box {
    margin: 16px 0;
    padding: 13px 15px;
    border: 1px solid #ead7a9;
    border-radius: 6px;
    background: #fffaf0;
    color: #6f4d00;
    font-size: 13px;
}
.warning-box strong { color: #5d4100; }
.warning-box p { margin: 5px 0 0; }
.admin-lab-warning { margin: 0 0 16px; }
