.theory-page .main-content,
.project-layout .theory-breadcrumbs {
    width: min(100%, 1200px);
}

.theory-page .main-content { padding-block-start: 22px; }
.theory-reader {
    --theory-text-size: 1rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
}
.theory-reader[data-text-size="90"] { --theory-text-size: .9rem; }
.theory-reader[data-text-size="110"] { --theory-text-size: 1.1rem; }
.theory-reader[data-text-size="120"] { --theory-text-size: 1.2rem; }
.theory-reader:not(.theory-reader--indexed) { max-width: 860px; margin-inline: auto; }
.theory-heading { grid-column: 1 / -1; padding-block: 4px 8px; }
.theory-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 15px;
    color: var(--muted);
    font: .78rem/1.4 var(--mono);
}
.theory-type {
    padding: 4px 8px;
    background: var(--soft);
    border: 1px solid var(--line);
    border-radius: 3px;
    color: var(--green);
}
.theory-heading h1 {
    margin: 13px 0 0;
    font-size: 1.9rem;
    line-height: 1.12;
    letter-spacing: -.04em;
}

.theory-main { min-width: 0; }
.theory-paper,
.theory-outline-mobile,
.theory-outline-desktop {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 4px;
}
.theory-paper { border-top: 3px solid var(--green); }
.theory-tools {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 5px;
    padding: 5px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--field);
    color: var(--muted);
    font-size: .77rem;
}
.theory-tools[hidden] { display: none; }
.theory-tools > span { margin-inline-end: auto; }
.theory-tools output {
    min-width: 4ch;
    font: .78rem/1.4 var(--mono);
    text-align: center;
}
.theory-tools button,
.theory-copy {
    min-height: 36px;
    padding: 4px 8px;
    border: 1px solid var(--line);
    border-radius: 3px;
    background: var(--surface);
    color: var(--green);
    font: 600 .82rem/1.3 var(--sans);
}
.theory-tools button { min-width: 40px; }
.theory-tools button[aria-disabled="true"] { color: var(--muted); background: var(--bg); }
.theory-tools button:not([aria-disabled="true"]):hover, .theory-copy:hover {
    border-color: var(--green);
    background: var(--soft);
}

.theory-outline-desktop { display: none; }
.theory-outline-desktop > p,
.theory-outline-mobile summary {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 11px 14px;
    color: var(--ink);
    font-size: .84rem;
    font-weight: 700;
}
.theory-outline-desktop > p .bi,
.theory-outline-mobile summary > .bi:first-child { color: var(--green); }
.theory-outline-mobile summary,
.theory-premium-entry summary { cursor: pointer; list-style: none; }
.theory-chevron { margin-inline-start: auto; flex: none; font-size: .72em; }
details[open] > summary > .theory-chevron { transform: rotate(180deg); }
.theory-outline nav { padding: 6px 8px 10px; border-top: 1px solid var(--line); }
.theory-outline ul { margin: 0; padding: 0; list-style: none; }
.theory-outline a {
    display: block;
    padding: 8px 10px;
    border-inline-start: 2px solid transparent;
    color: var(--muted);
    font-size: .8rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
    text-decoration: none;
}
.theory-outline-depth-1 a { padding-inline-start: 18px; }
.theory-outline-depth-2 a { padding-inline-start: 26px; }
.theory-outline a:hover,
.theory-outline a[aria-current="location"] {
    border-color: var(--green);
    background: var(--soft);
    color: var(--green-dark);
}
.theory-outline-premium {
    margin-block-start: 6px;
    padding-block-start: 5px;
    border-top: 1px solid var(--line);
}
.theory-outline-premium:first-child { margin: 0; padding: 0; border: 0; }
.theory-outline-premium .bi { color: var(--practice-premium-ink); margin-inline-end: 3px; }

