@import 'normalize.css';

/* ─── Design tokens ─────────────────────────────────────────── */
:root {
    --bg: #0f1115;
    --surface: #161a22;
    --surface-2: #1e2330;
    --surface-3: #262c3b;
    --border: #2a3142;
    --border-strong: #3a4256;
    --text: #e6e8ee;
    --text-dim: #aab2c5;
    --text-muted: #7a8499;
    --accent: #7cc4ff;
    --accent-hover: #a8d8ff;
    --accent-fg: #0b1220;
    --danger: #ff6b6b;
    --radius: 10px;
    --radius-lg: 16px;
    --shadow: 0 1px 2px rgba(0,0,0,.35), 0 6px 24px rgba(0,0,0,.25);
    --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI",
                 "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono",
                 Menlo, Consolas, monospace;
}

/* ─── Base ──────────────────────────────────────────────────── */
* { box-sizing: border-box; }

html { font-size: 16px; line-height: 1.5; }

html, button, input, select, textarea {
    color: var(--text);
    font-family: var(--font-sans);
}

body {
    margin: 0 auto;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-width: auto;
    display: block;
    padding: 1rem;
    max-width: 1600px;
}

/* Two-column layout only on generator pages, desktop only */
@media (min-width: 901px) {
    body:has(> #preview) {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 1.25rem;
        align-items: start;
        max-width: none;
    }
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
a h1, li a { color: inherit; }

hr {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 1rem 0;
}

audio, canvas, img, video { vertical-align: middle; max-width: 100%; }
/* Preview image opts out so zoom buttons can scale it beyond 100% */
#preview_img { max-width: none; }

/* ─── Typography ────────────────────────────────────────────── */
h1 {
    font-family: var(--font-sans);
    font-weight: 800;
    font-size: clamp(2rem, 3.2vw + .5rem, 3.2rem);
    line-height: 1.05;
    letter-spacing: -0.035em;
    margin: 0 0 .35rem;
    background: linear-gradient(120deg, #ff3d6e 0%, #ff6a3d 45%, #ffb84d 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    width: max-content;
    max-width: 100%;
}
h1 a {
    color: inherit;
    background: inherit;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-decoration: none;
}
h1 a:hover { opacity: .9; }

h2 {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: clamp(1.2rem, 1.4vw + .4rem, 1.6rem);
    letter-spacing: -0.01em;
    margin: 1rem 0 .5rem;
    color: var(--text);
}

/* Default h3 — compact inline section header (used inside forms) */
h3 {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: .95rem;
    color: var(--text);
    padding: .35rem 0;
    margin: .75rem 0 .25rem;
    width: auto;
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: .5rem;
    user-select: none;
    transition: color .15s ease, border-color .15s ease;
}

h3::before {
    font-family: var(--font-sans);
    content: "▸";
    color: var(--accent);
    font-size: .9em;
    transition: transform .2s ease;
    display: inline-block;
}
h3.open::before { content: "▾"; }

h3:hover {
    color: var(--accent-hover);
    border-bottom-color: var(--border-strong);
}

/* Menu page: h3-sections are full cards */
.menu h3 {
    font-size: 1.05rem;
    padding: .65rem .9rem;
    margin: .25rem 0;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.menu h3:hover {
    background-color: var(--surface-3);
    border-color: var(--border-strong);
    color: var(--text);
}
.menu h3.open {
    background: linear-gradient(90deg,
        rgba(255,61,110,.10) 0%,
        rgba(255,106,61,.06) 40%,
        rgba(255,184,77,.04) 100%);
    border-color: var(--border-strong);
}

p { margin: .5rem 0; color: var(--text-dim); }

/* ─── Layout containers ─────────────────────────────────────── */
.argumentcontainer,
.container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin: 0;
    padding: 1.25rem 1.5rem;
    width: 100%;
    float: none;
    min-width: 0;
}

/* Preview column on generator page */
#preview {
    position: sticky;
    top: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1rem;
    min-width: 0;
    max-height: calc(100vh - 2rem);
    overflow: auto;
}

#preview_buttons {
    padding: 0 0 .75rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: .75rem;
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--text-dim);
    font-size: .9rem;
}

