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

:root {
    --bg: hsl(0, 0%, 6%);
    --surface: #111111;
    --border: hsl(0, 0%, 18%);
    --text: hsl(0, 0%, 95%);
    --muted: hsl(0, 0%, 50%);
    --fugaz: #c8a96e;
    --literaria: #7eb8a4;
    --permanente: #a08fd1;
    --font-body: "Lora", serif;
    --font-serif: "Lora", serif;
    --font-mono: "IBM Plex Mono", monospace;
}

html,
body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.14);
}

/* Bento card base */
.bento {
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid var(--border);
    border-radius: 16px;
}
.bento-sm {
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid var(--border);
    border-radius: 12px;
}

/* ── NAV ── */
#header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

#logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid rgba(160, 143, 209, 0.3);
    background: rgba(160, 143, 209, 0.12);
    color: #a08fd1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-style: italic;
    font-size: var(--fs-4xl);
    font-family: var(--font-serif);
    transition:
        background 0.3s,
        border-color 0.3s;
    flex-shrink: 0;
}

#header-title {
    font-size: var(--fs-2xl);
    font-weight: 600;
    color: hsl(0, 0%, 95%);
}
#header-sub {
    font-size: var(--fs-base);
    color: rgba(255, 255, 255, 0.28);
    font-family: var(--font-mono);
    letter-spacing: 1.5px;
}

/* Desktop nav pills */
#nav-pills {
    display: none;
    gap: 2px;
    padding: 4px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 999px;
}

.nav-pill {
    padding: 5px 18px;
    border-radius: 999px;
    font-size: var(--fs-lg);
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.38);
    transition: all 0.2s;
    font-family: var(--font-body);
}

.nav-pill.active {
    background: rgba(160, 143, 209, 0.18);
    color: #a08fd1;
    border: 1px solid rgba(160, 143, 209, 0.3);
}

#note-count {
    font-size: var(--fs-md);
    font-family: var(--font-mono);
    color: rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
}

/* ── CONTENT LAYOUT ── */
#content {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 72px;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── SCREENS ── */
.screen {
    display: none;
    padding: 16px 16px 0;
}
.screen.active {
    display: block;
}

/* ── STAGE BAR ── */
#stage-bar {
    display: flex;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px;
    gap: 4px;
    margin-bottom: 16px;
}

.stage-btn {
    flex: 1;
    padding: 8px 4px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--muted);
    font-size: var(--fs-md);
    font-family: var(--font-mono);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}
.stage-btn .stage-icon {
    font-size: var(--fs-2xl);
}
.stage-btn .stage-num {
    font-size: var(--fs-base);
    letter-spacing: 0.5px;
}

/* ── INSTRUCTION CARD ── */
#instruction-card {
    border-left-width: 2px;
    border-left-style: solid;
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 16px;
    transition: all 0.3s;
}
#instruction-label {
    font-size: var(--fs-base);
    font-family: var(--font-mono);
    letter-spacing: 1px;
    margin-bottom: 5px;
    text-transform: uppercase;
}
#instruction-text {
    font-size: var(--fs-lg);
    color: rgba(255, 255, 255, 0.55);
    line-height: 1.6;
}

/* ── EDITOR CARD (Gemini style) ── */
#editor-card {
    border-radius: 16px;
    border: 1px solid var(--border);
    overflow: hidden;
    margin-bottom: 16px;
    background: rgba(255, 255, 255, 0.02);
}

#editor-body {
    padding: 20px 20px 0;
}

/* ── FIELDS ── */
.field-wrap {
    margin-bottom: 20px;
}
.field-label {
    font-size: var(--fs-base);
    font-family: var(--font-mono);
    color: rgba(255, 255, 255, 0.25);
    letter-spacing: 1.5px;
    margin-bottom: 6px;
    text-transform: uppercase;
}

