/**
 * Cornell Notes AI v3.0.0 — "Study Sheet Loop" app stylesheet.
 * Dispatch dark theme, fullbleed scaffold, responsive to 360px,
 * light print sheet at the bottom. Self-contained: all tokens live
 * on .cn3-app; theme-killing rules key off body.cornell-fullbleed.
 */

/* ============ HIDDEN CONTRACT ============ */
/* The JS drives ALL view/state visibility via the `hidden` property
   (showStage, practice bar, grade strips, session donut, no-match row,
   edit-only buttons). Author `display:` rules override the UA's
   non-important [hidden] rule, so this scoped override is load-bearing:
   without it every JS-hidden element that also has a display rule
   (flex/grid/inline-flex) stays visible. Covers the app root, every
   descendant, and template clones inserted into it. */
#cn3-app [hidden],
#cn3-app[hidden] {
    display: none !important;
}

/* ============ TOKENS ============ */
.cn3-app {
    --bg-0: #0a0e14;
    --bg-1: #0d1117;
    --bg-2: #151a23;
    --border: #232a36;
    --red: #cc342d;
    --red-hi: #e5484d;
    --text: #e6edf3;
    --muted: #8b96a5;
    --green: #27c93f;
}

/* ============ FULLBLEED SCAFFOLD (theme killers) ============ */
body.cornell-fullbleed {
    background: #0a0e14;
}
body.cornell-fullbleed .site-content {
    max-width: none;
    padding: 0;
}
body.cornell-fullbleed .site-content .container,
body.cornell-fullbleed .entry-content {
    max-width: none;
    padding: 0;
    margin: 0;
}
body.cornell-fullbleed .entry-header,
body.cornell-fullbleed .site-breadcrumbs,
body.cornell-fullbleed .breadcrumbs,
body.cornell-fullbleed #secondary,
body.cornell-fullbleed .widget-area,
body.cornell-fullbleed .sidebar-right,
body.cornell-fullbleed .right-sidebar {
    display: none;
}

/* ============ ROOT GRID ============ */
#cn3-app {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    grid-template-rows: 56px 1fr;
    grid-template-areas:
        "topbar topbar"
        "library stage";
    height: 100dvh;
    background: var(--bg-0);
    color: var(--text);
    font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.5;
    box-sizing: border-box;
    position: relative;
    text-align: left;
}
#cn3-app *,
#cn3-app *::before,
#cn3-app *::after {
    box-sizing: border-box;
}
#cn3-app.cn3-lib-hidden {
    grid-template-columns: 0 1fr;
}
#cn3-app.cn3-lib-hidden #cn3-library {
    overflow: hidden;
    border-right: none;
}

/* ============ SHARED PRIMITIVES ============ */
.cn3-kicker {
    font-family: Consolas, "SF Mono", Menlo, monospace;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .14em;
    color: var(--red);
}
.cn3-kbd {
    display: inline-block;
    font-family: Consolas, "SF Mono", Menlo, monospace;
    font-size: 11px;
    line-height: 1;
    padding: 3px 5px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--muted);
}
.cn3-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    padding: 0 14px;
    font: 600 13px/1 Inter, system-ui, sans-serif;
    color: var(--text);
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color .15s, background .15s, color .15s;
}
.cn3-btn-primary {
    background: var(--red);
    border-color: var(--red);
    color: #fff;
}
.cn3-btn-primary:hover {
    background: var(--red-hi);
    border-color: var(--red-hi);
}
.cn3-btn-ghost {
    background: transparent;
}
.cn3-btn-ghost:hover {
    border-color: var(--red);
}
.cn3-btn-ghost[aria-pressed="true"] {
    border-color: var(--red);
    color: var(--red-hi);
    background: rgba(204, 52, 45, .08);
}
.cn3-btn-lg {
    height: 52px;
    padding: 0 22px;
    font-size: 15px;
    border-radius: 10px;
}
.cn3-btn-wide {
    width: 100%;
    justify-content: center;
    border-style: dashed;
    color: var(--muted);
}
.cn3-btn-wide:hover {
    color: var(--text);
}
.cn3-btn:disabled {
    opacity: .6;
    cursor: default;
}
.cn3-btn .cn3-kbd {
    padding: 2px 4px;
    background: rgba(0, 0, 0, .25);
    border-color: rgba(255, 255, 255, .18);
    color: inherit;
    opacity: .8;
}
/* Busy state: CSS border-spinner; label span is never innerHTML-swapped. */
.cn3-spinner {
    display: none;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, .35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: cn3-spin .7s linear infinite;
}
.cn3-btn.is-busy .cn3-spinner {
    display: inline-block;
}
@keyframes cn3-spin {
    to { transform: rotate(360deg); }
}
.cn3-iconbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    font-size: 13px;
    line-height: 1;
    color: var(--muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
}
.cn3-iconbtn:hover {
    color: var(--text);
    border-color: var(--border);
    background: var(--bg-2);
}
.cn3-linkbtn {
    background: none;
    border: none;
    padding: 0;
    font: 500 12px/1 Consolas, monospace;
    color: var(--muted);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}