#preview_buttons button {
    padding: .35rem .65rem;
    font-size: .9rem;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}
#preview_buttons button:hover {
    background: var(--surface-3);
}

#preview_img {
    background: #fff;
    border-radius: 6px;
}

/* Header area: kill inline floats/widths so layout doesn't break */
.argumentcontainer > div[style*="width"],
.container > div[style*="width"] {
    width: auto !important;
    float: none !important;
}

/* Logo sits to the LEFT of the H1, both pages */
.argumentcontainer > div:first-child {
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
    justify-content: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
}
.argumentcontainer > div:first-child > div[style*="float: left"] {
    flex: 1 1 auto;
    min-width: 0;
}
.argumentcontainer > div:first-child > div[style*="float: right"] {
    flex: 0 0 auto;
    order: -1;
}

img[alt="self-Logo"] {
    max-width: 56px !important;
    width: 56px !important;
    height: auto;
    display: block;
}

/* Gallery page intro paragraph (lead) */
body:not(:has(> #preview)) .argumentcontainer > div p:nth-of-type(2) {
    font-size: 1rem;
    line-height: 1.55;
    color: var(--text-dim);
    max-width: 70ch;
    margin-top: .5rem;
}

/* ─── Top link bar ──────────────────────────────────────────── */
.linkbar {
    margin: .5rem 0 0;
    padding: 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: transparent;
}
.linkbar ul {
    margin: 0;
    padding: .5rem .25rem;
    display: flex;
    flex-wrap: wrap;
    gap: .5rem 1rem;
    align-items: center;
    list-style: none;
}
.linkbar ul li {
    list-style: none;
    display: inline-flex;
    align-items: center;
    font-size: .9rem;
}
.linkbar ul li a {
    color: var(--text-dim);
    margin: 0;
    padding: .25rem .35rem;
    border-radius: 6px;
    transition: color .15s ease, background-color .15s ease;
}
.linkbar ul li a:hover {
    color: var(--text);
    background: var(--surface-2);
    text-decoration: none;
}
.linkbar ul li.right { margin-left: auto; }

/* Search input in linkbar */
#search {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .35rem .6rem;
    font: inherit;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
#search::placeholder { color: var(--text-muted); }
#search:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(124,196,255,.15);
}

/* ─── Language selector ─────────────────────────────────────── */
.linkbar form select {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .3rem .5rem;
    font: inherit;
    cursor: pointer;
}
.linkbar form select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ─── Forms (generator parameters) ──────────────────────────── */
table { margin: .5rem 0 1rem; width: 100%; border-collapse: collapse; }
table tr p { display: inline; color: var(--text-dim); }
table td {
    padding: .35rem .6rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
}
table tr:last-child td { border-bottom: 0; }
table td:first-child {
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: .9rem;
    width: 12rem;
    white-space: nowrap;
}

input[type="text"],
input[type="number"],
input[type="search"],
input:not([type]),
select,
textarea {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .35rem .55rem;
    font: inherit;
    width: 100%;
    max-width: 16rem;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
input[type="text"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
input:not([type]):focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(124,196,255,.15);
}

input[type="checkbox"] {
    accent-color: var(--accent);
    width: 1.1rem;
    height: 1.1rem;
    cursor: pointer;
}

textarea { font-family: var(--font-mono); min-height: 6rem; }

/* Buttons — secondary by default */
input[type="submit"],
input[type="button"],
button {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .5rem 1rem;
    font: 600 .9rem var(--font-sans);
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, transform .05s ease;
}
input[type="submit"]:hover,
input[type="button"]:hover,
button:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
    text-decoration: none;
}
input[type="submit"]:active,
input[type="button"]:active,
button:active { transform: translateY(1px); }