input,
textarea {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 11px 14px;
    color: var(--text);
    font-size: var(--fs-2xl);
    font-family: var(--font-serif);
    width: 100%;
    outline: none;
    line-height: 1.6;
    -webkit-appearance: none;
    transition: border-color 0.2s;
}
input:focus,
textarea:focus {
    border-color: rgba(255, 255, 255, 0.2);
}
input::placeholder,
textarea::placeholder {
    color: rgba(255, 255, 255, 0.2);
    font-family: var(--font-serif);
    font-weight: 400;
    font-style: italic;
}
textarea {
    resize: none;
    min-height: 100px;
}
#title-input {
    font-size: var(--fs-5xl);
    font-weight: 600;
}

/* ── EDITOR FOOTER BAR (Gemini) ── */
#editor-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 16px;
}
#editor-footer-actions {
    display: flex;
    gap: 6px;
}
.footer-action-btn {
    padding: 5px 12px;
    border-radius: 6px;
    font-size: var(--fs-md);
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.35);
    transition: all 0.15s;
    font-family: var(--font-body);
}
.footer-action-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.7);
}

/* ── SAVE BUTTON ── */
#save-btn {
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: 10px;
    font-size: var(--fs-xl);
    font-weight: 600;
    font-family: var(--font-mono);
    cursor: pointer;
    letter-spacing: 0.3px;
    transition: all 0.2s;
    margin-bottom: 16px;
}
#save-btn:disabled {
    background: rgba(255, 255, 255, 0.05) !important;
    color: rgba(255, 255, 255, 0.18) !important;
    cursor: default;
}

/* ── LINKS SECTION ── */
#links-section {
    margin-bottom: 14px;
}
#links-toggle {
    width: 100%;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 8px 14px;
    color: var(--muted);
    font-size: var(--fs-md);
    font-family: var(--font-mono);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: color 0.2s;
}
#links-panel {
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    display: none;
}
#links-panel.open {
    display: block;
}
#links-hint {
    font-size: var(--fs-md);
    color: rgba(255, 255, 255, 0.3);
    margin-bottom: 10px;
    line-height: 1.5;
}
#active-links {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}
#active-links:empty {
    display: none;
}
#link-search {
    font-size: var(--fs-lg);
    margin-bottom: 8px;
}
#no-perms {
    font-size: var(--fs-lg);
    color: rgba(255, 255, 255, 0.2);
    text-align: center;
    padding: 10px 0;
}

.link-chip {
    font-size: var(--fs-base);
    padding: 3px 10px;
    border-radius: 20px;
    cursor: pointer;
    border-width: 1px;
    border-style: solid;
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: var(--font-mono);
}

.linkable-item {
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid var(--border);
    margin-bottom: 5px;
    background: rgba(255, 255, 255, 0.02);
    transition: background 0.15s;
}
.linkable-item:active {
    background: rgba(255, 255, 255, 0.06);
}
.linkable-label {
    font-size: var(--fs-base);
    font-family: var(--font-mono);
    margin-bottom: 2px;
}
.linkable-text {
    font-size: var(--fs-lg);
    color: rgba(255, 255, 255, 0.65);
}

/* ── ADD SOURCE BUTTON ── */
#add-source-btn:hover,
#add-edit-source-btn:hover {
    background: rgba(160, 143, 209, 0.25);
    border-color: rgba(160, 143, 209, 0.5);
}
#add-source-btn:active,
#add-edit-source-btn:active {
    background: rgba(160, 143, 209, 0.35);
}

/* ── FLOW GUIDE ── */
#flow-guide {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 8px;
}
#flow-guide-label {
    font-size: var(--fs-base);
    font-family: var(--font-mono);
    color: rgba(255, 255, 255, 0.2);
    letter-spacing: 1px;
    margin-bottom: 10px;
}
.flow-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 10px;
}
.flow-item:last-child {
    margin-bottom: 0;
}
.flow-dot {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.18);
    font-size: var(--fs-base);
    font-family: var(--font-mono);
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    transition: all 0.3s;
}
.flow-dot.active {
    border: none;
    color: #0a0a0e;
}
.flow-name {
    font-size: var(--fs-md);
    color: rgba(255, 255, 255, 0.3);
    transition: color 0.3s;
}
.flow-name.active {
    font-weight: 600;
}
.flow-sub {
    font-size: var(--fs-base);
    color: rgba(255, 255, 255, 0.2);
    line-height: 1.4;
}