.cn3-linkbtn:hover {
    color: var(--red-hi);
}
.cn3-badge {
    font-family: Consolas, monospace;
    font-size: 11px;
    color: var(--muted);
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 8px;
}
#cn3-app :focus-visible {
    outline: 2px solid var(--red-hi);
    outline-offset: 2px;
}
.cn3-donut {
    display: inline-block;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: conic-gradient(var(--red-hi) calc(var(--pct, 0) * 1%), var(--bg-2) 0);
    position: relative;
    flex: none;
}
.cn3-donut::after {
    content: "";
    position: absolute;
    inset: 5px;
    border-radius: 50%;
    background: var(--bg-1);
}

/* ============ REGION 1: TOP BAR ============ */
#cn3-topbar {
    grid-area: topbar;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 16px;
    background: var(--bg-1);
    border-bottom: 1px solid var(--border);
    min-width: 0;
    z-index: 61;
}
.cn3-brand {
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.25;
    flex: none;
}
.cn3-wordmark {
    font-size: 15px;
    font-weight: 600;
}
#cn3-capture {
    flex: 1;
    max-width: 560px;
    display: flex;
    gap: 8px;
    margin: 0;
    min-width: 0;
}
.cn3-capture-field {
    position: relative;
    flex: 1;
    min-width: 0;
}
#cn3-topic {
    width: 100%;
    height: 36px;
    padding: 0 34px 0 12px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font: 400 14px/1 Inter, system-ui, sans-serif;
}
#cn3-topic::placeholder,
#cn3-topic-hero::placeholder {
    color: var(--muted);
}
#cn3-topic:focus,
#cn3-topic-hero:focus,
#cn3-search:focus {
    outline: none;
    border-color: var(--red-hi);
    box-shadow: 0 0 0 3px rgba(229, 72, 77, .18);
}
.cn3-capture-field .cn3-kbd {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}
.cn3-capture-field:focus-within .cn3-kbd {
    display: none;
}
.cn3-session {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: none;
}
.cn3-session-caption {
    font-family: Consolas, monospace;
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
}
#cn3-lib-toggle {
    display: none;
    flex: none;
}
.cn3-nav {
    display: flex;
    gap: 8px;
    flex: none;
}
.cn3-session[hidden] + #cn3-lib-toggle,
.cn3-session[hidden] ~ .cn3-nav {
    margin-left: auto;
}
.cn3-session:not([hidden]) ~ .cn3-nav {
    margin-left: 0;
}
.cn3-nav-chip {
    display: inline-block;
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-family: Consolas, monospace;
    font-size: 11px;
    color: var(--muted);
    text-decoration: none;
    transition: border-color .15s, color .15s;
}
.cn3-nav-chip:hover {
    border-color: var(--red);
    color: var(--text);
}

