/* ═══════════════════════════════════════════════════════════════
   SANTI.WTF — terminal interface
   ═══════════════════════════════════════════════════════════════ */

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

:root {
    --page-bg: #c0392b;
    --bg: #191919;
    --text: #e0e0e0;
    --text-dim: #8a8a8a;
    --text-bright: #ffffff;
    --accent: #5dd9c1;
    --accent-secondary: #e8a84c;
    --accent-tertiary: #f687b3;
    --link: #5dd9c1;
    --link-hover: #81e6d9;
    --green: #68d391;
    --yellow: #f6e05e;
    --border: #2d2d2d;
    --surface: #232323;
    --error: #fc8181;
    --font: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;

    /* Note stages */
    --seedling: #68d391;
    --growing: #5dd9c1;
    --evergreen: #e8a84c;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.7;
    background: var(--page-bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    padding: 2rem;
    position: relative;
}

/* Film grain texture on red frame */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.04;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='grain'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23grain)'/%3E%3C/svg%3E");
}

/* ─── Terminal Container ───────────────────────────────────────── */
.terminal {
    max-width: 800px;
    margin: 0 auto;
    padding: 0;
    min-height: calc(100vh - 4rem);
    min-height: calc(100dvh - 4rem);
    background: var(--bg);
    border-radius: 12px;
    overflow: hidden;
    box-shadow:
        inset 0 0 80px rgba(0, 0, 0, 0.15),
        0 25px 50px -12px rgba(0, 0, 0, 0.4),
        0 0 40px rgba(93, 217, 193, 0.04);
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
}