/* ── VAULT ── */
#vault-stats {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}
.stat-card {
    flex: 1;
    border-radius: 10px;
    padding: 10px 8px;
    text-align: center;
}
.stat-num {
    font-size: var(--fs-7xl);
    font-weight: 700;
    line-height: 1;
}
.stat-lbl {
    font-size: var(--fs-sm);
    font-family: var(--font-mono);
    opacity: 0.55;
    margin-top: 3px;
    letter-spacing: 0.5px;
}

#filter-bar {
    display: flex;
    gap: 5px;
    margin-bottom: 14px;
    overflow-x: auto;
    padding-bottom: 2px;
}
.filter-btn {
    flex-shrink: 0;
    padding: 5px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 999px;
    color: var(--muted);
    font-size: var(--fs-md);
    font-family: var(--font-mono);
    cursor: pointer;
    transition: all 0.15s;
}
.filter-btn.active {
    background: rgba(255, 255, 255, 0.09);
    border-color: rgba(255, 255, 255, 0.16);
    color: var(--text);
}

#export-btn {
    width: 100%;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    color: var(--muted);
    font-size: var(--fs-md);
    font-family: var(--font-mono);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    margin-bottom: 14px;
    transition: all 0.2s;
    letter-spacing: 0.3px;
}
#export-btn.selecting {
    background: rgba(160, 143, 209, 0.1);
    border-color: rgba(160, 143, 209, 0.3);
    color: #a08fd1;
}

/* ── NOTE CARD ── */
.note-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-left-width: 2px;
    border-left-style: solid;
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.note-card:active {
    background: rgba(255, 255, 255, 0.06);
}
.note-card.selected {
    background: rgba(160, 143, 209, 0.07);
    border-color: rgba(160, 143, 209, 0.35);
}

.note-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}
.note-stage-badge {
    font-size: var(--fs-base);
    font-family: var(--font-mono);
    letter-spacing: 1px;
    text-transform: uppercase;
}
.note-date {
    font-size: var(--fs-base);
    color: rgba(255, 255, 255, 0.22);
    font-family: var(--font-mono);
}
.note-title {
    font-size: var(--fs-2xl);
    font-weight: 600;
    color: var(--text);
    margin-bottom: 3px;
    line-height: 1.3;
    font-family: var(--font-serif);
}
.note-preview {
    font-size: var(--fs-lg);
    color: rgba(255, 255, 255, 0.45);
    line-height: 1.5;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.note-links {
    margin-top: 7px;
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.note-link-tag {
    font-size: var(--fs-base);
    padding: 2px 7px;
    border-radius: 10px;
    font-family: var(--font-mono);
}

.note-card .select-indicator {
    display: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.18);
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-base);
    transition: all 0.15s;
}
.selecting-mode .note-card .select-indicator {
    display: flex;
}
.note-card.selected .select-indicator {
    background: #a08fd1;
    border-color: #a08fd1;
    color: #0a0a0e;
}

/* ── EMPTY STATE ── */
/* ── Note card hover link button ── */
.note-card {
    position: relative;
}
.card-link-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    background: rgba(160, 143, 209, 0.12);
    border: 1px solid rgba(160, 143, 209, 0.25);
    color: #a08fd1;
    font-size: var(--fs-lg);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
    z-index: 2;
}
.note-card:hover .card-link-btn {
    display: flex;
}
.card-link-btn:hover {
    background: rgba(160, 143, 209, 0.25);
}
.card-link-btn.linked {
    background: rgba(160, 143, 209, 0.3);
    border-color: rgba(160, 143, 209, 0.6);
    color: #fff;
}

#vault-empty {
    text-align: center;
    padding-top: 60px;
    color: rgba(255, 255, 255, 0.18);
}
#vault-empty .empty-icon {
    font-size: var(--fs-9xl);
    margin-bottom: 12px;
}
#vault-empty .empty-title {
    font-size: var(--fs-2xl);
    margin-bottom: 5px;
}
#vault-empty .empty-sub {
    font-size: var(--fs-lg);
}

