:root {
    --surface: #ffffff;
    --surface-muted: #f1f5f9;
    --surface-strong: #e2e8f0;
    --text-primary: #1f2937;
    --text-secondary: #475569;
    --accent-green-start: #50c878;
    --accent-green-end: #01823e;
    --accent-blue-start: #38bdf8;
    --accent-blue-end: #2563eb;
    /* Main card + title bar: use almost full viewport on wide monitors */
    --app-content-max: min(1680px, calc(100vw - 32px));
}

[data-theme="dark"] {
    --surface: #111827;
    --surface-muted: #1f2937;
    --surface-strong: #334155;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    margin: 0;
    min-height: 100vh;
    width: 100%;
    background: var(--surface-muted);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 16px;
    gap: 16px;
    box-sizing: border-box;
}

[data-theme="dark"] #menuPopup {
    background: var(--surface-strong) !important;
    color: var(--text-primary);
    border-color: var(--surface-strong) !important;
}

#title-bar {
    width: 100%;
    max-width: var(--app-content-max);
    margin-left: auto;
    margin-right: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 20px;
    background: var(--surface);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    position: relative;
    box-sizing: border-box;
    border-radius: 12px;
}

#title-bar h1 {
    margin: 0;
    font-size: 1.2rem;
    max-width: calc(100% - 220px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.title-bar-actions {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
}

#fullscreen-btn {
    background: transparent;
    border: 1px solid transparent;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 8px;
    color: var(--text-secondary);
    transition: background 0.15s ease, color 0.15s ease;
}

#fullscreen-btn:hover {
    color: var(--accent-blue-end);
    background: var(--surface-muted);
}

.connection-status-btn {
    --connection-status-color: #f59e0b;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-width: 44px;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--surface-strong);
    border-radius: 999px;
    background: var(--surface-muted);
    color: var(--text-primary);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.connection-status-btn:hover {
    background: var(--surface);
    border-color: var(--connection-status-color);
    transform: translateY(-1px);
}

.connection-status-dot {
    width: 10px;
    height: 10px;
    flex: 0 0 10px;
    border-radius: 999px;
    background: var(--connection-status-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--connection-status-color) 20%, transparent);
}

.connection-status-btn.is-online {
    --connection-status-color: #16a34a;
}

.connection-status-btn.is-limited,
.connection-status-btn.is-checking {
    --connection-status-color: #facc15;
}

.connection-status-btn.is-offline {
    --connection-status-color: #ef4444;
}

[data-theme="dark"] .connection-status-btn {
    background: var(--surface-strong);
    border-color: rgba(148, 163, 184, 0.32);
    color: var(--text-primary);
}

#appMenu {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1000;
}

.menu-icon-btn {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--surface-strong);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-primary);
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

.menu-icon-btn:hover {
    background: var(--surface-muted);
}

[data-theme="dark"] .menu-icon-btn {
    background: var(--surface-strong);
    border-color: #475569;
}

#menuPopup {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 340px;
    max-width: calc(100vw - 24px);
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--surface-strong);
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
}

.menu-header {
    margin: 0 0 10px;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.menu-divider {
    border: 0;
    border-top: 1px solid var(--surface-strong);
    margin: 12px -4px;
}

.menu-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.menu-section--actions {
    gap: 4px;
}

.menu-section--details {
    border: 1px solid var(--surface-strong);
    border-radius: 10px;
    padding: 8px;
    background: var(--surface-muted);
}

.menu-details-summary {
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    list-style-position: inside;
}

.menu-section--details[open] .menu-details-summary {
    margin-bottom: 8px;
}

.menu-action-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    text-align: left;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.menu-action-btn:hover {
    background: var(--surface-muted);
    border-color: var(--surface-strong);
}

.menu-action-btn__icon {
    font-size: 1.05rem;
    line-height: 1;
}

.menu-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

.menu-input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid var(--surface-strong);
    border-radius: 8px;
    background: var(--surface);
    color: inherit;
    font: inherit;
    font-size: 0.9rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.menu-input option {
    background: var(--surface);
    color: var(--text-primary);
}

.menu-input:focus {
    outline: none;
    border-color: var(--accent-blue-end);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

.menu-hint {
    margin: 0;
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.menu-hint code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.72rem;
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--surface-muted);
}

.menu-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
}