/* ============ REGION 2: LIBRARY ============ */
#cn3-library {
    grid-area: library;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg-1);
    border-right: 1px solid var(--border);
    transition: width .22s;
}
.cn3-lib-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 12px 10px;
}
.cn3-lib-head .cn3-kicker {
    flex: 1;
}
#cn3-refresh.is-busy {
    animation: cn3-spin .8s linear infinite;
}
.cn3-lib-search {
    padding: 0 12px 10px;
}
#cn3-search {
    width: 100%;
    height: 32px;
    padding: 0 10px;
    background: var(--bg-0);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font: 400 13px/1 Inter, system-ui, sans-serif;
}
#cn3-search::placeholder {
    font-family: Consolas, monospace;
    font-size: 12px;
    color: var(--muted);
}
#cn3-list {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    margin: 0;
    padding: 8px;
    list-style: none;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    min-height: 0;
}
#cn3-list::-webkit-scrollbar {
    width: 8px;
}
#cn3-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}
.cn3-item {
    position: relative;
    border-radius: 8px;
    margin: 0 0 2px;
    max-height: 200px;
    transition: max-height .2s, opacity .2s, background .15s;
    overflow: hidden;
}
.cn3-item:hover,
.cn3-item:focus-within {
    background: var(--bg-2);
}
.cn3-item.is-active {
    background: var(--bg-2);
    box-shadow: inset 3px 0 0 var(--red);
}
.cn3-item.is-collapsing {
    max-height: 0;
    opacity: 0;
}
.cn3-item.is-wash {
    animation: cn3-wash 1.2s ease-out;
}
@keyframes cn3-wash {
    0% { background: rgba(204, 52, 45, .18); }
    100% { background: transparent; }
}
.cn3-item.is-loading-row {
    background: linear-gradient(110deg, transparent 40%, rgba(229, 72, 77, .08) 50%, transparent 60%);
    background-size: 200% 100%;
    animation: cn3-shimmer 1.2s infinite;
}
/* Stretched-link row: the open button covers the whole row. */
.cn3-item-open {
    display: block;
    width: 100%;
    padding: 10px 30px 10px 12px;
    background: none;
    border: none;
    text-align: left;
    color: inherit;
    cursor: pointer;
    font: inherit;
    position: static;
}
.cn3-item-open::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
}
.cn3-item-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.35;
    overflow-wrap: break-word;
}
.cn3-item-date {
    display: block;
    margin-top: 2px;
    font-family: Consolas, monospace;
    font-size: 11px;
    color: var(--muted);
}
.cn3-item-preview {
    margin: 4px 0 0;
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cn3-meter {
    height: 3px;
    margin: 0 12px 10px;
    background: var(--bg-2);
    border-radius: 2px;
    overflow: hidden;
}
.cn3-item.is-active .cn3-meter,
.cn3-item:hover .cn3-meter {
    background: var(--bg-0);
}
.cn3-meter-fill {
    display: block;
    height: 100%;
    width: var(--pct, 0%);
    background: linear-gradient(90deg, var(--red), var(--red-hi));
}
.cn3-item-delete {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    width: 22px;
    height: 22px;
    padding: 0;
    font-size: 11px;
    line-height: 1;
    color: var(--muted);
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s, color .15s, border-color .15s;
}
.cn3-item:hover .cn3-item-delete,
.cn3-item:focus-within .cn3-item-delete {
    opacity: 1;
}
.cn3-item-delete:hover {
    color: var(--red-hi);
    border-color: var(--red);
}
.cn3-nomatch {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    font-family: Consolas, monospace;
    font-size: 12px;
    color: var(--muted);
}
.cn3-lib-empty {
    padding: 28px 20px;
    text-align: center;
}
.cn3-lib-empty-card {
    width: 64px;
    height: 80px;
    margin: 0 auto 14px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    background:
        linear-gradient(var(--bg-2), var(--bg-2)) 12px 12px / 40px 5px no-repeat,
        linear-gradient(var(--bg-2), var(--bg-2)) 12px 24px / 28px 4px no-repeat,
        linear-gradient(var(--bg-2), var(--bg-2)) 12px 34px / 34px 4px no-repeat;
}
.cn3-lib-empty-title {
    margin: 0 0 4px;
    font-size: 14px;
    font-weight: 600;
}
.cn3-lib-empty-sub {
    margin: 0;
    font-size: 12px;
    color: var(--muted);
}
.cn3-drawer-nav {
    display: none;
    gap: 8px;
    flex-wrap: wrap;
    padding: 12px;
    border-top: 1px solid var(--border);
}
#cn3-scrim {
    position: fixed;
    inset: 0;
    background: rgba(4, 6, 10, .6);
    z-index: 59;
}
/* The scrim belongs to the <1024px off-canvas drawer only. If it was
   shown below the breakpoint and the viewport grows past it (resize /
   rotate), the fixed full-screen layer must never keep intercepting
   clicks on the desktop layout. The JS also resets drawer state on the
   matchMedia change; this is the CSS backstop. */
@media (min-width: 1024px) {
    #cn3-scrim {
        display: none !important;
    }
}

/* ============ REGION 3: STAGE ============ */
#cn3-stage {
    grid-area: stage;
    overflow-y: auto;
    scroll-behavior: smooth;
    padding: 24px clamp(16px, 4vw, 48px);
    min-width: 0;
    min-height: 0;
}

/* ── The document sheet ── */
.cn3-doc {
    max-width: 880px;
    margin: 0 auto;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-top: 3px solid var(--red);
    border-radius: 14px;
    padding: 40px clamp(20px, 4vw, 44px) 72px;
}
.cn3-doc-head {
    margin-bottom: 18px;
}
#cn3-doc-title {
    margin: 6px 0 4px;
    font-size: clamp(26px, 3.5vw, 36px);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.15;
    color: var(--text);
    cursor: text;
}
#cn3-doc-title .cn3-title-edit {
    width: 100%;
    background: var(--bg-2);
    border: 1px dashed var(--red);
    border-radius: 8px;
    padding: 4px 10px;
    color: var(--text);
    font: inherit;
    letter-spacing: inherit;
}
.cn3-doc-meta {
    font-family: Consolas, monospace;
    font-size: 13px;
    color: var(--muted);
}