/* Primary action: Generate (the form submit button with value="1") */
form > p > button[value="1"],
button.primary {
    background: linear-gradient(120deg, #ff3d6e 0%, #ff6a3d 55%, #ffb84d 100%);
    color: #1a0a05;
    border: 0;
    padding: .6rem 1.4rem;
    font-size: .95rem;
    box-shadow: 0 1px 0 rgba(255,255,255,.08) inset, 0 4px 12px rgba(255,106,61,.25);
}
form > p > button[value="1"]:hover,
button.primary:hover {
    filter: brightness(1.08);
    background: linear-gradient(120deg, #ff3d6e 0%, #ff6a3d 55%, #ffb84d 100%);
    border: 0;
}

/* Action buttons row spacing */
form > p:has(> button) {
    display: flex;
    gap: .5rem;
    margin-top: 1.25rem;
    align-items: center;
}

/* ─── Generator menu (sidebar / grouped lists) ──────────────── */
.menu { color: var(--text-dim); }
.menu ul {
    padding-left: 0;
    list-style: none;
}
.menu li { list-style: none; }
.menu ul li {
    padding: .35rem .65rem;
    border-radius: 6px;
    transition: background-color .12s ease;
}
.menu ul li:hover {
    background: var(--surface-3);
    color: var(--text);
}
.menu ul li a { color: var(--text-dim); }
.menu ul li:hover a { color: var(--text); }
.menu ul li span {
    display: none;
    font-size: .85rem;
    color: var(--text-muted);
    margin-left: .5rem;
}
.menu ul li:hover span { display: inline; }
.menu h3 { cursor: pointer; }

/* ─── Gallery ───────────────────────────────────────────────── */
/* Grid container: direct parent of gallery cards (also contains h2/modenav) */
div:has(> .gallery + .gallery),
div:has(> .gallery_missing + .gallery_missing),
div:has(> .gallery + .gallery_missing),
div:has(> .gallery_missing + .gallery) {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: .75rem;
    align-items: stretch;
}
div:has(> .gallery + .gallery) > *:not(.gallery):not(.gallery_missing),
div:has(> .gallery_missing + .gallery_missing) > *:not(.gallery):not(.gallery_missing) {
    grid-column: 1 / -1;
}
div:has(> .gallery + .gallery) > h2,
div:has(> .gallery_missing + .gallery_missing) > h2 {
    margin: 1.25rem 0 .25rem;
    padding-bottom: .35rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 1.05rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    font-weight: 700;
}

.gallery,
.gallery_missing {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    text-align: center;
    width: auto;
    height: 240px;
    margin: 0;
    padding: .5rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-weight: 600;
    transition: border-color .15s ease, transform .12s ease, box-shadow .15s ease;
    overflow: hidden;
}
.gallery:hover,
.gallery_missing:hover {
    border-color: var(--border-strong);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0,0,0,.35);
}
.gallery a, .gallery_missing a {
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    gap: .35rem;
}
.gallery img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    margin: 0;
    border-radius: 6px;
    background: var(--surface-3);
}
.gallery_missing img {
    width: 100%;
    height: 180px;
    object-fit: contain;
    background: var(--surface-3);
    border-radius: 6px;
    opacity: .4;
}

/* ─── Mode buttons (preview tabs) ───────────────────────────── */
.modenav { overflow: hidden; margin-bottom: 1rem; }
.modebutton {
    float: left;
    border: 1px solid var(--border);
    outline: none;
    padding: .55rem 1rem;
    margin-right: .5rem;
    text-align: center;
    border-radius: 8px;
    font-size: .95rem;
    width: 25%;
    background: var(--surface-2);
    color: var(--text-dim);
    cursor: pointer;
}
.modebutton:hover { background: var(--surface-3); color: var(--text); }
.modeactive {
    background: var(--accent);
    color: var(--accent-fg);
    border-color: var(--accent);
}
.modeactive:hover { background: var(--accent-hover); color: var(--accent-fg); }

/* ─── Misc ──────────────────────────────────────────────────── */
.description img { width: 100%; border-radius: var(--radius); }

#preview_buttons { padding-top: 1.5rem; }
#preview_figure { margin: 0; }

img[id|=sample] {
    position: fixed;
    bottom: 80px;
    right: 1.5rem;
    max-width: 220px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    padding: .25rem;
}