.menu-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--accent-blue-end);
}

[data-theme="dark"] .menu-action-btn:hover {
    background: rgba(148, 163, 184, 0.12);
    border-color: rgba(148, 163, 184, 0.3);
}

[data-theme="dark"] .menu-input {
    background: var(--surface-muted);
    border-color: rgba(148, 163, 184, 0.3);
    color: var(--text-primary);
}

[data-theme="dark"] .menu-input option {
    background: var(--surface);
    color: var(--text-primary);
}

#cornellLayout {
    width: 100%;
    max-width: var(--app-content-max);
    min-width: 0;
    margin-left: auto;
    margin-right: auto;
    flex: 1 1 auto;
    min-height: 0;
    height: calc(100vh - 120px);
    max-height: calc(100svh - 120px);
    position: relative;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) minmax(0, 0.32fr);
    gap: 18px;
    background: var(--surface);
    border-radius: 20px;
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.16);
    overflow: hidden;
    box-sizing: border-box;
}

[data-theme="dark"] #cornellLayout {
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
}


#cornell-resizer {
    background-color: var(--surface-strong);
    cursor: col-resize;
    height: 100%;
    width: 2px;
    flex-shrink: 0;
    transition: background-color 0.2s ease;
}

#cornell-resizer:hover,
#cornell-resizer.is-resizing {
    background-color: #3b82f6;
}

.cornell-heading {
    background: linear-gradient(135deg, var(--accent-green-start), var(--accent-green-end));
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 28px;
    position: relative;
}

#headingText {
    width: 100%;
    max-width: min(960px, 100%);
    font-size: 1.6rem;
    font-weight: 600;
    text-align: center;
    outline: none;
}

.heading-color-controls {
    position: absolute;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 30;
}

.heading-color-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid rgba(255, 255, 255, 0.34);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    backdrop-filter: blur(4px);
    transition: background 0.15s ease, transform 0.15s ease;
}

.heading-color-menu-toggle:hover,
.heading-color-controls.is-open .heading-color-menu-toggle {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.heading-color-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 180px;
    padding: 8px;
    border: 1px solid var(--surface-strong);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-primary);
    box-shadow: 0 16px 34px rgba(15, 23, 42, 0.22);
    flex-direction: column;
    gap: 6px;
}

.heading-color-controls.is-open .heading-color-menu {
    display: flex;
}

.heading-color-button {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 7px 8px 7px 10px;
    border-radius: 9px;
    background: var(--surface-muted);
    color: var(--text-primary);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.heading-color-button input[type="color"] {
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
}

[data-theme="dark"] .heading-color-menu {
    background: var(--surface-strong);
    border-color: rgba(148, 163, 184, 0.34);
    color: var(--text-primary);
}

[data-theme="dark"] .heading-color-button {
    background: var(--surface-muted);
    color: var(--text-primary);
}

.cornell-body {
    display: flex;
    padding: 0 24px;
    min-height: 0;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

.cornell-column {
    background: var(--surface);
    border-radius: 18px;
    box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.24);
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

/* Cue column width capped — the notes / tree column takes all remaining space */
.cornell-column--cue {
    flex: 0 1 clamp(200px, 24vw, 300px);
    min-width: 0;
}

.cornell-column--notes {
    flex: 1 1 0;
    min-width: 0;
}


[data-theme="dark"] .cornell-column {
    box-shadow: inset 0 0 0 1px rgba(30, 41, 59, 0.9);
}

.column-title {
    margin: 18px 24px 12px;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.12em;
    color: var(--text-secondary);
}

.column-title--summary {
    margin-bottom: 8px;
}

#text .container,
#notesText,
#tree .container {
    background: var(--surface-muted);
    border-radius: 14px;
    margin: 0 24px 24px;
    padding: 18px;
    flex: 1;
    overflow: auto;
    line-height: 1.55;
    color: var(--text-primary);
}

#tree .container {
    position: relative;
    overflow: scroll;
    display: block;
    padding-top: 76px;
}

#tree .container::-webkit-scrollbar,
#notesText::-webkit-scrollbar,
#text .container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