/* ── Sticky toolbar ── */
#cn3-toolbar {
    position: sticky;
    top: -24px; /* stage padding offset: sits flush at scroll top */
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 8px 0;
    margin-bottom: 4px;
    background: color-mix(in srgb, var(--bg-1) 85%, transparent);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
    #cn3-toolbar { background: rgba(13, 17, 23, .92); }
    #cn3-practice-bar { background: rgba(10, 14, 20, .9); }
}
.cn3-dirty-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: Consolas, monospace;
    font-size: 11px;
    color: var(--red-hi);
}
.cn3-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--red-hi);
}
#cn3-status {
    margin-left: auto;
    font-family: Consolas, monospace;
    font-size: 12px;
    color: var(--muted);
}
#cn3-status.is-saved {
    color: var(--green);
}
#cn3-status.is-dirty {
    color: var(--red-hi);
}
.cn3-export {
    position: relative;
}
.cn3-export summary {
    list-style: none;
}
.cn3-export summary::-webkit-details-marker {
    display: none;
}
.cn3-export menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 20;
    margin: 0;
    padding: 6px;
    list-style: none;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
    min-width: 160px;
}
.cn3-menu-btn {
    display: block;
    width: 100%;
    padding: 8px 10px;
    background: none;
    border: none;
    border-radius: 6px;
    color: var(--text);
    font: 500 13px/1 Inter, system-ui, sans-serif;
    text-align: left;
    cursor: pointer;
}
.cn3-menu-btn:hover {
    background: rgba(204, 52, 45, .12);
}

/* ── Practice bar ── */
#cn3-practice-bar {
    position: sticky;
    top: 29px; /* under the toolbar */
    z-index: 4;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    background: color-mix(in srgb, var(--bg-0) 80%, transparent);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}
.cn3-progress {
    flex: 1;
    height: 2px;
    background: var(--bg-2);
    border-radius: 1px;
    overflow: hidden;
}
#cn3-pb-fill {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--red), var(--red-hi));
    transition: width .25s;
}
.cn3-pb-counter,
.cn3-pb-hint {
    font-family: Consolas, monospace;
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
}
.cn3-pb-hint-touch {
    display: none;
}

/* ── The Cornell grid ── */
#cn3-grid {
    display: grid;
    grid-template-columns: minmax(200px, 30%) minmax(0, 1fr);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    margin: 20px 0 28px;
}
.cn3-ghead {
    position: sticky;
    top: 29px;
    z-index: 3;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
}
.cn3-ghead .cn3-kicker {
    color: var(--muted);
}
.cn3-ghead:first-child {
    border-right: 1px solid var(--border);
}
.cn3-cue {
    position: relative;
    border-right: 1px solid var(--border);
    border-top: 1px solid var(--border);
    padding: 14px 16px 14px 40px;
    font-size: 14px;
    font-weight: 600;
    scroll-margin-top: 120px;
}
.cn3-cue-num {
    position: absolute;
    left: 14px;
    top: 17px;
    font-family: Consolas, monospace;
    font-size: 11px;
    color: var(--red);
    opacity: .7;
}
.cn3-note-cell {
    position: relative;
    border-top: 1px solid var(--border);
    padding: 14px 18px;
    scroll-margin-top: 120px;
}
.cn3-note-body {
    font-size: 17px;
    line-height: 1.75;
    max-width: 68ch;
    overflow-wrap: break-word;
}
.cn3-note-body > :first-child { margin-top: 0; }
.cn3-note-body > :last-child { margin-bottom: 0; }
.cn3-note-body pre {
    overflow-x: auto;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
}
.cn3-note-body code {
    font-family: Consolas, "SF Mono", Menlo, monospace;
    font-size: .88em;
}
.cn3-note-body a {
    color: var(--red-hi);
}
.cn3-cue:hover,
.cn3-cue:focus-within,
.cn3-note-cell:hover,
.cn3-note-cell:focus-within {
    background: linear-gradient(90deg, transparent, rgba(204, 52, 45, .04));
}
.cn3-cell-tools {
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity .15s;
    z-index: 2;
}
.cn3-cue:hover .cn3-cell-tools,
.cn3-cue:focus-within .cn3-cell-tools,
.cn3-note-cell:hover .cn3-cell-tools,
.cn3-note-cell:focus-within .cn3-cell-tools,
.cn3-summary-head:hover .cn3-cell-edit,
.cn3-code-head:hover .cn3-cell-tools,
.cn3-math-head:hover .cn3-cell-tools {
    opacity: 1;
}
.cn3-summary-head .cn3-cell-edit,
.cn3-code-head .cn3-cell-tools,
.cn3-math-head .cn3-cell-tools {
    opacity: 0;
    transition: opacity .15s;
}
.cn3-addrow {
    grid-column: 1 / -1;
    border-top: 1px solid var(--border);
    padding: 8px;
}

