/* CONNEX v2.17 stylesheet
   One layer of rules built on design tokens. Light and dark themes follow the
   device setting unless a member picks one with the header theme switch. */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --surface-3: #e6e9f1;
  --text: #161a26;
  --muted: #5d6475;
  --faint: #8a90a0;
  --line: #e1e4ec;
  --line-strong: #c9cedb;
  --accent: #3554d1;
  --accent-hover: #2a45b4;
  --accent-text: #ffffff;
  --accent-soft: #e9edfd;
  --accent-ink: #2440ad;
  --danger: #b4232c;
  --danger-soft: #fdecee;
  --success: #17733a;
  --success-soft: #e6f5ec;
  --warn: #8a5a00;
  --warn-soft: #fff5d6;
  --focus: #3554d1;
  --shadow-sm: 0 1px 2px rgb(20 26 45 / 6%);
  --shadow: 0 1px 2px rgb(20 26 45 / 5%), 0 6px 20px rgb(20 26 45 / 7%);
  --shadow-lg: 0 12px 40px rgb(20 26 45 / 18%);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --sidebar-width: 280px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* Legacy names kept for any custom additions. */
  --panel: var(--surface);
  --soft: var(--surface-2);
  --dark: var(--text);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1118;
  --surface: #161a24;
  --surface-2: #1d2230;
  --surface-3: #272d3d;
  --text: #e8ebf3;
  --muted: #a2a9ba;
  --faint: #7a8296;
  --line: #2a3040;
  --line-strong: #3a4256;
  --accent: #7d97ff;
  --accent-hover: #9aafff;
  --accent-text: #0c1020;
  --accent-soft: #232c4d;
  --accent-ink: #b3c2ff;
  --danger: #ff7b84;
  --danger-soft: #3a1d22;
  --success: #5fd38d;
  --success-soft: #16301f;
  --warn: #f2c35b;
  --warn-soft: #33290f;
  --focus: #9aafff;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 30%);
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 30%);
  --shadow-lg: 0 16px 48px rgb(0 0 0 / 55%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1118;
    --surface: #161a24;
    --surface-2: #1d2230;
    --surface-3: #272d3d;
    --text: #e8ebf3;
    --muted: #a2a9ba;
    --faint: #7a8296;
    --line: #2a3040;
    --line-strong: #3a4256;
    --accent: #7d97ff;
    --accent-hover: #9aafff;
    --accent-text: #0c1020;
    --accent-soft: #232c4d;
    --accent-ink: #b3c2ff;
    --danger: #ff7b84;
    --danger-soft: #3a1d22;
    --success: #5fd38d;
    --success-soft: #16301f;
    --warn: #f2c35b;
    --warn-soft: #33290f;
    --focus: #9aafff;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 30%);
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 30%);
    --shadow-lg: 0 16px 48px rgb(0 0 0 / 55%);
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
a { color: var(--accent-ink); text-underline-offset: 3px; }
a:hover { color: var(--accent); }
p { overflow-wrap: anywhere; }
hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
img, svg { max-width: 100%; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
summary { cursor: pointer; font-weight: 700; }
code, kbd { font-family: var(--mono); font-size: .9em; }

/* ---------- Form controls ---------- */
button, input, textarea, select { font: inherit; color: var(--text); -webkit-text-fill-color: currentColor; }
button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); font-weight: 600; font-size: 14px; line-height: 1.2; cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
button:hover { background: var(--surface-2); border-color: var(--faint); }
button:active { transform: translateY(1px); }
button:disabled, button:disabled:hover { cursor: not-allowed; opacity: 1; color: var(--faint); background: var(--surface-2); border-color: var(--line); transform: none; }
input, textarea, select {
  width: 100%; min-width: 0; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); font-weight: 400; transition: border-color .15s ease, box-shadow .15s ease;
}
input:hover, textarea:hover, select:hover { border-color: var(--faint); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
input::placeholder, textarea::placeholder { color: var(--faint); -webkit-text-fill-color: var(--faint); }
input:disabled, textarea:disabled { background: var(--surface-2); color: var(--muted); -webkit-text-fill-color: var(--muted); cursor: not-allowed; }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }
input[type="range"] { padding: 0; border: 0; accent-color: var(--accent); box-shadow: none; }
input[type="file"] { padding: 8px; background: var(--surface-2); }
textarea { resize: vertical; }
label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0; min-width: 0; }
legend { padding: 0 6px; font-weight: 700; font-size: 14px; }

.primary-button, .button-link {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text); -webkit-text-fill-color: var(--accent-text);
}
.primary-button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button-link { display: inline-flex; align-items: center; min-height: 40px; padding: 8px 18px; border: 1px solid var(--accent); border-radius: var(--radius-sm); font-weight: 600; text-decoration: none; }
.button-link:hover { background: var(--accent-hover); color: var(--accent-text); }
.danger-button { color: var(--danger); -webkit-text-fill-color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.danger-button:hover { background: var(--danger-soft); border-color: var(--danger); }
.link-button { min-height: 0; padding: 0; border: 0; background: transparent; font-weight: 500; }
.link-button:hover { background: transparent; color: var(--accent); }
.download-link { display: inline-flex; align-items: center; min-height: 40px; padding: 8px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); text-decoration: none; font-weight: 600; color: var(--text); }
.download-link:hover { background: var(--surface-2); color: var(--text); }

