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

.hidden { display: none !important; }

:root {
    --bg:        #0f1117;
    --surface:   #1a1d27;
    --border:    #2e3147;
    --accent:    #5b7fff;
    --accent-hover: #7b9bff;
    --text:      #e2e4ef;
    --muted:     #9aa0c0;
    --copyright: #9aa0c0;
    --success:   #3ecf8e;
    --error:     #f56565;
    --radius:    10px;
    --font:      'Inter', system-ui, -apple-system, sans-serif;
    --mono:      'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --link:      #5b9fff;
    --link-hover: #7bb5ff;
    --btn-secondary-hover: #3a3e57;
}

[data-theme="light"] {
    --bg:        #f0f2f8;
    --surface:   #ffffff;
    --border:    #d0d5e8;
    --accent:    #4a6cf7;
    --accent-hover: #6a8cff;
    --text:      #1a1d2e;
    --muted:     #8890b8;
    --copyright: #8890b8;
    --success:   #2ea872;
    --error:     #e53e3e;
    --link:      #3565d8;
    --link-hover: #1a3a8a;
    --btn-secondary-hover: #e0e3f0;
}

a { color: var(--link); text-decoration: none; transition: color .15s; }
a:hover { color: var(--link-hover); }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 48px 16px;
}

.container {
    width: 100%;
    max-width: 1100px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

/* Page header */

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.title-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

.site-logo {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
}

h1 {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text);
    line-height: 1.2;
}

.subtitle {
    font-size: 13px;
    color: var(--accent);
    margin-top: 3px;
}

/* Header controls */

.lang-switcher {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    padding-top: 4px;
}

.lang-sep {
    color: var(--muted);
    font-size: 13px;
}

.lang-btn {
    display: inline-flex;
    align-items: center;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    padding: 4px 10px;
    border-radius: 5px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
    text-decoration: none;
}

.lang-btn:hover {
    color: var(--text);
    border-color: var(--accent);
}

.lang-btn.active {
    border-color: var(--border);
    color: var(--accent);
}

.help-btn {
    display: inline-flex;
    align-items: center;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    padding: 4px 10px;
    border-radius: 5px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.help-btn:hover {
    border-color: var(--accent);
    color: #fff;
}

.home-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
}

.theme-btn {
    display: inline-flex;
    align-items: center;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 13px;
    line-height: 1;
    padding: 4px 10px;
    border-radius: 5px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.theme-btn:hover {
    color: var(--text);
    border-color: var(--accent);
}

/* Search */

.search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 9px;
    color: var(--muted);
    pointer-events: none;
    display: flex;
    align-items: center;
}

/* Unified form field — apply .form-field to any input/select/textarea
   to get site-wide consistent styling. Width is left to each form. */
.form-field {
    background: var(--surface);
    border: 1px solid #3d4160;
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--mono);
    font-size: 13px;
    padding: 10px 14px;
    outline: none;
    box-sizing: border-box;
}
.form-field::placeholder { color: var(--muted); }
[data-theme="light"] .form-field { border-color: #b8becf; }

/* ── Global button styles ────────────────────────────────────────────────── */
/* All action buttons: transparent + border. Hover: accent border + white text. No blue fill.
   Exclusions: nav controls (.lang-btn, .theme-btn, .home-btn, .result-close, .help-btn) keep own styles. */
button:not(.lang-btn):not(.theme-btn):not(.home-btn):not(.result-close):not(.help-btn):not(.btn-sm):not(.site-tab):not(.danger):not(.share-action):not(.awg-version-pill):not(.ss-icon-btn) {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--muted);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    padding: 10px 20px;
    cursor: pointer;
    transition: border-color .15s, color .15s;
    white-space: nowrap;
}
button:not(.lang-btn):not(.theme-btn):not(.home-btn):not(.result-close):not(.help-btn):not(.btn-sm):not(.site-tab):not(.danger):not(.share-action):not(.awg-version-pill):not(.ss-icon-btn):hover:not(:disabled) {
    border-color: var(--accent);
    color: #fff;
}
button:not(.lang-btn):not(.theme-btn):not(.home-btn):not(.result-close):not(.help-btn):not(.btn-sm):not(.site-tab):not(.danger):not(.share-action):not(.awg-version-pill):not(.ss-icon-btn):disabled {
    opacity: .4;
    cursor: default;
}

/* Small button — same height as lang-btn. Use for chips, type selectors, inline controls. */
button.btn-sm {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--muted);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    cursor: pointer;
    transition: border-color .15s, color .15s, background .15s;
    white-space: nowrap;
    user-select: none;
}
button.btn-sm:hover:not(:disabled) {
    border-color: var(--accent);
    color: #fff;
}
button.btn-sm.active {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(91, 127, 255, .1);
}
button.btn-sm:disabled {
    opacity: .4;
    cursor: default;
}

/* Danger button — destructive/stop actions, red border + text, no fill */
button.danger {
    background: transparent;
    border: 1px solid var(--error);
    border-radius: 7px;
    color: var(--error);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    padding: 10px 20px;
    cursor: pointer;
    transition: border-color .15s, color .15s, background .15s;
    white-space: nowrap;
}
button.danger:hover:not(:disabled) {
    background: rgba(245, 101, 101, .1);
}
button.danger:disabled {
    opacity: .4;
    cursor: default;
}

