:root {
    color-scheme: dark;
    --bg: #0b1017;
    --bg-soft: #0f151e;
    --panel: #121a24;
    --panel-2: #17212d;
    --panel-3: #1c2836;
    --text: #f4f7fa;
    --muted: #91a0b2;
    --line: rgba(168, 190, 218, .14);
    --line-strong: rgba(168, 190, 218, .26);
    --accent: #55d6aa;
    --accent-ink: #06251d;
    --blue: #7aa7ff;
    --amber: #ffc46b;
    --red: #ff7b88;
    --shadow: 0 16px 42px rgba(0, 0, 0, .2);
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --header-height: 60px;
    --mobile-nav-height: calc(62px + env(safe-area-inset-bottom));
    --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

:root[data-theme="light"] {
    color-scheme: light;
    --bg: #eef3f7;
    --bg-soft: #f8fafc;
    --panel: #ffffff;
    --panel-2: #f3f7fa;
    --panel-3: #e9f0f5;
    --text: #122033;
    --muted: #61748a;
    --line: rgba(41, 61, 84, .13);
    --line-strong: rgba(41, 61, 84, .23);
    --accent: #10b981;
    --accent-ink: #ffffff;
    --blue: #2563eb;
    --amber: #b96b00;
    --red: #d63f52;
    --shadow: 0 24px 70px rgba(37, 51, 70, .12);
}

:root[data-design="terminal"] {
    color-scheme: dark;
    --bg: #06130b;
    --bg-soft: #091a10;
    --panel: #0c2415;
    --panel-2: #10331c;
    --panel-3: #154323;
    --text: #d6ffe0;
    --muted: #78c98c;
    --line: rgba(98, 255, 145, .24);
    --line-strong: rgba(98, 255, 145, .46);
    --accent: #62ff91;
    --accent-ink: #001b08;
    --blue: #77ffad;
    --amber: #d7ff6b;
    --red: #ff657a;
    --shadow: 0 0 34px rgba(38, 255, 98, .08);
    --radius-sm: 2px;
    --radius: 3px;
    --radius-lg: 4px;
    --font: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

:root[data-design="ios"][data-theme="dark"] {
    color-scheme: dark;
    --bg: #000000;
    --bg-soft: #111113;
    --panel: #1c1c1e;
    --panel-2: #252527;
    --panel-3: #2c2c2e;
    --text: #f5f5f7;
    --muted: #98989f;
    --line: rgba(255, 255, 255, .11);
    --line-strong: rgba(255, 255, 255, .2);
    --accent: #0a84ff;
    --accent-ink: #ffffff;
    --blue: #64d2ff;
    --amber: #ffd60a;
    --red: #ff453a;
    --shadow: 0 18px 50px rgba(0, 0, 0, .35);
    --radius-sm: 12px;
    --radius: 18px;
    --radius-lg: 24px;
}

:root[data-design="ios"][data-theme="light"] {
    color-scheme: light;
    --bg: #f2f2f7;
    --bg-soft: #f7f7fa;
    --panel: #ffffff;
    --panel-2: #f2f2f7;
    --panel-3: #e5e5ea;
    --text: #1c1c1e;
    --muted: #6c6c70;
    --line: rgba(60, 60, 67, .13);
    --line-strong: rgba(60, 60, 67, .25);
    --accent: #007aff;
    --accent-ink: #ffffff;
    --blue: #007aff;
    --amber: #b25000;
    --red: #ff3b30;
    --shadow: 0 14px 38px rgba(60, 60, 67, .14);
    --radius-sm: 12px;
    --radius: 18px;
    --radius-lg: 24px;
}

:root[data-design="ios-light"] {
    color-scheme: light;
    --bg: #f2f2f7;
    --bg-soft: #f7f7fa;
    --panel: #ffffff;
    --panel-2: #f2f2f7;
    --panel-3: #e5e5ea;
    --text: #1c1c1e;
    --muted: #6c6c70;
    --line: rgba(60, 60, 67, .13);
    --line-strong: rgba(60, 60, 67, .25);
    --accent: #007aff;
    --accent-ink: #ffffff;
    --blue: #007aff;
    --amber: #b25000;
    --red: #ff3b30;
    --shadow: 0 14px 38px rgba(60, 60, 67, .14);
    --radius-sm: 12px;
    --radius: 18px;
    --radius-lg: 24px;
}

* { box-sizing: border-box; }
html { max-width: 100%; overflow-x: hidden; overscroll-behavior-x: none; background: var(--bg); }
body {
    margin: 0;
    min-height: 100dvh;
    max-width: 100%;
    overflow-x: hidden;
    overscroll-behavior-x: none;
    touch-action: pan-y;
    color: var(--text);
    background: var(--bg);
    font: 15px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button, a, label { -webkit-tap-highlight-color: transparent; }
button, .button, .mini-button { touch-action: manipulation; }
button { cursor: pointer; }
img { max-width: 100%; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.8rem, 4vw, 2.7rem); line-height: 1.08; letter-spacing: -.035em; }
h2 { letter-spacing: -.025em; }
small { color: var(--muted); }
::selection { color: var(--accent-ink); background: var(--accent); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.honeypot { position: absolute !important; left: -10000px !important; width: 1px !important; height: 1px !important; overflow: hidden !important; }

.site-header {
    position: sticky;
    z-index: 50;
    top: 0;
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 0 max(22px, calc((100vw - 1500px) / 2));
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(18px);
}

.brand { display: inline-flex; align-items: center; gap: 10px; min-width: 150px; }
.brand-logo, .auth-logo { display: block; flex: 0 0 auto; border-radius: 11px; object-fit: cover; }
.auth-logo { margin-bottom: 26px; border-radius: 15px; }
.brand-mark, .auth-mark {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 11px;
    color: var(--accent-ink);
    background: var(--accent);
    font-weight: 950;
    box-shadow: 0 8px 24px rgba(67, 227, 180, .18);
}
.brand strong { line-height: 1; letter-spacing: -.02em; }

.desktop-nav { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.desktop-nav a { padding: 9px 12px; border-radius: 8px; color: var(--muted); font-weight: 700; }
.desktop-nav a:hover, .desktop-nav a.active { color: var(--text); background: transparent; }
.desktop-nav a.active { box-shadow: inset 0 -2px var(--accent); }
.desktop-nav .admin-link { color: var(--accent); }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.icon-button:hover { border-color: var(--line-strong); }
.mobile-nav { display: none; }

.button {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: 12px;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}
.button-primary { color: var(--accent-ink); background: var(--accent); }
.button-primary:hover { filter: brightness(1.06); }
.button-secondary { color: var(--text); border-color: var(--line); background: var(--panel-2); }
.button-secondary:hover { border-color: var(--line-strong); }
.button-quiet { color: var(--muted); border-color: var(--line); background: transparent; }
.button-danger-quiet { color: var(--red); border-color: color-mix(in srgb, var(--red) 28%, transparent); background: transparent; }
.button-wide { width: 100%; }

.toast {
    position: fixed;
    z-index: 100;
    top: 76px;
    left: 50%;
    max-width: min(92vw, 620px);
    padding: 12px 18px;
    transform: translateX(-50%);
    border: 1px solid var(--line-strong);
    border-radius: 13px;
    background: var(--panel-3);
    box-shadow: var(--shadow);
    font-weight: 750;
    animation: toast-in .25s ease both, toast-out .35s ease 5s both;
}
.toast-success { border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.toast-error { border-color: color-mix(in srgb, var(--red) 40%, transparent); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -10px); } }
@keyframes toast-out { to { opacity: 0; visibility: hidden; transform: translate(-50%, -10px); } }

/* Chat */
.chat-app {
    height: calc(100dvh - var(--header-height));
    max-width: 1600px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 235px minmax(0, 1fr);
    border-inline: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg-soft) 94%, transparent);
}
.chat-sidebar {
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 18px 12px;
    border-right: 1px solid var(--line);
    background: color-mix(in srgb, var(--panel) 52%, transparent);
    overflow: hidden;
}
.sidebar-heading { padding: 0 9px 12px; }
.sidebar-heading strong { font-size: 18px; letter-spacing: -.025em; }
.chat-list { display: flex; flex-direction: column; gap: 5px; overflow-y: auto; }
.chat-list-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 9px; padding: 10px; border: 1px solid transparent; border-radius: 10px; color: var(--muted); }
.chat-list-item:hover { color: var(--text); background: var(--panel-2); }
.chat-list-item.active { color: var(--text); border-color: var(--line); background: var(--panel-3); box-shadow: inset 3px 0 var(--accent); }
.chat-list-item strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-lock, .toolbar-lock { color: var(--amber); font-size: 8px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-dot.public { background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 12%, transparent); }
.status-dot.private { background: var(--amber); }
.sidebar-action { margin: 14px 4px 0; }