#tree .container::-webkit-scrollbar-thumb,
#notesText::-webkit-scrollbar-thumb,
#text .container::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.35);
    border-radius: 999px;
}

[data-theme="dark"] #tree .container::-webkit-scrollbar-thumb,
[data-theme="dark"] #notesText::-webkit-scrollbar-thumb,
[data-theme="dark"] #text .container::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.45);
}

#tree .container.is-panning {
    cursor: grabbing;
    user-select: none;
}

#tree .container.is-panning * {
    user-select: none;
}

.notes-toolbar {
    position: sticky;
    top: 0;
    display: flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    gap: 8px;
    align-items: center;
    margin: 0 0 16px;
    padding: 8px 10px;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(6px);
    z-index: 20;
}

.notes-toolbar .button {
    flex: 0 0 auto;
}

[data-theme="dark"] .notes-toolbar {
    background: rgba(30, 41, 59, 0.92);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

#statusMessage {
    position: sticky;
    top: 74px;
    margin: 0 0 12px;
    padding: 8px 12px;
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.08);
    color: var(--text-secondary);
    font-size: 0.85rem;
    display: none;
}

#statusMessage.is-active {
    display: block;
}

#statusMessage.is-alert {
    background: rgba(220, 38, 38, 0.12);
    color: #b91c1c;
}

[data-theme="dark"] #statusMessage {
    background: rgba(148, 163, 184, 0.12);
    color: #cbd5f5;
}

[data-theme="dark"] #statusMessage.is-alert {
    background: rgba(248, 113, 113, 0.18);
    color: #fecaca;
}

/* Right-side sidebar à la Cursor chat: fixed to the viewport, full height,
   slides in/out with a CSS transform. While open, the body gets a matching
   right padding so the cornell layout reflows next to it instead of being
   covered. */
:root {
    --analysis-panel-width: min(380px, calc(100vw - 32px));
}

body.has-insights {
    padding-right: calc(var(--analysis-panel-width) + 24px);
    transition: padding-right 0.25s ease;
}

.analysis-panel {
    position: fixed;
    top: 16px;
    right: 16px;
    bottom: 16px;
    width: var(--analysis-panel-width);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.2);
    overflow: hidden;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transform: translateX(calc(100% + 24px));
    transition: transform 0.25s ease;
    border: 1px solid var(--surface-strong);
}

.analysis-panel.is-open {
    transform: translateX(0);
}

@media (max-width: 720px) {
    body.has-insights {
        /* On narrow screens the panel takes most of the width — don't try to
           reflow the layout next to it, just let it overlay. */
        padding-right: 16px;
    }
    .analysis-panel {
        top: 8px;
        right: 8px;
        bottom: 8px;
        width: calc(100vw - 16px);
    }
}

[data-theme="dark"] .analysis-panel {
    background: rgba(30, 41, 59, 0.95);
    box-shadow: 0 24px 40px rgba(0, 0, 0, 0.4);
}

.analysis-panel__header {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-align: left;
    cursor: pointer;
    user-select: none;
}

.analysis-panel__header:focus-visible {
    outline: 2px solid var(--accent-blue-end);
    outline-offset: -2px;
}

.analysis-panel__chevron {
    display: inline-block;
    font-size: 0.7rem;
    color: var(--text-secondary);
    transition: transform 0.15s ease;
}

.analysis-panel.is-collapsed .analysis-panel__chevron {
    transform: rotate(-90deg);
}

.analysis-panel__title {
    flex: 1 1 auto;
    min-width: 0;
}

.analysis-panel__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    transition: background 0.15s ease, color 0.15s ease;
}

.analysis-panel__close:hover {
    background: var(--surface-muted);
    color: var(--text-primary);
}

.analysis-panel__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.analysis-panel.is-collapsed .analysis-panel__body {
    display: none;
}

.analysis-panel__content {
    padding: 12px 16px;
    font-size: 0.92rem;
    line-height: 1.55;
}

.analysis-panel__content :first-child {
    margin-top: 0;
}

.analysis-panel__content p,
.analysis-panel__content ul {
    margin: 0 0 8px;
}

.analysis-panel__content ul {
    padding-left: 20px;
}

.analysis-panel__content li {
    margin-bottom: 4px;
}