/* Square icon button (e.g. clear/close with ✕) — same height as action buttons */
.btn-icon {
    padding: 10px !important;
    aspect-ratio: 1;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ── Section card — full-width tool wrapper ──────────────────────────────── */

.section-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.section-card-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
}

.section-card-header h2 {
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.7px;
    text-transform: uppercase;
}

.section-card-body {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Compact page-header — only lang-switcher, no title row */
.page-header--compact {
    justify-content: flex-end;
}

.search-input {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    padding: 5px 26px 5px 28px;
    width: 210px;
    outline: none;
    transition: border-color 0.15s;
}

.search-input::placeholder {
    color: var(--muted);
}

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

.search-clear {
    position: absolute;
    right: 7px;
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    border-radius: 3px;
    transition: color 0.15s;
}

.search-clear:hover {
    color: var(--text);
}

.search-empty {
    color: var(--muted);
    font-size: 14px;
    text-align: center;
    padding: 40px 0;
}

/* Group sections */

.group-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 18px;
}
.group-block:last-child { margin-bottom: 0; }

.group-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--accent);
    padding: 13px 20px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
}
.group-title:hover { color: color-mix(in srgb, var(--accent) 70%, white); }

.group-title--link,
.group-title--link:visited {
    text-decoration: none;
    color: var(--accent);
}

.group-toggle-arrow {
    margin-left: auto;
    flex-shrink: 0;
    color: var(--muted);
    transition: transform 0.2s;
}
.group-block.collapsed .group-toggle-arrow { transform: rotate(-90deg); }
.group-block.collapsed .group-content { display: none; }
.group-block.collapsed .group-title { border-bottom-color: transparent; }

.group-desc {
    margin: 0;
    padding: 8px 20px 10px;
    font-size: 12px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

/* Subgroup header inside .group-block */
.group-section {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    padding: 14px 20px 6px;
    border-bottom: 1px solid var(--border);
}
.group-block > .group-section + .projects-grid { padding-top: 12px; }

/* App cards */

.apps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 12px;
    padding: 16px;
}

.app-card {
    background: var(--bg);
    border: 1px solid var(--border);
    text-decoration: none;
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: border-color 0.15s, background 0.15s;
}
.app-card:hover {
    border-color: var(--accent);
    background: var(--btn-secondary-hover);
}

.app-card-header {
    display: flex;
    align-items: center;
    gap: 14px;
}

.app-card-logo {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
}

.app-card-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.app-card-desc {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.6;
    margin: 0;
}

.app-card-badges {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 4px;
    justify-content: center;
}

.app-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--text);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.app-badge:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.app-badge--soon {
    opacity: 0.35;
    cursor: default;
    pointer-events: none;
}

.app-badge--apk {
    opacity: 1;
    cursor: pointer;
    pointer-events: auto;
    background: transparent;
}

.app-badge svg { flex-shrink: 0; }

/* Projects grid */

.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 12px;
    padding: 16px;
}

.project-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s, background 0.15s;
}

.project-card:hover {
    border-color: var(--accent);
    background: var(--btn-secondary-hover);
}

.project-card--soon {
    opacity: 0.5;
    cursor: default;
}

.project-card--soon:hover {
    border-color: var(--border);
    box-shadow: none;
}

.project-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.project-logo {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 8px;
}

.project-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
}

.project-desc {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.55;
}

/* Copyright footer — styles live in nav.css (shared with all pages) */

/* Help modal */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 1100px;
    max-width: calc(100% - 40px);
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modal-in 0.18s ease;
}
.modal::-webkit-scrollbar { width: 5px; }
.modal::-webkit-scrollbar-track { background: transparent; }
.modal::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--border) 60%, transparent);
    border-radius: 4px;
}
.modal::-webkit-scrollbar-thumb:hover {
    background: var(--border);
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}

.modal-title {
    font-size: 15px;
    font-weight: 600;
}

.result-close {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color 0.15s;
}

.result-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 20px;
    font-size: 14px;
    color: var(--text);
    line-height: 1.6;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--border) 60%, transparent) transparent;
}
.modal-body::-webkit-scrollbar { width: 5px; }
.modal-body::-webkit-scrollbar-track { background: transparent; }
.modal-body::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--border) 60%, transparent);
    border-radius: 4px;
}
.modal-body::-webkit-scrollbar-thumb:hover { background: var(--border); }

.modal-body p { margin-bottom: 12px; }
.modal-body p:last-child { margin-bottom: 0; }
.modal-body strong { color: var(--text); font-weight: 600; }
.modal-body h3 {
    font-size: 11px; font-weight: 700; letter-spacing: 0.7px; text-transform: uppercase;
    color: var(--accent); margin: 20px 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.modal-body h3:first-child { margin-top: 4px; }
.modal-body ul { padding-left: 20px; margin-bottom: 12px; }
.modal-body li { margin-bottom: 6px; }
.modal-body a { color: var(--link); }
.modal-body a:hover { color: var(--link-hover); }
.modal-body code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 12px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px;
}