/* Editors */
.cn3-editor {
    width: 100%;
    background: var(--bg-0);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font: 400 14px/1.5 Inter, system-ui, sans-serif;
    padding: 8px 10px;
}
textarea.cn3-editor {
    min-height: 96px;
    resize: vertical;
    font-family: Consolas, "SF Mono", Menlo, monospace;
    font-size: 13px;
    line-height: 1.6;
}
.cn3-editor:focus {
    outline: 1px dashed var(--red);
    outline-offset: 2px;
    border-color: var(--red);
}
#cn3-app.cn3-editing .cn3-cell-tools .cn3-cell-edit {
    display: none;
}

/* ── Summary band ── */
.cn3-summary {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--red);
    border-radius: 10px;
    padding: 24px 28px;
    margin-bottom: 28px;
}
.cn3-summary-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
#cn3-summary-body {
    font-size: 16px;
    line-height: 1.7;
    max-width: 72ch;
}
#cn3-summary-body > :first-child { margin-top: 0; }
#cn3-summary-body > :last-child { margin-bottom: 0; }

/* ── Code examples ── */
.cn3-sec-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0 0 12px;
}
#cn3-code,
#cn3-math {
    margin-bottom: 28px;
}
.cn3-code {
    margin: 0 0 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-2);
}
.cn3-code-head,
.cn3-math-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}
.cn3-code-title {
    font-family: Consolas, monospace;
    font-size: 13px;
    color: var(--text);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cn3-code-tools {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: none;
}
.cn3-copy.is-copied {
    color: var(--green);
    text-decoration: none;
}
.cn3-code-pre {
    margin: 0;
    padding: 14px;
    overflow-x: auto;
    background: var(--bg-2);
    font-family: Consolas, "SF Mono", Menlo, monospace;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text);
    tab-size: 4;
}
.cn3-code-pre code {
    font-family: inherit;
    background: none;
    color: inherit;
}
.cn3-code-editors {
    padding: 12px;
    display: grid;
    gap: 8px;
}
/* Prism token colors overridden to Dispatch */
#cn3-app .token.string,
#cn3-app .token.char,
#cn3-app .token.attr-value {
    color: var(--green);
}
#cn3-app .token.keyword,
#cn3-app .token.boolean,
#cn3-app .token.important,
#cn3-app .token.tag {
    color: var(--red-hi);
}
#cn3-app .token.comment,
#cn3-app .token.prolog,
#cn3-app .token.doctype,
#cn3-app .token.cdata {
    color: var(--muted);
}
#cn3-app .token.function,
#cn3-app .token.class-name {
    color: #e6b450;
}
#cn3-app .token.number,
#cn3-app .token.operator,
#cn3-app .token.punctuation {
    color: var(--text);
}
#cn3-app pre[class*="language-"],
#cn3-app code[class*="language-"] {
    background: var(--bg-2);
    color: var(--text);
    text-shadow: none;
}

/* ── Math examples ── */
.cn3-math {
    margin: 0 0 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-2);
    padding: 0 0 12px;
}
.cn3-math-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}
.cn3-mblock {
    padding: 12px 16px 0;
}
.cn3-mlabel {
    display: block;
    font-family: Consolas, monospace;
    font-size: 10px;
    letter-spacing: .12em;
    color: var(--muted);
    margin-bottom: 4px;
}
.cn3-mbody {
    font-size: 15px;
    line-height: 1.7;
    overflow-x: auto;
}
.cn3-reveal > summary {
    cursor: pointer;
    padding: 10px 16px 0;
    font-family: Consolas, monospace;
    font-size: 12px;
    color: var(--red-hi);
    list-style: none;
}
.cn3-reveal > summary::-webkit-details-marker {
    display: none;
}
.cn3-reveal > summary::before {
    content: "\25B8 ";
}
.cn3-reveal[open] > summary::before {
    content: "\25BE ";
}
.cn3-doc-foot {
    margin: 0;
    font-family: Consolas, monospace;
    font-size: 11px;
    color: var(--muted);
}

/* ── Grade strip ── */
.cn3-grade {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    animation: cn3-fadein .2s ease-out;
}
@keyframes cn3-fadein {
    from { opacity: 0; }
    to { opacity: 1; }
}
.cn3-grade-again:hover {
    border-color: var(--red-hi);
    color: var(--red-hi);
}
.cn3-grade-got:hover {
    border-color: var(--green);
    color: var(--green);
}

/* ============ PRACTICE MODE ============ */
#cn3-app.cn3-practice .cn3-note-cell .cn3-note-body,
#cn3-app.cn3-practice #cn3-summary-body {
    filter: blur(7px) saturate(.6);
    user-select: none;
    -webkit-user-select: none;
    cursor: pointer;
    transition: filter .25s;
}
#cn3-app.cn3-practice .cn3-note-cell.cn3-revealed .cn3-note-body {
    filter: none;
    user-select: text;
    -webkit-user-select: text;
    cursor: auto;
}
#cn3-app.cn3-practice #cn3-code,
#cn3-app.cn3-practice #cn3-math {
    opacity: .3;
    pointer-events: none;
}
#cn3-app.cn3-practice .cn3-cue.is-active {
    background: rgba(204, 52, 45, .06);
    box-shadow: inset 3px 0 0 var(--red-hi);
}
#cn3-app.cn3-practice .cn3-cell-tools {
    display: none;
}