.analysis-panel__content code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85em;
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--surface-muted);
}

.analysis-panel__section {
    border-top: 1px solid var(--surface-strong);
    padding: 12px 16px;
}

.analysis-panel__section-title {
    margin: 0 0 8px;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.concept-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.concept-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--surface-muted);
    border: 1px solid var(--surface-strong);
    color: var(--text-primary);
    font-size: 0.82rem;
    line-height: 1.4;
}

.coach-question-list {
    margin: 12px 0 0;
    padding-left: 22px;
}

.coach-question {
    margin-bottom: 14px;
}

.coach-question__prompt {
    font-weight: 700;
}

.coach-choice-list {
    display: grid;
    gap: 6px;
}

.coach-choice,
.coach-short-answer button {
    border: 1px solid var(--surface-strong);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-primary);
    padding: 8px 10px;
    cursor: pointer;
    text-align: left;
}

.coach-choice.is-correct {
    border-color: #16a34a;
    background: rgba(34, 197, 94, 0.14);
}

.coach-choice.is-incorrect {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.12);
}

.coach-short-answer {
    display: flex;
    gap: 8px;
}

.coach-short-answer input {
    flex: 1;
    border: 1px solid var(--surface-strong);
    border-radius: 8px;
    padding: 8px 10px;
    background: var(--surface);
    color: var(--text-primary);
}

.coach-question__feedback {
    margin: 8px 0 0;
    color: var(--text-secondary);
    font-size: 0.88rem;
}

.coach-question__feedback.is-correct {
    color: #15803d;
}

.coach-question__feedback.is-incorrect {
    color: #b91c1c;
}

.coach-question details {
    margin-top: 6px;
}

.coach-question summary {
    cursor: pointer;
    font-weight: 700;
}

.swot-list {
    display: grid;
    gap: 8px;
}

.swot-group {
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--surface-muted);
    border: 1px solid var(--surface-strong);
}

.swot-group__title {
    margin: 0 0 5px;
    color: var(--text-primary);
    font-size: 0.84rem;
    font-weight: 600;
}

.swot-group ul {
    margin: 0;
    padding-left: 18px;
}

.swot-group li {
    margin: 3px 0;
}

[data-theme="dark"] .concept-chip {
    background: rgba(148, 163, 184, 0.12);
    border-color: rgba(148, 163, 184, 0.28);
}

.suggested-links {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.suggested-link-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--surface-muted);
    border: 1px solid var(--surface-strong);
    font-size: 0.88rem;
}

.suggested-link-item__label {
    color: var(--text-primary);
    min-width: 0;
}

.suggested-link-item__boxes {
    display: block;
    margin-top: 2px;
    color: var(--text-secondary);
    font-size: 0.76rem;
    line-height: 1.3;
}

.suggested-link-item__btn {
    border: 1px solid var(--surface-strong);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text-primary);
    padding: 4px 10px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.suggested-link-item__btn:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--accent-green-start), var(--accent-green-end));
    border-color: transparent;
    color: #ffffff;
}

.suggested-link-item__btn:disabled {
    cursor: default;
    color: var(--text-secondary);
    background: transparent;
}

.video-link-item {
    align-items: stretch;
}

.video-link-item__anchor {
    display: grid;
    grid-template-columns: 86px 1fr;
    gap: 3px 10px;
    align-items: center;
}

.video-link-item__thumbnail {
    grid-row: span 2;
    width: 86px;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 8px;
    background: #e5e7eb;
}

.video-link-item__channel {
    display: block;
    color: var(--text-secondary);
    font-size: 0.78rem;
    text-decoration: none;
}

[data-theme="dark"] .suggested-link-item {
    background: rgba(148, 163, 184, 0.08);
    border-color: rgba(148, 163, 184, 0.25);
}

[data-theme="dark"] .suggested-link-item__btn {
    background: var(--surface-strong);
    border-color: rgba(148, 163, 184, 0.3);
}

.status-message,
.analysis-panel__content {
    scrollbar-width: thin;
}

#zoom {
    transform-origin: left bottom;
    transition: transform 0.3s ease-in-out;
    position: relative;
    /* Fill the visible notes area, but no longer balloon to 1800x1200 — boxes stay
       in view and the SVG layer (which we size at 100% below) is never empty.        */
    min-width: 100%;
    min-height: 100%;
    background-color: var(--surface);
    isolation: isolate;
}

