:root {
    --bg: #1a1a1a;
    --screen: #000000;
    --fg: #c4f0c4;
    --dim: #6b8f6b;
    --green: #00ff41;
    --green-dim: #1a6b2e;
    --red: #ff5555;
    --yellow: #fce94f;
    --cyan: #34e2e2;
    --titlebar: #2d2d2d;
    --titlebar-hi: #3d3d3d;
    --scrollbar-track: #0a0a0a;
    --scrollbar-thumb: #2d3d2d;
    --scrollbar-thumb-hover: #3d5d3d;
}

* { box-sizing: border-box; }

*::-webkit-scrollbar {
    width: 9px;
    height: 9px;
}

*::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

*::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border: 2px solid var(--scrollbar-track);
    border-radius: 0;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

*::-webkit-scrollbar-corner {
    background: var(--scrollbar-track);
}

html {
    font-size: 15px;
    height: 100%;
    color-scheme: dark;
    -webkit-text-size-adjust: 100%;
}

html,
body,
.term-body {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    height: 100%;
    flex-direction: column;
    display: flex;
    font-family: "Cascadia Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
    font-feature-settings: "liga" 0;
    background: var(--bg);
    color: var(--fg);
    line-height: 1.5;
}

body.is-home {
    justify-content: center;
    overflow: auto;
}

body:not(.is-home) {
    overflow: hidden;
}

::selection {
    background: var(--green-dim);
    color: #fff;
}

.wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    max-width: 920px;
    width: 100%;
    margin: 0 auto;
    padding: 0.75rem 0.75rem 1rem;
}

body.is-home .wrap {
    flex: 0 1 auto;
}

.term {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    border: 1px solid #444;
    box-shadow:
        0 0 0 1px #0a0a0a,
        0 12px 40px rgba(0, 0, 0, 0.55);
}

body.is-home .term {
    flex: 0 0 auto;
}

.term-titlebar {
    display: grid;
    grid-template-columns: 2.4rem 1fr 2.4rem;
    align-items: center;
    gap: 0.65rem;
    height: 2rem;
    padding: 0 0.65rem;
    background: linear-gradient(180deg, var(--titlebar-hi), var(--titlebar));
    border-bottom: 1px solid #111;
    font-size: 0.72rem;
    color: #bbb;
    user-select: none;
}

.term-dots {
    display: flex;
    gap: 0.35rem;
    align-items: center;
}

.term-dots span {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    flex-shrink: 0;
}