.stack-form { display: grid; gap: 16px; }
.stack-form.compact { gap: 10px; }
.stack-form > button { justify-self: start; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input { flex: 1; }
.small-form input { width: 80px; }
.row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.check-label { display: flex !important; align-items: center; gap: 10px; font-weight: 500; }
.check-label input[type="checkbox"] { width: 18px; height: 18px; flex: 0 0 18px; margin: 0; }
.form-help { margin: 0; color: var(--muted); font-size: 13px; font-weight: 400; }
.form-error { margin: 0; color: var(--danger); font-size: 14px; }
.optional-label { margin-left: 4px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 500; vertical-align: middle; }
.muted { color: var(--muted); }
.preserve-lines { white-space: pre-wrap; overflow-wrap: anywhere; }

.alert { padding: 10px 14px; margin: 0 0 14px; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius-sm); background: var(--accent-soft); font-size: 14px; }
.alert.error { border-left-color: var(--danger); background: var(--danger-soft); color: var(--text); }
.admin-notice { padding: 12px 16px; border: 1px solid color-mix(in srgb, var(--success) 35%, var(--line)); border-radius: var(--radius-sm); background: var(--success-soft); }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 64px; padding: 10px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: saturate(160%) blur(12px); backdrop-filter: saturate(160%) blur(12px);
}
.brand { display: inline-flex; align-items: center; gap: 10px; min-width: 0; max-width: 45%; color: var(--text); text-decoration: none; font-size: 20px; font-weight: 800; letter-spacing: .08em; }
.brand:hover { color: var(--text); }
.brand-name { overflow-wrap: anywhere; }
.brand-mark { flex: 0 0 auto; width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 45%, #18c3b0)); box-shadow: inset 0 0 0 1px rgb(255 255 255 / 15%); position: relative; }
.brand-mark::before, .brand-mark::after { content: ''; position: absolute; width: 8px; height: 8px; border-radius: 50%; background: #fff; top: 9px; }
.brand-mark::before { left: 5px; }
.brand-mark::after { right: 5px; opacity: .75; }
.app-header nav { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 4px; min-width: 0; }
.app-header nav a, .app-header .link-button {
  display: inline-flex; align-items: center; min-height: 36px; padding: 6px 12px; border-radius: 99px;
  color: var(--muted); font-size: 14px; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.app-header nav a:hover, .app-header .link-button:hover { background: var(--surface-2); color: var(--text); }
.app-header nav form { margin: 0; }
.theme-toggle { width: 36px; min-height: 36px; height: 36px; margin-left: 4px; padding: 0; border-radius: 50%; border-color: var(--line); background: var(--surface); color: var(--muted); }
.theme-toggle:hover { color: var(--text); }
.theme-icon { display: none; }
:root:not([data-theme-choice]) .theme-icon-auto,
[data-theme-choice="auto"] .theme-icon-auto,
[data-theme-choice="light"] .theme-icon-light,
[data-theme-choice="dark"] .theme-icon-dark { display: block; }

/* ---------- Homepage ---------- */
.home-tagline { width: min(1180px, 92vw); margin: 28px auto 0; color: var(--muted); }
.home-grid {
  width: min(1180px, 92vw); margin: 40px auto 56px; display: grid; gap: clamp(28px, 5vw, 64px); align-items: start;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); grid-template-areas: "welcome login";
}
.home-grid .welcome-panel { grid-area: welcome; min-width: 0; }
.home-grid .auth-card { grid-area: login; width: 100%; position: sticky; top: 88px; }
.eyebrow { margin: 0; color: var(--accent-ink); font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.welcome-panel h1 { max-width: 780px; margin: 12px 0 20px; font-size: clamp(40px, 6.5vw, 76px); line-height: 1; letter-spacing: -0.035em; font-weight: 850; }
.welcome-panel > p { max-width: 640px; margin: 0; color: var(--muted); font-size: clamp(16px, 1.6vw, 19px); line-height: 1.65; }
.announcement-list { margin-top: 48px; max-width: 760px; display: grid; gap: 14px; }
.announcement-list h2 { margin: 0 0 4px; }
.announcement-card { padding: 20px 22px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.announcement-card h3 { margin: 0 0 6px; }
.announcement-card p { margin: 0 0 10px; white-space: pre-wrap; line-height: 1.6; color: var(--text); }
.announcement-card small { color: var(--faint); font-size: 13px; }
.auth-card h2 { margin-top: 0; }
.auth-card .stack-form > button, .auth-card .button-link { justify-self: stretch; width: 100%; justify-content: center; }
.auth-card h3 { margin: 0 0 4px; }
.analytics-public-note { max-width: 1180px; width: 92vw; margin: 0 auto 40px; padding: 20px 0 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }

/* ---------- Cards ---------- */
.auth-card, .settings-card, .admin-card, .profile-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: clamp(18px, 3vw, 28px); box-shadow: var(--shadow); min-width: 0;
}
.settings-card h2, .admin-card h2 { margin-top: 0; }
.settings-card > summary { font-size: 1.15rem; list-style-position: outside; }
.settings-card > summary + * { margin-top: 14px; }
details.settings-card[open] > summary { margin-bottom: 6px; }
.edit-card, .report-card { border-top: 1px solid var(--line); padding: 18px 0 4px; margin-top: 16px; overflow-wrap: anywhere; }
.edit-card > form + form, .edit-card > .row-actions { margin-top: 10px; }
.wide-card { grid-column: 1 / -1; }

/* ---------- App layout (chat + leaderboard) ---------- */
.chat-layout { position: relative; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); height: calc(100dvh - var(--header-height, 64px)); min-height: 0; }
.chat-layout.sidebar-collapsed { grid-template-columns: minmax(0, 1fr); }
.leaderboard-layout { height: auto; min-height: calc(100dvh - var(--header-height, 64px)); align-items: start; }
.leaderboard-layout .room-sidebar { align-self: stretch; }

.room-sidebar { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; padding: 18px 14px; background: var(--surface); border-right: 1px solid var(--line); }
.sidebar-content, .sidebar-scroll { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.sidebar-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 18px; background: var(--surface-2); border-radius: var(--radius); }
.sidebar-tabs a { display: flex; align-items: center; justify-content: center; min-height: 40px; padding: 6px 8px; border-radius: 9px; color: var(--muted); font-size: 13px; font-weight: 600; text-align: center; text-decoration: none; }
.sidebar-tabs a:hover { color: var(--text); background: var(--surface-3); }
.sidebar-tabs a[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.sidebar-title { padding: 0 10px 10px; color: var(--faint); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.room-category { margin-bottom: 10px; }
.room-category summary { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: var(--radius-sm); color: var(--muted); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; overflow-wrap: anywhere; list-style: none; }
.room-category summary::-webkit-details-marker { display: none; }
.room-category summary::before { content: ''; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s ease; flex: 0 0 auto; margin-right: 2px; }
.room-category[open] summary::before { transform: rotate(45deg); }
.room-category summary:hover { color: var(--text); background: var(--surface-2); }
.room-link { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 2px 0; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text); font-size: 14px; text-decoration: none; overflow-wrap: anywhere; }
.room-link:hover { background: var(--surface-2); color: var(--text); }
.room-link.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 650; }
.room-link.restricted { color: var(--faint); cursor: not-allowed; user-select: none; }
.room-link.restricted:hover { background: transparent; }
.room-badges { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
.room-badges small { padding: 1px 6px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-size: 11px; white-space: nowrap; }

.suggestion-box { margin-top: auto; padding: 16px 8px 0; border-top: 1px solid var(--line); }
.suggestion-box summary { font-size: 14px; }
.suggestion-box p { font-size: 13px; line-height: 1.5; color: var(--muted); }
.suggestion-box label { font-size: 13px; }
.suggestion-box small { color: var(--faint); font-size: 12px; }
.suggestion-box .stack-form { gap: 8px; }
#suggestion-status:empty, #poll-status:empty { display: none; }
#suggestion-status { margin: 0; font-size: 13px; }

/* Collapsible sidebar toggle in the title row */
.room-title-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.room-title-row h1 { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.room-title-content, .leaderboard-title-content { min-width: 0; width: 100%; }
.leaderboard-title-content { flex: 1; }
.sidebar-toggle {
  position: relative; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 32px;
  width: 32px; height: 32px; min-height: 0; margin: 0; padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); -webkit-appearance: none; appearance: none;
}
.sidebar-toggle:hover { background: var(--surface-2); color: var(--text); }
.sidebar-toggle::before { content: ''; position: absolute; inset: -6px; border-radius: 50%; }
.sidebar-toggle svg { display: block; width: 24px; height: 24px; pointer-events: none; }
.sidebar-chevron { transform-origin: 16px 16px; transition: transform .2s ease; }
.sidebar-toggle[aria-expanded="false"] .sidebar-chevron { transform: rotate(180deg); }

/* ---------- Chat panel ---------- */
.chat-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--bg); }
.chat-room-header { flex-shrink: 0; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.chat-room-header h1 { font-size: 18px; line-height: 28px; }
.chat-room-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
#room-description { white-space: pre-wrap; max-height: 90px; overflow-y: auto; }
#room-description:empty { display: none; }
#room-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--faint); }
#room-status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.chat-access-alert { margin: 14px 24px 0; padding: 10px 14px; border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--line)); border-radius: var(--radius-sm); background: var(--warn-soft); font-size: 14px; }

.room-polls, .pinned-section { flex-shrink: 0; overflow-y: auto; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.room-polls { max-height: 38vh; }
.pinned-section { max-height: 200px; }
.room-polls > summary, .pinned-section > summary { font-size: 13px; color: var(--muted); }
.poll-card { border-top: 1px solid var(--line); padding: 12px 0; }
.poll-card h3 { font-size: 15px; margin: 4px 0; overflow-wrap: anywhere; }
.poll-card p { font-size: 13px; margin: 4px 0; }
.poll-card fieldset { border: 0; padding: 0; margin: 10px 0; }
.poll-card legend { padding: 0; margin-bottom: 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.poll-option { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 6px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-weight: 500; overflow-wrap: anywhere; cursor: pointer; }
.poll-option:hover { background: var(--surface-2); }
.poll-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.poll-option input { width: auto; flex-shrink: 0; margin-top: 3px; }
.pinned-item { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.pinned-link { flex: 1; min-width: 0; justify-content: flex-start; text-align: left; font-size: 13px; font-weight: 500; overflow-wrap: anywhere; border-color: var(--line); background: var(--warn-soft); }
.pinned-item > button:not(.pinned-link) { min-height: 32px; padding: 4px 10px; font-size: 12px; }

.connection-status { flex-shrink: 0; display: flex; align-items: center; gap: 6px; margin: 8px 24px 0; color: var(--faint); font-size: 12px; }
.connection-status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.chat-kudos-status { flex-shrink: 0; margin: 8px 24px 0; font-size: 13px; }
.chat-notice { flex-shrink: 0; margin: 8px 24px 0; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--success-soft); font-size: 13px; }
.chat-error { flex-shrink: 0; margin: 8px 24px 0; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger); font-size: 14px; }

.messages { flex: 1; min-height: 100px; overflow-y: auto; overscroll-behavior: contain; padding: 16px 24px 20px; scroll-padding: 16px; }
.messages > .muted { margin: 40px auto; text-align: center; }
.message-item { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; column-gap: 12px; align-items: start; padding: 6px 8px; margin: 0 -8px; border-radius: var(--radius); }
.message-item:hover { background: color-mix(in srgb, var(--surface) 55%, transparent); }
.message-item:focus { outline: 2px solid var(--focus); outline-offset: 0; }
.message-item:target, .message-item:focus { background: var(--accent-soft); }
.message-body { min-width: 0; }
.message-item p { margin: 3px 0 0; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-meta { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; }
.message-author { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; max-width: 100%; }
.message-author > a, .message-meta a { color: var(--text); font-weight: 700; text-decoration: none; overflow-wrap: anywhere; min-width: 0; }
.message-author > a:hover { color: var(--accent); text-decoration: underline; }
.own-message .message-author > a { color: var(--accent-ink); }
.message-meta time { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.pin-label { padding: 1px 7px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); font-size: 11px; font-weight: 700; }
.deleted-message { color: var(--faint); font-style: italic; }
.mentioned-message { background: var(--warn-soft); box-shadow: inset 3px 0 0 var(--warn); }
.mentioned-message:hover { background: var(--warn-soft); }
.mention { padding: 1px 4px; border-radius: 4px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; text-decoration: none; }
.mention-self { background: color-mix(in srgb, var(--warn) 25%, transparent); color: var(--text); }
.chat-link { color: var(--accent-ink); overflow-wrap: anywhere; }
.reply-quote {
  display: block; width: auto; max-width: 100%; min-height: 0; margin: 6px 0 2px; padding: 6px 10px;
  border: 0; border-left: 3px solid var(--line-strong); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-2); color: var(--muted); font-size: 13px; font-weight: 400; text-align: left; overflow-wrap: anywhere;
}
.reply-quote:hover { background: var(--surface-3); border-left-color: var(--accent); }

.profile-avatar { display: grid; place-items: center; flex-shrink: 0; width: 38px; height: 38px; overflow: hidden; border-radius: 50%; background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 50%, #18c3b0)); color: #fff; font-weight: 800; }
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-avatar.large { width: 112px; height: 112px; font-size: 40px; flex: 0 0 auto; box-shadow: 0 0 0 4px var(--surface), 0 0 0 5px var(--line); }

.message-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 0; }
.reaction-button { min-width: 0; min-height: 28px; padding: 2px 8px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 600; }
.reaction-button:hover { border-color: var(--line-strong); background: var(--surface-2); }
.reaction-button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
/* Unused reactions appear on hover/focus (or a tap on touch screens) to keep the conversation calm. */
.reaction-button:not(.has-count) { display: none; }
.message-item:hover .reaction-button, .message-item:focus-within .reaction-button, .message-item:focus .reaction-button { display: inline-flex; }
.message-reactions:not(:has(.has-count)) { margin: 0; }
.message-item:hover .message-reactions, .message-item:focus-within .message-reactions, .message-item:focus .message-reactions { margin-top: 6px; }

.message-menu-trigger { width: 26px; height: 26px; min-height: 0; padding: 0; flex-shrink: 0; border: 0; border-radius: 50%; background: transparent; color: var(--faint); font-size: 18px; line-height: 1; opacity: .6; }
.message-item:hover .message-menu-trigger, .message-menu-trigger[aria-expanded="true"], .message-menu-trigger:focus-visible { opacity: 1; }
.message-menu-trigger:hover { background: var(--surface-3); color: var(--text); }
.message-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.message-actions button { min-height: 30px; padding: 4px 10px; font-size: 12px; }
.message-actions.message-menu {
  position: fixed; z-index: 100; flex-direction: column; flex-wrap: nowrap; gap: 2px; margin: 0; padding: 6px;
  min-width: 150px; max-width: calc(100vw - 16px); max-height: calc(100dvh - 16px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.message-menu button { justify-content: flex-start; width: 100%; min-height: 34px; padding: 6px 10px; border: 0; border-radius: 6px; background: transparent; font-size: 14px; font-weight: 500; text-align: left; }
.message-menu button:hover, .message-menu button:focus-visible { background: var(--surface-2); outline: none; }
.message-menu .danger-button:hover { background: var(--danger-soft); }

.chat-kudos { display: inline-flex; gap: 4px; flex-shrink: 0; align-self: start; justify-self: end; }
.chat-kudos button { width: 28px; height: 28px; min-height: 0; padding: 0; border-radius: 50%; border-color: var(--line); background: var(--surface); color: var(--muted); font-size: 15px; font-weight: 700; line-height: 1; }
.chat-kudos.has-voted button { opacity: 0; }
.chat-kudos.has-voted:hover button, .chat-kudos.has-voted:has(:focus-visible) button { opacity: 1; }
.kudos-vote[value="1"][aria-pressed="true"] { background: var(--success); border-color: var(--success); color: var(--surface); -webkit-text-fill-color: var(--surface); }
.kudos-vote[value="-1"][aria-pressed="true"] { background: var(--danger); border-color: var(--danger); color: var(--surface); -webkit-text-fill-color: var(--surface); }
@media (hover: none) {
  .chat-kudos.has-voted:focus-within button, .chat-kudos.has-voted.touch-revealed button { opacity: 1; }
  .message-menu-trigger { opacity: 1; }
}
.kudos-tooltip { position: fixed; z-index: 10000; pointer-events: none; max-width: calc(100vw - 16px); padding: 7px 11px; border-radius: var(--radius-sm); background: var(--text); color: var(--bg); font-size: 13px; line-height: 1.4; box-shadow: var(--shadow); }

/* Ignoring dims a member's content for the viewer only. */
.ignored-message .message-body > p, .ignored-message .message-body > p a, .ignored-message .message-meta a,
.ignored-message .message-meta time, .ignored-message .reply-quote, .reply-quote.ignored-message, .ignored-message .pinned-link { color: var(--faint); font-style: italic; }
.ignored-message .mention { background: transparent; }
.ignored-message .profile-avatar { opacity: .45; }
.message-item.ignored-message { background: transparent; box-shadow: none; }

.reply-preview { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 24px; padding: 8px 12px; border: 1px solid var(--line); border-bottom: 0; border-left: 3px solid var(--accent); border-radius: var(--radius-sm) var(--radius-sm) 0 0; background: var(--surface); font-size: 13px; }
.reply-preview span { min-width: 0; overflow-wrap: anywhere; color: var(--muted); }
.reply-preview button { flex-shrink: 0; min-height: 30px; padding: 4px 10px; font-size: 12px; }
.message-form { flex-shrink: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 12px 24px max(16px, env(safe-area-inset-bottom)); background: var(--bg); }
.message-form input { min-height: 48px; padding: 12px 16px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.message-form button { min-height: 48px; padding: 0 22px; border-radius: var(--radius); background: var(--accent); border-color: var(--accent); color: var(--accent-text); -webkit-text-fill-color: var(--accent-text); }
.message-form button:hover { background: var(--accent-hover); }
.message-form button:disabled { background: var(--surface-2); border-color: var(--line); color: var(--faint); -webkit-text-fill-color: var(--faint); }
.empty-state, .empty-page { padding: 56px clamp(20px, 5vw, 56px); }
.empty-state { color: var(--muted); }
.empty-page { width: min(720px, 92vw); margin: 40px auto; text-align: center; }
.empty-page h1 { margin: 0; font-size: clamp(64px, 12vw, 120px); letter-spacing: -0.04em; color: var(--accent); }

dialog { width: min(520px, 92vw); max-height: 85dvh; overflow: auto; padding: 24px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgb(8 10 18 / 55%); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
dialog h2 { margin-top: 0; }
.report-preview { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--muted); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
#original-message { margin: 10px 0 16px; }

/* ---------- Leaderboard ---------- */
.leaderboard-panel { min-width: 0; width: 100%; max-width: 1050px; padding: 24px clamp(14px, 3vw, 32px); }
.leaderboard-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.leaderboard-heading h1 { margin: 0; font-size: 26px; }
.leaderboard-heading p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.refresh-rankings { display: inline-flex; align-items: center; min-height: 40px; padding: 8px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600; text-decoration: none; }
.refresh-rankings:hover { background: var(--surface-2); color: var(--text); }
.leaderboard-help { color: var(--muted); font-size: 13px; line-height: 1.5; }
.leaderboard-table { width: 100%; margin: 20px 0; border-collapse: separate; border-spacing: 0; table-layout: fixed; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.leaderboard-table caption { padding-bottom: 10px; color: var(--muted); font-size: 13px; text-align: left; }
.leaderboard-table th, .leaderboard-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; }
.leaderboard-table tbody tr:last-child td { border-bottom: 0; }
.leaderboard-table th { background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.leaderboard-table th:first-child { width: 72px; }
.leaderboard-table th:last-child { width: 92px; text-align: right; }
.leaderboard-table td:last-child { text-align: right; }
.leaderboard-table tbody tr:hover { background: var(--surface-2); }
.leaderboard-user { display: flex; align-items: center; gap: 12px; color: var(--text); font-weight: 650; text-decoration: none; }
.leaderboard-user:hover { color: var(--text); }
.leaderboard-user:hover .leaderboard-username { text-decoration: underline; }
.leaderboard-username { min-width: 0; overflow-wrap: anywhere; }
.leaderboard-you { color: var(--muted); font-size: 12px; font-weight: 500; }
.leaderboard-self, .leaderboard-self:hover { background: var(--accent-soft); }
.leaderboard-rank, .leaderboard-score { font-variant-numeric: tabular-nums; }
.leaderboard-rank { color: var(--muted); font-weight: 700; }
.leaderboard-table tbody tr:nth-child(-n+3) .leaderboard-rank { color: var(--warn); }
.leaderboard-score { font-weight: 800; }
.leaderboard-score.positive { color: var(--success); }
.leaderboard-score.negative { color: var(--danger); }
.leaderboard-pagination, .pagination { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.leaderboard-pagination a, .leaderboard-pagination > span { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; min-width: 40px; padding: 6px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600; text-decoration: none; }
.leaderboard-pagination a:hover { background: var(--surface-2); }
.leaderboard-pagination a[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.leaderboard-pagination > span { color: var(--faint); background: var(--surface-2); }
.pagination { gap: 16px; }

/* ---------- Profile ---------- */
.profile-wrap { width: min(1100px, 92vw); margin: 40px auto 56px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: start; }
.profile-card { display: flex; align-items: flex-start; gap: 24px; grid-column: 1 / -1; }
.profile-card > div:last-child { min-width: 0; flex: 1; }
.profile-card h1 { margin: 6px 0 8px; font-size: clamp(26px, 4vw, 36px); overflow-wrap: anywhere; }
.profile-bio { margin: 12px 0 16px; color: var(--muted); line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.recovery-settings { grid-column: 1 / -1; }
.recovery-settings > form { max-width: 560px; }
.recovery-settings p { line-height: 1.55; }
.remove-email { margin-top: 24px; max-width: 560px; }
#ignored-users { align-self: start; }
.kudos-panel { margin: 16px 0; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.kudos-summary { display: flex; align-items: baseline; flex-wrap: wrap; gap: 10px; margin: 0 0 6px; font-size: 17px; }
#kudos-score { font-variant-numeric: tabular-nums; }
.kudos-label { padding: 2px 9px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: 12px; font-weight: 600; }
.kudos-help { margin: 6px 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.kudos-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.kudos-actions button { min-height: 44px; padding: 8px 14px; font-size: 14px; }
#kudos-status { font-size: 13px; line-height: 1.4; }
.avatar-editor { min-width: 0; }
.avatar-editor input[type="range"] { width: 100%; min-height: 32px; }
.avatar-preview { width: 180px; height: 180px; margin: 12px auto; touch-action: none; cursor: grab; }
.avatar-preview:active { cursor: grabbing; }

/* ---------- Account pages ---------- */
.account-action-wrap { width: min(560px, 92vw); margin: 48px auto; }
.account-action-wrap h1 { margin-top: 0; font-size: 26px; }
.account-action-wrap > .preserve-lines { margin-bottom: 24px; color: var(--muted); line-height: 1.65; }
.account-action-wrap p { line-height: 1.55; overflow-wrap: anywhere; }
.account-links { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 24px; font-size: 14px; }
main.account-action-wrap:has(> .preserve-lines) { width: min(760px, 92vw); }

/* ---------- Admin ---------- */
.admin-wrap { width: min(1100px, 92vw); margin: 36px auto 56px; }
.analytics-wrap { width: min(1280px, 94vw); }
.page-heading { margin-bottom: 20px; }
.page-heading h1 { margin: 6px 0; font-size: clamp(28px, 4vw, 40px); letter-spacing: -0.02em; }
.admin-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 20px 0; padding: 4px; background: var(--surface-2); border-radius: var(--radius); width: fit-content; max-width: 100%; }
.admin-tabs a { padding: 8px 16px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 14px; text-decoration: none; }
.admin-tabs a:hover { background: var(--surface-3); color: var(--text); }
.admin-tabs a[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.admin-nav { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 20px; font-size: 14px; }
.admin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.admin-row, .user-admin-row, .announcement-admin-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px; padding: 14px 0; border-top: 1px solid var(--line); }
.user-admin-row small { display: block; margin-top: 4px; color: var(--muted); }
.user-admin-row .stack-form { max-width: 340px; }
.account-editor { width: 100%; padding-top: 12px; border-top: 1px solid var(--line); }
.user-admin-row .account-editor .stack-form { max-width: 600px; margin: 14px 0; }
.account-meta { overflow-wrap: anywhere; }
.announcement-admin-row p { margin: 5px 0 0; color: var(--muted); max-width: 680px; white-space: pre-wrap; }
.report-card h3 { margin-top: 0; font-size: 16px; }
.report-card blockquote { margin: 10px 0; padding: 12px; border-left: 3px solid var(--line-strong); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--surface-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.admin-message-list { max-height: 500px; overflow-y: auto; }
.moderation-filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; align-items: end; margin: 18px 0; }
.moderation-filters label { min-width: 0; font-size: 14px; }
.moderation-filters input, .moderation-filters select { min-width: 0; max-width: 100%; }
.bulk-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.member-results { max-height: min(70dvh, 760px); overflow-y: auto; overscroll-behavior: contain; padding: 4px 14px; border: 1px solid var(--line); border-radius: var(--radius); }
.poll-admin-list { margin-top: 24px; }
#poll-room-choices { display: grid; gap: 10px; margin-top: 14px; }
.security-page .admin-card { min-width: 0; }
#events .analytics-table, #ip-bans .analytics-table { min-width: 760px; }
#events .analytics-table td:first-child, #ip-bans .analytics-table td:first-child { white-space: nowrap; }

/* ---------- Analytics ---------- */
.analytics-filters { display: flex; align-items: end; flex-wrap: wrap; gap: 14px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.analytics-filters input { max-width: 210px; }
.analytics-presets, .analytics-jumps { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 10px 0; font-size: 14px; }
.analytics-note { color: var(--muted); font-size: 13px; line-height: 1.6; overflow-wrap: anywhere; }
.analytics-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-top: 20px; }
.analytics-metric { min-width: 0; padding: 18px 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.analytics-metric h2 { margin: 0 0 10px; color: var(--muted); font-size: 13px; font-weight: 600; }
.analytics-metric a { color: inherit; }
.analytics-metric > strong { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.analytics-metric p { margin-bottom: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.visitor-tile { display: block; color: inherit; text-decoration: none; transition: border-color .15s ease, box-shadow .15s ease; }
.visitor-tile:hover, .visitor-tile:focus-visible { color: inherit; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.visitor-details > .admin-card { margin: 16px 0; }
.analytics-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-top: 22px; }
.analytics-grid > section { min-width: 0; scroll-margin-top: 80px; }
.analytics-grid h2 { margin-top: 0; font-size: 19px; }
.analytics-wide { grid-column: 1 / -1; }
.analytics-bars { margin: 18px 0; padding: 0; list-style: none; }
.analytics-bars li { margin-bottom: 12px; }
.analytics-bars li > div:first-child { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 6px; font-size: 13px; }
.analytics-bars span { overflow-wrap: anywhere; }
.analytics-bar-track { height: 8px; overflow: hidden; border-radius: 99px; background: var(--surface-2); }
.analytics-bar-track > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.analytics-line-chart { display: block; width: 100%; max-height: 260px; margin-top: 18px; }
.analytics-line-chart text { fill: var(--muted); font-size: 12px; }
.analytics-line-chart .chart-axis { stroke: var(--line-strong); }
.analytics-line-chart .chart-grid { stroke: var(--line); }
.analytics-line-chart .chart-series-1 { stroke: var(--accent); }
.analytics-line-chart .chart-series-2 { stroke: #d97706; }
.analytics-line-chart .chart-point { fill: var(--accent); }
.analytics-legend { display: flex; flex-wrap: wrap; gap: 20px; font-size: 13px; font-weight: 600; }
.analytics-legend span:first-child { color: var(--accent-ink); }
.analytics-legend span:last-child { color: #d97706; }
.analytics-table-wrap { max-height: 430px; overflow: auto; margin: 14px 0; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.analytics-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.analytics-table td, .analytics-table th { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.analytics-table th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); color: var(--muted); font-weight: 700; }
.analytics-table tbody tr:hover { background: var(--surface-2); }
.analytics-table td small { display: block; color: var(--muted); }
.analytics-table .message-text { min-width: 230px; white-space: pre-wrap; overflow-wrap: anywhere; }
.analytics-facts { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; font-size: 14px; }
.analytics-facts dt { line-height: 1.5; color: var(--muted); }
.analytics-facts dd { max-width: 220px; margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.analytics-hours { display: grid; grid-template-columns: repeat(24, minmax(20px, 1fr)); gap: 5px; overflow-x: auto; padding-bottom: 12px; }
.analytics-hours > div { display: flex; flex-direction: column; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; }
.hour-track { display: flex; align-items: flex-end; width: 100%; height: 110px; overflow: hidden; border-radius: 4px; background: var(--surface-2); }
.hour-track i { display: block; width: 100%; background: var(--accent); }
.analytics-insights { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.analytics-insights article { padding: 16px; border-left: 3px solid var(--accent); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--surface-2); }
.analytics-insights h3 { margin: 0; font-size: 16px; }
.analytics-insights p { font-size: 14px; line-height: 1.6; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .analytics-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  body { font-size: 15px; }
  input, textarea, select { font-size: 16px; } /* prevents iOS zoom on focus */
  .app-header { flex-wrap: wrap; gap: 8px 12px; padding: 8px 12px; }
  .brand { max-width: 100%; font-size: 18px; }
  .brand-mark { width: 22px; height: 22px; }
  .brand-mark::before, .brand-mark::after { width: 6px; height: 6px; top: 8px; }
  .app-header nav { flex: 1 1 220px; gap: 2px; }
  .app-header nav a, .app-header .link-button { padding: 6px 10px; }

  .home-grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "login" "welcome"; margin: 20px auto 40px; gap: 28px; }
  .home-grid .auth-card { position: static; }
  .profile-wrap, .admin-grid, .analytics-grid, .analytics-insights { grid-template-columns: minmax(0, 1fr); }
  .wide-card { grid-column: auto; }
  .user-admin-row, .announcement-admin-row { flex-direction: column; align-items: flex-start; }
  .row-actions { justify-content: flex-start; }

  /* Chat: the room directory unfolds below the room title instead of a side column. */
  .chat-layout, .chat-layout.sidebar-collapsed { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .leaderboard-layout { grid-template-rows: auto; }
  .chat-panel { min-height: 0; }
  .room-sidebar { position: absolute; z-index: 25; top: var(--sidebar-top, 80px); bottom: 0; left: 0; width: min(320px, 92vw); padding: 16px; border-right: 1px solid var(--line); box-shadow: var(--shadow-lg); }
  .leaderboard-layout .room-sidebar { bottom: auto; height: min(65dvh, 600px); }
  :is(.chat-panel, .leaderboard-panel) > .room-sidebar,
  .sidebar-collapsed :is(.chat-panel, .leaderboard-panel) > .room-sidebar {
    position: static; z-index: auto; width: 100%; height: auto; max-height: none; padding: 0; border: 0; box-shadow: none;
    overflow: hidden; flex-shrink: 0; display: grid; grid-template-rows: 1fr; visibility: visible;
    transition: grid-template-rows 200ms ease, visibility 0s;
  }
  .sidebar-collapsed :is(.chat-panel, .leaderboard-panel) > .room-sidebar { grid-template-rows: 0fr; visibility: hidden; transition: grid-template-rows 200ms ease, visibility 0s 200ms; }
  :is(.chat-panel, .leaderboard-panel) > .room-sidebar .sidebar-content { overflow: hidden; min-height: 0; margin: 0; }
  :is(.chat-panel, .leaderboard-panel) > .room-sidebar .sidebar-scroll { max-height: min(42dvh, 340px); overflow-y: auto; overscroll-behavior-y: contain; padding: 12px; border-bottom: 1px solid var(--line); background: var(--surface); }
  .leaderboard-panel > .room-sidebar { margin: 12px 0; border-radius: var(--radius); }
  .sidebar-collapsed .leaderboard-panel > .room-sidebar { margin: 0; }
  .sidebar-toggle[aria-expanded="true"] .sidebar-chevron { transform: rotate(90deg); }
  .sidebar-toggle[aria-expanded="false"] .sidebar-chevron { transform: rotate(270deg); }

  .chat-room-header, .room-polls, .pinned-section { padding: 10px 12px; }
  .room-polls { max-height: 30vh; }
  .messages { padding: 12px; }
  .message-item { column-gap: 10px; }
  .message-form { padding: 10px 12px max(12px, env(safe-area-inset-bottom)); }
  .reply-preview { margin: 0 12px; }
  .connection-status, .chat-kudos-status, .chat-notice, .chat-error { margin-left: 12px; margin-right: 12px; }
  .message-meta time { flex-basis: auto; }
  .reaction-button { min-height: 34px; min-width: 36px; }
  .member-results { max-height: 65dvh; }
}
@media (max-width: 480px) {
  .app-header { flex-wrap: nowrap; }
  .app-header nav { flex-wrap: nowrap; gap: 0; }
  .app-header nav a, .app-header .link-button { padding: 6px 8px; font-size: 13px; }
  .brand-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .theme-toggle { width: 32px; height: 32px; min-height: 32px; margin-left: 2px; }
}
@media (max-width: 520px) {
  .profile-card { flex-direction: column; gap: 14px; }
  .leaderboard-table th, .leaderboard-table td { padding: 10px 8px; }
  .leaderboard-table th:first-child { width: 48px; }
  .leaderboard-table th:last-child { width: 64px; }
  .leaderboard-user { gap: 8px; font-size: 14px; }
  .leaderboard-user .profile-avatar { width: 30px; height: 30px; }
  .message-item { grid-template-columns: 34px minmax(0, 1fr) auto; column-gap: 8px; }
  .message-item > .profile-avatar { width: 34px; height: 34px; }
  .chat-kudos { flex-direction: column; }
  .message-form button { padding: 0 16px; }
}
@media (max-width: 650px) {
  .moderation-filters { grid-template-columns: minmax(0, 1fr); }
  .bulk-toolbar { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 420px) {
  .analytics-metrics { grid-template-columns: minmax(0, 1fr); }
  .analytics-metric { padding: 14px; }
  .analytics-facts { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .analytics-facts dd { text-align: left; margin-bottom: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media print {
  .app-header, .room-sidebar, .message-form, .theme-toggle { display: none !important; }
  body { background: #fff; color: #000; }
}
