:root {
    --bg: #f6f8fb;
    --surface: #fff;
    --surface-2: #f1f4f9;
    --text: #1f2937;
    --muted: #667085;
    --line: #e4e7ec;
    --accent: #2563eb;
    --accent-soft: #eaf1ff;
    --nav: #0f172a;
    --nav-text: #cbd5e1;
    --nav-muted: #7f8da3;
    --code: #101827;
    --shadow: 0 14px 40px rgba(15, 23, 42, .08);
    --radius: 18px;
    --body-font: "Google Sans Text", "Google Sans", "Noto Sans Thai", "Leelawadee UI", "Segoe UI", Tahoma, sans-serif;
    --heading-font: "Google Sans", "Google Sans Text", "Noto Sans Thai", "Leelawadee UI", "Segoe UI", Tahoma, sans-serif
}

[data-theme="dark"] {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #182235;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --line: #263348;
    --accent: #79a7ff;
    --accent-soft: #142446;
    --nav: #070c16;
    --nav-text: #d7dfeb;
    --nav-muted: #8493aa;
    --code: #050a13;
    --shadow: 0 14px 40px rgba(0, 0, 0, .26)
}

* {
    box-sizing: border-box
}

html {
    scroll-behavior: smooth
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--body-font);
    font-size: 17px;
    line-height: 1.78;
    letter-spacing: .005em
}

a {
    color: var(--accent);
    text-decoration: none
}

a:hover {
    text-decoration: underline
}

.top-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: var(--accent);
    width: 0;
    z-index: 1000;
    transition: width .25s ease
}

.layout {
    min-height: 100vh
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 310px;
    background: var(--nav);
    color: var(--nav-text);
    padding: 30px 20px 24px;
    overflow-y: auto;
    z-index: 30
}

.brand {
    padding: 0 10px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, .09);
    margin-bottom: 18px
}

.brand-kicker {
    font-size: 11px;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: #7ea7ff;
    font-weight: 700
}

.brand-title {
    font-family: var(--heading-font);
    font-size: 20px;
    line-height: 1.22;
    font-weight: 700;
    color: #fff;
    margin-top: 7px
}

.brand-sub {
    font-size: 13px;
    color: var(--nav-muted);
    margin-top: 7px
}

.brand-redirect {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 14px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, .14);
    background: rgba(255, 255, 255, .06);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: background .15s ease, border-color .15s ease
}

.brand-redirect:hover {
    background: var(--accent);
    border-color: var(--accent)
}

.search {
    width: 100%;
    border: 1px solid rgba(255, 255, 255, .12);
    background: rgba(255, 255, 255, .06);
    color: white;
    border-radius: 12px;
    padding: 11px 12px;
    font: inherit;
    font-size: 14px;
    outline: none;
    margin: 0 0 16px
}

.search::placeholder {
    color: #7f8da3
}

.nav-group {
    margin: 18px 0
}

.nav-group-title {
    font-size: 11px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--nav-muted);
    font-weight: 700;
    padding: 0 10px 5px
}

.nav-link {
    display: block;
    color: var(--nav-text);
    font-size: 13.5px;
    line-height: 1.4;
    padding: 9px 10px;
    border-radius: 9px;
    margin: 2px 0;
    transition: .18s
}

.nav-link:hover {
    background: rgba(255, 255, 255, .07);
    text-decoration: none;
    color: #fff
}

.nav-link.active {
    background: #1e3a6f;
    color: #fff
}

.sidebar-credit {
    font-size: 12px;
    color: var(--nav-muted);
    padding: 18px 10px 0;
    border-top: 1px solid rgba(255, 255, 255, .09);
    margin-top: 22px
}

.sidebar-credit strong {
    color: #d6dfec;
    display: block
}

.main {
    margin-left: 310px;
    min-height: 100vh
}

.toolbar {
    height: 66px;
    position: sticky;
    top: 0;
    z-index: 20;
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px
}

.toolbar-left {
    display: flex;
    gap: 11px;
    align-items: center;
    min-width: 0
}

.menu-btn {
    display: none
}

.toolbar-title {
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis
}

.tool-actions {
    display: flex;
    gap: 8px
}

.icon-btn {
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    border-radius: 10px;
    padding: 8px 11px;
    font: inherit;
    font-size: 13px;
    cursor: pointer
}

.icon-btn:hover {
    background: var(--surface-2)
}

.reader {
    max-width: 1040px;
    margin: 0 auto;
    padding: 52px 54px 90px
}

