:root {
    /* --- TOKYO NIGHT PALETTE --- */
    --bg: #24283b;
    --bg-dark: #1f2335;
    --fg: #c0caf5;
    --comment: #565f89;
    --blue: #7aa2f7;
    --cyan: #7dcfff;
    --purple: #bb9af7;
    --orange: #ff9e64;
    --yellow: #e0af68;
    --green: #9ece6a;
    --red: #f7768e;
    --magenta: #ff007c;
    --line-nr: #3b4261;
    --selection: #2e3c64;
    --status-bg: #16161e;

    /* --- DIMENSIONS --- */
    --header-h: 36px;
    --footer-h: 24px;
    --cmd-h: 28px;
    --font-size: 14px;
    --line-height: 24px;
}

/* --- GRUVBOX THEME --- */
[data-theme="gruvbox"] {
    --bg: #282828;
    --bg-dark: #1d2021;
    --fg: #ebdbb2;
    --comment: #928374;
    --blue: #83a598;
    --cyan: #8ec07c;
    --purple: #d3869b;
    --orange: #fe8019;
    --yellow: #fabd2f;
    --green: #b8bb26;
    --red: #fb4934;
    --magenta: #d3869b;
    --line-nr: #504945;
    --selection: #504945;
    --status-bg: #32302f;
}

/* --- DRACULA THEME (Vampire) --- */
[data-theme="dracula"] {
    --bg: #282a36;
    --bg-dark: #21222c;
    --fg: #f8f8f2;
    --comment: #6272a4;
    --blue: #8be9fd;
    --cyan: #8be9fd;
    --purple: #bd93f9;
    --orange: #ffb86c;
    --yellow: #f1fa8c;
    --green: #50fa7b;
    --red: #ff5555;
    --magenta: #ff79c6;
    --line-nr: #44475a;
    --selection: #44475a;
    --status-bg: #191a21;
}

/* --- CYBERPUNK THEME --- */
[data-theme="cyberpunk"] {
    --bg: #050505;
    --bg-dark: #000000;
    --fg: #e0e0e0;
    --comment: #5e5e5e;
    --blue: #00f3ff;
    --cyan: #00f3ff;
    --purple: #bc13fe;
    --orange: #ff9e00;
    --yellow: #f7f700;
    --green: #00ff9f;
    --red: #ff0055;
    --magenta: #ff0099;
    --line-nr: #333333;
    --selection: #222222;
    --status-bg: #111111;
}

* {
    box-sizing: border-box;
}

html {
    height: 100%;
    width: 100%;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg);
    color: var(--fg);
    font-family: 'JetBrains Mono', monospace;
    font-size: var(--font-size);
    line-height: var(--line-height);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* --- VISUAL FX --- */

.scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(to bottom, rgba(255,255,255,0), rgba(255,255,255,0) 50%, rgba(0,0,0,0.1) 50%, rgba(0,0,0,0.1));
    background-size: 100% 4px;
    pointer-events: none;
    z-index: 999;
    opacity: 0.6;
}

.glow-text {
    text-shadow: 0 0 2px rgba(122, 162, 247, 0.3);
}

/* --- LAYOUT --- */

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    z-index: 1;
    padding-bottom: env(safe-area-inset-bottom);
}

.workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* --- BUFFER BAR --- */

.buffer-bar {
    background-color: var(--bg-dark);
    height: var(--header-h);
    display: flex;
    align-items: flex-end;
    padding-left: 0;
    overflow-x: auto;
    flex-shrink: 0;
    white-space: nowrap;
    border-bottom: 1px solid #111;
    scrollbar-width: none;
}

.buffer-bar::-webkit-scrollbar {
    display: none;
}

.tab {
    background-color: var(--bg-dark);
    color: var(--comment);
    padding: 5px 15px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    border-right: 1px solid #111;
    font-size: 0.8rem;
    height: 100%;
    user-select: none;
    min-width: 120px;
    transition: background 0.1s;
    line-height: normal;
}

.tab:hover {
    background-color: var(--bg);
}

.tab.active {
    background-color: var(--bg);
    color: var(--fg);
    border-top: 2px solid var(--blue);
}

.tab-close {
    font-size: 0.7rem;
    margin-left: auto;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.tab-close:hover {
    background: var(--red);
    color: #fff;
}

/* --- SIDEBAR --- */

.nvim-tree {
    width: 240px;
    background-color: var(--bg-dark);
    display: flex;
    flex-direction: column;
    padding: 10px;
    border-right: 1px solid #111;
    transition: transform 0.2s ease;
    font-size: 0.9rem;
}

.tree-header {
    color: var(--blue);
    font-weight: bold;
    margin-bottom: 15px;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 1px;
    margin-top: 10px;
    line-height: normal;
}

.file-node {
    padding: 4px 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--comment);
    border-radius: 4px;
    margin-bottom: 2px;
    transition: 0.1s;
    line-height: normal;
}

.file-node:hover {
    color: var(--fg);
    background: rgba(255,255,255,0.03);
}

