/* Arcadia - FT-inspired minimal newspaper design */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #ede0de;
    --canvas-bg: #e3d6d3;
    --text: #2c1e18;
    --muted: #73615a;
    --accent: #2c1e18;
    --highlight: #2c1e18;
    --link: #0070ff;
    --selection-bg: rgba(166, 206, 255, 0.42);
    --hl-cyan: #00d8ff;
    --hl-orange: #ff5b2e;
    --hl-yellow: #ffff33;
    --hl-lime: #7fff00;
    --hl-magenta: #d63bd8;
    --hl-electricblue: #2f6cff;
    --hl-gradient-a: #ffff33;
    --hl-gradient-b: #7fff00;
    --hl-gradient-c: #00d8ff;
    --hl-gradient-angle: 132deg;
    --card-width: 390px;
    --card-gap: 24px;
    --card-track-padding: 24px;
    --ui-font: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    --ui-pill-h: 24px;
    --ui-icon-size: 14px;
    --row-content-x-pad: 6px;
}

html, body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}

/* Layout */
.card-track {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    overscroll-behavior: none;
    padding: 0 var(--card-track-padding);
    gap: var(--card-gap);
    -webkit-overflow-scrolling: touch;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.card-track.focus-mode {
    overflow-x: hidden;
    justify-content: center;
}

.card-track.canvas-mode {
    display: block;
    position: relative;
    overflow: auto;
    overscroll-behavior: none;
    padding: 0;
    background-color: var(--canvas-bg);
    touch-action: pan-x pan-y;
    -webkit-overflow-scrolling: touch;
}

.card-track.canvas-mode::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: var(--canvas-surface-width, 100%);
    height: var(--canvas-surface-height, 100%);
    min-width: 100%;
    min-height: 100%;
    pointer-events: none;
    opacity: 0;
    z-index: 0;
    transition: opacity 180ms ease;
}

.card-track.canvas-mode .hl-webgpu-layer {
    position: absolute;
    left: 0;
    top: 0;
    width: var(--canvas-surface-width, 100%);
    height: var(--canvas-surface-height, 100%);
    min-width: 100%;
    min-height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0;
    transition: opacity 180ms ease;
    mix-blend-mode: screen;
    image-rendering: pixelated;
    filter: saturate(1.2) contrast(1.06);
}

.card-track.canvas-mode .canvas-spacer,
.card-track.canvas-mode .card {
    position: relative;
    z-index: 1;
}

html[data-hl-effect-mode="linear-gradient"] .card-track.canvas-mode::before {
    opacity: 0.18;
    background: linear-gradient(
        var(--hl-gradient-angle, 132deg),
        var(--hl-gradient-a) 0%,
        var(--hl-gradient-b) 46%,
        var(--hl-gradient-c) 100%
    );
    filter: saturate(1.08) contrast(1.03);
}

@keyframes hl-hdr-aurora {
    0% {
        transform: translate3d(-2%, -1%, 0) scale(1.04);
    }
    50% {
        transform: translate3d(2%, 1.5%, 0) scale(1.1);
    }
    100% {
        transform: translate3d(-1%, 2%, 0) scale(1.05);
    }
}

html[data-hl-effect-mode="hdr-shader"] .card-track.canvas-mode::before {
    opacity: 0.34;
    background-image:
        radial-gradient(
            115% 120% at 8% 6%,
            var(--hl-gradient-a) 0%,
            transparent 55%
        ),
        radial-gradient(
            120% 120% at 92% 88%,
            var(--hl-gradient-c) 0%,
            transparent 58%
        ),
        linear-gradient(
            var(--hl-gradient-angle, 132deg),
            var(--hl-gradient-a) 0%,
            var(--hl-gradient-b) 50%,
            var(--hl-gradient-c) 100%
        );
    background-size: 100% 100%, 100% 100%, 100% 100%;
    mix-blend-mode: screen;
    filter: saturate(1.3) contrast(1.08);
    animation: hl-hdr-aurora 18s ease-in-out infinite alternate;
}

html[data-hl-webgpu-proto="1"] .card-track.canvas-mode .hl-webgpu-layer {
    opacity: 0.38;
}

html[data-hl-webgpu-proto="1"] .card-track.canvas-mode::before {
    opacity: 0.08;
}

@media (prefers-reduced-motion: reduce) {
    html[data-hl-effect-mode="hdr-shader"] .card-track.canvas-mode::before {
        animation: none;
        opacity: 0.24;
    }

    html[data-hl-webgpu-proto="1"] .card-track.canvas-mode .hl-webgpu-layer {
        opacity: 0.24;
    }
}

.card-track.canvas-mode.texture-dots {
    background-image:
        radial-gradient(rgba(44, 30, 24, 0.08) 0.5px, transparent 0.5px),
        radial-gradient(rgba(44, 30, 24, 0.05) 0.5px, transparent 0.5px);
    background-size: 4px 4px, 7px 7px;
    background-position: 0 0, 2px 3px;
    background-attachment: local, local;
}

.card-track.canvas-mode.texture-crosshatch {
    background-image:
        repeating-linear-gradient(
            45deg,
            transparent 0,
            transparent 4px,
            rgba(44, 30, 24, 0.035) 4px,
            rgba(44, 30, 24, 0.035) 5px
        ),
        repeating-linear-gradient(
            -45deg,
            transparent 0,
            transparent 4px,
            rgba(44, 30, 24, 0.035) 4px,
            rgba(44, 30, 24, 0.035) 5px
        );
    background-attachment: local, local;
}

.card-track.canvas-mode.focus-mode {
    overflow: auto;
    justify-content: initial;
}

.canvas-spacer {
    display: none;
    pointer-events: none;
}

.card-track.canvas-mode .canvas-spacer {
    display: block;
}

.card {
    flex: 0 0 var(--card-width);
    width: var(--card-width);
    min-width: var(--card-width);
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 0;
}