.chat-main { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.chat-toolbar { min-width: 0; display: flex; align-items: center; gap: 14px; padding: 11px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-title { min-width: 0; }
.chat-title h1 { margin: 0; overflow: hidden; font-size: 18px; text-overflow: ellipsis; white-space: nowrap; }
.chat-title p { max-width: 660px; margin: 3px 0 0; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.toolbar-actions { display: flex; align-items: center; gap: 7px; margin-left: auto; }
.toolbar-actions form { margin: 0; }
.mobile-chat-picker { display: none; }
.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--panel-2); font-size: 10px; font-weight: 850; letter-spacing: .03em; white-space: nowrap; }
.badge-private { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 28%, transparent); background: color-mix(in srgb, var(--amber) 8%, var(--panel)); }
.badge-accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 28%, transparent); }
.badge-muted { opacity: .65; }

.message-list {
    min-width: 0;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    padding: 18px clamp(14px, 3vw, 36px) 24px;
}
.message-stack { min-height: 100%; display: flex; flex-direction: column; justify-content: flex-end; }
.message-card { position: relative; width: 100%; max-width: 1050px; margin: 0 auto 9px; padding: 14px 15px 11px; border: 1px solid var(--line); border-left: 2px solid var(--line-strong); border-radius: 11px; background: var(--panel); }
.message-card:hover { border-color: var(--line-strong); }
.message-card.color-blue { border-left-color: var(--blue); background: color-mix(in srgb, var(--blue) 5%, var(--panel)); }
.message-card.color-green { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 5%, var(--panel)); }
.message-card.color-amber { border-left-color: var(--amber); background: color-mix(in srgb, var(--amber) 5%, var(--panel)); }
.message-card.color-red { border-left-color: var(--red); background: color-mix(in srgb, var(--red) 5%, var(--panel)); }
.chat-style-bubbles .message-card { max-width: min(88%, 850px); margin-left: max(0px, 4%); border-left-width: 1px; border-radius: 20px 20px 20px 7px; }
.message-meta { display: flex; gap: 8px; margin-bottom: 8px; color: var(--muted); font: 10px/1.2 var(--font); }
.message-text { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; color: var(--text); font: 14px/1.6 var(--mono); tab-size: 4; }
.message-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: 11px; opacity: .76; }
.message-card:hover .message-actions, .message-actions:focus-within { opacity: 1; }
.message-actions form { display: inline-flex; margin: 0; }
.mini-button { min-height: 32px; display: inline-flex; align-items: center; padding: 6px 9px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: transparent; font-size: 11px; font-weight: 800; }
.mini-button:hover { color: var(--text); border-color: var(--line-strong); background: var(--panel-2); }
.mini-button.admin-action { color: var(--blue); }
.mini-button.danger { color: var(--red); }
.attachment-list { display: grid; gap: 7px; margin-top: 13px; }
.attachment { min-width: 0; display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-2); }
.attachment:hover { border-color: var(--accent); }
.attachment-icon { flex: 0 0 32px; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; color: var(--accent-ink); background: var(--accent); font-weight: 900; }
.attachment strong, .attachment small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment small { font-size: 10px; }
.message-edit { display: grid; grid-template-columns: minmax(0, 1fr) 150px auto; align-items: end; gap: 10px; margin-top: 13px; padding-top: 13px; border-top: 1px solid var(--line); }
.message-edit[hidden] { display: none; }
.message-edit label { color: var(--muted); font-size: 11px; font-weight: 800; }
.message-edit textarea, .message-edit select { width: 100%; margin-top: 4px; }