.file-node.active {
    color: #fff;
    background-color: var(--selection);
}

/* --- EDITOR --- */

.editor-container {
    flex: 1;
    display: flex;
    background-color: var(--bg);
    position: relative;
    overflow: hidden;
}

.gutter {
    width: 50px;
    background: var(--bg);
    color: var(--line-nr);
    text-align: right;
    padding-right: 15px;
    padding-top: 20px;
    user-select: none;
    overflow: hidden;
    height: 100%;
    box-sizing: border-box;
}

.content-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 20px 20px 20px 5px;
    scroll-behavior: smooth;
    outline: none;
}

/* --- MARKDOWN --- */

.markdown-body {
    font-size: var(--font-size);
    line-height: var(--line-height);
}

.markdown-body * {
    font-size: var(--font-size) !important;
    line-height: var(--line-height) !important;
    margin: 0;
    padding: 0;
    font-weight: normal;
}

.markdown-body > *:first-child {
    margin-top: 0 !important;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body pre,
.markdown-body blockquote {
    margin-bottom: var(--line-height);
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
    font-weight: bold;
    margin-top: var(--line-height);
    margin-bottom: var(--line-height);
}

.markdown-body h1 { color: var(--red); }
.markdown-body h2 { color: var(--yellow); }
.markdown-body h3 { color: var(--green); }

.markdown-body blockquote {
    border-left: 3px solid var(--purple);
    padding-left: 15px;
    color: var(--comment);
    font-style: italic;
}

.markdown-body blockquote p {
    margin-bottom: 0;
}

.markdown-body ul,
.markdown-body ol {
    padding-left: 20px;
}

.markdown-body li {
    margin-bottom: 0;
}

.markdown-body li::marker {
    color: var(--purple);
}

.markdown-body a {
    color: var(--cyan);
    text-decoration: none;
    border-bottom: 1px dashed var(--cyan);
}

.markdown-body a:hover {
    background: var(--selection);
}

.markdown-body code {
    font-family: 'JetBrains Mono', monospace;
    background: #1f2335;
    padding: 0 4px;
    border-radius: 4px;
    color: var(--green);
}

.markdown-body pre {
    background: #1f2335;
    padding: 10px;
    border-radius: 4px;
    overflow-x: auto;
    color: var(--fg);
}

.markdown-body img {
    max-width: 100%;
    display: block;
    margin-bottom: var(--line-height);
    border: 2px solid var(--line-nr);
    cursor: zoom-in;
    transition: transform 0.2s, border-color 0.2s;
}

.markdown-body img:hover {
    transform: scale(1.02);
    border-color: var(--blue);
    box-shadow: 0 0 15px rgba(122, 162, 247, 0.1);
}

/* --- STATUS & COMMAND --- */

.status-line {
    height: var(--footer-h);
    background-color: var(--status-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    user-select: none;
    line-height: normal;
}

.segment {
    padding: 0 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    height: 100%;
}

.mode-normal { background: var(--blue); color: #1a1b26; font-weight: bold; }
.mode-command { background: var(--orange); color: #1a1b26; font-weight: bold; }
.seg-dark { background: #3b4261; color: var(--fg); }
.seg-light { background: transparent; color: var(--comment); }

.cmd-bar {
    height: var(--cmd-h);
    display: flex;
    align-items: center;
    padding: 0 10px;
    border-top: 1px solid #111;
    background: var(--bg);
    line-height: normal;
}

.cmd-input {
    background: transparent;
    border: none;
    color: var(--fg);
    width: 100%;
    outline: none;
    font-family: inherit;
    font-size: 0.9rem;
    display: none;
}

/* --- MOBILE SPECIFIC --- */

.mobile-toggle {
    display: none;
    position: absolute;
    bottom: 80px;
    right: 20px;
    background: var(--blue);
    color: #000;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    z-index: 50;
}

@media (max-width: 768px) {
    .nvim-tree {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 20;
        transform: translateX(-100%);
        border-right: 1px solid #111; /* Kept Dark Border */
        overflow-y: auto;
        padding-bottom: 120px;
    }

    .nvim-tree.open {
        transform: translateX(0);
    }

    .mobile-toggle {
        display: flex;
    }

    .gutter {
        display: none;
    }

    .content-scroll {
        padding-left: 15px;
        padding-bottom: 80px;
    }

    .buffer-bar {
        height: 40px;
    }

    .tab {
        min-width: auto;
        padding: 0 10px;
        font-size: 0.75rem;
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* --- GALLERY & LIGHTBOX --- */

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
    margin-bottom: 24px;
}

.gallery-grid img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border: 2px solid var(--line-nr);
    cursor: zoom-in;
    transition: transform 0.2s, border-color 0.2s;
    margin-bottom: 0 !important;
}

.gallery-grid img:hover {
    transform: scale(1.02);
    border-color: var(--blue);
}

#lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    opacity: 0;
    transition: opacity 0.3s;
}

#lightbox.active {
    display: flex;
    opacity: 1;
}

#lightbox img {
    max-width: 90%;
    max-height: 90%;
    border: 2px solid var(--fg);
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
}

/* --- BUFFER BAR --- */

.buffer-bar {
    background-color: var(--bg-dark);
    height: var(--header-h);
    display: flex;
    align-items: center; /* Center vertically */
    justify-content: space-between; /* Split Left/Right */
    padding-left: 0;
    border-bottom: 1px solid #111;
    flex-shrink: 0;
}

/* Left side (Tabs) */
.tabs-left {
    display: flex;
    overflow-x: auto;
    height: 100%;
    scrollbar-width: none;
    flex-grow: 1; /* Take available space */
}
.tabs-left::-webkit-scrollbar { display: none; }

/* Right side (Widgets) */
.widgets-right {
    display: flex;
    align-items: center;
    height: 100%;
    z-index: 2;
    background: var(--bg-dark);
}

.widget {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    height: 100%;
    font-size: 0.75rem;
    font-weight: bold;
    user-select: none;
    border-left: 1px solid var(--bg);
}

.widget-blue {
    color: var(--blue);
    background: rgba(122, 162, 247, 0.1);
}

.widget-purple {
    color: var(--purple);
    background: rgba(187, 154, 247, 0.1);
}

.widget-green {
    color: var(--green);
    background: rgba(158, 206, 106, 0.1);
}

.widget:hover {
    filter: brightness(1.2);
}

/* Mobile: Hide widgets */
@media (max-width: 768px) {
    .widgets-right { display: none; }
}

/* --- PRISMJS OVERRIDE --- */

code[class*="language-"], pre[class*="language-"] {
    background: var(--bg-dark) !important;
    text-shadow: none !important;
    border-radius: 4px;
    margin-bottom: var(--line-height);
}

/* --- MOBILE COMMAND INPUT --- */

#mobile-cmd-wrapper {
    display: none;
    margin-top: 20px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    align-items: center;
    border: 1px solid var(--line-nr);
}

#mobile-cmd-input {
    background: transparent;
    border: none;
    color: var(--fg);
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    flex: 1;
    outline: none;
    min-width: 0;
}

