/* ── Theme tokens (palette from the original Geometric Interior app) ── */

:root {
    color-scheme: dark;
    --font: 'Space Grotesk', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --bg: #0b0d12;
    --text: #e9eefc;
    --text-muted: rgba(233, 238, 252, 0.75);
    --text-dim: rgba(233, 238, 252, 0.55);
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.14);
    --surface: rgba(255, 255, 255, 0.03);
    --surface-hover: rgba(255, 255, 255, 0.06);
    --surface-active: rgba(255, 255, 255, 0.09);
    --accent: rgba(180, 130, 255, 0.35);
    --accent-bg: rgba(180, 130, 255, 0.16);
    --accent-text: rgb(180, 130, 255);
    --accent-glow: rgba(180, 130, 255, 0.5);
    --tooltip-bg: #151823;
    --danger-text: rgba(240, 126, 60, 0.9);
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        color-scheme: light;
        --bg: #f0f2f7;
        --text: #1a1e2e;
        --text-muted: rgba(26, 30, 46, 0.65);
        --text-dim: rgba(26, 30, 46, 0.5);
        --border: rgba(0, 0, 0, 0.1);
        --border-strong: rgba(0, 0, 0, 0.18);
        --surface: rgba(0, 0, 0, 0.03);
        --surface-hover: rgba(0, 0, 0, 0.06);
        --surface-active: rgba(0, 0, 0, 0.1);
        --accent: rgba(120, 40, 200, 0.4);
        --accent-bg: rgba(120, 40, 200, 0.12);
        --accent-text: rgb(100, 30, 180);
        --accent-glow: rgba(120, 40, 200, 0.4);
        --tooltip-bg: #ffffff;
        --danger-text: rgb(200, 80, 20);
    }
}

:root[data-theme="light"] {
    color-scheme: light;
    --bg: #f0f2f7;
    --text: #1a1e2e;
    --text-muted: rgba(26, 30, 46, 0.65);
    --text-dim: rgba(26, 30, 46, 0.5);
    --border: rgba(0, 0, 0, 0.1);
    --border-strong: rgba(0, 0, 0, 0.18);
    --surface: rgba(0, 0, 0, 0.03);
    --surface-hover: rgba(0, 0, 0, 0.06);
    --surface-active: rgba(0, 0, 0, 0.1);
    --accent: rgba(120, 40, 200, 0.4);
    --accent-bg: rgba(120, 40, 200, 0.12);
    --accent-text: rgb(100, 30, 180);
    --accent-glow: rgba(120, 40, 200, 0.4);
    --tooltip-bg: #ffffff;
    --danger-text: rgb(200, 80, 20);
}

/* ── Base ── */

*, *::before, *::after { box-sizing: border-box; }
:focus:not(:focus-visible) { outline: none; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* Hidden until a non-English page's strings load (see index.html). */
.i18n-pending body { visibility: hidden; }

h1, h2 { font-weight: 500; letter-spacing: 0.01em; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

button, .button, select, input { font: inherit; color: inherit; }

/* ── Header ── */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--border);
}

.app-header h1 { font-size: 1rem; margin: 0; }

.brand {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    flex-wrap: wrap;
}

.link-button {
    padding: 0;
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 0.8125rem;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-color: var(--border-strong);
    text-underline-offset: 3px;
}
.link-button:hover { color: var(--accent-text); text-decoration-color: currentColor; }

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.locale-select {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.25rem 0.625rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    cursor: pointer;
}
.locale-select:hover { color: var(--text); }
.locale-select option { background: var(--bg); color: var(--text); }

.theme-switch {
    display: flex;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px;
    margin: 0;
}

.theme-switch label { position: relative; }

.theme-switch input {
    position: absolute;
    opacity: 0;
    inset: 0;
    margin: 0;
    cursor: pointer;
}

.theme-switch span {
    display: block;
    padding: 0.2rem 0.7rem;
    border-radius: 999px;
    font-size: 0.75rem;
    color: var(--text-muted);
    transition: background-color 0.15s, color 0.15s;
}

.theme-switch input:checked + span { background: var(--accent-bg); color: var(--accent-text); }
.theme-switch input:hover + span { color: var(--text); }
.theme-switch input:focus-visible + span { outline: 2px solid var(--accent-text); }

/* ── Layout ── */

main {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 320px 1fr;
}

/* ── Sidebar ── */

.sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-right: 1px solid var(--border);
}

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0.75rem;
}

.section { border-bottom: 1px solid var(--border); }
.section:last-child { border-bottom: none; }