/* ============ SESSION SUMMARY VIEW ============ */
.cn3-sum-doc {
    text-align: center;
    padding-bottom: 48px;
}
.cn3-sum-ring-wrap {
    margin: 24px 0;
}
.cn3-donut-big {
    width: 120px;
    height: 120px;
    animation: cn3-sweep .8s ease-out;
}
.cn3-donut-big::after {
    inset: 14px;
}
@keyframes cn3-sweep {
    from { opacity: 0; transform: scale(.9); }
    to { opacity: 1; transform: scale(1); }
}
.cn3-sum-caption {
    margin: 14px 0 0;
    font-size: clamp(20px, 3vw, 28px);
    font-weight: 600;
}
.cn3-sum-missed-label {
    font-family: Consolas, monospace;
    font-size: 12px;
    color: var(--muted);
    margin: 20px 0 8px;
}
#cn3-sum-missed {
    list-style: none;
    margin: 0 auto 8px;
    padding: 0;
    max-width: 480px;
    text-align: left;
}
#cn3-sum-missed li {
    padding: 8px 12px;
    margin-bottom: 6px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--red-hi);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
}
.cn3-sum-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 24px;
}

/* ============ EMPTY STATE ============ */
#cn3-empty {
    max-width: 640px;
    margin: auto;
    min-height: 100%;
    display: grid;
    place-content: center;
    text-align: center;
}
#cn3-empty-body {
    display: grid;
    gap: 24px;
    justify-items: center;
    margin-top: 12px;
}
#cn3-empty-h2 {
    margin: 0;
    font-size: clamp(26px, 3.5vw, 36px);
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
}
.cn3-empty-lede {
    margin: 0;
    color: var(--muted);
    font-size: 15px;
    max-width: 46ch;
}
.cn3-hero-group {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 560px;
}
#cn3-topic-hero {
    flex: 1;
    min-width: 0;
    height: 52px;
    padding: 0 16px;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font: 400 17px/1 Inter, system-ui, sans-serif;
}
.cn3-alert {
    width: 100%;
    max-width: 560px;
    text-align: left;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-left: 3px solid var(--red-hi);
    border-radius: 8px;
    background: rgba(229, 72, 77, .08);
    color: var(--text);
    font-size: 14px;
}
.cn3-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}
.cn3-chip {
    padding: 6px 14px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    font-family: Consolas, monospace;
    font-size: 12px;
    cursor: pointer;
    transition: border-color .15s;
}
.cn3-chip:hover {
    border-color: var(--red);
}
.cn3-empty-foot {
    margin: 0;
    font-family: Consolas, monospace;
    font-size: 12px;
    color: var(--muted);
}