#mobile-cmd-input::placeholder {
    color: var(--comment);
    opacity: 0.5;
}

#mobile-cmd-btn {
    background: transparent;
    border: none;
    padding: 10px;
    margin: 0;
    margin-left: 5px;
    cursor: pointer;
    color: var(--blue);
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-appearance: none;
    appearance: none;
}

#mobile-cmd-btn:active {
    color: var(--green);
    transform: scale(0.9);
}

@media (max-width: 768px) {
    #mobile-cmd-wrapper {
        display: flex;
    }
}

/* --- TOAST NOTIFICATIONS --- */
#toast-container {
    position: fixed;
    bottom: 40px; /* Above status bar */
    right: 20px;
    display: flex;
    flex-direction: column-reverse; /* Newest at bottom */
    gap: 10px;
    z-index: 10002;
    pointer-events: none;
}

.toast {
    background: var(--bg-dark);
    color: var(--fg);
    border: 1px solid var(--line-nr);
    border-left: 4px solid var(--blue); /* Accent color */
    padding: 12px 20px;
    border-radius: 4px;
    font-size: 0.9rem;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    opacity: 0;
    transform: translateX(50px);
    animation: slide-in 0.3s forwards;
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }
.toast.warning { border-left-color: var(--yellow); }

@keyframes slide-in {
    to { opacity: 1; transform: translateX(0); }
}

@keyframes fade-out {
    from { opacity: 1; transform: translateX(0); } /* Keep it visible at start */
    to { opacity: 0; transform: translateX(20px); }
}

/* --- SNAKE MOBILE CONTROLS --- */

#snake-controls {
    display: none; /* Hidden by default */
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 150px;
    height: 150px;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    gap: 5px;
    z-index: 10005;
}

.snake-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--comment);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--blue);
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.snake-btn:active {
    background: var(--blue);
    color: var(--bg);
}

/* Specific Grid Placements for D-Pad */
#btn-up    { grid-column: 2; grid-row: 1; }
#btn-left  { grid-column: 1; grid-row: 2; }
#btn-down  { grid-column: 2; grid-row: 3; }
#btn-right { grid-column: 3; grid-row: 2; }
#btn-quit  { grid-column: 1; grid-row: 1; border-color: var(--red); color: var(--red); font-size: 0.8rem; }

/* Show only on mobile when game is active */
@media (max-width: 768px) {
    .game-active #snake-controls {
        display: grid;
    }
}

/* --- RESPONSIVE THEME LABELS --- */

/* Desktop */
.theme-tokyo::after { content: "TOKYO"; }
.theme-gruvbox::after { content: "GRUVBOX"; }
.theme-dracula::after { content: "DRACULA"; }
.theme-cyberpunk::after { content: "CYBERPUNK"; }

/* Mobile */
@media (max-width: 768px) {
    .theme-tokyo::after { content: "T"; }
    .theme-gruvbox::after { content: "G"; }
    .theme-dracula::after { content: "D"; }
    .theme-cyberpunk::after { content: "C"; }
}