/* ── GRAPH ── */
#screen-graph {
    padding: 0 !important;
    overflow: hidden !important;
    height: calc(100vh - 130px);
}
#graph-container {
    width: 100%;
    height: 100%;
    position: relative;
}
#graph-svg {
    width: 100%;
    height: 100%;
    cursor: grab;
}
#graph-svg:active {
    cursor: grabbing;
}
#graph-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.18);
    font-size: var(--fs-xl);
    pointer-events: none;
}
#graph-legend {
    position: absolute;
    bottom: 20px;
    left: 20px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: var(--fs-base);
    font-family: var(--font-mono);
    color: rgba(255, 255, 255, 0.3);
}
.legend-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}
.graph-label {
    font-family: var(--font-serif);
    font-size: var(--fs-md);
    fill: rgba(255, 255, 255, 0.7);
    pointer-events: none;
    text-anchor: middle;
}
.graph-link {
    stroke: rgba(255, 255, 255, 0.1);
    stroke-width: 1.5;
}
.graph-node {
    cursor: pointer;
}

/* ── GRAPH INTELLIGENCE ── */
#graph-insights {
    display: none;
    position: absolute;
    top: 16px;
    right: 16px;
    width: min(280px, calc(100% - 32px));
    max-height: calc(100% - 32px);
    overflow-y: auto;
    background: rgba(18, 18, 18, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    backdrop-filter: blur(12px);
    font-family: var(--font-mono);
    z-index: 10;
}
#graph-insights::-webkit-scrollbar {
    width: 4px;
}
#graph-insights::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}
.gi-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-size: var(--fs-lg);
    color: rgba(255, 255, 255, 0.5);
}
.gi-header:hover {
    color: rgba(255, 255, 255, 0.7);
}
.gi-header-icon {
    font-size: var(--fs-xl);
    color: #a08fd1;
}
.gi-badge {
    background: rgba(160, 143, 209, 0.2);
    color: #a08fd1;
    font-size: var(--fs-base);
    padding: 1px 7px;
    border-radius: 8px;
    margin-left: auto;
}
.gi-arrow {
    font-size: var(--fs-base);
    opacity: 0.4;
}
.gi-body {
    padding: 6px 0;
}
.gi-insight {
    padding: 8px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.gi-insight:last-child {
    border-bottom: none;
}
.gi-insight-header {
    font-size: var(--fs-md);
    font-weight: 600;
    display: flex;
    gap: 6px;
    align-items: center;
}
.gi-insight-desc {
    font-size: var(--fs-base);
    color: rgba(255, 255, 255, 0.3);
    margin-top: 3px;
    line-height: 1.4;
}
.gi-items {
    margin-top: 8px;
}
.gi-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px;
    margin: 2px 0;
    border-radius: 4px;
    font-size: var(--fs-base);
    color: rgba(255, 255, 255, 0.5);
    transition: background 0.15s;
}
.gi-item:hover {
    background: rgba(255, 255, 255, 0.05);
}
.gi-item-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
}
.gi-item-meta {
    font-size: var(--fs-base);
    color: rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
    margin-left: 8px;
}
.gi-more {
    font-size: var(--fs-base);
    color: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    text-align: center;
}
.gi-cluster {
    padding: 6px 8px;
    margin: 3px 0;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.02);
    font-size: var(--fs-base);
}
.gi-cluster-size {
    color: #a08fd1;
    font-weight: 600;
    margin-right: 6px;
}
.gi-cluster-stages {
    color: rgba(255, 255, 255, 0.3);
}
.gi-cluster-preview {
    color: rgba(255, 255, 255, 0.4);
    margin-top: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.gi-cluster-candidate {
    margin-top: 4px;
    font-size: var(--fs-base);
    opacity: 0.8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}
.gi-cluster-candidate:hover {
    opacity: 1;
}
.gi-stage-pill {
    font-size: var(--fs-sm);
    font-weight: 600;
    opacity: 0.8;
    flex-shrink: 0;
}
.gi-pair {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    margin: 2px 0;
    border-radius: 4px;
    font-size: var(--fs-base);
    transition: background 0.15s;
}
.gi-pair:hover {
    background: rgba(255, 255, 255, 0.05);
}
.gi-pair-note {
    color: rgba(255, 255, 255, 0.5);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 90px;
}
.gi-pair-arrow {
    color: rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
}
.gi-pair-score {
    color: #7eb8a4;
    flex-shrink: 0;
    margin-left: auto;
    font-size: var(--fs-base);
}

/* ── SELECTION BAR ── */
#selection-bar {
    display: none;
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 32px);
    max-width: 448px;
    background: #1a1924;
    border: 2px solid rgba(160, 143, 209, 0.5);
    border-radius: 14px;
    padding: 14px;
    z-index: 25;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