.book-page {
    display: none
}

.book-page.active {
    display: block;
    animation: fade .18s ease-out
}

@keyframes fade {
    from {
        opacity: .5;
        transform: translateY(4px)
    }

    to {
        opacity: 1;
        transform: none
    }
}

.hero {
    padding: 28px 0 8px
}

.eyebrow {
    font-size: 12px;
    letter-spacing: .18em;
    font-weight: 800;
    color: var(--accent);
    margin-bottom: 13px
}

.hero h1,
.lesson-header h1 {
    font-family: var(--heading-font);
    font-weight: 700;
    letter-spacing: -.025em;
    line-height: 1.15;
    margin: 0;
    color: var(--text)
}

.hero h1 {
    font-size: 48px
}

.hero-sub {
    font-size: 19px;
    color: var(--muted);
    margin: 18px 0 24px
}

.author-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    border-left: 3px solid var(--accent);
    padding: 4px 0 4px 16px;
    gap: 1px;
    font-size: 14px
}

.author-card span {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted)
}

.author-card strong {
    font-size: 18px
}

.author-card em {
    font-style: normal;
    color: var(--muted)
}

.hero-figure {
    margin: 34px 0 42px
}

.hero-figure img {
    width: 100%;
    border-radius: 16px;
    display: block;
    border: 1px solid var(--line);
    background: white
}

.hero-figure figcaption,
figure figcaption {
    text-align: center;
    font-size: 13px;
    color: var(--muted);
    margin-top: 10px
}

.content-block,
.lesson-body {
    max-width: 850px
}

.lesson-header {
    margin-bottom: 35px;
    padding-bottom: 27px;
    border-bottom: 1px solid var(--line)
}

.lesson-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px
}

.stage-chip {
    display: inline-flex;
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .035em;
    background: var(--accent-soft);
    color: var(--accent)
}

.lesson-number {
    font-size: 11px;
    letter-spacing: .14em;
    color: var(--muted);
    font-weight: 700
}

.lesson-header h1 {
    font-size: 41px
}

.lesson-lead {
    font-size: 18px;
    color: var(--muted);
    line-height: 1.65;
    margin: 15px 0 0;
    max-width: 760px
}

h2 {
    font-family: var(--heading-font);
    font-size: 27px;
    line-height: 1.3;
    margin: 48px 0 16px;
    letter-spacing: -.015em
}

h3 {
    font-size: 20px;
    margin: 34px 0 12px
}

p {
    margin: 0 0 18px
}

.lesson-body>p:first-child {
    margin-top: 0
}

.lesson-body ul,
.lesson-body ol {
    padding-left: 1.4em;
    margin: 16px 0 24px
}

.lesson-body li {
    padding-left: .25em;
    margin: 7px 0
}

.lesson-body strong {
    font-weight: 700
}

.tldr,
.callout {
    border: 1px solid #bed1ff;
    background: var(--accent-soft);
    border-radius: 15px;
    padding: 20px 22px;
    margin: 24px 0 30px
}

.callout {
    border-color: var(--line);
    background: var(--surface-2)
}

.callout-title {
    font-family: var(--heading-font);
    font-weight: 800;
    font-size: 14px;
    letter-spacing: .035em;
    color: var(--accent);
    margin-bottom: 7px
}

.callout p,
.tldr p {
    margin: 0
}

.code-block {
    background: var(--code);
    color: #e6edf7;
    border-radius: 14px;
    padding: 20px 22px;
    overflow: auto;
    font: 14px/1.62 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    margin: 22px 0 30px;
    white-space: pre-wrap;
    border: 1px solid rgba(148, 163, 184, .15)
}

code {
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    background: var(--surface-2);
    border-radius: 5px;
    padding: .08em .32em;
    font-size: .9em
}

.code-block code {
    background: transparent;
    padding: 0;
    font-size: inherit
}

.table-scroll {
    overflow-x: auto;
    margin: 24px 0 32px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface)
}

table.data-table {
    border-collapse: collapse;
    width: 100%;
    min-width: 620px;
    font-size: 14.5px;
    line-height: 1.55
}

table.data-table th {
    background: var(--surface-2);
    font-weight: 700;
    text-align: left;
    color: var(--text)
}

table.data-table th,
table.data-table td {
    padding: 13px 15px;
    border-bottom: 1px solid var(--line);
    vertical-align: top
}

table.data-table tr:last-child td {
    border-bottom: 0
}

.figure-img {
    width: 100%;
    display: block;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff
}