.clear {
    clear: both;
    display: block;
    overflow: hidden;
    visibility: hidden;
    width: 0;
    height: 0;
}

/* ─── Footer ────────────────────────────────────────────────── */
.site-footer {
    grid-column: 1 / -1;
    margin-top: .5rem;
    padding: .9rem 1rem;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: .82rem;
    display: flex;
    flex-wrap: wrap;
    gap: .35rem .5rem;
    align-items: center;
    justify-content: center;
}
.site-footer a {
    color: var(--text-dim);
    text-decoration: none;
}
.site-footer a:hover {
    color: var(--accent);
}
.site-footer .dot {
    color: var(--text-muted);
    opacity: .5;
}

/* ─── Changed field indicator ───────────────────────────────── */
input.is-changed,
select.is-changed,
textarea.is-changed {
    border-left: 3px solid var(--accent);
    padding-left: calc(.55rem - 2px);
}

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
    body {
        grid-template-columns: minmax(0, 1fr);
        padding: .75rem;
        gap: .75rem;
    }
    #preview {
        position: static;
        max-height: none;
    }
    .argumentcontainer,
    .container {
        padding: 1rem;
        border-radius: 12px;
    }
    .linkbar ul { gap: .25rem .5rem; }
    .modebutton { width: 48%; margin-bottom: .5rem; }
    table td:first-child { width: auto; }
    img[id|=sample] { position: static; max-width: 100%; margin-top: 1rem; border-radius: var(--radius); width: 100%; height: auto; }
    .gallery, .gallery_missing { width: 45%; }
}

@media (max-width: 540px) {
    h1 { font-size: 1.5rem; }
    .gallery, .gallery_missing { width: 100%; }

    /* Touch targets — checkboxes 44×44 */
    input[type="checkbox"] { width: 1.5rem; height: 1.5rem; }

    /* Inputs/selects min-height 44 */
    input[type="text"], input[type="number"], input[type="search"],
    input:not([type]), select {
        min-height: 44px;
        padding: .6rem .75rem;
        font-size: 1rem;
        max-width: 100%;
    }

    /* Block-layout for parameter rows */
    table, tbody, tr { display: block; width: 100%; }
    table tr {
        border-bottom: 1px solid var(--border);
        padding: .55rem 0;
    }
    table tr:last-child { border-bottom: 0; }
    table td {
        display: block;
        padding: .25rem .4rem;
        border-bottom: 0;
        width: 100%;
    }
    table td:first-child {
        color: var(--text);
        font-weight: 600;
        white-space: normal;
        font-size: .95rem;
        padding-bottom: 0;
        width: 100%;
    }
    table tr p {
        display: block;
        font-size: .8rem;
        color: var(--text-muted);
        margin-top: .25rem;
    }

    /* Action buttons row → flex, full width, 44px */
    form > p:has(> button) {
        display: flex;
        flex-wrap: wrap;
        gap: .5rem;
        position: sticky;
        bottom: .5rem;
        background: var(--surface);
        padding: .5rem 0;
        margin: 0 -.5rem;
        box-shadow: 0 -2px 12px rgba(0,0,0,.4);
        z-index: 100;
    }
    form > p:has(> button) button {
        flex: 1 1 45%;
        min-height: 44px;
        padding: .75rem .5rem;
    }
    form > p:has(> button) button[value="1"] {
        flex: 1 1 100%;
        font-size: 1.05rem;
    }

    /* Preview zoom controls */
    #preview_buttons {
        flex-wrap: wrap;
        gap: .4rem;
    }
    #preview_buttons button {
        min-height: 44px;
        min-width: 44px;
        flex: 0 0 auto;
    }

    /* Mode buttons */
    .modenav {
        display: flex;
        flex-wrap: wrap;
        gap: .4rem;
    }
    .modebutton {
        float: none;
        width: auto;
        flex: 1 1 40%;
        min-height: 44px;
        margin: 0;
    }
}

/* ─── Polish pass v2 ──────────────────────────────────────── */