#selection-bar.visible {
    display: block;
}
#selection-info {
    font-size: var(--fs-md);
    font-family: var(--font-mono);
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
#selection-count {
    color: #a08fd1;
    font-weight: 700;
    font-size: var(--fs-2xl);
}
#selection-expand {
    font-size: var(--fs-base);
    color: rgba(255, 255, 255, 0.28);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 6px;
    padding: 3px 8px;
    cursor: pointer;
    font-family: var(--font-mono);
    transition: all 0.15s;
}
#selection-expand.active {
    color: var(--literaria);
    background: rgba(160, 143, 209, 0.1);
    border-color: rgba(160, 143, 209, 0.3);
}
#selection-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}
.sel-action-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 10px;
    font-size: var(--fs-lg);
    font-weight: 700;
    font-family: var(--font-mono);
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}
.sel-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.sel-action-btn:active {
    transform: translateY(0);
}
#btn-copy {
    background: rgba(160, 143, 209, 0.12);
    border: 1px solid rgba(160, 143, 209, 0.25) !important;
    color: var(--literaria);
}
#btn-download {
    background: linear-gradient(
        135deg,
        rgba(160, 143, 209, 0.9),
        rgba(160, 143, 209, 0.6)
    );
    color: #0a0a0e;
}

/* Close buttons (small) */
#btn-cancel-sel,
#ea-cancel {
    width: 24px !important;
    height: 24px !important;
    padding: 0 !important;
    flex: none !important;
    border-radius: 6px;
    font-size: var(--fs-2xl);
    background: transparent !important;
    color: rgba(255, 255, 255, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
}
#btn-cancel-sel:hover,
#ea-cancel:hover {
    background: rgba(255, 255, 255, 0.04) !important;
    color: rgba(255, 255, 255, 0.5);
}

/* ── TAB BAR ── */
#tabbar {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    background: rgba(15, 14, 19, 0.96);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 30;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}
.tab-btn {
    flex: 1;
    padding: 11px 0 15px;
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    transition: color 0.2s;
    position: relative;
    font-family: var(--font-mono);
}
.tab-indicator {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 28px;
    height: 2px;
    border-radius: 0 0 2px 2px;
    opacity: 0;
    transition:
        opacity 0.2s,
        background 0.3s;
}
.tab-btn.active .tab-indicator {
    opacity: 1;
}
.tab-icon {
    font-size: var(--fs-4xl);
}
.tab-label {
    font-size: var(--fs-base);
    letter-spacing: 0.5px;
}