.card-track.canvas-mode .card {
    position: absolute;
    flex: none;
    min-width: 0;
    min-height: 0;
    height: auto;
    padding: 0;
    border: 1px solid rgba(44, 30, 24, 0.08);
    background: rgba(237, 224, 222, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 1px 1px rgba(44, 30, 24, 0.03), 0 2px 6px rgba(44, 30, 24, 0.025);
    overflow: visible;
}

.card.hidden {
    display: none;
}

.card.active {
    background: transparent;
}

.card-move-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--ui-pill-h);
    height: var(--ui-pill-h);
    min-width: var(--ui-pill-h);
    border: 0;
    background: var(--bg);
    font-family: var(--ui-font);
    font-size: calc(var(--ui-icon-size) - 1px);
    letter-spacing: -1px;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease;
}

.card-track.canvas-mode .card.active .card-move-handle {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    cursor: grab;
}

.card-track.canvas-mode .card.active .card-move-handle:active {
    cursor: grabbing;
}

.progress-ring {
    --progress: 0;
    width: 16px;
    height: 16px;
    min-width: 16px;
    border-radius: 50%;
    border: 1px solid rgba(44, 30, 24, 0.24);
    background: conic-gradient(
        rgba(44, 30, 24, 0.55) calc(var(--progress) * 1turn),
        rgba(44, 30, 24, 0.06) 0
    );
    position: relative;
    margin-left: 6px;
}

.progress-ring::after {
    content: "";
    position: absolute;
    inset: 3px;
    border-radius: 50%;
    background: var(--bg);
}

.card-controls {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 4;
    display: flex;
    align-items: center;
    gap: 0;
    min-height: var(--ui-pill-h);
    margin-left: auto;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease;
}

.card-track.canvas-mode .card.active .card-controls {
    visibility: visible;
    opacity: 1;
    pointer-events: none;
}

.card-track.canvas-mode .card-controls {
    top: 0;
    height: calc(1.32em + 6px);
    min-height: calc(1.32em + 6px);
    color: rgb(44, 30, 24);
}