.zoom.grid-on {
    background-image:
        linear-gradient(to right, rgba(2, 132, 199, 0.18) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(2, 132, 199, 0.18) 1px, transparent 1px);
    background-size: 140px 140px;
}

[data-theme="dark"] .zoom.grid-on {
    background-image:
        linear-gradient(to right, rgba(148, 163, 184, 0.25) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(148, 163, 184, 0.25) 1px, transparent 1px);
}

#notes {
    background: var(--surface);
    border-radius: 18px;
    box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.24);
    display: flex;
    flex-direction: column;
    padding: 0 24px 24px;
    min-height: 0;
}

#notesText {
    flex: 1;
    padding: 18px;
}

/* Box styling ------------------------------------------------------------ */

#tree .box {
    background-color: var(--surface-muted);
    border: 1px solid rgba(15, 23, 42, 0.12);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
    position: absolute;
    text-align: left;
    padding: 10px 14px 14px;
    border-radius: 10px;
    user-select: none;
    max-width: 240px;
    min-width: 140px;
    left: 120px;
    top: 120px;
    z-index: 2;
    transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
    outline: none;
    overflow: auto;
    resize: both;
}

#tree .box:hover {
    border-color: rgba(15, 23, 42, 0.22);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.1);
}

[data-theme="dark"] #tree .box {
    color: #f8fafc;
    background-color: #020617;
    border-color: rgba(148, 163, 184, 0.28);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

#tree .box.is-empty::before {
    content: attr(data-placeholder);
    color: #64748b;
    opacity: 0.85;
    pointer-events: none;
}

[data-theme="dark"] #tree .box.is-empty::before {
    color: #cbd5e1;
}

[data-theme="dark"] #tree .box:hover {
    border-color: rgba(148, 163, 184, 0.5);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
}

[data-theme="dark"] #tree .box::after,
[data-theme="dark"] #tree .box .boxFooter {
    color: #cbd5e1;
}

#tree .box::after {
    content: attr(data-label);
    position: absolute;
    left: 2px;
    top: -20px;
    color: #475569;
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    pointer-events: none;
    user-select: none;
}

.boxFooter {
    position: absolute;
    left: 2px;
    top: -20px;
    color: #475569;
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    pointer-events: none;
    user-select: none;
    display: none;
}

.glow {
    box-shadow: 0 0 20px 8px var(--glow-color, #10b981);
}

#tree svg {
    /* `inset: 0` stretches the SVG to the actual rendered size of #zoom even
       though #zoom only sets min-height (percentage heights from `height: 100%`
       do not resolve in that case and would collapse the SVG to 0 px). */
    position: absolute;
    inset: 0;
    display: block;
    z-index: 1;
    pointer-events: none;
    overflow: visible;
}

.line {
    stroke-width: 2;
    stroke: #64748b;
}

[data-theme="dark"] .line {
    stroke: #94a3b8;
}

.button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 10px;
    background: #f5f5f5;
    font-size: 1.25rem;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.button:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.12);
    background: var(--surface);
    outline: 1px solid rgba(15, 23, 42, 0.06);
}

.button.is-active,
.button[aria-pressed="true"] {
    background: linear-gradient(135deg, var(--accent-green-start), var(--accent-green-end));
    color: #ffffff;
    box-shadow: 0 6px 16px rgba(1, 130, 62, 0.25);
}

.button.is-active:hover,
.button[aria-pressed="true"]:hover {
    background: linear-gradient(135deg, #4ab671, #016f33);
}

[data-theme="dark"] .button {
    background: var(--surface-strong);
    color: var(--text-primary);
}

[data-theme="dark"] .button:hover {
    background: #4b4b4b;
}

.tree-menu {
    position: absolute;
    display: none;
    flex-direction: column;
    gap: 8px;
    min-width: 180px;
    padding: 14px;
    border-radius: 14px;
    background-color: rgba(255, 255, 255, 0.96);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.16);
    z-index: 20;
    backdrop-filter: blur(6px);
}

.tree-menu.visible {
    display: flex;
}