/* ── BOTTOM SHEET ── */
#sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 50;
    display: none;
    align-items: flex-end;
}
#sheet-overlay.open {
    display: flex;
}
#sheet {
    width: 100%;
    max-height: 88vh;
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom: none;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
#sheet-overlay.open #sheet {
    transform: translateY(0);
}
#sheet-handle-wrap {
    display: flex;
    justify-content: center;
    padding: 12px 0 0;
}
#sheet-handle {
    width: 36px;
    height: 4px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 2px;
}
#sheet-body {
    padding: 14px 20px 36px;
}
#sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}
#sheet-badge {
    font-size: var(--fs-base);
    font-family: var(--font-mono);
    padding: 3px 10px;
    border-radius: 6px;
    letter-spacing: 1px;
}
#sheet-close {
    background: rgba(255, 255, 255, 0.07);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    color: rgba(255, 255, 255, 0.45);
    cursor: pointer;
    font-size: var(--fs-xl);
    display: flex;
    align-items: center;
    justify-content: center;
}
#sheet-title {
    font-size: var(--fs-6xl);
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 14px;
    font-family: var(--font-serif);
}
#sheet-content {
    font-size: var(--fs-2xl);
    color: rgba(255, 255, 255, 0.7);
    line-height: 1.8;
    margin-bottom: 18px;
    font-family: var(--font-serif);
}
#sheet-source {
    background: rgba(160, 143, 209, 0.07);
    border: 1px solid rgba(160, 143, 209, 0.18);
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 18px;
}
#sheet-source-lbl {
    font-size: var(--fs-base);
    font-family: var(--font-mono);
    color: var(--literaria);
    margin-bottom: 3px;
    letter-spacing: 1px;
}
#sheet-source-val {
    font-size: var(--fs-lg);
    color: rgba(255, 255, 255, 0.55);
}
#sheet-connections-lbl {
    font-size: var(--fs-base);
    font-family: var(--font-mono);
    color: rgba(255, 255, 255, 0.25);
    letter-spacing: 1px;
    margin-bottom: 10px;
}
.sheet-link-item {
    padding: 9px 12px;
    border-radius: 10px;
    margin-bottom: 7px;
}
.sheet-link-lbl {
    font-size: var(--fs-base);
    font-family: var(--font-mono);
    margin-bottom: 3px;
}
.sheet-link-text {
    font-size: var(--fs-3xl);
    color: var(--text);
}
#sheet-ts {
    margin-top: 18px;
    font-size: var(--fs-base);
    font-family: var(--font-mono);
    color: rgba(255, 255, 255, 0.12);
}
#sheet-edit-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 4px 12px;
    color: rgba(255, 255, 255, 0.55);
    font-size: var(--fs-base);
    font-family: var(--font-mono);
    cursor: pointer;
    transition: all 0.2s;
}
#sheet-edit-btn.editing {
    background: rgba(255, 255, 255, 0.03);
    color: rgba(255, 255, 255, 0.25);
}

/* ── EXPORT OVERLAY ── */
#export-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    z-index: 50;
    display: none;
    align-items: flex-end;
}
#export-overlay.open {
    display: flex;
}
#export-sheet {
    width: 100%;
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    padding: 0 0 40px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom: none;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
#export-overlay.open #export-sheet {
    transform: translateY(0);
}
#export-sheet-handle {
    display: flex;
    justify-content: center;
    padding: 12px 0 0;
}
#export-sheet-handle span {
    width: 36px;
    height: 4px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 2px;
    display: block;
}
#export-sheet-body {
    padding: 14px 20px 0;
}
#export-sheet-title {
    font-size: var(--fs-3xl);
    font-weight: 700;
    margin-bottom: 4px;
}
#export-sheet-sub {
    font-size: var(--fs-md);
    color: rgba(255, 255, 255, 0.3);
    font-family: var(--font-mono);
    margin-bottom: 16px;
}
#export-notes-preview {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 14px;
    max-height: 180px;
    overflow-y: auto;
}
.export-note-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    font-size: var(--fs-lg);
}
.export-note-row:last-child {
    border-bottom: none;
}
.export-note-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}
.export-note-name {
    color: rgba(255, 255, 255, 0.65);
    flex: 1;
}
.export-note-origin {
    font-size: var(--fs-sm);
    font-family: var(--font-mono);
    color: rgba(255, 255, 255, 0.18);
}
#export-sheet-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.export-action {
    width: 100%;
    padding: 13px;
    border-radius: 10px;
    border: none;
    font-size: var(--fs-lg);
    font-weight: 700;
    font-family: var(--font-mono);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    transition: all 0.2s;
    letter-spacing: 0.3px;
}
#ea-copy {
    background: rgba(160, 143, 209, 0.1);
    border: 1px solid rgba(160, 143, 209, 0.25) !important;
    color: var(--literaria);
}
#ea-download {
    background: linear-gradient(
        135deg,
        rgba(160, 143, 209, 0.9),
        rgba(160, 143, 209, 0.6)
    );
    color: #0a0a0e;
}
#ea-cancel {
    width: 40px;
    padding: 10px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.07) !important;
    color: rgba(255, 255, 255, 0.25);
    font-weight: 400;
}