.theory-page .theory-body {
    max-width: 76ch;
    margin-inline: auto;
    padding: 26px 16px 30px;
    font-size: var(--theory-text-size);
    line-height: 1.72;
}
.theory-body > :first-child { margin-block-start: 0; }
.theory-body > :last-child { margin-block-end: 0; }
.theory-page .theory-body h2,
.theory-page .theory-body h3,
.theory-page .theory-body h4 {
    margin: 1.55em 0 .58em;
    color: var(--ink);
    font-weight: 700;
    line-height: 1.25;
}
.theory-page .theory-body > :is(h2, h3, h4):first-child { margin-block-start: 0; }
.theory-page .theory-body h2 { font-size: 1.45em; }
.theory-page .theory-body h3 { font-size: 1.23em; }
.theory-page .theory-body h4 { font-size: 1.08em; }
.theory-body :is(h2, h3, h4):target { color: var(--green); }
.theory-page .theory-body p { margin-block-end: .92em; }
.theory-body :is(ul, ol) { padding-inline-start: 1.45em; }
.theory-body li + li { margin-block-start: .32em; }
.theory-body figure { max-width: 100%; }
.theory-body img { object-fit: contain; }
.theory-body blockquote {
    margin-block: 1.15em;
    padding: 10px 16px;
    border-inline-start: 3px solid var(--green);
    background: var(--soft);
}
.theory-body blockquote > :last-child { margin-block-end: 0; }
.theory-page .theory-body :not(pre) > code {
    padding: .1em .23em;
    border-radius: 3px;
    color: var(--green-dark);
    font-size: .94em;
}
.theory-body pre {
    overflow: auto;
    margin-block: 0 1.15em;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-inline-start: 3px solid var(--green);
    border-radius: 3px;
    background: var(--soft);
    color: var(--ink);
    font: .95em/1.6 var(--mono);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.theory-page .theory-body pre code { background: transparent; color: inherit; }
.theory-code-tools {
    display: flex;
    justify-content: flex-end;
    padding: 4px 6px;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-inline-start: 3px solid var(--green);
    border-radius: 3px 3px 0 0;
    background: var(--field);
}
.theory-copy { min-height: 33px; }
.theory-copy .bi { margin-inline-end: 5px; }
.theory-code-tools + pre { border-start-start-radius: 0; border-start-end-radius: 0; }

.theory-table {
    max-width: 100%;
    margin-block: 1em 1.25em;
    overflow-x: auto;
}
.theory-table > table {
    --bs-table-color: var(--ink);
    --bs-table-striped-color: var(--ink);
    --bs-table-striped-bg: var(--field);
    --bs-table-bg: var(--surface);
    --bs-table-border-color: var(--line);
    width: 100%;
    min-width: 22em;
    margin: 0;
    color: var(--ink);
    font-size: .88em;
    line-height: 1.5;
    overflow-wrap: normal;
}
.theory-table :is(th, td) {
    padding: 9px 12px;
    border: 1px solid var(--line);
    text-align: start;
    vertical-align: top;
}
.theory-table thead th {
    background: var(--sidebar);
    color: var(--green-dark);
    font-weight: 700;
}
.theory-table td { overflow-wrap: break-word; }

.theory-premium {
    margin-block-start: 24px;
    padding: 18px 16px;
    border: 1px solid var(--practice-premium-line);
    border-radius: 4px;
    background: var(--surface);
}
.theory-premium-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 9px 13px;
    margin-block-end: 12px;
}
.theory-premium-heading h2 { margin: 0; font-size: 1.22rem; }
.theory-premium-entry { border-top: 1px solid var(--line); }
.theory-premium-entry summary {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    color: var(--ink);
    font-weight: 600;
}
.theory-premium-entry summary:hover { color: var(--green); }
.theory-premium-text {
    max-width: 72ch;
    padding-block-end: 12px;
    font-size: var(--theory-text-size);
    line-height: 1.68;
    overflow-wrap: anywhere;
}
.theory-premium-text p + p { margin-block-start: .75em; }
.theory-premium-list { margin: 0 0 14px; padding: 0; list-style: none; }
.theory-premium-list li { padding-block: 3px; color: var(--muted); font-size: .88rem; }
.theory-premium-list .bi { margin-inline-end: 5px; color: var(--practice-premium-ink); }
.theory-completion { margin-block-start: 20px; }
.theory-completion > span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 44px;
    color: var(--green);
    font-weight: 650;
}

.theory-navigation {
    display: grid;
    gap: 10px;
    margin-block-start: 24px;
}
.theory-reader:not(.theory-reader--indexed) ~ .theory-navigation {
    max-width: 860px;
    margin-inline: auto;
}
.theory-navigation a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--surface);
    color: var(--ink);
    line-height: 1.35;
    overflow-wrap: anywhere;
    text-decoration: none;
}
.theory-navigation a:hover { border-color: var(--green); background: var(--soft); }
.theory-navigation a:not([rel="prev"]) { justify-content: space-between; }
.theory-navigation strong { font-size: .88rem; }
.theory-navigation small { display: block; margin-bottom: 3px; color: var(--muted); font-size: .72rem; }
.theory-navigation .bi { color: var(--green); }
.theory-reader :focus-visible,
.theory-navigation :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.theory-table:focus-visible { outline-offset: -2px; }

@media (max-width: 639px) {
    .project-layout .theory-breadcrumbs { padding-inline: 18px; }
    .theory-breadcrumbs .breadcrumb-item.active { display: none; }
}
@media (min-width: 640px) {
    .theory-heading h1 { font-size: 2.35rem; }
    .theory-page .theory-body { padding: 36px 32px 38px; }
    .theory-tools { padding-inline: 22px; }
    .theory-premium { padding: 22px 24px; }
    .theory-navigation { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .theory-navigation a:not([rel="prev"]) { grid-column: 2; }
}
@media (min-width: 960px) {
    .theory-reader--indexed { grid-template-columns: minmax(0, 1fr) 266px; gap: 24px 28px; }
    .theory-reader--indexed .theory-heading { grid-column: 1; }
    .theory-reader--indexed .theory-main { grid-column: 1; grid-row: 2; }
    .theory-heading { padding-block: 8px 10px; }
    .theory-heading h1 { font-size: 2.6rem; }
    .theory-outline { grid-column: 2; grid-row: 2; position: sticky; top: 92px; align-self: start; }
    .theory-outline-desktop {
        display: block;
        max-height: calc(100dvh - 110px);
        overflow: auto;
    }
    .theory-outline-mobile { display: none; }
    .theory-reader--indexed ~ .theory-navigation { margin-inline-end: 294px; }
}