/* Ghost sheet */
.cn3-ghost {
    width: 100%;
    max-width: 480px;
    opacity: .8;
}
.cn3-ghost-callouts {
    display: flex;
    justify-content: space-between;
    padding: 0 12px 6px;
    font-family: Consolas, monospace;
    font-size: 11px;
    color: var(--muted);
}
.cn3-ghost-callouts-bottom {
    justify-content: flex-start;
    padding: 6px 12px 0;
}
.cn3-ghost-sheet {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-top: 2px solid var(--red);
    border-radius: 10px;
    padding: 16px;
}
.cn3-ghost-title {
    height: 12px;
    width: 45%;
    background: var(--bg-2);
    border-radius: 4px;
    margin-bottom: 12px;
    opacity: .8;
}
.cn3-ghost-grid {
    display: grid;
    grid-template-columns: 30% 1fr;
    border-left: 1px solid transparent;
}
.cn3-ghost-cue,
.cn3-ghost-note {
    height: 10px;
    margin: 7px 10px 7px 0;
    background: var(--bg-2);
    border-radius: 4px;
    opacity: .7;
}
.cn3-ghost-cue {
    border-right: 1px solid var(--border);
    background: linear-gradient(var(--bg-2), var(--bg-2)) 0 50% / 70% 10px no-repeat;
    height: 24px;
    margin: 0;
    padding: 0;
    border-radius: 0;
}
.cn3-ghost-note {
    height: 10px;
    margin: 7px 0 7px 12px;
}
.cn3-ghost-blur {
    filter: blur(4px);
    transition: filter .25s;
    cursor: pointer;
    background: var(--red);
    opacity: .35;
}
.cn3-ghost-blur:hover,
.cn3-ghost-blur:active {
    filter: none;
}
.cn3-ghost-summary {
    height: 12px;
    margin-top: 12px;
    background: var(--bg-2);
    border-left: 2px solid var(--red);
    border-radius: 4px;
    opacity: .7;
}
.cn3-shake {
    animation: cn3-shake .3s;
}
@keyframes cn3-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* ── Resume cards (variant B) ── */
#cn3-resume {
    width: 100%;
}
#cn3-resume-cards {
    display: grid;
    gap: 10px;
    width: 100%;
    text-align: left;
}
.cn3-resume-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
}
.cn3-resume-main {
    flex: 1;
    min-width: 0;
}
.cn3-resume-title {
    margin: 0 0 6px;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.cn3-resume-meta {
    font-family: Consolas, monospace;
    font-size: 11px;
    color: var(--muted);
}
.cn3-resume-card .cn3-meter {
    margin: 8px 0 0;
    height: 3px;
}
.cn3-resume-actions {
    display: flex;
    gap: 8px;
    flex: none;
}
.cn3-or-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 22px 0;
    font-family: Consolas, monospace;
    font-size: 11px;
    color: var(--muted);
    letter-spacing: .12em;
}
.cn3-or-divider::before,
.cn3-or-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ============ LOADING SKELETON ============ */
#cn3-loading .cn3-skel-doc {
    padding-bottom: 48px;
}
.cn3-skel {
    background: linear-gradient(110deg, var(--bg-2) 40%, #1b2230 50%, var(--bg-2) 60%);
    background-size: 200% 100%;
    animation: cn3-shimmer 1.4s infinite;
    border-radius: 6px;
}
@keyframes cn3-shimmer {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
}
.cn3-skel-title {
    height: 28px;
    width: 55%;
    margin-bottom: 28px;
}
.cn3-skel-grid {
    display: grid;
    grid-template-columns: 30% 1fr;
    gap: 18px 0;
    border-left: 1px solid var(--border);
    border-radius: 0;
    padding-left: 0;
    margin-bottom: 28px;
}
.cn3-skel-cue {
    height: 14px;
    width: 70%;
    border-right: 0;
    position: relative;
}
.cn3-skel-grid .cn3-skel-cue {
    margin-right: 24px;
}
.cn3-skel-grid {
    border-left: none;
    position: relative;
}
.cn3-skel-grid::before {
    content: "";
    position: absolute;
    left: 30%;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--border);
}
.cn3-skel-note {
    height: 14px;
    width: 90%;
    margin-left: 20px;
}
.cn3-skel-summary {
    height: 64px;
    width: 100%;
    border-left: 3px solid var(--red);
}

/* ============ TOAST ============ */
#cn3-toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%) translateY(8px);
    z-index: 100;
    max-width: min(480px, calc(100vw - 32px));
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--green);
    border-radius: 8px;
    padding: 12px 16px;
    color: var(--text);
    font-size: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
    opacity: 0;
    transition: opacity .2s, transform .2s;
}
#cn3-toast.is-err {
    border-left-color: var(--red-hi);
}
#cn3-toast.is-show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============ DIALOGS ============ */
#cn3-keys,
#cn3-confirm {
    background: var(--bg-1);
    color: var(--text);
    border: 1px solid var(--border);
    border-top: 3px solid var(--red);
    border-radius: 12px;
    padding: 24px;
    max-width: min(440px, calc(100vw - 32px));
    font-family: Inter, system-ui, sans-serif;
}
#cn3-keys::backdrop,
#cn3-confirm::backdrop {
    background: rgba(4, 6, 10, .65);
}
.cn3-keys-list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px 16px;
    margin: 16px 0 20px;
    font-size: 13px;
}
.cn3-keys-list dt {
    white-space: nowrap;
}
.cn3-keys-list dd {
    margin: 0;
    color: var(--muted);
}
#cn3-confirm-msg {
    margin: 0 0 20px;
    font-size: 15px;
    line-height: 1.55;
}
.cn3-confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 1023px) {
    #cn3-app {
        grid-template-columns: 1fr;
        grid-template-areas:
            "topbar"
            "stage";
    }
    #cn3-library {
        position: fixed;
        inset: 56px auto 0 0;
        width: min(320px, 86vw);
        transform: translateX(-100%);
        transition: transform .22s;
        z-index: 60;
        border-right: 1px solid var(--border);
    }
    #cn3-library.is-open {
        transform: translateX(0);
    }
    #cn3-lib-toggle {
        display: inline-flex;
    }
}
@media (max-width: 719px) {
    .cn3-doc {
        border-radius: 0;
        border-left: none;
        border-right: none;
        padding-left: 16px;
        padding-right: 16px;
        margin-left: -16px;
        margin-right: -16px;
    }
    #cn3-stage {
        padding-left: 16px;
        padding-right: 16px;
    }
    #cn3-topbar .cn3-nav {
        display: none;
    }
    .cn3-drawer-nav {
        display: flex;
    }
    .cn3-session {
        display: none;
    }
    .cn3-pb-hint-full {
        display: none;
    }
    .cn3-pb-hint-touch {
        display: inline;
    }
    #cn3-topic {
        min-width: 120px;
    }
    .cn3-brand .cn3-wordmark {
        display: none;
    }
}
@media (max-width: 639px) {
    #cn3-grid {
        grid-template-columns: 1fr;
    }
    .cn3-ghead {
        display: none;
    }
    .cn3-cue {
        border-right: none;
        border-top: 1px solid var(--border);
        padding: 12px 16px 0 40px;
        background: rgba(204, 52, 45, .06);
    }
    .cn3-cue:first-of-type {
        border-top: none;
    }
    .cn3-cue .cn3-cue-text {
        display: inline-block;
        font-family: Consolas, monospace;
        font-size: 12px;
        letter-spacing: .04em;
        color: var(--red-hi);
        text-transform: none;
        padding-bottom: 10px;
    }
    .cn3-note-cell {
        border-top: none;
    }
    .cn3-hero-group {
        flex-direction: column;
    }
    .cn3-resume-card {
        flex-direction: column;
        align-items: stretch;
    }
    .cn3-resume-actions {
        justify-content: flex-end;
    }
}