/* ── TOAST ── */
#toast {
    position: fixed;
    bottom: 88px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    background: rgba(24, 23, 31, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 7px 18px;
    font-size: var(--fs-lg);
    font-family: var(--font-mono);
    color: rgba(255, 255, 255, 0.75);
    opacity: 0;
    pointer-events: none;
    transition: all 0.22s;
    z-index: 40;
    white-space: nowrap;
}
#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── DESKTOP ── */
@media (min-width: 768px) {
    #app {
        max-width: 100%;
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }
    #header {
        padding: 12px 28px;
    }
    #header-title {
        font-size: var(--fs-3xl);
    }
    #tabbar {
        display: none;
    }
    #nav-pills {
        display: flex;
    }

    #content {
        display: grid;
        grid-template-columns: 280px 1fr 260px;
        grid-template-rows: 1fr;
        flex: 1;
        overflow: hidden;
        padding: 20px;
        gap: 16px;
        padding-bottom: 20px;
    }

    /* ── Left sidebar: stats + connect ── */
    #screen-vault {
        display: flex !important;
        flex-direction: column;
        gap: 12px;
        overflow-y: auto;
        height: 100%;
        order: 1;
    }

    /* Stats row inside vault becomes sidebar stats */
    #screen-vault #vault-stats {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        margin-bottom: 12px;
        flex-shrink: 0;
    }

    /* Notes list scrollable in desktop sidebar */
    #screen-vault #notes-list {
        flex: 1;
        overflow-y: auto;
        min-height: 0;
    }

    /* Hide mobile-only vault elements on desktop */
    #screen-vault #filter-bar,
    #screen-vault #vault-empty,
    #screen-vault::before {
        display: none !important;
    }

    /* ── Center: editor ── */
    #screen-write {
        display: flex !important;
        flex-direction: column;
        overflow-y: auto;
        height: 100%;
        order: 2;
        padding: 0;
    }

    /* Hide mobile-only write elements on desktop */
    #screen-write #stage-bar,
    #screen-write #instruction-card,
    #screen-write::before {
        display: none !important;
    }

    /* Editor card takes full height on desktop */
    #editor-card {
        flex: 1;
        display: flex;
        flex-direction: column;
        margin-bottom: 0;
        border-radius: 14px;
    }
    #editor-body {
        flex: 1;
        display: flex;
        flex-direction: column;
        padding: 24px 28px 0;
        gap: 0;
    }
    #editor-body .field-wrap {
        margin-bottom: 0;
    }
    #editor-body #title-field {
        flex-shrink: 0;
    }
    #editor-body #source-field {
        flex-shrink: 0;
    }
    #editor-body #links-section {
        display: none !important;
    }
    #content-field-wrap {
        flex: 1;
        display: flex;
        flex-direction: column;
    }
    #editor-body textarea {
        flex: 1;
        min-height: 200px;
    }
    #title-input {
        font-size: var(--fs-7xl);
        font-weight: 600;
        background: transparent;
        border: none;
        padding: 0 0 14px 0;
        border-bottom: 1px solid var(--border);
        border-radius: 0;
    }
    #title-input:focus {
        border-color: rgba(255, 255, 255, 0.15);
    }
    #editor-body textarea {
        font-size: var(--fs-4xl);
        background: transparent;
        border: none;
        padding: 16px 0 0;
        border-radius: 0;
        resize: none;
        line-height: 1.8;
    }
    #editor-body textarea:focus {
        border: none;
        box-shadow: none;
    }
    #editor-body .field-label {
        display: none;
    }
    #save-btn {
        margin: 0;
        border-radius: 0 0 14px 14px;
        flex-shrink: 0;
    }

    /* Desktop instruction banner */
    #desktop-instruction-banner {
        display: flex !important;
        flex-direction: column;
        padding: 12px 16px;
        flex-shrink: 0;
        border-bottom: 1px solid var(--border);
    }

    /* Desktop stage bar */
    #desktop-stage-bar {
        display: flex !important;
        gap: 2px;
        padding: 10px 14px;
        border-bottom: 1px solid var(--border);
        background: rgba(0, 0, 0, 0.08);
        flex-shrink: 0;
        border-radius: 14px 14px 0 0;
    }
    .desktop-stage-btn {
        padding: 5px 14px;
        border-radius: 6px;
        font-size: var(--fs-md);
        font-family: var(--font-mono);
        cursor: pointer;
        border: 1px solid transparent;
        background: transparent;
        color: rgba(255, 255, 255, 0.3);
        transition: all 0.2s;
    }

    /* ── Right sidebar ── */
    #desktop-right-sidebar {
        display: flex !important;
        flex-direction: column;
        gap: 12px;
        overflow-y: auto;
        height: 100%;
        order: 3;
    }

    /* Graph full-screen exclusive */
    #screen-graph {
        position: absolute;
        inset: 0;
        top: 57px;
        height: calc(100vh - 57px);
        padding: 0 !important;
        overflow: hidden !important;
        background: var(--bg);
        display: none;
        z-index: 10;
    }
    #screen-graph.active {
        display: flex !important;
    }
    #content.graph-active {
        display: flex !important;
    }
    #content.graph-active #screen-write,
    #content.graph-active #screen-vault,
    #content.graph-active #desktop-right-sidebar {
        display: none !important;
    }

    /* Sheets centered */
    #sheet {
        max-width: 540px;
        margin: 0 auto;
        border-radius: 16px;
    }
    #sheet-overlay {
        align-items: center;
        justify-content: center;
    }
    #sheet-overlay.open #sheet {
        transform: translateY(0);
    }
    #export-sheet {
        max-width: 460px;
        margin: 0 auto;
        border-radius: 16px;
    }
    #export-overlay {
        align-items: center;
        justify-content: center;
    }
    #export-overlay.open #export-sheet {
        transform: translateY(0);
    }

    .note-title {
        font-size: var(--fs-3xl);
    }
    .note-preview {
        font-size: var(--fs-lg);
        -webkit-line-clamp: 2;
    }
    #sheet-title {
        font-size: var(--fs-7xl);
    }
    #sheet-content {
        font-size: var(--fs-3xl);
    }
    .stat-num {
        font-size: var(--fs-6xl);
    }
    .stat-card {
        padding: 10px 6px;
    }
}