/* Terminal title bar (macOS style) */
.terminal::before {
    content: '';
    display: block;
    height: 36px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

/* Traffic light buttons */
.terminal-buttons {
    position: absolute;
    top: 10px;
    left: 12px;
    display: flex;
    gap: 8px;
    z-index: 10;
}

.terminal-btn {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.terminal-btn.red { background: #ff5f56; cursor: pointer; }
.terminal-btn.yellow { background: #ffbd2e; cursor: pointer; }
.terminal-btn.green { background: #27c93f; cursor: pointer; }

.terminal-btn:hover {
    transform: scale(1.1);
    transition: transform 0.15s ease;
}

.terminal-btn:active {
    transform: scale(0.9);
}

/* Traffic light effects */
.terminal.glitch {
    animation: glitchEffect 0.5s ease;
}

@keyframes glitchEffect {
    0% { transform: translate(0); filter: hue-rotate(0deg); }
    10% { transform: translate(-5px, 2px); filter: hue-rotate(90deg); }
    20% { transform: translate(5px, -2px); filter: hue-rotate(180deg); }
    30% { transform: translate(-3px, -1px); filter: hue-rotate(270deg); }
    40% { transform: translate(3px, 1px); filter: hue-rotate(0deg); }
    50% { transform: translate(-2px, 2px); filter: hue-rotate(90deg); }
    60% { transform: translate(2px, -2px); }
    70% { transform: translate(-1px, 1px); }
    80% { transform: translate(1px, -1px); }
    90% { transform: translate(0); }
    100% { transform: translate(0); filter: hue-rotate(0deg); }
}

.terminal.minimize {
    animation: minimizeEffect 0.6s ease;
}

@keyframes minimizeEffect {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(0.1) translateY(100%); opacity: 0.5; }
    51% { transform: scale(0.1) translateY(100%); opacity: 0; }
    52% { transform: scale(0.1) translateY(100%); opacity: 0.5; }
    100% { transform: scale(1); opacity: 1; }
}

.terminal.flash-green {
    animation: flashGreen 0.3s ease;
}

@keyframes flashGreen {
    0% { box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.15), 0 25px 50px -12px rgba(0, 0, 0, 0.4), 0 0 40px rgba(93, 217, 193, 0.04); }
    50% { box-shadow: 0 0 50px rgba(39, 201, 63, 0.6), 0 0 100px rgba(39, 201, 63, 0.3); }
    100% { box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.15), 0 25px 50px -12px rgba(0, 0, 0, 0.4), 0 0 40px rgba(93, 217, 193, 0.04); }
}

/* ─── CRT Bootup Sequence ─────────────────────────────────────── */
.terminal.crt-boot {
    transform: scaleY(0.005);
    filter: brightness(2);
    box-shadow:
        inset 0 0 80px rgba(0, 0, 0, 0.15),
        0 25px 50px -12px rgba(0, 0, 0, 0.4),
        0 0 60px rgba(93, 217, 193, 0.15);
    animation: crtBootExpand 450ms cubic-bezier(0.22, 1.2, 0.36, 1) forwards;
}

@keyframes crtBootExpand {
    0% {
        transform: scaleY(0.005);
        filter: brightness(2);
    }
    60% {
        transform: scaleY(1.02);
        filter: brightness(1.1);
    }
    100% {
        transform: scaleY(1);
        filter: brightness(1);
    }
}

.terminal.crt-boot .terminal-inner {
    opacity: 0;
}

.terminal.crt-booted .terminal-inner {
    animation: crtContentFade 300ms ease forwards;
}

@keyframes crtContentFade {
    from { opacity: 0; }
    to { opacity: 1; }
}


/* Terminal inner content */
.terminal-inner {
    flex: 1;
    padding: 1.5rem 2rem 2rem;
    overflow-y: auto;
}

/* ─── ASCII Banner ─────────────────────────────────────────────── */
.ascii-banner {
    color: var(--accent);
    font-size: 0.85rem;
    line-height: 1.15;
    margin-bottom: 1.5rem;
    white-space: pre;
    overflow-x: auto;
    transition: opacity 0.3s ease, height 0.3s ease, margin 0.3s ease;
}

.ascii-banner.collapsed {
    opacity: 0;
    height: 0;
    margin: 0;
    overflow: hidden;
}

/* ─── Welcome Message ──────────────────────────────────────────── */
.welcome {
    margin-bottom: 2rem;
    min-height: 4.5rem;
}

.welcome p {
    margin-bottom: 0.5rem;
}

.welcome .greeting {
    color: var(--accent);
}

.welcome .hint {
    color: var(--text-dim);
}

.welcome .hl {
    color: var(--accent);
}

/* Typing cursor */
.typing-cursor {
    display: inline-block;
    width: 0.6em;
    height: 1.1em;
    background: var(--accent);
    margin-left: 2px;
    animation: blink 0.8s step-end infinite;
    vertical-align: text-bottom;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* ─── Output Area ──────────────────────────────────────────────── */
.output {
    min-height: 200px;
}

/* Command echo */
.cmd-echo {
    color: var(--text-dim);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.cmd-echo .prompt {
    color: var(--accent);
}

/* System messages */
.system-msg {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.error {
    color: var(--error);
}

/* ─── Slash Menu ───────────────────────────────────────────────── */
.slash-menu {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.slash-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-dim);
    cursor: pointer;
    padding: 0.25rem 0;
    transition: color 0.15s ease, transform 0.1s ease;
    opacity: 0;
    animation: slashMenuFadeIn 0.2s ease forwards;
}

.slash-menu-item:nth-child(1) { animation-delay: 0ms; }
.slash-menu-item:nth-child(2) { animation-delay: 30ms; }
.slash-menu-item:nth-child(3) { animation-delay: 60ms; }
.slash-menu-item:nth-child(4) { animation-delay: 90ms; }
.slash-menu-item:nth-child(5) { animation-delay: 120ms; }
.slash-menu-item:nth-child(6) { animation-delay: 150ms; }

@keyframes slashMenuFadeIn {
    from {
        opacity: 0;
        transform: translateX(-8px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.slash-menu-item:hover {
    color: var(--text);
}

.slash-menu-item:active {
    transform: scale(0.98);
}

.slash-menu-item.selected {
    color: var(--accent);
}

.menu-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: transparent;
    transition: all 0.15s ease;
}

.slash-menu-item.selected .menu-dot {
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent), 0 0 12px var(--accent);
}

.slash-menu-empty {
    color: var(--text-dim);
    font-style: italic;
    padding: 0.25rem 0;
}

/* ─── Help Section ─────────────────────────────────────────────── */
.help-block {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--surface);
    border-left: 3px solid var(--accent);
    animation: fadeIn 0.3s ease;
}

.help-title {
    color: var(--accent);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 1rem;
}

.help-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.5rem 1.5rem;
}

.help-cmd {
    color: var(--text-bright);
}

.help-desc {
    color: var(--text-dim);
}

/* ─── Note List ────────────────────────────────────────────────── */
.note-list {
    list-style: none;
    margin-bottom: 1.5rem;
    animation: fadeIn 0.3s ease;
}

.note-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
}

.note-list li:last-child {
    border-bottom: none;
}

.note-list a {
    color: var(--link);
    text-decoration: none;
    transition: color 0.15s ease, text-shadow 0.15s ease;
}

.note-list a:hover {
    color: var(--link-hover);
    text-shadow: 0 0 8px var(--accent), 0 0 12px rgba(93, 217, 193, 0.4);
}

.note-list .meta {
    color: var(--text-dim);
    font-size: 0.8rem;
    white-space: nowrap;
}

.note-list .stage-seedling { color: var(--green); }
.note-list .stage-growing { color: var(--accent); }
.note-list .stage-evergreen { color: var(--accent-secondary); }

.list-count {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin-top: 1rem;
}

/* Collection badge */
.collection-badge {
    color: var(--accent-secondary);
    font-size: 0.75rem;
    padding: 0.1rem 0.4rem;
    background: var(--surface);
    border-radius: 3px;
    margin-right: 0.5rem;
}

/* ─── Note Content ─────────────────────────────────────────────── */
.note-view {
    margin-bottom: 3rem;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Cinematic staggered reveal */
.note-view.cinematic {
    animation: none;
}

.note-view.cinematic .note-box {
    opacity: 0;
    animation: noteReveal 350ms ease forwards;
    animation-delay: 0ms;
}

.note-view.cinematic .note-body {
    opacity: 0;
    animation: noteReveal 400ms ease forwards;
    animation-delay: 120ms;
}

.note-view.cinematic .note-footer {
    opacity: 0;
    animation: noteReveal 350ms ease forwards;
    animation-delay: 220ms;
}

@keyframes noteReveal {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Note header box */
.note-box {
    border: 1px solid var(--border);
    margin-bottom: 2rem;
}

.note-box-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.note-box-title {
    color: var(--text-bright);
    font-size: 1.1rem;
    font-weight: 500;
}

.note-box-stage {
    font-size: 0.85rem;
}

.note-box-stage.seedling { color: var(--green); }
.note-box-stage.growing { color: var(--accent); }
.note-box-stage.evergreen { color: var(--accent-secondary); }

.note-box-meta {
    padding: 0.75rem 1rem;
    color: var(--text-dim);
    font-size: 0.85rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
}

.note-tags {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.note-tag {
    color: var(--accent-tertiary);
}

/* Note Body */
.note-body {
    color: var(--text);
    font-size: 1rem;
    line-height: 1.85;
}

.note-body h1,
.note-body h2,
.note-body h3,
.note-body h4 {
    color: var(--text-bright);
    font-weight: 500;
    margin: 3rem 0 1rem;
    line-height: 1.3;
}

.note-body h1 { font-size: 1.5rem; }
.note-body h2 { font-size: 1.35rem; color: var(--accent-secondary); }
.note-body h3 { font-size: 1.15rem; color: var(--accent); }
.note-body h4 { font-size: 1rem; color: var(--text-dim); }

.note-body p {
    margin-bottom: 1.25rem;
}

.note-body a {
    color: var(--link);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.15s ease, text-shadow 0.15s ease;
}

.note-body a:hover {
    border-bottom-color: var(--link);
    text-shadow: 0 0 8px var(--accent), 0 0 12px rgba(93, 217, 193, 0.4);
}

/* Wikilinks styled as [link] */
.note-body a.wikilink {
    color: var(--accent-tertiary);
    border-bottom: none;
    transition: color 0.15s ease, text-shadow 0.15s ease;
}

.note-body a.wikilink:hover {
    color: var(--text-bright);
    text-shadow: 0 0 8px var(--accent-tertiary), 0 0 12px rgba(246, 135, 179, 0.4);
}

.note-body a.wikilink::before {
    content: '[';
    color: var(--text-dim);
}

.note-body a.wikilink::after {
    content: ']';
    color: var(--text-dim);
}

.wikilink-private {
    color: var(--text-dim);
    font-style: italic;
}

/* ─── Wikilink Preview Tooltip ─────────────────────────────────── */
.wikilink-preview {
    position: fixed;
    max-width: 300px;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.wikilink-preview.visible {
    opacity: 1;
    transform: translateY(0);
}

.wikilink-preview-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent-tertiary);
    margin-bottom: 0.35rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.wikilink-preview-stage {
    font-size: 0.75rem;
}

.wikilink-preview-excerpt {
    font-size: 0.8rem;
    color: var(--text-dim);
    line-height: 1.5;
}

/* Hide on touch devices */
@media (hover: none) {
    .wikilink-preview {
        display: none;
    }
}

.note-body strong {
    color: var(--text-bright);
    font-weight: 500;
}

.note-body em {
    font-style: italic;
    color: var(--text);
}

.note-body ul,
.note-body ol {
    margin: 1.25rem 0;
    padding-left: 2rem;
}

.note-body li {
    margin-bottom: 0.6rem;
    padding-left: 0.25rem;
}

.note-body li::marker {
    color: var(--accent-tertiary);
}

.note-body blockquote {
    margin: 1.5rem 0;
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-left: 4px solid var(--accent);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-style: italic;
    font-size: 1.05em;
}

.note-body blockquote p:last-child {
    margin-bottom: 0;
}

.note-body code {
    background: var(--surface);
    color: var(--yellow);
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    font-size: 0.9em;
}

.note-body pre {
    background: var(--surface);
    padding: 1.25rem;
    border-radius: 4px;
    overflow-x: auto;
    margin: 1.5rem 0;
    border: 1px solid var(--border);
}

.note-body pre code {
    background: none;
    padding: 0;
    color: var(--text);
}

.note-body hr {
    border: none;
    margin: 2.5rem 0;
    text-align: center;
    line-height: 0;
}

.note-body hr::after {
    content: '· · ·';
    color: var(--text-dim);
    font-size: 1.2rem;
    letter-spacing: 0.5em;
}

.note-body img {
    max-width: 100%;
    border-radius: 4px;
    margin: 1.5rem 0;
}

/* Note Footer */
.note-footer {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 0.85rem;
}

.note-footer a {
    color: var(--link);
    text-decoration: none;
    transition: text-shadow 0.15s ease;
}

.note-footer a:hover {
    text-decoration: underline;
    text-shadow: 0 0 8px var(--accent), 0 0 12px rgba(93, 217, 193, 0.4);
}

.backlinks {
    margin-top: 1rem;
}

.backlinks-title {
    color: var(--text-dim);
    margin-bottom: 0.5rem;
}

.backlinks-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.backlinks-list li {
    border-left: 3px solid var(--accent);
    border-radius: 3px;
    transition: box-shadow 0.15s ease;
}

.backlinks-list li.backlink-seedling { border-left-color: var(--seedling); }
.backlinks-list li.backlink-growing { border-left-color: var(--growing); }
.backlinks-list li.backlink-evergreen { border-left-color: var(--evergreen); }

.backlinks-list li:hover {
    box-shadow: 0 0 12px rgba(93, 217, 193, 0.15);
}

.backlinks-list a {
    color: var(--link);
    padding: 0.35rem 0.6rem;
    background: var(--surface);
    border-radius: 0 3px 3px 0;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    transition: text-shadow 0.15s ease, background 0.15s ease;
}

.backlinks-list a:hover {
    text-shadow: 0 0 8px var(--accent), 0 0 12px rgba(93, 217, 193, 0.4);
    background: var(--border);
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-dim);
    transition: color 0.15s ease, transform 0.1s ease;
    cursor: pointer;
}

.back-link:hover {
    color: var(--accent-tertiary);
}

.back-link:active {
    transform: scale(0.97);
}

/* ─── About Page ───────────────────────────────────────────────── */
.about-view {
    animation: fadeIn 0.3s ease;
}

.about-view h1 {
    color: var(--text-bright);
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
}

.about-view p {
    margin-bottom: 1rem;
    color: var(--text);
}

.about-view .highlight {
    color: var(--accent);
}

.about-links {
    margin-top: 2rem;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.about-links a {
    color: var(--link);
    text-decoration: none;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    transition: border-color 0.15s ease, transform 0.1s ease, text-shadow 0.15s ease;
}

.about-links a:hover {
    border-color: var(--accent);
    text-shadow: 0 0 8px var(--accent), 0 0 12px rgba(93, 217, 193, 0.4);
}

.about-links a:active {
    transform: scale(0.97);
}

/* ─── Now Page ─────────────────────────────────────────────────── */
.now-view {
    animation: fadeIn 0.3s ease;
}

.now-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.now-header h1 {
    color: var(--text-bright);
    font-size: 1.25rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.now-grid {
    display: grid;
    gap: 1rem;
    margin-bottom: 2rem;
}

.now-card {
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.now-card-label {
    color: var(--text-dim);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
}

.now-card-value {
    color: var(--text-bright);
}

.now-card-value a {
    color: var(--link);
    text-decoration: none;
}

/* ─── Letters (Newsletter) ────────────────────────────────────────── */
.letters-view {
    animation: fadeIn 0.3s ease;
}

.letters-view h1 {
    color: var(--text-bright);
    font-size: 1.25rem;
    margin-bottom: 1rem;
}

.letters-view p {
    color: var(--text);
    margin-bottom: 0.75rem;
}

.letters-form {
    margin-top: 2rem;
    padding: 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.letters-input-line {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
}

.letters-prompt {
    color: var(--accent);
}

.letters-input {
    color: var(--text-bright);
    flex: 1;
}

.letters-form .cursor {
    display: inline-block;
    width: 10px;
    height: 1.2em;
    background-color: var(--accent);
    animation: blink 1s step-end infinite;
}

.letters-hint {
    color: var(--text-dim);
    font-size: 0.8rem;
    margin-top: 1rem;
    margin-bottom: 0;
}

.letters-success {
    color: var(--green);
}

.letters-error {
    color: var(--error);
}

/* ─── Inline Prompt ────────────────────────────────────────────── */
.inline-prompt {
    margin-top: 1.5rem;
    min-height: 1.5em;
}

.prompt-line {
    display: flex;
    align-items: center;
    margin-bottom: 0.75rem;
}

.inline-prompt .cursor {
    display: inline-block;
    width: 10px;
    height: 1.2em;
    background-color: var(--accent);
    animation: blink 1s step-end infinite;
    vertical-align: middle;
}

.inline-prompt .placeholder {
    color: var(--text-dim);
    vertical-align: middle;
    transition: opacity 0.15s ease;
}

.inline-prompt .placeholder.hint-fade {
    opacity: 0;
}

.inline-prompt .typed {
    color: var(--text);
    vertical-align: middle;
}

/* ─── Mobile Command Palette ───────────────────────────────────── */
.command-palette {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg);
    border-top: 1px solid var(--border);
    padding: 0.5rem 1rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
    z-index: 101;
    justify-content: space-around;
    border-radius: 0 0 12px 12px;
}

.command-palette button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    padding: 0.5rem 0.75rem;
    min-height: 40px;
    min-width: 40px;
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-family: inherit;
    font-size: 0.65rem;
    cursor: pointer;
    transition: color 0.15s ease, transform 0.1s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.command-palette button:hover {
    color: var(--accent-tertiary);
}

.command-palette button:active {
    color: var(--accent-tertiary);
    transform: scale(0.95);
}

.palette-icon {
    font-size: 1.1rem;
}

/* More menu overlay */
.more-menu {
    position: fixed;
    bottom: calc(3.5rem + env(safe-area-inset-bottom, 0px));
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 1rem;
    padding-left: calc(1rem + env(safe-area-inset-left, 0px));
    padding-right: calc(1rem + env(safe-area-inset-right, 0px));
    z-index: 102;
    display: none;
    animation: slideUp 0.2s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.more-menu.visible {
    display: block;
}

.more-menu-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.more-menu button {
    padding: 0.875rem 1rem;
    min-height: 44px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s ease, transform 0.1s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.more-menu button:hover {
    border-color: var(--accent);
}

.more-menu button:active {
    transform: scale(0.97);
}

/* ─── Loading ──────────────────────────────────────────────────── */
.loading {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 200;
}

.loading.hidden {
    display: none;
}

.loading-dots::after {
    content: '...';
    animation: dots 1.2s steps(4, end) infinite;
    color: var(--accent);
    font-size: 1.5rem;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* ─── Graph Transitions ───────────────────────────────────────── */
.terminal-inner.graph-transition-out {
    transform: scale(0.95);
    opacity: 0;
    transition: transform 250ms ease, opacity 250ms ease;
}

/* ─── Graph Overlay ────────────────────────────────────────────── */
.graph-overlay {
    display: none;
    position: absolute;
    top: 36px;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    z-index: 500;
    opacity: 0;
    transition: opacity 300ms ease-out;
    transform: scale(1);
}

.graph-overlay.graph-zoom-in {
    animation: graphZoomIn 300ms ease forwards;
}

@keyframes graphZoomIn {
    from {
        opacity: 0;
        transform: scale(1.05);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.graph-overlay #graph-canvas {
    width: 100%;
    height: 100%;
    touch-action: none;
}

.graph-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-dim);
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.graph-close:hover {
    color: var(--text);
    border-color: var(--accent);
}

.graph-close:active {
    transform: scale(0.95);
}

/* ─── Matrix Easter Egg ────────────────────────────────────────── */
.matrix-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    pointer-events: none;
}

.matrix-canvas.hidden {
    display: none;
}

/* ─── Scrollbar ────────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}

/* ─── Selection ────────────────────────────────────────────────── */
::selection {
    background: var(--accent-tertiary);
    color: var(--bg);
}

/* ─── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
    body {
        padding: 1rem;
    }

    .terminal {
        min-height: calc(100vh - 2rem);
        min-height: calc(100dvh - 2rem);
        border-radius: 10px;
    }

    .terminal-inner {
        padding: 1.25rem 1.5rem;
        padding-bottom: calc(4rem + env(safe-area-inset-bottom, 0px));
    }

    .ascii-banner {
        font-size: 0.65rem;
    }

    .command-palette {
        display: flex;
    }

    /* Improve touch targets for links */
    .note-list a {
        padding: 0.25rem 0;
    }

    .slash-menu-item {
        padding: 0.5rem 0;
        min-height: 44px;
    }

    /* Graph close button */
    .graph-close {
        width: 44px;
        height: 44px;
    }

    /* Newsletter whisper - thumb-reachable zone on mobile */
    .newsletter-whisper {
        bottom: 35%;
        right: 1rem;
        flex-direction: column-reverse;
        align-items: flex-end;
        gap: 0.5rem;
    }

    .whisper-envelope {
        font-size: 3rem;
    }

    .newsletter-whisper .whisper-message {
        transform: translateY(-10px) scale(0.95);
    }

    .newsletter-whisper.expanded .whisper-message {
        transform: translateY(0) scale(1);
    }
}

@media (max-width: 480px) {
    body {
        padding: 0;
    }

    .terminal {
        min-height: 100vh;
        min-height: 100dvh;
        border-radius: 0;
        padding-top: env(safe-area-inset-top, 0px);
    }

    .terminal::before {
        display: none;
    }

    .terminal-buttons {
        display: none;
    }

    .terminal-inner {
        padding: 1rem;
        padding-bottom: calc(4rem + env(safe-area-inset-bottom, 0px));
        padding-left: calc(1rem + env(safe-area-inset-left, 0px));
        padding-right: calc(1rem + env(safe-area-inset-right, 0px));
    }

    .ascii-banner {
        font-size: 0.5rem;
        margin-bottom: 1rem;
    }

    .help-grid {
        grid-template-columns: 1fr;
        gap: 0.25rem;
    }

    .help-desc {
        margin-bottom: 0.75rem;
        padding-left: 1rem;
    }

    .note-box-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .note-list li {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .command-palette {
        border-radius: 0;
        padding-left: calc(0.5rem + env(safe-area-inset-left, 0px));
        padding-right: calc(0.5rem + env(safe-area-inset-right, 0px));
    }

    /* Graph overlay - fixed position on mobile for full coverage */
    .graph-overlay {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        padding-top: env(safe-area-inset-top, 0px);
        border-radius: 0;
    }

    /* Improve touch targets for note list */
    .note-list a {
        display: inline-block;
        padding: 0.5rem 0;
        min-height: 44px;
        line-height: 1.5;
    }

    /* Ensure backlinks are tappable */
    .backlinks-list a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        padding: 0.5rem 0.75rem;
    }
}

/* ─── Focus States ─────────────────────────────────────────────── */
a:focus-visible,
button:focus-visible,
input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ─── Easter Eggs ──────────────────────────────────────────────── */
.easter-egg {
    animation: fadeIn 0.3s ease;
    margin-bottom: 2rem;
}

.ascii-art {
    color: var(--accent);
    font-size: 0.8rem;
    line-height: 1.2;
    margin-bottom: 1rem;
}

.ascii-art.coffee {
    color: #d4a574;
}

.ascii-art.cowsay {
    color: var(--text);
}

.fortune-text {
    color: var(--accent-secondary);
    font-style: italic;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.fortune-attr {
    color: var(--text-dim);
    font-size: 0.85rem;
}

.text-dim {
    color: var(--text-dim);
}

/* Hack animation */
.hack-output {
    font-family: var(--font);
}

.hack-line {
    color: var(--green);
    margin-bottom: 0.25rem;
    animation: hackType 0.1s ease;
}

@keyframes hackType {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Vim trap */
.vim-trap {
    font-family: var(--font);
}

.vim-screen {
    color: var(--text-dim);
    font-size: 0.9rem;
    line-height: 1.4;
    margin-bottom: 0;
}

.vim-status {
    color: var(--text);
    background: var(--surface);
    padding: 0.25rem 0.5rem;
    margin-top: 0;
}

.vim-command {
    display: flex;
    align-items: center;
    padding: 0.25rem 0;
}

.vim-input {
    color: var(--text);
}

.vim-escape-btn {
    display: block;
    margin: 2rem auto 0;
    padding: 1rem 2rem;
    background: var(--surface);
    border: 2px solid var(--accent);
    border-radius: 8px;
    color: var(--accent);
    font-family: var(--font);
    font-size: 1.25rem;
    cursor: pointer;
    transition: all 0.15s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.vim-escape-btn:active {
    background: var(--accent);
    color: var(--bg);
    transform: scale(0.95);
}

/* Snake game (konami code easter egg) */
.snake-game {
    animation: fadeIn 0.3s ease;
}

.snake-ascii {
    color: var(--accent);
    font-size: 0.75rem;
    line-height: 1.15;
    margin-bottom: 1.5rem;
}

.snake-main {
    display: flex;
    gap: 2rem;
    margin-bottom: 0.75rem;
}

.snake-board {
    color: var(--accent);
    font-size: 1rem;
    line-height: 1.05;
}

.snake-sidebar {
    min-width: 100px;
}

.snake-highscores {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.highscores-title {
    color: var(--accent-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.highscores-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.highscore-entry {
    color: var(--text-dim);
    font-size: 0.85rem;
}

.highscore-rank {
    color: var(--text-dim);
    margin-right: 0.5rem;
}

.snake-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.snake-controls {
    color: var(--text-dim);
    font-size: 0.85rem;
}

.snake-score {
    color: var(--text-dim);
    font-size: 0.85rem;
}

.snake-game-over {
    color: var(--error);
}

.snake-new-highscore {
    color: var(--yellow);
}

/* Snake D-pad for touch devices */
.snake-dpad {
    display: grid;
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(3, 52px);
    gap: 4px;
    margin-top: 1.5rem;
    justify-content: center;
}

.dpad-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--accent);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.dpad-btn:active {
    background: var(--accent);
    color: var(--bg);
    transform: scale(0.95);
}

.dpad-btn.dpad-center {
    background: transparent;
    border: none;
    cursor: default;
}

.dpad-btn.dpad-up {
    grid-column: 2;
    grid-row: 1;
}

.dpad-btn.dpad-left {
    grid-column: 1;
    grid-row: 2;
}

.dpad-btn.dpad-center {
    grid-column: 2;
    grid-row: 2;
}

.dpad-btn.dpad-right {
    grid-column: 3;
    grid-row: 2;
}

.dpad-btn.dpad-down {
    grid-column: 2;
    grid-row: 3;
}

@media (max-width: 480px) {
    .snake-ascii {
        font-size: 0.5rem;
    }

    .snake-main {
        flex-direction: column;
        gap: 1rem;
    }

    .snake-board {
        font-size: 0.7rem;
    }

    .snake-sidebar {
        display: none;
    }

    .snake-dpad {
        grid-template-columns: repeat(3, 60px);
        grid-template-rows: repeat(3, 60px);
    }

    .dpad-btn {
        font-size: 1.75rem;
    }
}

/* ─── Command Execution Flash ──────────────────────────────────── */
.terminal-inner.cmd-flash {
    animation: cmdFlash 0.3s ease;
}

@keyframes cmdFlash {
    0% { background: var(--bg); }
    15% { background: rgba(93, 217, 193, 0.05); }
    100% { background: var(--bg); }
}

/* ─── Newsletter Whisper ───────────────────────────────────────── */
.newsletter-whisper {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 150;
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
    pointer-events: none;
}

.newsletter-whisper.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.newsletter-whisper.hidden { display: none; }

.whisper-envelope {
    font-size: 3.5rem;
    cursor: pointer;
    animation: envelopeFloat 3s ease-in-out infinite, envelopeGlow 2s ease-in-out infinite;
    transition: transform 0.2s ease;
    filter: drop-shadow(0 0 8px var(--accent));
}

.whisper-envelope:hover {
    transform: scale(1.15) rotate(-5deg);
    animation-play-state: paused;
}

@keyframes envelopeFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-6px) rotate(2deg); }
    75% { transform: translateY(-3px) rotate(-2deg); }
}

@keyframes envelopeGlow {
    0%, 100% { filter: drop-shadow(0 0 6px var(--accent)); }
    50% { filter: drop-shadow(0 0 16px var(--accent)) drop-shadow(0 0 24px rgba(93, 217, 193, 0.4)); }
}

.whisper-message {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    opacity: 0;
    transform: translateX(10px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    position: relative;
}

.newsletter-whisper.expanded .whisper-message {
    opacity: 1;
    transform: translateX(0) scale(1);
    pointer-events: auto;
}

.whisper-text {
    color: var(--text);
    font-size: 0.9rem;
    white-space: nowrap;
}

.whisper-form {
    display: flex;
    gap: 0.5rem;
}

.whisper-input {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.4rem 0.6rem;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
    width: 160px;
    outline: none;
    transition: border-color 0.2s ease;
}

.whisper-input:focus {
    border-color: var(--accent);
    caret-color: var(--accent);
}

.whisper-input::placeholder {
    color: var(--text-dim);
}

.whisper-submit {
    background: var(--accent);
    border: none;
    border-radius: 4px;
    padding: 0.4rem 0.75rem;
    color: var(--bg);
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
}

.whisper-submit:hover {
    background: var(--link-hover);
}

.whisper-submit:active {
    transform: scale(0.95);
}

.whisper-status {
    font-size: 0.8rem;
    display: none;
}

.whisper-status.success {
    display: block;
    color: var(--green);
}

.whisper-status.error {
    display: block;
    color: var(--error);
}

.whisper-dismiss {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.2s ease, color 0.2s ease;
}

.whisper-dismiss:hover {
    opacity: 1;
    color: var(--error);
}

/* ─── Utilities ────────────────────────────────────────────────── */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Ensure hidden input stays hidden */
#command-input {
    opacity: 0;
    pointer-events: none;
}

/* ─── Reduced Motion Support ───────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .typing-cursor {
        animation: none;
        opacity: 1;
    }

    .status-dot {
        animation: none;
        opacity: 1;
    }

    .loading-dots::after {
        animation: none;
        content: '...';
    }

    .slash-menu-item {
        opacity: 1;
        animation: none;
    }

    .terminal-inner.cmd-flash {
        animation: none;
    }

    .whisper-envelope {
        animation: none;
        filter: drop-shadow(0 0 8px var(--accent));
    }

    /* CRT boot: skip entirely */
    .terminal.crt-boot {
        transform: none !important;
        filter: none !important;
        animation: none !important;
    }

    .terminal.crt-boot .terminal-inner {
        opacity: 1 !important;
    }

    .terminal.crt-booted .terminal-inner {
        animation: none !important;
        opacity: 1 !important;
    }

    /* Staggered reveal: show immediately */
    .note-view.cinematic .note-box,
    .note-view.cinematic .note-body,
    .note-view.cinematic .note-footer {
        opacity: 1 !important;
        animation: none !important;
    }

    /* Graph transitions: instant */
    .terminal-inner.graph-transition-out {
        transform: none !important;
        opacity: 1 !important;
        transition: none !important;
    }

    .graph-overlay.graph-zoom-in {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }

    html {
        scroll-behavior: auto;
    }
}