.empty-state { max-width: 460px; margin: 14vh auto 0; padding: 24px; color: var(--muted); text-align: center; }
.empty-state h2 { font-size: 17px; font-weight: 650; }
.empty-icon { display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto 14px; border: 1px solid var(--line); border-radius: 17px; color: var(--accent); background: var(--panel-2); font-size: 25px; font-weight: 900; }
.empty-state h2 { margin-bottom: 7px; }
.empty-state p { color: var(--muted); }

.composer { position: relative; padding: 10px clamp(14px, 3vw, 36px) calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
.composer-input-wrap { position: relative; max-width: 1100px; margin: 0 auto; }
.composer textarea { width: 100%; min-height: 50px; max-height: 190px; resize: none; overflow-y: auto; padding: 14px 90px 14px 15px; border: 1px solid var(--line-strong); border-radius: 15px; outline: 0; color: var(--text); background: var(--bg-soft); font-size: 16px; line-height: 1.45; }
.composer textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent); }
.paste-button { position: absolute; top: 8px; right: 8px; min-height: 34px; padding: 6px 10px; border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent); border-radius: 9px; color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--panel)); font-size: 11px; font-weight: 850; }
.paste-button.is-reading { opacity: 0; pointer-events: none; }
.upload-progress { max-width: 1100px; margin: 0 auto 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--bg-soft); }
.upload-progress[hidden] { display: none; }
.upload-progress-row, .upload-details { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.upload-progress-row strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.upload-cancel { padding: 2px 0; border: 0; color: var(--red); background: transparent; font-size: 11px; font-weight: 800; }
.upload-track { height: 5px; margin: 8px 0 6px; overflow: hidden; border-radius: 999px; background: var(--panel-3); }
.upload-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .18s linear; }
.upload-details { color: var(--muted); font: 10px/1.3 var(--mono); }
.composer-actions { max-width: 1100px; min-height: 42px; display: flex; align-items: center; gap: 9px; margin: 7px auto 0; }
.file-button input { display: none; }
.file-summary { min-width: 0; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.file-summary.error { color: var(--red); }
.composer-status { margin-left: auto; color: var(--muted); font-size: 12px; }
.send-button { min-width: 110px; }
.send-button:disabled { opacity: .55; cursor: wait; transform: none; }
.composer.is-sending .file-button { opacity: .5; pointer-events: none; }

/* Public pages */
.page-shell { width: min(1080px, calc(100% - 36px)); margin: 0 auto; padding: 48px 0 90px; }
.page-hero { max-width: 720px; margin-bottom: 24px; }
.page-hero.compact h1 { margin-bottom: 16px; }
.page-hero p { max-width: 700px; color: var(--muted); font-size: 17px; }
.search-field { max-width: 480px; display: flex; align-items: center; gap: 8px; margin-top: 14px; padding: 0 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.search-field span { color: var(--accent); font-size: 22px; }
.search-field input { width: 100%; min-height: 48px; border: 0; outline: 0; background: transparent; font-size: 16px; }
.card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.info-card { min-height: 150px; display: flex; flex-direction: column; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.info-card:hover { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.card-topline { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; }
.card-index { color: var(--accent); font: 700 13px/1 var(--mono); }
.info-card h2 { margin: 4px 0 8px; font-size: 18px; line-height: 1.22; }
.info-card p { color: var(--muted); font-size: 13px; }
.card-link { margin-top: auto; color: var(--accent); font-size: 12px; font-weight: 850; }
.article-shell { width: min(920px, calc(100% - 34px)); margin: 0 auto; padding: 46px 0 110px; }
.back-link { display: inline-block; margin-bottom: 18px; color: var(--muted); font-weight: 750; }
.back-link:hover { color: var(--accent); }
.back-link.centered { display: block; margin: 22px auto 0; text-align: center; }
.article-card { overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); }
.article-header { padding: clamp(25px, 6vw, 56px); border-bottom: 1px solid var(--line); background: linear-gradient(140deg, color-mix(in srgb, var(--accent) 7%, var(--panel)), var(--panel)); }
.article-header h1 { max-width: 760px; margin-bottom: 14px; }
.article-header p { max-width: 680px; margin-bottom: 14px; color: var(--muted); font-size: 17px; }
.prose { padding: clamp(25px, 6vw, 58px); color: color-mix(in srgb, var(--text) 94%, var(--muted)); font-size: 16px; line-height: 1.75; }
.prose h2 { margin: 2.2em 0 .75em; color: var(--text); font-size: 26px; }
.prose h2:first-child { margin-top: 0; }
.prose h3 { margin: 1.8em 0 .6em; color: var(--text); }
.prose p, .prose ul, .prose ol { margin-bottom: 1.2em; }
.prose a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.prose blockquote { margin: 1.5em 0; padding: 15px 18px; border-left: 3px solid var(--amber); border-radius: 0 12px 12px 0; color: var(--text); background: color-mix(in srgb, var(--amber) 7%, var(--panel-2)); }
.prose pre { position: relative; margin: 1.2em 0; padding: 20px 18px; overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; color: #e8f6ff; background: #07111e; font: 13px/1.65 var(--mono); }
:root[data-theme="light"] .prose pre { color: #e8f6ff; }
.prose code { font-family: var(--mono); }
.prose :not(pre) > code { padding: 2px 5px; border-radius: 5px; color: var(--accent); background: var(--panel-2); font-size: .9em; }
.code-copy { position: absolute; top: 9px; right: 9px; min-height: 31px; padding: 5px 9px; border: 1px solid rgba(255, 255, 255, .16); border-radius: 8px; color: #a9b9ca; background: #111d2b; font-size: 10px; font-weight: 850; }
.program-list { display: grid; gap: 10px; }
.program-card { display: grid; grid-template-columns: 46px minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.program-card:hover { border-color: var(--line-strong); }
.program-icon { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 10px; color: var(--accent); background: var(--panel-3); font-size: 18px; font-weight: 900; }
.program-copy { min-width: 0; }
.program-title-line { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.program-title-line h2 { margin: 0; font-size: 18px; }
.program-copy p { margin: 6px 0; color: var(--muted); }
.empty-panel { grid-column: 1 / -1; padding: 42px 20px; border: 1px solid var(--line); border-radius: var(--radius); text-align: center; background: var(--panel); }
.empty-panel p { color: var(--muted); }

/* Admin */
.auth-shell { min-height: calc(100dvh - var(--header-height)); display: grid; place-items: center; padding: 35px 18px 90px; }
.auth-card { width: min(400px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); }
.auth-card .auth-mark { width: 50px; height: 50px; margin-bottom: 26px; border-radius: 15px; font-size: 20px; }
.auth-card h1 { margin-bottom: 20px; font-size: 30px; }
.auth-card > p { color: var(--muted); }
.stack-form, .editor-form { display: grid; gap: 16px; }
.stack-form { margin-top: 24px; }
.stack-form label, .editor-form label, .message-edit label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 800; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 11px; outline: 0; background: var(--bg-soft); }
input, select { min-height: 44px; padding: 9px 12px; }
textarea { padding: 12px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 10%, transparent); }
.check-row { grid-template-columns: auto 1fr !important; align-items: center; }
.check-row input, .check-card input { width: 18px; min-height: 18px; accent-color: var(--accent); }
.admin-shell { width: min(1440px, 100%); min-height: calc(100dvh - var(--header-height)); display: grid; grid-template-columns: 220px minmax(0, 1fr); margin: 0 auto; }
.admin-nav { display: flex; flex-direction: column; gap: 5px; padding: 26px 16px; border-right: 1px solid var(--line); }
.admin-nav a, .admin-nav button { width: 100%; display: block; padding: 11px 12px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; text-align: left; font-weight: 750; }
.admin-nav a:hover, .admin-nav a.active, .admin-nav button:hover { color: var(--text); background: var(--panel-2); }
.admin-nav a.active { box-shadow: inset 3px 0 var(--accent); }
.admin-nav form { margin-top: auto; }
.admin-content { min-width: 0; padding: 34px clamp(20px, 4vw, 44px) 90px; }
.admin-content.narrow { max-width: 1040px; }
.admin-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.admin-heading h1 { margin: 0; font-size: clamp(28px, 4vw, 38px); }
.admin-heading p { max-width: 660px; color: var(--muted); }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stats-grid a { display: flex; flex-direction: column; min-height: 135px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.stats-grid a:hover { border-color: var(--accent); }
.stats-grid span { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.stats-grid strong { margin-top: auto; font-size: 40px; letter-spacing: -.05em; }
.stats-grid small { font-size: 12px; }
.admin-quick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
.admin-quick-card { display: grid; gap: 4px; padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: color-mix(in srgb, var(--panel) 70%, transparent); }
.admin-quick-card > span { color: var(--accent); font-size: 22px; }
.admin-quick-card small { font-size: 11px; }
.admin-list { display: grid; gap: 8px; }
.admin-row { min-width: 0; display: grid; grid-template-columns: 42px minmax(220px, 1fr) auto auto; align-items: center; gap: 12px; padding: 13px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.reorder-buttons { display: grid; grid-template-columns: repeat(2, 1fr); gap: 3px; }
.reorder-buttons form { margin: 0; }
.reorder-buttons button { width: 19px; height: 27px; padding: 0; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); background: var(--panel-2); }
.admin-row-copy { min-width: 0; }
.admin-row-copy strong, .admin-row-copy > small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-row-copy > small { margin-top: 3px; font-size: 11px; }
.admin-row-flags, .admin-row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.admin-row-actions form { margin: 0; }
.editor-form { padding: clamp(18px, 4vw, 26px); border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.editor-form label small { font-weight: 500; }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.code-editor { min-height: 420px; font: 13px/1.55 var(--mono); tab-size: 4; }
.check-card { grid-template-columns: auto 1fr !important; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-soft); }
.check-card span, .check-card strong, .check-card small { display: block; }
.check-card strong { color: var(--text); }
.upload-card { padding: 18px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--bg-soft); }
.upload-card p { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.program-form { max-width: 680px; gap: 18px; }
.program-form .optional { margin-left: 5px; color: var(--muted); font-size: 11px; font-weight: 500; }
.primary-upload { padding: 22px; border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.primary-upload input[type="file"] { min-height: 46px; padding: 8px; background: var(--panel); cursor: pointer; }
.primary-upload small { display: block; margin-top: 8px; }
.toolbar-icon { width: 38px; min-width: 38px; min-height: 38px; padding: 0; font-size: 18px; }
.or-divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.or-divider::before, .or-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.form-actions { display: flex; justify-content: flex-end; gap: 9px; padding-top: 8px; }

/* Design selector */
.design-form { display: grid; gap: 18px; }
.design-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.design-option { position: relative; display: grid; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); cursor: pointer; }
.design-option:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 16%, transparent); }
.design-option > input { position: absolute; top: 18px; right: 18px; z-index: 2; width: 18px; min-height: 18px; accent-color: var(--accent); }
.design-option > span:last-child strong, .design-option > span:last-child small { display: block; }
.design-option > span:last-child small { margin-top: 3px; }
.design-preview { position: relative; height: 150px; overflow: hidden; border-radius: 11px; background: #0b1017; }
.design-preview::before { content: ""; position: absolute; inset: 0 0 auto; height: 25px; border-bottom: 1px solid rgba(255,255,255,.12); }
.design-preview i, .design-preview b, .design-preview em { position: absolute; display: block; border-radius: 6px; }
.design-preview i { top: 39px; left: 12px; width: 35%; height: 8px; background: #55d6aa; }
.design-preview b { top: 60px; right: 12px; bottom: 12px; left: 12px; border: 1px solid rgba(255,255,255,.12); background: #121a24; }
.design-preview em { right: 22px; bottom: 21px; width: 28%; height: 8px; background: #55d6aa; }
.preview-terminal { color: #62ff91; background: #06130b; font-family: var(--mono); }
.preview-terminal i { width: auto; height: auto; color: #62ff91; background: none; font-style: normal; font-weight: 800; }
.preview-terminal b { border-color: rgba(98,255,145,.38); border-radius: 1px; background: repeating-linear-gradient(0deg, #0c2415 0 8px, #10331c 8px 9px); }
.preview-terminal em { border-radius: 1px; background: #62ff91; }
.preview-ios { background: #000000; }
.preview-ios::before { background: rgba(28,28,30,.82); }
.preview-ios i { border-radius: 999px; background: #0a84ff; }
.preview-ios b { border: 0; border-radius: 18px; background: #1c1c1e; box-shadow: 0 8px 20px rgba(0,0,0,.3); }
.preview-ios em { border-radius: 999px; background: #0a84ff; }
.preview-ios-light { background: #f2f2f7; }
.preview-ios-light::before { border-color: rgba(60,60,67,.15); background: rgba(255,255,255,.75); }
.preview-ios-light i { border-radius: 999px; background: #007aff; }
.preview-ios-light b { border: 0; border-radius: 18px; background: #ffffff; box-shadow: 0 8px 20px rgba(60,60,67,.14); }
.preview-ios-light em { border-radius: 999px; background: #007aff; }

/* Terminal / Matrix design */
:root[data-design="terminal"] body { background-image: repeating-linear-gradient(0deg, transparent 0 3px, rgba(98,255,145,.03) 3px 4px); }
:root[data-design="terminal"] .site-header,
:root[data-design="terminal"] .chat-toolbar,
:root[data-design="terminal"] .composer,
:root[data-design="terminal"] .mobile-nav { backdrop-filter: none; background: rgba(6, 19, 11, .96); }
:root[data-design="terminal"] .button,
:root[data-design="terminal"] .mini-button,
:root[data-design="terminal"] input,
:root[data-design="terminal"] textarea,
:root[data-design="terminal"] select,
:root[data-design="terminal"] .message-card,
:root[data-design="terminal"] .program-card,
:root[data-design="terminal"] .info-card { border-radius: 2px; box-shadow: none; }
:root[data-design="terminal"] .brand-logo { border-radius: 2px; filter: saturate(1.35) contrast(1.1); }
:root[data-design="terminal"] .message-card { border-left-color: var(--accent); }
:root[data-design="terminal"] .message-text { color: var(--text); }

/* Modern iOS design */
:root:is([data-design="ios"], [data-design="ios-light"]) body { font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif; }
:root:is([data-design="ios"], [data-design="ios-light"]) .site-header,
:root:is([data-design="ios"], [data-design="ios-light"]) .mobile-nav { background: color-mix(in srgb, var(--panel) 82%, transparent); backdrop-filter: blur(28px) saturate(1.5); }
:root:is([data-design="ios"], [data-design="ios-light"]) .chat-toolbar,
:root:is([data-design="ios"], [data-design="ios-light"]) .composer { background: color-mix(in srgb, var(--panel) 90%, transparent); backdrop-filter: blur(24px) saturate(1.4); }
:root:is([data-design="ios"], [data-design="ios-light"]) .message-card,
:root:is([data-design="ios"], [data-design="ios-light"]) .program-card,
:root:is([data-design="ios"], [data-design="ios-light"]) .info-card,
:root:is([data-design="ios"], [data-design="ios-light"]) .editor-form { border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.08); }
:root:is([data-design="ios"], [data-design="ios-light"]) .button { border-radius: 14px; }
:root:is([data-design="ios"], [data-design="ios-light"]) .button-primary { box-shadow: 0 7px 20px color-mix(in srgb, var(--accent) 24%, transparent); }
:root:is([data-design="ios"], [data-design="ios-light"]) .brand-logo,
:root:is([data-design="ios"], [data-design="ios-light"]) .auth-logo { border-radius: 12px; }

@media (max-width: 980px) {
    .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .admin-row { grid-template-columns: 38px minmax(180px, 1fr) auto; }
    .admin-row-actions { grid-column: 2 / -1; }
}

@media (max-width: 760px) {
    :root { --header-height: 58px; }
    body { padding-bottom: var(--mobile-nav-height); }
    .site-header { height: var(--header-height); padding: 0 13px; }
    .brand { min-width: 0; }
    .brand small { display: none; }
    .desktop-nav { display: none; }
    .theme-toggle { margin-left: auto; }
    .mobile-nav {
        position: fixed;
        z-index: 70;
        right: 0;
        bottom: 0;
        left: 0;
        height: var(--mobile-nav-height);
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        padding: 4px 5px env(safe-area-inset-bottom);
        border-top: 1px solid var(--line);
        background: color-mix(in srgb, var(--panel) 94%, transparent);
        backdrop-filter: blur(20px);
    }
    .mobile-nav a { min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; border-radius: 10px; color: var(--muted); font-size: 9px; font-weight: 800; }
    .mobile-nav a span { height: 25px; color: inherit; font-size: 20px; line-height: 1; }
    .mobile-nav a.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); }
    .toast { top: 12px; }

    body.chat-page { position: fixed; top: var(--app-top, 0); right: 0; bottom: auto; left: 0; height: var(--app-height, 100dvh); padding: 0; overflow: hidden; overscroll-behavior: none; }
    body.chat-page .site-header { display: none; }
    .chat-app { width: 100%; height: calc(var(--app-height, 100dvh) - var(--mobile-nav-height)); display: block; border: 0; }
    body.chat-page.keyboard-open .mobile-nav { display: none; }
    body.chat-page.keyboard-open .chat-app { height: var(--app-height, 100dvh); }
    .chat-sidebar { display: none; }
    .chat-main { height: 100%; grid-template-rows: auto minmax(0, 1fr) auto; }
    .chat-toolbar { min-height: 58px; gap: 9px; padding: calc(7px + env(safe-area-inset-top)) 10px 7px; }
    .mobile-chat-picker { display: block; min-width: 0; flex: 1; }
    .mobile-chat-picker select { width: 100%; min-height: 42px; padding: 7px 31px 7px 11px; border-color: var(--line); background: var(--panel-2); font-weight: 850; }
    .chat-title { display: none; }
    .toolbar-actions { flex: 0 0 auto; gap: 4px; }
    .toolbar-actions .badge, .toolbar-actions .button span { display: none; }
    .toolbar-actions .button { width: 42px; min-height: 42px; padding: 0; font-size: 20px; }
    .message-list { padding: 12px 10px 17px; }
    .message-card, .chat-style-bubbles .message-card { max-width: 100%; margin: 0 0 9px; padding: 13px 12px 11px; border-radius: 13px; }
    .chat-style-bubbles .message-card { max-width: 92%; border-radius: 18px 18px 18px 6px; }
    .message-text { font-size: 13px; line-height: 1.55; }
    .message-meta { margin-bottom: 8px; }
    .message-actions { gap: 4px; margin-top: 10px; }
    .message-actions { opacity: 1; }
    .mini-button { min-height: 36px; padding: 7px 9px; }
    .message-edit { grid-template-columns: 1fr; }
    .composer { padding: 8px 9px calc(7px + env(safe-area-inset-bottom)); }
    body.chat-page.keyboard-open .composer { padding-bottom: 7px; }
    .composer textarea { min-height: 48px; max-height: 145px; padding: 12px 84px 12px 12px; }
    .upload-progress { margin-bottom: 6px; padding: 8px 10px; }
    .upload-progress-row strong { font-size: 11px; }
    .upload-details { font-size: 9px; }
    .composer-actions { min-height: 40px; gap: 6px; margin-top: 6px; }
    .file-button { min-height: 40px; padding: 8px 10px; }
    .file-summary { max-width: 90px; }
    .composer-status { max-width: 110px; overflow: hidden; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
    .send-button { min-width: 116px; min-height: 42px; margin-left: auto; }
    .empty-state { margin-top: 7vh; }

    .page-shell { width: min(100% - 24px, 1180px); padding: 42px 0 50px; }
    .page-hero p { font-size: 15px; }
    .card-grid { grid-template-columns: 1fr; }
    .info-card { min-height: 220px; }
    .article-shell { width: calc(100% - 20px); padding: 24px 0 44px; }
    .article-card { border-radius: 20px; }
    .article-header { padding: 25px 20px; }
    .article-header h1 { font-size: 34px; }
    .article-header p { font-size: 15px; }
    .prose { padding: 25px 19px; font-size: 15px; }
    .prose h2 { font-size: 23px; }
    .prose pre { margin-inline: -8px; padding: 48px 14px 16px; font-size: 12px; }
    .program-card { grid-template-columns: 46px minmax(0, 1fr); gap: 11px; }
    .program-icon { width: 46px; height: 46px; border-radius: 13px; }
    .program-download { grid-column: 1 / -1; }

    .auth-shell { min-height: calc(100dvh - var(--header-height) - var(--mobile-nav-height)); padding: 20px 12px 34px; }
    .auth-card { padding: 25px 20px; border-radius: 20px; }
    .admin-shell { display: block; }
    .admin-nav { overflow-x: auto; flex-direction: row; padding: 9px 10px; border-right: 0; border-bottom: 1px solid var(--line); }
    .admin-nav a, .admin-nav button { width: auto; min-height: 38px; padding: 8px 11px; white-space: nowrap; }
    .admin-nav form { margin: 0 0 0 auto; }
    .admin-content { padding: 28px 12px 50px; }
    .admin-heading { align-items: stretch; flex-direction: column; margin-bottom: 22px; }
    .admin-heading .button { align-self: flex-start; }
    .stats-grid, .admin-quick-grid { grid-template-columns: 1fr; }
    .stats-grid a { min-height: 140px; }
    .admin-row { grid-template-columns: 34px minmax(0, 1fr); gap: 9px; }
    .admin-row-flags, .admin-row-actions { grid-column: 2 / -1; }
    .form-grid.two { grid-template-columns: 1fr; }
    .editor-form { padding: 16px 13px; }
    .code-editor { min-height: 340px; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .button { width: 100%; }
    .design-picker { grid-template-columns: 1fr; }
    .design-preview { height: 125px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation-duration: .01ms !important; }
}