@media (min-width: 1200px) {
    #content {
        grid-template-columns: 300px 1fr 280px;
    }
}

@media (min-width: 1400px) {
    #content {
        grid-template-columns: 320px 1fr 300px;
        padding: 24px;
        gap: 20px;
    }
}

/* ── Vault Importer Modal ── */
#vault-import-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.7);
    align-items: center;
    justify-content: center;
}
#vault-import-overlay.open {
    display: flex;
}
#vault-import-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    width: min(480px, 92vw);
    font-family: var(--font-mono);
    max-height: 85vh;
    overflow-y: auto;
}
#vault-drop-zone {
    border: 1px dashed rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 24px;
    text-align: center;
    color: var(--muted);
    font-size: var(--fs-base);
    transition: border-color 0.2s;
    cursor: pointer;
}
#vault-drop-zone:hover {
    border-color: rgba(255, 255, 255, 0.25);
}
.vault-mapping-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
}
.vault-mapping-row input {
    flex: 1;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 5px 10px;
    font-family: var(--font-mono);
    font-size: var(--fs-base);
}
.vault-mapping-row select,
.vault-stage-select {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 5px 8px;
    font-family: var(--font-mono);
    font-size: var(--fs-base);
}
.vault-mapping-row select option,
.vault-stage-select option {
    background: var(--surface);
    color: var(--text);
}
.vault-btn {
    padding: 7px 16px;
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: var(--fs-base);
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    transition: all 0.15s;
}
.vault-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}
.vault-btn-primary {
    background: rgba(160, 143, 209, 0.15);
    border-color: rgba(160, 143, 209, 0.4);
    color: #a08fd1;
}
.vault-btn-primary:hover {
    background: rgba(160, 143, 209, 0.25);
}
.vault-folder-preview {
    font-size: var(--fs-sm);
    color: var(--muted);
    background: rgba(255, 255, 255, 0.02);
    border-left: 2px solid var(--border);
    margin: 2px 0 8px 4px;
    padding: 6px 10px;
    border-radius: 0 4px 4px 0;
    white-space: pre;
    line-height: 1.6;
    font-family: var(--font-mono);
}