.card-track.canvas-mode .card:has(.row.card-drag-target.row-full-hl) .card-controls {
    color: var(--card-hl-fg, #fff);
}

.card-track.canvas-mode .card:has(.row.card-drag-target.row-full-hl) .card-move-handle {
    background: transparent;
}

.card-actions {
    display: flex;
    gap: 0;
    height: var(--ui-pill-h);
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease;
}

.card-share-target {
    display: inline-flex;
    align-items: center;
    height: var(--ui-pill-h);
    max-width: 108px;
    padding: 0 4px;
    font-size: 9px;
    line-height: 1;
    letter-spacing: 0.05em;
    font-weight: 600;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.82;
    pointer-events: none;
    user-select: none;
}

.card-track.canvas-mode .card:has(.card-actions .card-share-target) .card-controls,
.card-track.canvas-mode .card:has(.card-actions .card-share-target) .card-actions {
    visibility: visible;
    opacity: 1;
}

.card-track.canvas-mode .card:not(.active):has(.card-actions .card-share-target) .card-actions {
    pointer-events: none;
}

.card-track.canvas-mode .card:not(.active):has(.card-actions .card-share-target) .card-actions .card-action {
    visibility: hidden;
    pointer-events: none;
}

.card-track.canvas-mode .card.active .card-actions {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

.card-track.canvas-mode .card-controls .card-action {
    background: transparent;
    color: inherit;
}

.card-track.canvas-mode .card-controls .card-move-handle {
    background: transparent;
    color: inherit;
}

.card-track.canvas-mode .card-controls .card-action[data-on="1"] {
    background: transparent;
    color: inherit;
}

.card-track.canvas-mode .card-controls .card-action:hover {
    background: transparent;
    color: inherit;
}

.card-track.canvas-mode .card-controls .card-action:focus-visible {
    outline: 1px solid currentColor;
    outline-offset: 1px;
}

.card-track.canvas-mode .card.active .row.card-drag-target {
    cursor: grab;
}

.card-track.canvas-mode .card.active .row.card-drag-target:active {
    cursor: grabbing;
}

.card-action {
    appearance: none;
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
    height: var(--ui-pill-h);
    width: var(--ui-pill-h);
    min-width: var(--ui-pill-h);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    font-family: var(--ui-font);
    font-size: var(--ui-icon-size);
    font-weight: 500;
    color: inherit;
    cursor: pointer;
    user-select: none;
}

.card-action[data-on="1"] {
    background: rgba(44, 30, 24, 0.06);
    color: var(--text);
}

.card-action:hover {
    color: var(--text);
    background: rgba(44, 30, 24, 0.04);
}

.card-action:focus-visible {
    outline: 2px solid rgba(0, 112, 255, 0.6);
    outline-offset: 2px;
}

.context-menu {
    position: fixed;
    z-index: 28;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px;
    min-width: 184px;
    border: 1px solid rgba(44, 30, 24, 0.24);
    background: #f2eae8;
    border-radius: 0;
    box-shadow: 0 10px 24px rgba(12, 10, 8, 0.16);
}

.context-menu.hidden {
    display: none;
}

.context-menu .context-menu-item {
    all: unset;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 10px;
    border-radius: 0;
    cursor: pointer;
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 13px;
    line-height: 1.3;
    text-transform: none;
    white-space: nowrap;
}

.context-menu .context-menu-item::before {
    content: attr(data-icon);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    min-width: 14px;
    color: rgba(44, 30, 24, 0.75);
    font-family: var(--ui-font);
    font-size: 12px;
}

.context-menu .context-menu-item:hover,
.context-menu .context-menu-item:focus-visible {
    background: rgba(44, 30, 24, 0.12);
    outline: none;
}

.context-menu .context-menu-item:disabled {
    opacity: 0.5;
    pointer-events: none;
}

.context-menu.mobile-docked {
    min-width: 0;
    width: auto;
    max-width: none;
}

.context-menu.mobile-docked .context-menu-item {
    padding: 10px 12px;
    font-size: 14px;
}

.text-highlight-menu {
    position: fixed;
    z-index: 30;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    align-items: center;
    gap: 5px;
    padding: 6px;
    border: 1px solid rgba(44, 30, 24, 0.24);
    background: #f2eae8;
    border-radius: 0;
    box-shadow: 0 10px 24px rgba(12, 10, 8, 0.16);
    transform: translate(-50%, -100%);
    max-width: min(90vw, 360px);
    max-height: min(65vh, 260px);
    overflow-x: hidden;
    overflow-y: auto;
}

.text-highlight-menu.hidden {
    display: none;
}

.text-highlight-menu.below {
    transform: translate(-50%, 0);
}

.text-highlight-menu-btn {
    all: unset;
    box-sizing: border-box;
    width: 24px;
    height: 24px;
    border: 1px solid rgba(44, 30, 24, 0.35);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-family: var(--ui-font);
    font-size: 11px;
    line-height: 1;
    font-weight: 700;
    text-transform: uppercase;
}

.text-highlight-menu-btn:focus-visible {
    outline: 2px solid rgba(0, 112, 255, 0.6);
    outline-offset: 1px;
}

.text-highlight-menu-btn.wf-highlight-blue {
    background: var(--hl-cyan);
}

.text-highlight-menu-btn.wf-highlight-orange {
    background: var(--hl-orange);
}

.text-highlight-menu-btn.wf-highlight-teal {
    background: var(--hl-yellow);
}

.text-highlight-menu-btn.wf-highlight-green {
    background: var(--hl-lime);
}

.text-highlight-menu-btn.wf-highlight-magenta {
    background: var(--hl-magenta);
}

.text-highlight-menu-btn.wf-highlight-electricblue {
    background: var(--hl-electricblue);
}

.text-highlight-menu-btn.wf-highlight-custom {
    background: var(--hl-custom-bg, var(--hl-yellow));
    font-size: 9px;
}

.text-highlight-menu-btn.text-highlight-menu-control {
    width: 20px;
    height: 20px;
    color: rgba(44, 30, 24, 0.9);
    background: rgba(241, 216, 210, 0.92);
    border-style: dashed;
    border-color: rgba(44, 30, 24, 0.4);
    font-size: 9px;
}

.text-highlight-menu-status {
    box-sizing: border-box;
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed rgba(44, 30, 24, 0.4);
    font-family: var(--ui-font);
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
    color: rgba(44, 30, 24, 0.9);
    background: rgba(241, 216, 210, 0.92);
    text-transform: uppercase;
}

.text-highlight-menu-status.is-idle {
    border-style: solid;
}

.doc-share-popover {
    position: fixed;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    border: 1px solid rgba(44, 30, 24, 0.22);
    background: rgba(246, 229, 225, 0.98);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 10px 24px rgba(12, 10, 8, 0.16);
    transform: translate(-100%, 0);
}

.doc-share-popover.hidden {
    display: none;
}

.doc-share-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.doc-share-input {
    min-width: 180px;
    max-width: min(52vw, 280px);
    height: var(--ui-pill-h);
    border: 1px solid rgba(44, 30, 24, 0.24);
    background: rgba(255, 255, 255, 0.65);
    color: var(--text);
    font-family: var(--ui-font);
    font-size: 12px;
    line-height: 1;
    padding: 0 8px;
}

.doc-share-input:focus-visible {
    outline: 1px solid rgba(17, 127, 184, 0.6);
    outline-offset: 1px;
}

.doc-share-submit {
    width: var(--ui-pill-h);
    min-width: var(--ui-pill-h);
}

.doc-share-unshare {
    color: rgba(136, 34, 18, 0.92);
}

.text-highlight-menu-status.is-sampling {
    background: rgba(255, 221, 105, 0.86);
}

.text-highlight-menu-status.is-failed {
    background: rgba(255, 120, 92, 0.9);
    color: #fff;
}

.text-highlight-menu-empty {
    display: inline-flex;
    align-items: center;
    height: 20px;
    padding: 0 6px;
    border: 1px dashed rgba(44, 30, 24, 0.38);
    background: rgba(241, 216, 210, 0.72);
    color: rgba(44, 30, 24, 0.82);
    font-family: var(--ui-font);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    line-height: 1;
}

.card-content {
    flex: 1;
    padding: 16px 8px;
    overflow-y: auto;
}

.card-track.canvas-mode .card-content {
    padding: 0;
    overflow: visible;
}

.card-track.canvas-mode .row.active::before,
.card-track.canvas-mode .row.selected::before,
.card-track.canvas-mode .row.dom-selected::before,
.card-track.canvas-mode .row.row-full-hl::before {
    left: 0;
    right: 0;
}

.card-track.canvas-mode .card-footer {
    display: flex;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    padding: 0;
    min-height: 11px;
    justify-content: flex-start;
    align-items: center;
    pointer-events: none;
    z-index: 3;
}

.card-track.canvas-mode .card-footer .footer-msg,
.card-track.canvas-mode .card-footer .mobile-nav {
    display: none;
}

.card-footer {
    padding: 16px 8px;
    display: flex;
    justify-content: space-between;
    position: relative;
    font-family: -apple-system, sans-serif;
    font-size: 11px;
    color: var(--muted);
}

.card-track.canvas-mode .card.active {
    border-color: rgba(44, 30, 24, 0.2);
    box-shadow: 0 1px 1px rgba(44, 30, 24, 0.03), 0 2px 6px rgba(44, 30, 24, 0.025);
}

.card-track.canvas-mode .card.card-canvas-placeholder {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.card-track.canvas-mode .tree.tree-canvas-placeholder {
    min-height: 56px;
}

.card-viewport-placeholder {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
    color: rgba(44, 30, 24, 0.72);
    pointer-events: none;
    user-select: none;
}

.card-viewport-placeholder-label {
    font-family: var(--ui-font);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.card-viewport-placeholder-title {
    font-family: var(--font);
    font-size: 13px;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (hover: hover) and (pointer: fine) {
    .card-track.canvas-mode .card:hover {
        border-color: rgba(44, 30, 24, 0.2);
    }
}

.mobile-nav {
    display: none;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    align-items: center;
    gap: 10px;
    height: var(--ui-pill-h);
}

.mobile-nav-indicator {
    min-width: 64px;
    text-align: center;
    font-family: var(--ui-font);
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    user-select: none;
}

.mobile-nav-btn {
    width: auto;
    min-width: var(--ui-pill-h);
    padding: 0 10px;
}

@media (max-width: 480px) {
    :root {
        --ui-pill-h: 28px;
        --ui-icon-size: 16px;
    }

    html,
    body {
        font-size: 16px;
        line-height: 1.34;
    }

    .card-track {
        padding: 0;
        gap: 0;
        scroll-snap-type: x mandatory;
    }

    .card {
        flex: 0 0 100%;
        width: 100%;
        min-width: 100%;
        padding: 0;
        scroll-snap-align: start;
    }

    .mobile-nav {
        display: inline-flex;
    }

    .footer-msg {
        display: none;
    }

    .row {
        padding: 4px 0;
        line-height: 1.28;
    }

    .card-track.canvas-mode .card-controls {
        height: calc(1.28em + 8px);
        min-height: calc(1.28em + 8px);
    }

    .text,
    .text-editor {
        min-height: 1.28em;
    }

    .note,
    .note-editor {
        line-height: 1.2;
        min-height: 1.2em;
    }
}

/* Tree/Rows */
.tree {
    display: flex;
    flex-direction: column;
    min-height: calc(1.32em * 4);
}

.row {
    --row-indent: 0px;
    display: flex;
    width: 100%;
    align-items: flex-start;
    padding: 3px 0 3px calc(var(--row-indent) + var(--row-content-x-pad));
    line-height: 1.32;
    position: relative;
    z-index: 0;
}

.cell {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-right: var(--row-content-x-pad);
}

/* -- Attachments: masonry layout for multiple images -- */
.attachments {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: flex-start;
}

.attachments.attachment-only {
    margin-top: 0;
}

/* Full-bleed media: negate all row/cell padding so content touches card edges */
.row.image-only {
    padding: 0;
}

.row.image-only .bullet {
    width: 0;
    margin: 0;
    opacity: 0;
    pointer-events: none;
}

.row.image-only .cell {
    gap: 0;
    padding-right: 0;
}

/* -- Single attachment: width controlled by S/M/L, no forced crop -- */
.attachment {
    position: relative;
    background: rgba(44, 30, 24, 0.05);
    border: none;
    border-radius: 0;
    overflow: hidden;
    flex-shrink: 0;
}

@keyframes attachment-shimmer {
    from { transform: translateX(-100%); }
    to { transform: translateX(100%); }
}

.attachment::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 180ms ease;
    z-index: 0;
}

.attachment.attachment-loading::before {
    opacity: 1;
    background:
        linear-gradient(
            105deg,
            rgba(255, 255, 255, 0) 20%,
            rgba(255, 255, 255, 0.22) 50%,
            rgba(255, 255, 255, 0) 80%
        ),
        linear-gradient(
            180deg,
            rgba(44, 30, 24, 0.06) 0%,
            rgba(44, 30, 24, 0.11) 100%
        );
    animation: attachment-shimmer 1.1s ease-in-out infinite;
}

/* S/M/L control width as percentage of container */
.attachment.size-small {
    width: calc(33.333% - 3px);
}

.attachment.size-medium {
    width: calc(66.666% - 2px);
}

.attachment.size-large {
    width: 100%;
}

/* -- Crop presets -- */
.attachment.crop-none {
    /* No aspect-ratio: image determines height */
}

.attachment.crop-portrait {
    aspect-ratio: 3 / 4;
}

.attachment.crop-square {
    aspect-ratio: 1 / 1;
}

.attachment.crop-landscape {
    aspect-ratio: 4 / 3;
}

.attachment.crop-widescreen {
    aspect-ratio: 16 / 9;
}

/* No crop: image shown at natural aspect, width-constrained */
.attachment.crop-none .attachment-img,
.attachment.crop-none .attachment-video,
.attachment.crop-none .attachment-embed {
    width: 100%;
    height: auto;
    display: block;
    opacity: 1;
    transition: opacity 180ms ease;
}

/* With crop: fill the aspect-ratio box */
.attachment:not(.crop-none) .attachment-img,
.attachment:not(.crop-none) .attachment-video,
.attachment:not(.crop-none) .attachment-embed {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    opacity: 1;
    transition: opacity 180ms ease;
}

.attachment.attachment-loading .attachment-img,
.attachment.attachment-loading .attachment-video,
.attachment.attachment-loading .attachment-embed {
    opacity: 0;
}

.attachment.attachment-missing .attachment-img,
.attachment.attachment-missing .attachment-video {
    display: none;
}

.attachment.attachment-missing::after {
    content: ":(";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: rgba(61, 37, 25, 0.25);
    pointer-events: none;
    background: rgba(61, 37, 25, 0.04);
}

.attachment-video {
    background: #000;
}

/* Video loading overlay: animated crosshatch shown until playback begins */
@keyframes crosshatch-drift {
    from { background-position: 0 0, 0 0; }
    to { background-position: 7px 7px, -7px 7px; }
}

.attachment-video-wrap::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    background-color: #000;
    background-image:
        repeating-linear-gradient(
            45deg,
            transparent 0,
            transparent 4px,
            rgba(255, 255, 255, 0.06) 4px,
            rgba(255, 255, 255, 0.06) 5px
        ),
        repeating-linear-gradient(
            -45deg,
            transparent 0,
            transparent 4px,
            rgba(255, 255, 255, 0.06) 4px,
            rgba(255, 255, 255, 0.06) 5px
        );
    animation: crosshatch-drift 4s linear infinite;
    pointer-events: none;
    transition: opacity 200ms ease;
}

.attachment-video-wrap.video-ready::after {
    opacity: 0;
    animation: none;
}

.attachment-embed {
    background: #000;
    border: 0;
}

/* -- Toolbar: size + crop buttons, top-left overlay -- */
.attachment-toolbar {
    position: absolute;
    top: 4px;
    left: 4px;
    display: flex;
    gap: 2px;
    z-index: 1;
}

.attachment-size-btn,
.attachment-crop-btn {
    width: 18px;
    height: 18px;
    border: 1px solid rgba(255, 255, 255, 0.72);
    background: rgba(18, 16, 14, 0.52);
    color: #fff;
    font-family: var(--ui-font);
    font-size: 10px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
    cursor: pointer;
    user-select: none;
    padding: 0;
}

.attachment:hover .attachment-toolbar,
.attachment:focus-within .attachment-toolbar {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

.attachment-size-btn:hover,
.attachment-size-btn:focus-visible,
.attachment-crop-btn:hover,
.attachment-crop-btn:focus-visible {
    background: rgba(18, 16, 14, 0.72);
    outline: none;
}

@media (hover: hover) and (pointer: fine) {
    .attachment-toolbar {
        visibility: hidden;
        opacity: 0;
        pointer-events: none;
        transition: opacity 120ms ease;
    }
}

/* -- Crop popover menu -- */
.attachment-crop-menu {
    position: absolute;
    top: 26px;
    left: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 4px;
    background: rgba(18, 16, 14, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.24);
    z-index: 2;
    min-width: 90px;
}

.attachment-crop-menu.hidden {
    display: none;
}

.crop-option {
    all: unset;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    color: #fff;
    font-family: var(--ui-font);
    font-size: 11px;
    line-height: 1.3;
    cursor: pointer;
    white-space: nowrap;
}

.crop-option:hover,
.crop-option:focus-visible {
    background: rgba(255, 255, 255, 0.16);
}

.crop-option.active {
    background: rgba(255, 255, 255, 0.10);
}

.crop-option-icon {
    font-size: 13px;
    width: 16px;
    text-align: center;
}

.row.active::before,
.row.selected::before,
.row.dom-selected::before,
.row.row-full-hl::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: -8px;
    right: -8px;
    z-index: -1;
    background: var(--selection-bg);
}

.row.row-full-hl::before {
    background: var(--row-hl-bg);
}

.row:not(.row-full-hl) .text .wf-highlight,
.row:not(.row-full-hl) .text-editor .wf-highlight,
.row:not(.row-full-hl) .text [class*="wf-highlight"],
.row:not(.row-full-hl) .text-editor [class*="wf-highlight"],
.row:not(.row-full-hl) .text span[style*="background"],
.row:not(.row-full-hl) .text-editor span[style*="background"],
.row:not(.row-full-hl) .text mark,
.row:not(.row-full-hl) .text-editor mark {
    background: transparent !important;
    background-color: transparent !important;
    color: inherit !important;
    font-weight: inherit !important;
}

.row.row-full-hl .text,
.row.row-full-hl .text-editor {
    color: var(--row-hl-fg, #fff);
    font-weight: 700;
}

.row.row-full-hl .text .wf-highlight,
.row.row-full-hl .text-editor .wf-highlight,
.row.row-full-hl .text [class*="wf-highlight"],
.row.row-full-hl .text-editor [class*="wf-highlight"],
.row.row-full-hl .text span[style*="background"],
.row.row-full-hl .text-editor span[style*="background"],
.row.row-full-hl .text mark,
.row.row-full-hl .text-editor mark {
    background: transparent !important;
    background-color: transparent !important;
    color: inherit !important;
    font-weight: inherit !important;
}

.row.drop-before::after,
.row.drop-after::after,
.row.drop-child::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background: #f26522;
    opacity: 0.5;
    pointer-events: none;
}

.row.drop-before::after {
    top: 0;
}

.row.drop-after::after {
    bottom: 0;
}

.row.drop-child::after {
    bottom: 0;
    left: calc(var(--row-indent) + 16px + var(--row-content-x-pad));
}

.row.drag-source {
    opacity: 0.5;
}

.row.done .text {
    color: var(--muted);
    text-decoration: line-through;
}

/* Bullet */
.bullet {
    width: 20px;
    font-size: 14px;
    color: var(--muted);
    flex-shrink: 0;
    cursor: pointer;
    position: relative;
    user-select: none;
}

.bullet:hover {
    color: var(--text);
}

.row.top-level .bullet {
    width: 0;
    margin: 0;
    opacity: 0;
    pointer-events: none;
}

/* Touch device optimizations: larger tap targets.
   Must appear after base .row and .bullet rules to win at equal specificity. */
@media (pointer: coarse) {
    .card-track.canvas-mode {
        scroll-snap-type: both proximity;
    }

    .card-track.canvas-mode .card {
        scroll-snap-align: start;
    }

    .row {
        padding: 6px 0;
        min-height: 38px;
        align-items: center;
        line-height: 1.28;
    }

    .card-track.canvas-mode .card-controls {
        min-height: calc(1.28em + 12px);
    }

    .bullet {
        width: 32px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .card-action {
        height: 36px;
        width: 36px;
        min-width: 36px;
    }

    .card-move-handle {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }

    .mobile-nav-btn {
        min-width: 36px;
        min-height: 36px;
    }

    .text,
    .text-editor {
        min-height: 1.28em;
    }

    .note,
    .note-editor {
        line-height: 1.2;
        min-height: 1.2em;
    }

    .context-menu .context-menu-item {
        padding: 12px 14px;
        font-size: 15px;
    }

    .attachment-size-btn,
    .attachment-crop-btn {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
}

/* Check (legacy) */
.check {
    width: 16px;
    font-size: 14px;
    color: var(--muted);
    margin-right: 8px;
    flex-shrink: 0;
}

.check.done {
    color: var(--highlight);
}

/* Text */
.text {
    cursor: text;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    min-height: 1.32em;
    user-select: text;
    -webkit-user-select: text;
}

.text a {
    color: var(--link);
    text-decoration: underline;
}

.wf-highlight {
    font-weight: 700;
    border-radius: 0;
    /* Keep highlighted text width stable across normal-mode cursor segment splits. */
    padding: 0;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

.wf-highlight-blue {
    background: var(--hl-cyan);
}

.wf-highlight-orange {
    background: var(--hl-orange);
}

.wf-highlight-teal {
    background: var(--hl-yellow);
}

.wf-highlight-green {
    background: var(--hl-lime);
}

.wf-highlight-magenta {
    background: var(--hl-magenta);
}

.wf-highlight-electricblue {
    background: var(--hl-electricblue);
}

.wf-highlight-custom {
    background: var(--hl-custom-bg, var(--hl-yellow));
}

.wf-highlight-cyan {
    background: var(--hl-cyan);
}

.wf-highlight-yellow {
    background: var(--hl-yellow);
}

.wf-highlight-lime {
    background: var(--hl-lime);
}

.text-editor {
    width: 100%;
    background: transparent;
    border: 0;
    outline: none;
    padding: 0;
    margin: 0;
    display: block;
    resize: none;
    overflow: visible;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    min-height: 1.32em;
    caret-color: var(--accent);
    line-height: inherit;
    font: inherit;
    color: inherit;
    user-select: text;
    -webkit-user-select: text;
}

.text-editor a {
    color: var(--link);
    text-decoration: underline;
    pointer-events: none;
}

.note {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.24;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    min-height: 1.24em;
    cursor: text;
}

.note-editor {
    width: 100%;
    background: transparent;
    border: 0;
    outline: none;
    padding: 0;
    margin: 0;
    resize: none;
    overflow: visible;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    min-height: 1.24em;
    caret-color: var(--accent);
    line-height: inherit;
    font: inherit;
    color: inherit;
    user-select: text;
    -webkit-user-select: text;
}

.text-selected {
    background: var(--selection-bg);
}

/* Cursors */
.cursor-block {
    background: var(--text);
    color: var(--bg);
}

.tree-endcap {
    height: 80px;
    cursor: text;
}

.card-track.canvas-mode .tree-endcap {
    height: 0;
}

.cursor-line {
    color: var(--accent);
    font-weight: bold;
}

/* Footer */
.mode-badge {
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--muted);
}

.mode-badge.mode-normal { color: var(--accent); }
.mode-badge.mode-insert { color: var(--highlight); }
.mode-badge.mode-visual { color: var(--highlight); }

.drag-pos-badge {
    display: none;
    margin-left: 6px;
    font-family: var(--ui-font);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.card-track.canvas-mode .drag-pos-badge.is-visible {
    display: inline-flex;
}

.footer-msg {
    font-family: monospace;
    font-size: 10px;
    color: var(--muted);
    margin-top: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Misc */
.count {
    font-size: 12px;
    color: var(--muted);
    margin-left: 8px;
    font-family: -apple-system, sans-serif;
}

.empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 14px;
    font-family: -apple-system, sans-serif;
}

.empty-state .key {
    font-family: monospace;
    background: rgba(0,0,0,0.05);
    padding: 2px 6px;
    margin: 0 4px;
}

/* Command overlay */
.cmd-overlay {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px;
    background: var(--bg);
    border-top: 1px solid var(--text);
}

.cmd-overlay.hidden {
    display: none;
}

.cmd-input {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    display: block;
    padding: 12px 0;
    font-family: monospace;
    font-size: 16px;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
}

/* Image modal */
.image-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.82);
    z-index: 190;
    padding: 18px;
}

.image-modal.hidden {
    display: none;
}

.image-modal-content {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-modal-img {
    max-width: min(96vw, 1400px);
    max-height: 94vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border: 1px solid rgba(255, 255, 255, 0.26);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.45);
    background: rgba(0, 0, 0, 0.24);
}

.image-modal-close {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 26px;
    height: 26px;
    border: 1px solid rgba(255, 255, 255, 0.38);
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.72);
    color: #fff;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.image-modal-close:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.7);
    outline-offset: 2px;
}

/* Help modal */
.help-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.help-modal.hidden {
    display: none;
}

.help-content {
    background: var(--bg);
    padding: 24px;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
    font-family: -apple-system, sans-serif;
    font-size: 13px;
}

.help-content h2 {
    font-size: 14px;
    margin-bottom: 16px;
    font-weight: 600;
}

.help-content dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 16px;
}

.help-content dt {
    font-family: monospace;
    font-weight: 600;
}

.help-content dd {
    color: var(--muted);
}

/* PIN modal */
.pin-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(242, 221, 217, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.pin-modal.hidden {
    display: none;
}

.pin-content {
    width: min(340px, 92vw);
    padding: 24px;
    border: 1px solid rgba(44, 30, 24, 0.2);
    background: var(--bg);
    font-family: var(--ui-font);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pin-title {
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.pin-msg {
    font-family: Georgia, "Times New Roman", serif;
    color: var(--text);
    font-size: 13px;
    line-height: 1.35;
    min-height: 1.35em;
}

.pin-input {
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid rgba(44, 30, 24, 0.25);
    border-radius: 4px;
    outline: none;
    font-family: var(--ui-font);
    font-size: 14px;
    color: var(--text);
}

.pin-input:focus-visible {
    outline: 2px solid rgba(0, 112, 255, 0.6);
    outline-offset: 2px;
}

.pin-submit {
    width: 100%;
    justify-content: center;
}

/* Note overview dropdown (fixed top-left) */
.doc-overview {
    position: fixed;
    top: max(10px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    z-index: 91;
    display: inline-flex;
    flex-direction: column;
    align-items: stretch;
    --doc-overview-expanded-width: min(92vw, var(--card-width));
    --doc-overview-collapsed-width: calc(var(--doc-overview-expanded-width) / 4);
    width: max(72px, var(--doc-overview-collapsed-width));
}

.doc-overview[data-open="1"] {
    width: var(--doc-overview-expanded-width);
}

.doc-overview-trigger {
    height: 24px;
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 8px;
    border: 1px solid rgba(44, 30, 24, 0.26);
    background: rgba(242, 221, 217, 0.96);
    color: var(--text);
    font-family: var(--ui-font);
    font-size: 11px;
    line-height: 1;
    text-align: left;
    cursor: pointer;
}

.doc-overview-trigger:focus-visible {
    outline: 2px solid rgba(0, 112, 255, 0.55);
    outline-offset: 2px;
}

.doc-overview-active-title {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-overview-caret {
    flex: 0 0 auto;
    opacity: 0.72;
    transition: transform 120ms ease;
}

.doc-overview-trigger[aria-expanded="true"] .doc-overview-caret {
    transform: rotate(180deg);
}

.doc-overview-menu {
    margin-top: 6px;
    width: 100%;
    max-height: min(62vh, 460px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 6px;
    background: rgba(242, 221, 217, 0.96);
    border: 1px solid rgba(44, 30, 24, 0.22);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.11);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.doc-overview-menu.hidden {
    display: none;
}

.doc-overview-item {
    display: block;
    min-height: 28px;
    width: 100%;
    border: 1px solid rgba(44, 30, 24, 0.12);
    background: rgba(255, 255, 255, 0.25);
    color: var(--text);
    padding: 0;
    cursor: pointer;
    text-align: left;
    overflow: hidden;
    transition: border-color 120ms ease, background-color 120ms ease;
}

.doc-overview-item.active {
    border-color: rgba(44, 30, 24, 0.5);
    background: rgba(44, 30, 24, 0.08);
}

.doc-overview-item:hover,
.doc-overview-item:focus-visible {
    border-color: rgba(44, 30, 24, 0.42);
    background: rgba(44, 30, 24, 0.12);
    outline: none;
}

.doc-overview-item.row-full-hl {
    background-color: var(--row-hl-bg, rgba(44, 30, 24, 0.16));
    border-color: rgba(44, 30, 24, 0.22);
}

.doc-overview-item.row-full-hl .wf-highlight,
.doc-overview-item.row-full-hl [class*="wf-highlight"] {
    background: transparent !important;
    background-color: transparent !important;
    color: inherit !important;
    font-weight: inherit !important;
    box-shadow: none !important;
}

.doc-overview-item.row-full-hl .doc-overview-item-text {
    color: var(--row-hl-fg, #fff);
    font-weight: 700;
}

.doc-overview-item.row-full-hl .doc-overview-item-badge,
.doc-overview-item.row-full-hl .doc-overview-item-source,
.doc-overview-item.row-full-hl .doc-overview-item-shared-indicator,
.doc-overview-item.row-full-hl .doc-overview-item-media-embed {
    color: var(--row-hl-fg, #fff);
    border-color: var(--row-hl-fg, #fff);
}

.doc-overview-item-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: start;
    gap: 0;
    min-width: 0;
    min-height: 28px;
}

.doc-overview-item-text {
    display: flex;
    align-items: flex-start;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 3px 8px;
    font-size: 12px;
    line-height: 1.32;
    min-height: 1.32em;
}

.doc-overview-item-badge {
    font-family: var(--ui-font);
    font-size: 9px;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: rgba(44, 30, 24, 0.75);
}

.doc-overview-item-meta {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0 6px 0 0;
}

.doc-overview-item-shared-indicator {
    display: inline-flex;
    align-items: center;
    font-family: var(--ui-font);
    font-size: 9px;
    line-height: 1;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: rgba(44, 30, 24, 0.9);
}

.doc-overview-item-source {
    font-family: var(--ui-font);
    font-size: 10px;
    line-height: 1;
    letter-spacing: 0.02em;
    color: rgba(44, 30, 24, 0.88);
}

.doc-overview-item-media {
    width: 52px;
    min-width: 52px;
    border-left: 1px solid rgba(44, 30, 24, 0.18);
    background: rgba(44, 30, 24, 0.08);
    overflow: hidden;
    align-self: stretch;
}

.doc-overview-item-media-img,
.doc-overview-item-media-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.doc-overview-item-media-embed {
    width: 100%;
    height: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: rgba(44, 30, 24, 0.82);
}

/* Sync bar — fixed top-right container for update-ready + sync status */
.sync-bar {
    position: fixed;
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    z-index: 90;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    pointer-events: none;
}

/* Update ready button — shown when SW update is pending */
.update-ready-btn {
    display: none;
    position: relative;
    align-items: center;
    padding: 4px 8px;
    border: 0;
    cursor: pointer;
    pointer-events: auto;
    color: #fff;
    font-size: 11px;
    line-height: 1;
    font-family: var(--ui-font);
    font-weight: 600;
    letter-spacing: 0.02em;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.24);
    /* CSS fallback for non-WebGPU browsers — noisy grey static feel */
    background: linear-gradient(
        180deg,
        #606068 0%,
        #48484f 20%,
        #787880 40%,
        #505058 60%,
        #686870 80%,
        #585860 100%
    );
    background-size: 100% 400%;
    animation: update-ready-gradient 0.8s steps(4) infinite;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.update-ready-btn.visible {
    display: inline-flex;
}

.update-ready-btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 1px;
}

/* When the WebGPU canvas is rendering, pause the CSS fallback animation. */
.update-ready-btn.shader-active {
    animation: none;
}

.update-ready-btn canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.update-ready-btn span {
    position: relative;
    z-index: 1;
}

@keyframes update-ready-gradient {
    0% { background-position: 0% 0%; }
    100% { background-position: 0% 100%; }
}

@media (prefers-reduced-motion: reduce) {
    .update-ready-btn {
        animation: none;
        background-size: 100% 100%;
    }
}

/* Sync status — global indicator */
.sync-status {
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
    padding: 4px 8px;
    border-radius: 0;
    background: var(--sync-status-bg, rgba(44, 30, 24, 0.65));
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.16);
    font-size: 11px;
    line-height: 1;
    font-family: var(--ui-font);
    font-weight: 500;
    letter-spacing: 0.02em;
}
.sync-status--disconnected { --sync-status-bg: #cc0000; animation: sync-blink 1.5s ease-in-out infinite; }
.sync-status--disconnected::after { content: "\00d7"; }
.sync-status--local { --sync-status-bg: #ff8800; animation: sync-breathe 3s ease-in-out infinite; }
.sync-status--local::after { content: "\25c7"; }
.sync-status--pending { --sync-status-bg: #e6b800; animation: sync-breathe 1.5s ease-in-out infinite; }
.sync-status--pending::after { content: "\25b3"; }
.sync-status--syncing { --sync-status-bg: #0088ff; }
.sync-status--syncing::after { content: "\25d0"; animation: sync-quarter-cycle 0.8s steps(1, end) infinite; }
.sync-status--online { display: none; }

/* Sync dot — per-card indicator (bottom-right of card) */
.sync-dot {
    position: absolute;
    bottom: 6px;
    right: 6px;
    z-index: 5;
    font-size: 8px;
    line-height: 1;
    pointer-events: none;
}
.card-track.canvas-mode .sync-dot {
    bottom: -16px;
    right: 0;
}
.sync-dot--disconnected { color: #cc0000; animation: sync-blink 1.5s ease-in-out infinite; }
.sync-dot--disconnected::after { content: "\00d7"; }
.sync-dot--local { color: #ff8800; animation: sync-breathe 3s ease-in-out infinite; }
.sync-dot--local::after { content: "\25c7"; }
.sync-dot--pending { color: #e6b800; animation: sync-breathe 1.5s ease-in-out infinite; }
.sync-dot--pending::after { content: "\25b3"; }
.sync-dot--syncing { color: #0088ff; }
.sync-dot--syncing::after { content: "\25d0"; animation: sync-quarter-cycle 0.8s steps(1, end) infinite; }
.sync-dot--online { /* hidden — only show for active/unsynced/error states */ }

@keyframes sync-quarter-cycle {
    0%, 24.99% { content: "\25d0"; }   /* ◐ */
    25%, 49.99% { content: "\25d3"; }  /* ◓ */
    50%, 74.99% { content: "\25d1"; }  /* ◑ */
    75%, 100% { content: "\25d2"; }    /* ◒ */
}
@keyframes sync-blink { 0%, 100% { opacity: 0.95; } 50% { opacity: 0.72; } }
@keyframes sync-breathe { 0%, 100% { opacity: 0.95; transform: scale(1); } 50% { opacity: 0.78; transform: scale(0.92); } }

/* Card sync block overlay (remote bootstrap loading only) */
.card.card--sync-blocked::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 50;
    background-color: var(--bg);
    background-image:
        repeating-linear-gradient(
            45deg,
            transparent 0,
            transparent 4px,
            rgba(44, 30, 24, 0.06) 4px,
            rgba(44, 30, 24, 0.06) 5px
        ),
        repeating-linear-gradient(
            -45deg,
            transparent 0,
            transparent 4px,
            rgba(44, 30, 24, 0.06) 4px,
            rgba(44, 30, 24, 0.06) 5px
        );
    animation: crosshatch-drift 4s linear infinite;
    opacity: 0.85;
    pointer-events: none;
}

.card.card--sync-blocked > * {
    pointer-events: none;
}

/* Scrollbar */
::-webkit-scrollbar { display: none; }

/* Prevent long-press callout and text-selection on chrome UI */
.card-action,
.card-move-handle,
.card-controls,
.card-drag-target,
.mobile-nav,
.doc-overview-trigger,
.doc-overview-item,
.bullet,
.mode-badge,
.drag-pos-badge {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Floating canvas mobile nav (visible on touch devices in canvas mode) */
.canvas-mobile-nav {
    display: none;
    position: fixed;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    align-items: center;
    gap: 10px;
    height: 36px;
    z-index: 20;
    background: var(--bg);
    border: 1px solid rgba(44, 30, 24, 0.18);
    padding: 0 12px;
    box-shadow: 0 2px 8px rgba(12, 10, 8, 0.1);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.canvas-mobile-nav.hidden {
    display: none !important;
}

@media (pointer: coarse) {
    .canvas-mobile-nav {
        display: inline-flex;
    }
}

/* Safe area */
@supports (padding: env(safe-area-inset-top)) {
    .card-track { padding-top: env(safe-area-inset-top); }
    .card-track.canvas-mode { padding-top: env(safe-area-inset-top); }
}

@supports (padding: env(safe-area-inset-bottom)) {
    .card-footer { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
}

/* Paste capture floating button */
.paste-capture-btn {
    position: fixed;
    z-index: 30;
    bottom: max(16px, env(safe-area-inset-bottom));
    right: 16px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border: 1px solid rgba(44, 30, 24, 0.18);
    border-radius: 0;
    box-shadow: 0 2px 8px rgba(12, 10, 8, 0.12);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    color: var(--text);
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

.paste-capture-btn.hidden {
    display: none;
}

.paste-capture-btn:hover {
    background: rgba(44, 30, 24, 0.06);
}

.paste-capture-btn:active {
    background: rgba(44, 30, 24, 0.12);
}

.paste-capture-popover {
    position: fixed;
    z-index: 31;
    bottom: max(62px, calc(env(safe-area-inset-bottom) + 46px));
    right: 16px;
    display: flex;
    flex-direction: column;
    min-width: 180px;
    background: var(--bg);
    border: 1px solid rgba(44, 30, 24, 0.18);
    border-radius: 0;
    box-shadow: 0 4px 16px rgba(12, 10, 8, 0.14);
}

.paste-capture-popover.hidden {
    display: none;
}

.paste-capture-popover-item {
    all: unset;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    padding: 10px 14px;
    font-family: var(--ui-font);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}

.paste-capture-popover-item:hover,
.paste-capture-popover-item:focus-visible {
    background: rgba(44, 30, 24, 0.08);
    outline: none;
}

/* PWA standalone mode */
@media (display-mode: standalone) {
    /* Extra top padding when there's no browser chrome */
    .card-track {
        padding-top: max(16px, env(safe-area-inset-top));
    }
    .card-track.canvas-mode {
        padding-top: max(0px, env(safe-area-inset-top));
    }
}