.lesson-body figure {
    margin: 32px 0 38px
}

.fig-media {
    position: relative
}

.zoom-btn {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 85%, transparent);
    color: var(--text);
    font-size: 17px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(3px);
    transition: background .15s, transform .15s
}

.zoom-btn:hover {
    background: var(--surface);
    transform: scale(1.06)
}

.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    padding: 48px 20px;
    background: rgba(10, 12, 18, .84);
    align-items: center;
    justify-content: center
}

.lightbox.open {
    display: flex
}

.lightbox-inner {
    max-width: min(1100px, 92vw);
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px
}

.lightbox-inner img {
    max-width: 100%;
    max-height: 78vh;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .45)
}

.lightbox-caption {
    color: #e5e7eb;
    font-size: 13px;
    text-align: center
}

.lightbox-close {
    position: absolute;
    top: 18px;
    right: 20px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, .3);
    background: rgba(255, 255, 255, .08);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, .2)
}

.source-note {
    margin-top: 38px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    font-size: 13px;
    color: var(--muted)
}

.stage-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 18px 0 30px
}

.stage-grid>div {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 15px 16px;
    display: flex;
    flex-direction: column;
    gap: 3px
}

.stage-grid b {
    font-family: var(--heading-font);
    font-size: 14px
}

.stage-grid span {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.45
}

.pager {
    max-width: 1040px;
    margin: 0 auto;
    padding: 0 54px 70px;
    display: flex;
    gap: 14px;
    justify-content: space-between
}

.page-btn {
    flex: 1;
    max-width: 440px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 16px 18px;
    color: var(--text);
    cursor: pointer;
    text-align: left
}

.page-btn.next {
    text-align: right;
    margin-left: auto
}

.page-btn small {
    display: block;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em
}

.page-btn strong {
    display: block;
    font-size: 14px;
    margin-top: 3px
}

.page-btn:hover {
    border-color: #a8b8d4;
    box-shadow: var(--shadow)
}

.mobile-overlay {
    display: none
}

.muted {
    color: var(--muted)
}

@media(max-width:940px) {
    .sidebar {
        transform: translateX(-102%);
        transition: transform .2s ease;
        width: min(84vw, 310px)
    }

    body.nav-open .sidebar {
        transform: none;
        box-shadow: 20px 0 60px rgba(0, 0, 0, .24)
    }

    body.nav-open .mobile-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(2, 6, 23, .45);
        z-index: 25
    }

    .main {
        margin-left: 0
    }

    .menu-btn {
        display: inline-flex
    }

    .reader {
        padding: 38px 24px 70px
    }

    .pager {
        padding: 0 24px 52px
    }

    .toolbar {
        padding: 0 18px
    }

    .hero h1 {
        font-size: 38px
    }

    .lesson-header h1 {
        font-size: 34px
    }
}

@media(max-width:620px) {
    body {
        font-size: 16px
    }

    .reader {
        padding: 30px 18px 58px
    }

    .pager {
        padding: 0 18px 42px;
        flex-direction: column
    }

    .page-btn {
        max-width: none
    }

    .page-btn.next {
        text-align: left
    }

    .hero h1 {
        font-size: 32px
    }

    .lesson-header h1 {
        font-size: 31px
    }

    .hero-sub {
        font-size: 17px
    }

    .stage-grid {
        grid-template-columns: 1fr
    }

    .lesson-meta {
        align-items: flex-start;
        flex-direction: column
    }

    .table-scroll {
        margin-left: -4px;
        margin-right: -4px
    }

    .toolbar-title {
        max-width: 48vw
    }

    .tldr,
    .callout {
        padding: 17px 18px
    }

    .tool-actions .print-btn {
        display: none
    }
}

@media print {

    .sidebar,
    .toolbar,
    .pager,
    .top-progress,
    .mobile-overlay {
        display: none !important
    }

    .main {
        margin: 0
    }

    .reader {
        max-width: none;
        padding: 0
    }

    .book-page {
        display: block !important;
        page-break-after: always;
        padding: 12mm 14mm
    }

    .book-page:last-child {
        page-break-after: auto
    }

    body {
        background: white;
        color: #111;
        font-size: 11pt
    }

    .hero h1 {
        font-size: 29pt
    }

    .lesson-header h1 {
        font-size: 25pt
    }

    .source-note {
        break-inside: avoid
    }

    .tldr,
    .callout,
    .table-scroll,
    figure,
    pre {
        break-inside: avoid
    }
}