/* 1. Linkbar — compact, items wrap onto a second row when needed */
.linkbar ul {
    gap: .35rem .65rem;
    font-size: .88rem;
}
.linkbar ul li:has(#preview_chk) {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    color: var(--text-dim);
}
.linkbar ul li:has(#preview_chk) input[type="checkbox"] {
    margin: 0;
    width: 1.05rem;
    height: 1.05rem;
}
.linkbar ul li.right form { margin: 0; padding: 0; display: inline-flex; }
#search {
    width: 8rem;
    padding: .25rem .5rem;
    font-size: .85rem;
}
#search:focus { width: 12rem; transition: width .15s ease; }
.linkbar ul li a { padding: .15rem .25rem; }

/* 2. Box description (h2 + short doc) — make doc italic, lighter */
.argumentcontainer h2 + p,
.container h2 + p,
form > p:first-of-type {
    color: var(--text-muted);
    font-style: italic;
    margin-top: -.25rem;
    margin-bottom: 1rem;
}

/* 3. Preview SVG — keep server's inline width:max-content + width:100% intact */
/* (Any rules touching #preview_figure or #preview_img width break zoom) */

/* 4. Sample photo card on box page — softer integration */
.description {
    margin-top: 1.5rem;
    /* Wrap long descriptions / instructions that may not contain explicit <br> */
    word-wrap: break-word;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: pre-wrap;
    max-width: 100%;
    overflow-x: hidden;
}
.description p,
.description li {
    margin: .5rem 0;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.55;
    color: var(--text-dim);
    max-width: 100%;
}
.description ol, .description ul {
    padding-left: 1.5rem;
    color: var(--text-dim);
}
.description li { margin: .25rem 0; }
.description code {
    background: var(--surface-2);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: .9em;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: pre-wrap;
}
/* Sometimes class docstrings are indented and markdown treats them as code-blocks.
   Make those readable inside the dark card. */
.description pre {
    background: transparent;
    border: 0;
    padding: 0;
    margin: .5rem 0;
    color: var(--text-dim);
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
}
.description pre code {
    background: transparent;
    padding: 0;
    font-family: inherit;
    font-size: inherit;
}
.description img {
    background: var(--surface-2);
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* 5. Inline info icon (.info-icon replaces 🛈) */
a.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin-left: .35rem;
    border-radius: 50%;
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    transition: color .15s ease, background-color .15s ease, border-color .15s ease;
}
a.info-icon:hover {
    color: var(--accent);
    background: var(--surface-3);
    border-color: var(--accent);
    text-decoration: none;
}

/* 6. Emphasise "Default Settings" / "Основные настройки" section header */
h3.toggle:has(+ table) {
    /* base — already styled */
}
/* Mark the LAST h3 (default settings) more prominent */
form > h3.toggle:last-of-type,
h3.toggle:nth-last-of-type(1) {
    /* fallback if structure varies */
}
/* Use a sturdier rule: any h3 whose text contains common defaults keywords */
h3.toggle {
    position: relative;
}
/* Bold contrast for the section currently open + has many fields */
h3.toggle.open {
    color: var(--text);
    border-bottom-color: var(--accent);
    border-bottom-width: 2px;
}

/* 7. bottom_edge / format selects — widen */
select {
    max-width: 100%;
    min-width: 12rem;
}
td > select {
    width: 100%;
    max-width: 18rem;
}

/* 8. is-changed marker — stronger */
input.is-changed,
select.is-changed,
textarea.is-changed {
    border-left: 3px solid var(--accent);
    padding-left: calc(.55rem - 2px);
    background-color: rgba(124, 196, 255, 0.06);
    box-shadow: inset 0 0 0 1px rgba(124, 196, 255, 0.15);
}

/* 9. Action button row: Generate prominent, others compact */
form > p:has(> button) {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    align-items: center;
}
form > p:has(> button) button[value="1"] {
    flex: 0 0 auto;
    min-width: 10rem;
    padding: .65rem 1.5rem;
    font-size: 1rem;
}
form > p:has(> button) button:not([value="1"]) {
    flex: 0 0 auto;
    padding: .45rem .9rem;
    font-size: .85rem;
}