/* ============ REDUCED MOTION ============ */
@media (prefers-reduced-motion: reduce) {
    .cn3-skel,
    .cn3-item.is-loading-row {
        animation: none;
    }
    .cn3-donut-big {
        animation: none;
    }
    #cn3-app.cn3-practice .cn3-note-cell .cn3-note-body,
    #cn3-app.cn3-practice #cn3-summary-body,
    #cn3-library,
    .cn3-item,
    #cn3-pb-fill {
        transition: none;
    }
    .cn3-item.is-wash,
    .cn3-shake,
    .cn3-grade {
        animation: none;
    }
    #cn3-stage {
        scroll-behavior: auto;
    }
}

/* ============ PRINT (light paper sheet, note only) ============ */
@media print {
    body.cornell-fullbleed * {
        visibility: hidden;
    }
    body.cornell-fullbleed #cn3-note,
    body.cornell-fullbleed #cn3-note * {
        visibility: visible;
    }
    body.cornell-fullbleed {
        background: #fff;
    }
    /* unclip pagination: no viewport-height grid, no scroll container, static note flow */
    #cn3-app {
        display: block;
        height: auto;
    }
    #cn3-stage {
        overflow: visible;
        padding: 0;
    }
    #cn3-note {
        position: static;
        width: 100%;
        margin: 0;
        padding: 0;
    }
    #cn3-note .cn3-doc {
        max-width: none;
        background: #fff;
        color: #111;
        border: none;
        border-radius: 0;
        padding: 0;
    }
    #cn3-note,
    #cn3-note * {
        background: #fff !important;
        color: #111 !important;
        filter: none !important; /* practice blur can NEVER print */
        text-shadow: none !important;
        box-shadow: none !important;
    }
    #cn3-toolbar,
    #cn3-practice-bar,
    #cn3-library,
    #cn3-topbar,
    #cn3-scrim,
    #cn3-toast,
    .cn3-cell-tools,
    .cn3-grade,
    .cn3-copy,
    .cn3-summary-head .cn3-cell-edit,
    #cn3-add-code,
    #cn3-add-math,
    .cn3-addrow {
        display: none !important;
    }
    #cn3-doc-title {
        -webkit-line-clamp: none;
        overflow: visible;
    }
    #cn3-grid {
        border: 1px solid #000;
        border-radius: 0;
    }
    .cn3-ghead {
        position: static;
        border-bottom: 1px solid #000;
    }
    .cn3-ghead .cn3-kicker,
    .cn3-app .cn3-kicker {
        color: #444 !important;
    }
    .cn3-cue {
        border-right: 1px solid #000; /* the cue rail prints as a real hairline */
        border-top: 1px solid #ccc;
    }
    .cn3-note-cell {
        border-top: 1px solid #ccc;
    }
    .cn3-cue-num {
        color: #999 !important;
    }
    .cn3-summary {
        border: 1px solid #ccc;
        border-left: 3px solid #111;
        border-radius: 0;
    }
    .cn3-code,
    .cn3-math {
        border: 1px solid #ccc;
        border-radius: 0;
    }
    .cn3-code-pre {
        white-space: pre-wrap;
        word-break: break-word;
    }
    /* Force reveal blocks open in print */
    details.cn3-reveal > summary {
        display: none;
    }
    details.cn3-reveal > *:not(summary) {
        display: block !important;
    }
    .cn3-cue,
    .cn3-note-cell,
    .cn3-code,
    .cn3-math,
    .cn3-summary {
        break-inside: avoid;
    }
}