.term-dot-close { background: #ff5f56; }
.term-dot-min { background: #ffbd2e; }
.term-dot-full { background: #27ca40; }

.term-title {
    text-align: center;
    letter-spacing: 0.04em;
    color: #999;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.term-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--screen);
    padding: 0.65rem 0.85rem;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.term-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    margin-top: 0.85rem;
    overflow-y: auto;
    overflow-x: hidden;
}

body.is-home .term-body {
    display: none;
}

.term-prompt {
    flex-shrink: 0;
    display: flex;
    align-items: baseline;
    direction: ltr;
    margin: 0 0 0.85rem;
    font-size: 0.88rem;
    line-height: 1.4;
}

.term-prompt-cmd {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.term-prompt .u { color: var(--green); font-weight: 600; }
.term-prompt .at { color: var(--dim); }
.term-prompt .h { color: var(--green); }
.term-prompt .path { color: var(--cyan); }
.term-prompt .sym { color: var(--dim); margin: 0 0.2rem; }
.term-prompt .cmd { color: var(--fg); }

.term-cursor {
    display: inline-block;
    width: 0.55em;
    height: 1.1em;
    margin-left: 1px;
    vertical-align: text-bottom;
    background: var(--green);
    animation: term-blink 1s step-end infinite;
}

@keyframes term-blink {
    50% { opacity: 0; }
}

.search {
    position: relative;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.bar {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
}

.search input {
    flex: 1;
    min-width: 0;
    padding: 0.5rem 0.65rem;
    border: none;
    border-radius: 0;
    background: #0a0a0a;
    color: var(--green);
    font: inherit;
    font-size: 0.88rem;
    line-height: 1.45;
    caret-color: var(--green);
    box-shadow: inset 0 0 0 1px #222;
}

.search input::placeholder {
    color: #1a4a1a;
}

.search input:focus {
    outline: none;
    box-shadow: inset 0 0 0 1px var(--green-dim), 0 0 0 1px var(--green);
}

.search input[type="search"]::-webkit-search-decoration,
.search input[type="search"]::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
}

.bar > button,
.pager button {
    padding: 0.35rem 0.85rem;
    border: 1px solid var(--dim);
    border-radius: 0;
    background: #0d0d0d;
    color: var(--fg);
    font-size: 0.85rem;
    font-family: inherit;
    font-weight: 400;
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

@media (hover: hover) {
    .bar > button:hover,
    .pager button:hover:not(:disabled):not(.is-current) {
        border-color: var(--green);
        color: var(--green);
        background: #0a120a;
    }

    .mode:hover {
        color: var(--fg);
        background: #111;
    }

    .history button:hover {
        background: #111;
        color: var(--fg);
    }

    .title:hover {
        color: #fff;
        border-bottom-color: #fff;
    }
}

.bar > button:active,
.pager button:active:not(:disabled):not(.is-current) {
    transform: translateY(1px);
}

.bar > button:focus-visible,
.pager button:focus-visible,
.mode:has(input:focus-visible) {
    outline: 2px solid #fff;
    outline-offset: 1px;
}

.bar > button:disabled {
    opacity: 0.45;
    cursor: default;
}

.modes {
    display: flex;
    flex-wrap: nowrap;
    gap: 0;
    margin-top: 0.65rem;
    border-bottom: 1px solid #333;
}

.mode {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    padding: 0.4rem 0.75rem;
    color: var(--dim);
    border: 1px solid transparent;
    border-bottom: none;
    margin-bottom: -1px;
    font-size: 0.85rem;
    user-select: none;
}

.mode::before {
    content: "$ ";
    color: var(--green);
}

.mode input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.mode:has(input:checked) {
    color: var(--fg);
    background: var(--screen);
    border-color: #333;
    border-bottom-color: var(--screen);
}

.history {
    margin-top: 0.35rem;
    background: #0a0a0a;
    box-shadow: inset 0 0 0 1px #222;
}

.history[hidden] {
    display: none;
}

.history button {
    display: block;
    width: 100%;
    padding: 0.4rem 0.65rem;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--green);
    font: inherit;
    font-size: 0.88rem;
    text-align: start;
    cursor: pointer;
    box-shadow: none;
}

.history button.is-active {
    background: #111;
    color: var(--fg);
}

.status {
    flex-shrink: 0;
    margin: 0 0 0.45rem;
    font-size: 0.8rem;
    color: var(--dim);
}

.status:empty {
    display: none;
}

.status::before {
    content: "$ ";
    color: var(--green);
}

.status:empty::before {
    content: none;
}

.status.is-bad {
    color: var(--red);
    font-size: 0.88rem;
}

.status.is-bad::before {
    content: "bash: ";
    color: var(--dim);
}

.status.is-ok {
    color: var(--yellow);
}

.list:not(:empty) {
    flex-shrink: 0;
    position: relative;
}

.list:not(:empty)::before {
    content: "┌─ hits ─────────────────────────────────────────";
    display: block;
    direction: ltr;
    color: var(--dim);
    font-size: 0.72rem;
    margin-bottom: 0.35rem;
    white-space: nowrap;
    overflow: hidden;
}

.result {
    margin: 0;
    padding: 0.45rem 0.2rem 0.55rem;
    border-bottom: 1px solid #1a2a1a;
}

.result:nth-child(even) {
    background: rgba(0, 255, 65, 0.03);
}

.source {
    margin: 0 0 0.15rem;
    color: var(--yellow);
    font-size: 0.72rem;
}

.title {
    display: inline;
    color: var(--cyan);
    font-size: 0.95rem;
    font-weight: 400;
    line-height: 1.4;
    text-decoration: none;
    border-bottom: 1px dotted var(--cyan);
}

.title:visited {
    color: #2a9a8a;
    border-bottom-color: #2a9a8a;
}

.cite,
.files {
    margin: 0.2rem 0 0;
    color: var(--dim);
    font-size: 0.8rem;
    line-height: 1.45;
}

.files {
    padding-block: 0.15rem;
    padding-inline-start: 1.5ch;
    list-style: none;
    color: var(--fg);
    border-inline-start: 1px solid var(--green-dim);
}

.files li::before {
    content: "│ ";
    color: var(--dim);
    user-select: none;
}

.pager {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 0.85rem 0 0.35rem;
}

.page.is-current {
    color: var(--yellow);
    border-color: var(--yellow);
    cursor: default;
}

.step:disabled {
    display: none;
}

.gap {
    padding: 0 0.15rem;
    color: var(--dim);
}

@media (max-width: 700px) {
    body {
        position: fixed;
        inset: 0;
        padding:
            env(safe-area-inset-top)
            env(safe-area-inset-right)
            env(safe-area-inset-bottom)
            env(safe-area-inset-left);
    }

    .wrap {
        padding: 0;
    }

    body.is-home {
        overflow-x: hidden;
    }

    body.is-home .wrap {
        padding: 0.75rem;
    }

    .term {
        border-inline: 0;
        box-shadow: none;
    }

    body.is-home .term {
        border: 1px solid #444;
        box-shadow:
            0 0 0 1px #0a0a0a,
            0 12px 40px rgba(0, 0, 0, 0.55);
    }

    .term-screen {
        padding: 0.55rem 0.7rem 0.7rem;
    }

    .term-prompt {
        margin-bottom: 0.55rem;
    }

    .search input {
        font-size: 16px;
        padding: 0.65rem 0.7rem;
        -webkit-appearance: none;
        appearance: none;
    }

    .bar > button,
    .mode,
    .history button,
    .pager button {
        touch-action: manipulation;
    }

    .bar > button {
        flex-shrink: 0;
        min-height: 2.75rem;
        padding-inline: 0.7rem;
    }

    .modes {
        overflow-x: auto;
    }

    .mode {
        flex: 1;
        justify-content: center;
        min-width: 0;
        min-height: 2.75rem;
    }

    .history button {
        min-height: 2.75rem;
        font-size: 16px;
    }

    .title,
    .cite,
    .files li,
    .source,
    .status {
        overflow-wrap: anywhere;
    }

    .title {
        display: inline-block;
        max-width: 100%;
    }

    .pager {
        flex-wrap: nowrap;
        gap: 0.2rem;
    }

    .pager button {
        min-width: 2.5rem;
        min-height: 2.5rem;
        padding: 0 0.3rem;
    }

    .pager .step {
        width: 2.5rem;
        min-width: 2.5rem;
        padding: 0;
        font-size: 0;
    }

    .step.prev::before,
    .step.next::after {
        font-size: 1.35rem;
        line-height: 1;
    }

    .step.prev::before {
        content: "‹";
    }

    .step.next::after {
        content: "›";
    }

    [dir="rtl"] .step.prev::before {
        content: "›";
    }

    [dir="rtl"] .step.next::after {
        content: "‹";
    }

    .list:not(:empty)::before {
        content: "┌─ hits ────────";
    }
}

@media (max-height: 500px) {
    body.is-home {
        justify-content: flex-start;
    }

    body.is-home .wrap {
        padding-block: 0.4rem;
    }

    .term-prompt {
        margin-bottom: 0.4rem;
    }
}