.tree-menu__icon {
    width: 48px;
    height: 48px;
    align-self: center;
    pointer-events: none;
}

.tree-menu__item {
    border: none;
    border-radius: 10px;
    padding: 8px 12px;
    text-align: left;
    background: #f3f3f3;
    color: #1f2937;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background 0.18s ease, transform 0.18s ease;
}

.tree-menu__item:hover {
    background: #e9e9e9;
    transform: translateX(2px);
}

[data-theme="dark"] .tree-menu {
    background-color: rgba(40, 40, 40, 0.96);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.45);
}

[data-theme="dark"] .tree-menu__item {
    background: #3a3a3a;
    color: #f5f5f5;
}

[data-theme="dark"] .tree-menu__item:hover {
    background: #4b4b4b;
}

.toolbar {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(148, 163, 184, 0.35);
    padding: 12px;
    border-radius: 12px;
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.15);
    backdrop-filter: blur(6px);
    z-index: 40;
    gap: 10px;
    align-items: center;
}

.toolbar input[type="color"] {
    width: 42px;
    height: 42px;
    padding: 0;
    border: none;
    border-radius: 10px;
    background: transparent;
    cursor: pointer;
}

.toolbar-color-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    border-radius: 9px;
    padding: 7px 9px;
    background: #f3f4f6;
    color: #1f2933;
    cursor: pointer;
}

.toolbar-color-button span {
    font-size: 0.82rem;
    font-weight: 700;
    white-space: nowrap;
}

.toolbar button {
    border: none;
    border-radius: 9px;
    padding: 8px 12px;
    background: #f3f4f6;
    color: #1f2933;
    cursor: pointer;
    transition: background 0.18s ease, transform 0.18s ease;
}

.toolbar button:hover {
    background: #e5e7eb;
    transform: translateY(-1px);
}

[data-theme="dark"] .toolbar {
    background: rgba(38, 38, 38, 0.96);
    border-color: rgba(148, 163, 184, 0.18);
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.35);
}

[data-theme="dark"] .toolbar button {
    background: #3a3a3a;
    color: #f5f5f5;
}

[data-theme="dark"] .toolbar-color-button {
    background: #3a3a3a;
    color: #f5f5f5;
}

[data-theme="dark"] .toolbar button:hover {
    background: #4b4b4b;
}

/* Floating "Link 🖇️" dropdown next to the box quick-toolbar.
   The list of other boxes is rendered inside .dropdown-content; clicking
   an item toggles the SVG link between the active box and that one.     */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    /* No gap between button and popover — otherwise the cursor crosses an
       unhovered area while moving down and the :hover-driven popover hides. */
    top: 100%;
    left: 0;
    min-width: 140px;
    max-height: 240px;
    overflow-y: auto;
    padding: 6px 4px 4px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--surface-strong);
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
    z-index: 50;
}

/* Show on hover of the wrapper OR when JS adds the .show class. */
.dropdown:hover .dropdown-content,
.dropdown.show .dropdown-content {
    display: block;
}

.dropdown-item {
    display: block;
    padding: 6px 10px;
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease;
}

.dropdown-item:hover {
    background: var(--surface-muted);
}

.dropdown-item + .dropdown-item {
    margin-top: 2px;
}

[data-theme="dark"] .dropdown-content {
    background: var(--surface-strong);
    border-color: rgba(148, 163, 184, 0.3);
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .dropdown-item:hover {
    background: rgba(148, 163, 184, 0.18);
}

.highlight {
    cursor: pointer;
    border-radius: 25%;
}

[contenteditable][data-placeholder] {
    position: relative;
    min-height: 24px;
}

[contenteditable][data-placeholder].is-empty::before {
    content: attr(data-placeholder);
    position: static;
    width: 100%;
    color: #7a8a9d;
    opacity: 0.82;
    pointer-events: none;
    transition: opacity 0.2s ease;
    display: block;
    text-align: inherit;
}

#cueText[contenteditable][data-placeholder].is-empty::before,
#notesText[contenteditable][data-placeholder].is-empty::before {
    line-height: inherit;
}

[contenteditable][data-placeholder]:focus {
    outline: none;
}

#heading [contenteditable][data-placeholder].is-empty::before {
    text-align: center;
    color: rgba(255, 255, 255, 0.78);
}

