/* ── Theme: Dark (default) ── */
:root {
    --bg-color: #1e1e2e;
    --text-color: #cdd6f4;
    --subtext-color: #a6adc8;
    --link-color: #89b4fa;
    --cmd-color: #a6e3a1;
    --dir-color: #94e2d5;
    --error-color: #f38ba8;
    --prompt-color: #cba6f7;
    --highlight: #f5c2e7;
    --cursor: #f5e0dc;
    --surface0: #313244;
    --surface1: #45475a;
    --yellow: #f9e2af;
    --peach: #fab387;
    --mauve: #cba6f7;
}

/* ── Theme: Light ── */
html[data-theme="light"] {
    --bg-color: #eff1f5;
    --text-color: #4c4f69;
    --subtext-color: #6c6f85;
    --link-color: #1e66f5;
    --cmd-color: #40a02b;
    --dir-color: #179299;
    --error-color: #d20f39;
    --prompt-color: #8839ef;
    --highlight: #ea76cb;
    --cursor: #5c5f77;
    --surface0: #ccd0da;
    --surface1: #bcc0cc;
    --yellow: #df8e1d;
    --peach: #fe640b;
    --mauve: #8839ef;
}

/* ── Theme: Auto (follow system) ── */
@media (prefers-color-scheme: light) {
    html[data-theme="auto"] {
        --bg-color: #eff1f5;
        --text-color: #4c4f69;
        --subtext-color: #6c6f85;
        --link-color: #1e66f5;
        --cmd-color: #40a02b;
        --dir-color: #179299;
        --error-color: #d20f39;
        --prompt-color: #8839ef;
        --highlight: #ea76cb;
        --cursor: #5c5f77;
        --surface0: #ccd0da;
        --surface1: #bcc0cc;
        --yellow: #df8e1d;
        --peach: #fe640b;
        --mauve: #8839ef;
    }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    color: var(--text-color);
    font-family: 'Maple Mono', 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
    font-size: 16px;
    line-height: 1.6;
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
    touch-action: manipulation;
}

/* ── Terminal container ── */
#terminal {
    width: 100%;
    height: 100%;
    padding: 16px 20px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    cursor: text;
    scrollbar-color: var(--surface0) transparent;
    -webkit-overflow-scrolling: touch;
}

#terminal::-webkit-scrollbar {
    width: 10px;
}

#terminal::-webkit-scrollbar-track {
    background: transparent;
}

#terminal::-webkit-scrollbar-thumb {
    background: var(--surface0);
    border-radius: 5px;
}

#terminal::-webkit-scrollbar-thumb:hover {
    background: var(--surface1);
}

/* ── Output lines ── */
.output-line {
    white-space: pre-wrap;
    word-wrap: break-word;
    min-height: 1.6em;
}

.output-line:empty::after {
    content: '\200b';
}

.output-block {
    margin-bottom: 2px;
}

.welcome-ascii {
    font-weight: bold;
    color: var(--link-color);
    white-space: pre;
    font-size: 10px;
    line-height: 1.2;
}

/* ── Prompt ── */
.prompt-line {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.prompt-label {
    color: var(--cmd-color);
    font-weight: bold;
    margin-right: 0;
    white-space: nowrap;
}

.path-label {
    color: var(--link-color);
    font-weight: bold;
}

.dollar {
    color: var(--prompt-color);
    font-weight: bold;
}

/* Clickable path segments in prompt */
.path-seg {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
}

.path-seg:hover {
    text-decoration: none;
    background: var(--link-color);
    color: var(--bg-color);
}

.path-sep {
    opacity: 0.6;
}

/* ── Input area ── */
.input-container {
    position: relative;
    flex-grow: 1;
    display: flex;
    align-items: center;
}

#cmd-input {
    position: absolute;
    opacity: 0;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    z-index: 10;
    outline: none;
    caret-color: transparent;
    font-size: 16px;
    /* Prevent iOS zoom */
}

#input-visual {
    z-index: 1;
    min-height: 24px;
    white-space: pre;
    display: flex;
    align-items: center;
}