.section > summary {
    list-style: none;
    cursor: pointer;
    padding: 0.625rem 0;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.section > summary::-webkit-details-marker { display: none; }
.section > summary::before {
    content: '\25BE';
    font-size: 0.8125rem;
    transition: transform 0.15s;
}
.section:not([open]) > summary::before { transform: rotate(-90deg); }
.section > summary:hover { color: var(--text); }

.section-description {
    margin: -0.25rem 0 0.5rem;
    font-size: 0.75rem;
    line-height: 1.4;
    color: var(--text-dim);
}

/* ── Sliders ── */

.sliders {
    display: grid;
    /* The name column grows for longer translated names. */
    grid-template-columns: minmax(6rem, max-content) 1fr 3rem;
    align-items: center;
    row-gap: 0.375rem;
    column-gap: 0.5rem;
    padding-bottom: 0.875rem;
}

.slider-row { display: contents; }

.slider-name {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
}

.info {
    width: 0.95rem;
    height: 0.95rem;
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: 50%;
    background: none;
    color: var(--text-dim);
    font-size: 0.6rem;
    font-style: italic;
    font-family: Georgia, serif;
    line-height: 1;
    cursor: help;
    flex-shrink: 0;
}
.info:hover, .info:focus-visible { color: var(--accent-text); border-color: var(--accent); }

input[type="range"] {
    --track: none;
    width: 100%;
    height: 6px;
    margin: 0;
    -webkit-appearance: none;
    appearance: none;
    background: var(--track), var(--border);
    border: 1px solid var(--border);
    border-radius: 3px;
    cursor: pointer;
}
input[type="range"]::-moz-range-track { background: transparent; border: none; }

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--accent-text);
    border: none;
    transition: transform 0.12s, box-shadow 0.12s;
}
input[type="range"]::-moz-range-thumb {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--accent-text);
    border: none;
    transition: transform 0.12s, box-shadow 0.12s;
}
input[type="range"]:hover::-webkit-slider-thumb,
input[type="range"]:focus-visible::-webkit-slider-thumb { transform: scale(1.3); box-shadow: 0 0 6px var(--accent-glow); }
input[type="range"]:hover::-moz-range-thumb,
input[type="range"]:focus-visible::-moz-range-thumb { transform: scale(1.3); box-shadow: 0 0 6px var(--accent-glow); }
input[type="range"]:focus-visible { outline-offset: 4px; }

.slider-value {
    width: 100%;
    padding: 0.125rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    text-align: center;
}
.slider-value:hover { color: var(--text); }
.slider-value:focus { color: var(--text); border-color: var(--accent); outline: none; }

/* ── Buttons ── */

button:not(.info, .link-button), .button {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    padding: 0.45rem 0.9rem;
    font-size: 0.875rem;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.15s, border-color 0.15s;
}
button:not(.info, .link-button):hover, .button:hover { background: var(--surface-hover); }
button:not(.info, .link-button):active, .button:active { background: var(--surface-active); }

button.primary {
    background: var(--accent-bg);
    border-color: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
}
button.primary:hover { background: var(--accent); }

button:disabled { opacity: 0.5; cursor: wait; }

/* The download link is inactive until the first image exists. */
.button[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

/* ── Stage ── */

.stage {
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.toolbar {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1.5rem;
    padding-bottom: 0.875rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.toolbar-fields, .toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
}
.toolbar-actions { gap: 0.5rem; }

.toolbar label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.toolbar select, .toolbar input {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.25rem 0.375rem;
    font-size: 0.8125rem;
}
.toolbar input { width: 5.5rem; }
.toolbar select option { background: var(--bg); }

.toolbar-actions button:not(.info, .link-button), .toolbar-actions .button {
    padding: 0.35rem 0.8rem;
    font-size: 0.8125rem;
}

.status {
    margin: 0 0 0.75rem;
    min-height: 1.2em;
    color: var(--text-muted);
    white-space: pre-line;
    font-size: 0.875rem;
}

figure { margin: 0; display: flex; flex-direction: column; align-items: center; }

#image {
    display: block;
    max-width: 100%;
    max-height: 66dvh;
    width: auto;
    height: auto;
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: opacity 0.2s;
}
.stage.busy #image { opacity: 0.75; }

figcaption { width: 100%; max-width: 70ch; margin-top: 1.25rem; }
figcaption h2 { font-size: 1.25rem; margin: 0 0 0.375rem; }
figcaption p { color: var(--text-muted); line-height: 1.55; margin: 0 0 0.75rem; }
figcaption summary { cursor: pointer; color: var(--text-dim); font-size: 0.875rem; margin-bottom: 0.5rem; }
figcaption summary:hover { color: var(--text); }

/* ── Modal ── */

.modal {
    width: min(40rem, calc(100vw - 2rem));
    max-height: min(80dvh, 48rem);
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.45);
}
.modal[open] { display: flex; flex-direction: column; }
.modal::backdrop { background: rgba(0, 0, 0, 0.7); }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.125rem; margin: 0; }

button.modal-close {
    width: 2rem;
    height: 2rem;
    padding: 0;
    border-color: transparent;
    background: none;
    font-size: 1.375rem;
    line-height: 1;
    color: var(--text-muted);
}
button.modal-close:hover { color: var(--text); }

.modal-body {
    overflow-y: auto;
    padding: 1.25rem 1.5rem 1.5rem;
    line-height: 1.65;
    color: var(--text-muted);
}
.modal-body p { margin: 0 0 1em; }
.modal-body p:last-child { margin-bottom: 0; }

/* ── Tooltip ── */

.tooltip {
    position: fixed;
    z-index: 100;
    top: 0;
    left: 0;
    max-width: min(20rem, calc(100vw - 24px));
    padding: 0.5rem 0.75rem;
    background: var(--tooltip-bg);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    font-size: 0.75rem;
    line-height: 1.45;
    color: var(--text);
    pointer-events: none;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.12s;
}
.tooltip.visible { visibility: visible; opacity: 1; }

/* ── Small screens ── */

@media (max-width: 720px) {
    body { height: auto; }
    main { grid-template-columns: 1fr; }
    .sidebar { border-right: none; border-bottom: 1px solid var(--border); order: 2; }
    .stage { order: 1; padding: 1rem; }
    .sidebar-scroll { overflow: visible; }
    /* Title and statement link on one row, language and theme on the next. */
    .app-header { flex-wrap: wrap; row-gap: 0.5rem; }
    .header-controls { width: 100%; justify-content: space-between; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; }
}