[data-theme="dark"] [contenteditable][data-placeholder].is-empty::before {
    color: #a5a5a5;
}

[data-theme="dark"] #heading [contenteditable][data-placeholder].is-empty::before {
    color: rgba(224, 255, 235, 0.85);
}

@media (max-width: 960px) {
    #cornellLayout {
        grid-template-rows: auto minmax(0, 1fr) minmax(0, 0.32fr);
        height: auto;
        min-height: min(100vh, 100dvh);
        max-height: none;
    }

    .cornell-body {
        flex-direction: column;
    }

    .cornell-column--cue {
        flex: 0 0 auto;
        max-width: none;
        width: 100%;
    }

    .cornell-column--notes {
        flex: 1 1 auto;
        min-height: 280px;
    }

    #cornell-resizer {
        display: none;
    }
}

@media (max-width: 720px) {
    #title-bar h1 {
        max-width: calc(100% - 140px);
    }

    .connection-status-label {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .connection-status-btn {
        width: 34px;
        padding: 0;
    }

    .notes-toolbar {
        justify-content: flex-start;
    }
}

.menu-api-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-top: 2px;
}

.menu-api-btn {
    min-width: 0;
    padding: 8px 6px;
    border: 1px solid var(--surface-strong);
    border-radius: 8px;
    background: var(--surface-muted, #f1f5f9);
    color: inherit;
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    text-align: center;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.menu-api-btn:hover {
    background: var(--surface-strong);
    transform: translateY(-1px);
}

[data-theme="dark"] .menu-api-btn {
    background: var(--surface-strong);
    border-color: rgba(148, 163, 184, 0.3);
}

[data-theme="dark"] .menu-api-btn:hover {
    background: rgba(148, 163, 184, 0.18);
}

.api-note-indicator {
    display: block;
    font-size: 0.7rem;
    font-family: ui-monospace, monospace;
    color: var(--muted, #64748b);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.api-open-dialog {
    border: none;
    border-radius: 12px;
    padding: 0;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
    max-width: min(420px, 94vw);
    color: var(--text-primary);
}

.api-open-dialog::backdrop {
    background: rgba(15, 23, 42, 0.4);
}

.api-open-dialog__inner {
    padding: 16px;
    background: var(--surface);
    color: var(--text-primary);
}

.api-open-dialog__header {
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.api-open-dialog__error {
    color: #b91c1c;
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.api-open-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 50vh;
    overflow: auto;
}

.api-open-list li {
    margin: 0;
    padding: 0;
    border-bottom: 1px solid var(--surface-strong);
}

.api-open-list__empty {
    padding: 12px 8px;
    color: var(--text-secondary);
    font-style: italic;
    border: none;
}

.api-open-list button {
    width: 100%;
    text-align: left;
    padding: 10px 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: inherit;
    font: inherit;
}

.api-open-list button:hover {
    background: var(--surface-muted);
}

.api-open-dialog__actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 12px;
}

.api-open-dialog__actions button {
    padding: 8px 14px;
    cursor: pointer;
    border: 1px solid var(--surface-strong);
    border-radius: 8px;
    background: var(--surface-muted);
    color: var(--text-primary);
    font: inherit;
}

.api-open-dialog__actions button:hover {
    background: var(--surface-strong);
}

[data-theme="dark"] .api-open-dialog__inner {
    background: var(--surface);
    color: var(--text-primary);
}

[data-theme="dark"] .api-open-dialog__actions button {
    background: var(--surface-strong);
    border-color: rgba(148, 163, 184, 0.35);
    color: var(--text-primary);
}

[data-theme="dark"] .api-open-dialog__actions button:hover {
    background: rgba(148, 163, 184, 0.18);
}

:fullscreen #title-bar {
    max-width: none;
    width: 100%;
    border-radius: 0;
}

:fullscreen #cornellLayout {
    height: 100vh;
    width: 100vw;
    max-width: none;
    margin: 0;
    border-radius: 0;
}

:fullscreen .cornell-body {
    flex-direction: row;
}

:fullscreen #cornell-resizer {
    display: block;
}

:fullscreen .cornell-summary {
    grid-row: 3;
    height: 25vh;
}