#cmd-before-cursor {
    white-space: pre;
}

#cmd-after-cursor {
    white-space: pre;
}

/* ── Cursor ── */
.cursor {
    display: inline-block;
    min-width: 9px;
    background: var(--cursor);
    color: var(--bg-color);
    animation: blink 1s step-end infinite;
    line-height: inherit;
}

.cursor.typing {
    animation: none;
    background: var(--cursor);
    color: var(--bg-color);
    opacity: 1;
}

/* When cursor has ghost char, blink shows ghost style */
.cursor.has-ghost {
    animation: blink-ghost 1s step-end infinite;
    font-style: italic;
}

.cursor.has-ghost.typing {
    animation: none;
    background: var(--cursor);
    color: var(--bg-color);
    opacity: 0.7;
    font-style: italic;
}

@keyframes blink {

    0%,
    49% {
        background: var(--cursor);
        color: var(--bg-color);
    }

    50%,
    100% {
        background: transparent;
        color: var(--text-color);
    }
}

@keyframes blink-ghost {

    0%,
    49% {
        background: var(--cursor);
        color: var(--bg-color);
        opacity: 0.7;
    }

    50%,
    100% {
        background: transparent;
        color: var(--subtext-color);
        opacity: 0.5;
    }
}

/* ── Ghost autocomplete ── */
#cmd-ghost {
    position: absolute;
    left: 0;
    color: var(--subtext-color);
    opacity: 0.4;
    pointer-events: none;
    white-space: pre;
    z-index: 0;
    font-style: italic;
}

/* ── Clickable elements ── */
.clickable {
    --_clk-color: var(--text-color);
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
}

.clickable.is-dir,
.clickable:has(.is-dir) {
    --_clk-color: var(--link-color);
}

.clickable.is-exe,
.clickable:has(.is-exe) {
    --_clk-color: var(--cmd-color);
}

.clickable.is-link,
.clickable:has(.is-link) {
    --_clk-color: var(--highlight);
}

.clickable.highlight,
.clickable:has(.highlight) {
    --_clk-color: var(--highlight);
}

.clickable:hover {
    text-decoration: none;
    background: var(--_clk-color);
    color: var(--bg-color);
}

.clickable:hover * {
    color: inherit !important;
}

.clickable:active {
    filter: brightness(0.85);
}

/* ── File type colors ── */
.is-dir {
    color: var(--link-color);
    font-weight: bold;
}

.is-file {
    color: var(--text-color);
}

.is-exe {
    color: var(--cmd-color);
    font-weight: bold;
}

.is-link {
    color: var(--highlight);
    font-style: italic;
}

.error {
    color: var(--error-color);
}

.dim {
    color: var(--subtext-color);
    font-style: italic;
}

.highlight {
    color: var(--highlight);
    font-weight: bold;
}

.yellow {
    color: var(--yellow);
}

.peach {
    color: var(--peach);
}

.mauve {
    color: var(--mauve);
}

/* ── ls grid ── */
.ls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 2px 24px;
}

.ls-grid>span {
    white-space: nowrap;
}

.progress-bar {
    color: var(--cmd-color);
}

a {
    color: var(--link-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ── Selection ── */
::selection {
    background: var(--surface1);
    color: var(--text-color);
}

::-moz-selection {
    background: var(--surface1);
    color: var(--text-color);
}

/* ── Focus visible ── */
:focus-visible {
    outline: 2px solid var(--link-color);
    outline-offset: 2px;
}

/* ── Mobile ── */
@media (max-width: 600px) {

    html,
    body {
        font-size: 13px;
    }

    #terminal {
        padding: 10px 10px 10px;
    }

    .welcome-ascii {
        font-size: 7px;
    }

    .ls-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

    .ls-grid>span {
        padding: 4px 6px;
    }


}

/* very small screens */
@media (max-width: 360px) {

    html,
    body {
        font-size: 12px;
    }

    .welcome-ascii {
        font-size: 6px;
    }
}