/* Global tabs — unified style for all pages */
.site-tabs-block {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 16px;
}
.site-tabs {
    display: flex;
    gap: 0;
    background: var(--bg);
}
.site-tab {
    flex: 1;
    padding: 10px 0;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    background: var(--bg);
    border: none;
    border-radius: 0;
    border-right: 1px solid var(--border);
    border-bottom: 2px solid transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-bottom-color 0.15s;
}
.site-tab:last-child { border-right: none; }
.site-tab.active { background: var(--surface); color: var(--accent); border-bottom-color: var(--accent); }
.site-tab:hover:not(.active) { color: var(--text); }
.site-tab-panel {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 16px 20px;
}

/* Responsive */

/* ssh-confgen: collapse two-column layout on narrow screens */
@media (max-width: 900px) {
    .ssh-layout { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    body {
        padding: 28px 12px;
    }

    h1 {
        font-size: 18px;
    }

    .site-logo {
        width: 36px;
        height: 36px;
    }

    /* Stack page header vertically */
    .page-header {
        flex-direction: column;
        gap: 8px;
    }

    /* Lang-switcher: full width + centered, buttons on one line */
    .lang-switcher {
        padding-top: 0;
        gap: 4px;
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
    }

    /* Search bar moves to its own row, separated from buttons above */
    .search-wrap {
        order: 99;
        width: 95%;
        margin-top: 6px;
        border-top: 1px solid var(--border);
        padding-top: 10px;
    }

    .search-input {
        width: 100%;
        transition: none;
    }

    .search-input:focus {
        width: 100%;
    }

    /* Hide | separators — buttons still visually distinct */
    .lang-sep {
        display: none;
    }

    /* Prevent iOS auto-zoom on input focus (requires font-size >= 16px) */
    input, select, textarea {
        font-size: 16px;
    }

    /* Modals: reduce side margin on mobile */
    .modal {
        max-width: calc(100% - 20px);
    }

    /* Section card mobile */
    .section-card-header { padding: 12px 16px; }
    .section-card-body { padding: 14px 16px; gap: 12px; }

    /* Global tabs mobile */
    .site-tabs { flex-wrap: wrap; }
    .site-tab { flex: 1 1 45%; font-size: 13px; padding: 9px 0; border-bottom: 1px solid var(--border); }
    .site-tab.active { border-bottom-color: var(--accent); }
    .site-tab-panel { padding: 12px 14px; }

    /* Single-column cards on mobile */
    .projects-grid {
        grid-template-columns: 1fr;
        padding: 12px;
        gap: 8px;
    }

    /* Fail2ban + Regex constructor mobile */
    .f2b-actions { flex-direction: column; }
    .f2b-actions button { width: 100%; }
    .f2b-token-table th:last-child,
    .f2b-token-table td:last-child { display: none; }
    .f2b-copy-wrap { flex-direction: column; }
    .f2b-copy-wrap button { width: 100%; }
    .f2b-fields-table th:nth-child(3),
    .f2b-fields-table td:nth-child(3) { display: none; }
    .f2b-rx-input { min-width: 120px; }

    /* Regex tester mobile — use .rx-pattern-row parent to beat inline <style> specificity */
    .rx-pattern-row { padding: 8px 12px; gap: 6px; }
    /* Line 1: /input/ — full width */
    .rx-pattern-row .rx-pattern-main { flex: 1 1 100%; }
    .rx-pattern-row .rx-pattern-input { font-size: 16px; }
    /* Line 2: flags — full width, each flag shares row equally */
    .rx-pattern-row .rx-flags { flex: 1 1 100%; }
    .rx-pattern-row .rx-flag { flex: 1; padding: 8px 4px; font-size: 13px; text-align: center; min-width: 0; }
    /* Lines 3-4: Copy / Clear — each on its own full-width line */
    .rx-pattern-row .rx-copy-btn { flex: 1 1 100%; width: 100%; padding: 10px; text-align: center; }
    .rx-presets-row { padding: 8px 12px; gap: 5px; }
    .rx-preset { font-size: 12px; padding: 5px 10px; }
    .rx-textarea { font-size: 16px; min-height: 120px; }
    .rx-highlighted { font-size: 12px; max-height: 180px; }
    .rx-table td, .rx-table th { padding: 5px 8px; font-size: 11px; }
    .rx-table .rx-td-groups, .rx-table th:nth-child(4) { display: none; }
    /* Cheatsheet: 1 column, higher specificity to beat inline <style> */
    .group-block .rx-cs-grid,
    .modal-body .rx-cs-grid { grid-template-columns: 1fr; }
    .rx-cs-table td { font-size: 11px; padding: 4px 6px; }
    .rx-cs-table td:first-child { padding-right: 8px; width: auto; }

    /* ssh-confgen mobile */
    .ssh-basic-grid { grid-template-columns: 1fr 1fr; }
    .ssh-adv-grid   { grid-template-columns: 1fr; }
    .ssh-toolbar    { flex-direction: column; }
    .ssh-toolbar button { width: 100%; }
    .ssh-check-group { gap: 12px; }
}