/* 10. Tabs Gallery/Menu — more separation */
.modenav {
    margin: 1.25rem 0 1.5rem;
    padding-top: .25rem;
    display: flex;
    gap: .5rem;
}
.modebutton {
    flex: 0 0 auto;
    width: auto;
    min-width: 8rem;
    padding: .6rem 1.5rem;
    font-weight: 600;
}

/* Footer — more breathing room */
.site-footer {
    margin-top: 2rem;
    padding: 1.25rem 1rem;
}

/* Header on root page: title block stays inline */
.argumentcontainer > div:first-child > div[style*="float: left"] {
    flex: 1 1 0;
    min-width: 0;
}
.argumentcontainer > div:first-child {
    flex-wrap: nowrap;
}
@media (max-width: 700px) {
    .argumentcontainer > div:first-child { flex-wrap: wrap; }
}

/* ═══ Polish v3 — focus, contrast, microinteractions ═══ */

/* Focus-visible: тонкий лазерный ring только при keyboard-навигации */
:root { --focus-ring: 0 0 0 2px rgba(255,106,61,.55); }
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-color: #ff6a3d;
}
button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}
h3.toggle:focus-visible {
    box-shadow: 0 0 0 2px rgba(255,106,61,.55) inset;
    border-radius: 6px;
}
/* Mouse click — не показывать ring */
button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
[role="button"]:focus:not(:focus-visible) {
    box-shadow: none;
    outline: none;
}

/* Contrast — input/placeholder читаемые */
input[type="text"],
input[type="number"],
input[type="search"],
input:not([type]),
select,
textarea {
    color: var(--text);
}
input::placeholder, textarea::placeholder {
    color: #9aa3b8;
    opacity: 1;
}
table td:first-child {
    color: #c0c8db;
    font-family: var(--font-mono);
    font-size: .9rem;
    letter-spacing: .01em;
}

/* Tooltip на info-иконках */
a.info-icon {
    position: relative;
}
a.info-icon::after {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-3);
    color: var(--text);
    padding: .4rem .65rem;
    border-radius: 6px;
    border: 1px solid var(--border-strong);
    white-space: nowrap;
    font-size: .8rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease;
    z-index: 10;
}
a.info-icon:hover::after,
a.info-icon:focus-visible::after {
    opacity: 1;
}

/* Sticky action bar внизу формы */
form > p:has(> button) {
    position: sticky;
    bottom: 0;
    background: linear-gradient(to top,
        var(--surface) 70%,
        rgba(22, 26, 34, 0));
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding-bottom: 1rem;
    margin-bottom: 0;
    z-index: 5;
}

/* Preview skeleton-shimmer пока грузится */
#preview_img[src*="nothing.png"],
#preview.loading #preview_img {
    background: linear-gradient(90deg,
        var(--surface-2) 0%,
        var(--surface-3) 50%,
        var(--surface-2) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Лазерный progress-bar поверх превью при обновлении */
#preview.loading::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg,
        transparent,
        #ff3d6e 25%,
        #ff6a3d 50%,
        #ffb84d 75%,
        transparent);
    background-size: 200% 100%;
    animation: laserBeam 1.2s linear infinite;
    z-index: 2;
}
@keyframes laserBeam {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
#preview { position: sticky; top: 1rem; }

/* Кастомные чекбоксы (laser-fill) */
input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 1.15rem;
    height: 1.15rem;
    border: 1.5px solid var(--border-strong);
    border-radius: 4px;
    background: var(--surface-2);
    cursor: pointer;
    position: relative;
    transition: border-color .15s ease, background .15s ease;
    flex-shrink: 0;
    vertical-align: -3px;
}
input[type="checkbox"]:hover {
    border-color: #ff6a3d;
}
input[type="checkbox"]:checked {
    background: linear-gradient(135deg, #ff3d6e 0%, #ff6a3d 50%, #ffb84d 100%);
    border-color: transparent;
}
input[type="checkbox"]:checked::after {
    content: "";
    position: absolute;
    left: 4px;
    top: 1px;
    width: 4px;
    height: 8px;
    border: solid #1a0a05;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Inline-валидация: invalid input glow + микро-сдвиг */
input:invalid:not(:placeholder-shown):not(:focus) {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(255, 107, 107, .12);
}
input:valid:not(:placeholder-shown) {
    /* Без зелёного — слишком навязчиво, оставляем стандарт */
}

/* Hero на главной (только Gallery) */
body:not(:has(> #preview)) .argumentcontainer > div:first-child {
    padding: 1.5rem 0 .5rem;
}
body:not(:has(> #preview)) .argumentcontainer h1 {
    font-size: clamp(2.5rem, 5vw + .5rem, 4rem);
    line-height: .95;
    margin-bottom: .5rem;
}
body:not(:has(> #preview)) .argumentcontainer h1 + p,
body:not(:has(> #preview)) .argumentcontainer > div p:first-of-type {
    font-size: 1.15rem;
    color: var(--text-dim);
    max-width: 64ch;
    margin: 0 0 .35rem;
    font-weight: 500;
}
body:not(:has(> #preview)) .argumentcontainer > div p:nth-of-type(2) {
    font-size: .95rem;
    color: var(--text-muted);
    max-width: 70ch;
    line-height: 1.55;
}

/* Section headers (h2 в Gallery) — лазерный акцент слева */
div:has(> .gallery + .gallery) > h2,
div:has(> .gallery_missing + .gallery_missing) > h2 {
    position: relative;
    padding-left: 0.85rem;
    border-bottom: 0;
    margin-top: 2rem;
}
div:has(> .gallery + .gallery) > h2::before,
div:has(> .gallery_missing + .gallery_missing) > h2::before {
    content: "";
    position: absolute;
    left: 0;
    top: 15%;
    bottom: 15%;
    width: 3px;
    background: linear-gradient(180deg, #ff3d6e 0%, #ff6a3d 50%, #ffb84d 100%);
    border-radius: 2px;
}

/* Карточки галереи — поднимаются плавнее, акцент на ховере */
.gallery,
.gallery_missing {
    cursor: pointer;
    will-change: transform;
}
.gallery::before,
.gallery_missing::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: var(--radius);
    background: linear-gradient(135deg,
        rgba(255,61,110,0) 0%,
        rgba(255,106,61,0) 50%,
        rgba(255,184,77,0) 100%);
    opacity: 0;
    transition: opacity .25s ease;
    pointer-events: none;
}
.gallery:hover::before,
.gallery_missing:hover::before {
    opacity: .08;
}
.gallery, .gallery_missing { position: relative; }

/* Code-style mono labels (x, y, h, thickness) */
table td:first-child label {
    font-family: var(--font-mono);
    color: #c0c8db;
}

/* "Открыть в Inkscape / Lightburn" hint у Generate */
form > p:has(> button)::before {
    content: "";
    flex: 1;
}

/* ═══ Light theme ═══════════════════════════════════════════ */
:root[data-theme="light"] {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --surface-2: #f0f1f4;
    --surface-3: #e6e8ed;
    --border: #d6d9e0;
    --border-strong: #b8bdc8;
    --text: #1a1d24;
    --text-dim: #4a5163;
    --text-muted: #7a8499;
    --accent: #1f7bd9;
    --accent-hover: #1665b8;
    --accent-fg: #ffffff;
    --shadow: 0 1px 2px rgba(0,0,0,.08), 0 6px 24px rgba(0,0,0,.06);
}

/* Theme toggle button (lives in the linkbar) */
.theme-toggle {
    background: var(--surface-2);
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .25rem .5rem;
    font-size: .85rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    transition: background-color .15s, color .15s, border-color .15s;
}
.theme-toggle:hover {
    background: var(--surface-3);
    color: var(--text);
    border-color: var(--border-strong);
}
.theme-toggle .theme-icon { line-height: 1; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: inline; }
.theme-toggle .icon-sun { display: inline; }
.theme-toggle .icon-moon { display: none; }
