:root {
  /* Every visual decision is a variable so themes (public/themes.js) can override it. */
  --bg: #313338; --side: #2b2d31; --dark: #1e1f22; --hover: #35373c; --active: #404249;
  --userbar: #232428; --input: #383a40; --text: #dbdee1; --muted: #949ba4; --header-text: #f2f3f5;
  --accent: #5865f2; --accent-hover: #4752c4; --accent-text: #ffffff; --link: #00a8fc;
  --green: #23a55a; --red: #f23f43; --mention: #f0b232; --btn2: #4e5058; --btn2-hover: #6d6f78; --btn2-text: #ffffff;
  --stream-bg: #000000; --msg-hover: rgba(2,2,2,.06); --shadow: rgba(0,0,0,.25); --overlay: rgba(0,0,0,.7);
  --radius: 4px; --radius-lg: 8px; --avatar-radius: 50%; --avatar-size: 40px;
  --font: "gg sans", "Noto Sans", "Segoe UI", system-ui, sans-serif; --font-size: 16px;
  --color-scheme: dark; --sidebar-w: 240px; --header-h: 48px; --msg-gap: 16px; --avatar-sat: 55%; --avatar-light: 45%;
}
* { box-sizing: border-box; scrollbar-width: thin; scrollbar-color: var(--active) transparent; }
html, body { height: 100%; margin: 0; }
html { color-scheme: var(--color-scheme); } /* native controls (audio/video, selects, scrollbars) follow the theme */
body { background: var(--bg); color: var(--text); font: var(--font-size)/1.4 var(--font); overflow: hidden; }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
ul { list-style: none; margin: 0; padding: 0; }
a { color: var(--link); }
.ic { width: 1em; height: 1em; fill: currentColor; vertical-align: -0.125em; flex: none; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.dot.on { background: var(--green); }
.owner-crown { color: var(--mention); margin-left: 6px; width: .85em; height: .85em; }
.spacer { flex: 1; }

/* ---------- buttons and inputs ---------- */
.btn { background: var(--accent); border: 0; border-radius: var(--radius); padding: 10px 16px; cursor: pointer; font-weight: 500; color: var(--accent-text); }
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--btn2); color: var(--btn2-text); }
.btn.secondary:hover { background: var(--btn2-hover); }
.btn.secondary.on { background: var(--red); color: var(--accent-text); }
.btn.danger { background: var(--red); color: var(--accent-text); }
.btn.link { background: none; color: var(--text); }
.btn.link:hover { text-decoration: underline; background: none; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.icon { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 18px; padding: 0 4px; }
.icon:hover { color: var(--text); }
.text-input, .theme-grid input[type=text], #settings textarea, .modal-panel textarea { background: var(--dark); color: var(--text); border: 0; border-radius: var(--radius); padding: 8px 10px; width: 100%; }
.range { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { appearance: none; -webkit-appearance: none; width: 22px; height: 22px; flex: none; margin: 0; border: 2px solid var(--muted); border-radius: 6px; background: transparent; position: relative; cursor: pointer; }
input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
input[type=checkbox]:checked::after { content: ""; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px; border: solid var(--accent-text); border-width: 0 2px 2px 0; transform: rotate(45deg); }
input[type=checkbox]:disabled { opacity: .5; cursor: default; }
/* snappier taps on touch screens (no 300ms wait, no grey flash) */
button, a, label, .chan, .vmember, .cat, li, select, input { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

/* ---------- sign in ---------- */
#auth { height: 100%; display: grid; place-items: center; background: var(--accent); overflow: auto; }
#auth-form { background: var(--bg); padding: 32px; border-radius: var(--radius); width: min(480px, 92vw); display: grid; gap: 16px; box-shadow: 0 2px 10px var(--shadow); }
#auth-form h1 { margin: 0; text-align: center; font-size: 24px; }
#auth-form p { margin: 0; text-align: center; color: var(--muted); }
#auth-form label { font-size: 12px; font-weight: 700; color: var(--muted); display: grid; gap: 8px; }
#auth-form input { background: var(--dark); border: 0; border-radius: var(--radius); padding: 10px; font-size: 16px; }
#auth-error { color: var(--red); min-height: 1.2em; font-size: 14px; }
#auth-toggle { color: var(--link); font-size: 14px; text-decoration: none; }

/* ---------- layout ---------- */
#app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--sidebar-w); height: 100%; height: 100dvh; position: relative; }
@media (min-width: 901px) { body.members-hidden #app { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); } }
body.members-hidden #members { display: none; }
#sidebar, #members { background: var(--side); display: flex; flex-direction: column; min-height: 0; }
#members { overflow-y: auto; padding: 8px; }
#nav-backdrop { display: none; }
#server-name { height: var(--header-h); display: flex; align-items: center; padding: 0 16px; font-weight: 700; color: var(--header-text); box-shadow: 0 1px 0 var(--shadow); cursor: default; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.is-admin #server-name { cursor: pointer; }
body:not(.can-invite) .invite-only { display: none; }
.section { color: var(--muted); font-size: 12px; font-weight: 700; padding: 16px 8px 4px 16px; display: flex; justify-content: space-between; align-items: center; }
#members .section { padding-left: 8px; }

/* ---------- channel list ---------- */
#channel-list { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: 8px; }
.chan { margin: 1px 8px; padding: 6px 8px; border-radius: var(--radius); color: var(--muted); cursor: pointer; display: flex; align-items: center; gap: 6px; }
.chan:hover { background: var(--hover); color: var(--text); }
.chan.active { background: var(--active); color: var(--header-text); }
.chan.unread { color: var(--header-text); font-weight: 600; }
.chan.muted { opacity: .5; }
.chan.connected .chan-icon { color: var(--green); }
.chan-icon { width: 20px; text-align: center; flex: none; font-size: 18px; line-height: 1; }
.chan-icon .ic { width: 16px; height: 16px; }
.chan-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chan-gear { display: none; font-size: 14px; }
.chan-del { display: none; font-size: 14px; }
.chan.active .chan-del { display: inline-grid; place-items: center; }
.badge.mention { background: var(--red); color: var(--accent-text); font-size: 12px; font-weight: 700; border-radius: 10px; padding: 0 6px; min-width: 18px; text-align: center; }
.cat { display: flex; align-items: center; gap: 4px; padding: 16px 8px 4px 12px; color: var(--muted); font-size: 12px; font-weight: 700; cursor: pointer; }
.cat:hover { color: var(--text); }
.cat-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.voice-members { margin: 0 8px 4px 32px; }
.vmember { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: var(--radius); color: var(--muted); font-size: 14px; cursor: pointer; }
.vmember:hover { background: var(--hover); color: var(--text); }
.vname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vmember .avatar { outline: 2px solid transparent; }
.vmember.speaking .avatar { outline-color: var(--green); }
.live { background: var(--red); color: var(--accent-text); font-size: 10px; font-weight: 700; padding: 0 4px; border-radius: var(--radius); }

/* ---------- avatars ---------- */
.avatar { width: var(--avatar-size); height: var(--avatar-size); border-radius: var(--avatar-radius); display: grid; place-items: center; font-weight: 700; color: var(--accent-text); flex: none; object-fit: cover; }
.avatar.preset { font-size: calc(var(--avatar-size) * .5); }
.avatar .ic { width: 1em; height: 1em; }
.avatar.small { --avatar-size: 24px; font-size: 12px; }
.avatar.large { --avatar-size: 72px; font-size: 32px; }
.avatar-btn { cursor: pointer; display: contents; }
.avatar-wrap { position: relative; display: flex; }
.avatar-wrap .status { position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%; background: var(--muted); border: 3px solid var(--side); box-sizing: content-box; }
.avatar-wrap .status.on { background: var(--green); }

/* ---------- voice panel ---------- */
#voice-panel { background: var(--userbar); margin: 8px; padding: 8px; border-radius: var(--radius-lg); }
#v-status { color: var(--green); font-weight: 600; font-size: 14px; }
.voice-buttons { display: flex; gap: 6px; margin-top: 8px; }
.vbtn .ic { width: 18px; height: 18px; vertical-align: middle; }
.vbtn { flex: 1; background: var(--btn2); color: var(--btn2-text); border: 0; border-radius: var(--radius); padding: 6px 0; cursor: pointer; font-size: 16px; }
.vbtn:hover { background: var(--btn2-hover); }
.vbtn.on { background: var(--red); color: var(--accent-text); }
.vbtn.danger { background: var(--red); color: var(--accent-text); }
.whisper-bar { background: var(--accent); color: var(--accent-text); border-radius: var(--radius); padding: 2px 8px; margin-top: 6px; font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
.whisper-bar .icon { color: var(--accent-text); font-size: 14px; }
#userbar { background: var(--userbar); padding: 8px 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 600; }
.me-btn { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; background: none; border: 0; padding: 4px; border-radius: var(--radius); cursor: pointer; text-align: left; color: var(--header-text); font-weight: 600; }
.me-btn:hover { background: var(--hover); }
.me-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar.userbar-avatar { --avatar-size: 32px; font-size: 14px; }
#userbar .avatar-wrap .status { border-color: var(--userbar); }
#userbar .icon { font-size: 20px; }

/* ---------- main column ---------- */
#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
#channel-header { height: var(--header-h); flex: none; padding: 0 16px; font-weight: 700; color: var(--header-text); background: var(--bg); position: relative; z-index: 9; box-shadow: 0 1px 0 var(--shadow); display: flex; align-items: center; gap: 10px; }
#channel-title { white-space: nowrap; min-width: 0; max-width: 55%; overflow: hidden; text-overflow: ellipsis; flex: none; }
#channel-header .icon { flex: none; }
#channel-topic { flex: 0 1 auto; min-width: 0; font-weight: 400; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 10px; border-left: 1px solid var(--muted); }
#channel-topic:empty { display: none; }
#search { background: var(--dark); border: 0; border-radius: var(--radius); padding: 4px 8px; flex: 0 0 150px; min-width: 0; color: var(--text); font-weight: 400; }
#nav-toggle, #search-btn { display: none; }
#conn-banner { background: var(--btn2); color: var(--btn2-text); padding: 8px 16px; font-size: 14px; }
#conn-banner.bad { background: var(--red); color: var(--accent-text); }
.link-btn { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; }
#streams { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px; background: var(--stream-bg); }
#streams:empty { display: none; }
.tile { position: relative; flex: 1 1 320px; min-width: 0; max-height: 40vh; background: var(--stream-bg); border-radius: var(--radius-lg); overflow: hidden; }
.tile.self { outline: 2px solid var(--green); }
.tile video { width: 100%; height: 100%; max-height: 40vh; display: block; object-fit: contain; }
.tile-name { position: absolute; left: 8px; bottom: 8px; background: var(--overlay); color: var(--accent-text); padding: 2px 8px; border-radius: var(--radius); font-size: 13px; }
.tile-fs { position: absolute; right: 8px; top: 8px; background: var(--overlay); color: var(--accent-text); border: 0; border-radius: var(--radius); cursor: pointer; }

/* ---------- messages ---------- */
#messages { flex: 1; overflow-y: auto; padding: 16px 0; min-height: 0; }
.msg { display: flex; gap: 16px; padding: 2px 16px 2px 16px; margin-top: var(--msg-gap); position: relative; }
.msg.cont { margin-top: 0; }
.msg:hover { background: var(--msg-hover); }
.msg.mentioned { background: color-mix(in srgb, var(--mention) 10%, transparent); box-shadow: inset 2px 0 0 var(--mention); }
.msg.flash { animation: flash 1.8s; }
@keyframes flash { 0%, 60% { background: color-mix(in srgb, var(--accent) 30%, transparent); } }
.msg-gutter { width: var(--avatar-size); flex: none; font-size: 11px; color: var(--muted); text-align: center; visibility: hidden; align-self: center; }
.msg-main { min-width: 0; flex: 1; }
.msg-head { font-weight: 500; display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 8px; }
.msg-name { cursor: pointer; overflow-wrap: anywhere; }
.msg-name:hover { text-decoration: underline; }
.msg-time { color: var(--muted); font-size: 12px; font-weight: 400; }
.msg-pin { margin-left: 6px; font-size: 12px; color: var(--muted); }
.msg-content { word-break: break-word; }
.msg-edited { color: var(--muted); font-size: 11px; }
.msg-reply { color: var(--muted); font-size: 13px; cursor: pointer; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-reply:hover { color: var(--text); }
.reply-name { font-weight: 500; }
.edit-box { width: 100%; background: var(--input); border: 0; border-radius: var(--radius); padding: 8px; resize: none; max-height: 40vh; }
.edit-hint { font-size: 12px; color: var(--muted); }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; }
.attachments > .attach-img, .attachments > .attach-media { margin-top: 4px; }
.attach-img { max-width: min(400px, 100%); max-height: 320px; border-radius: var(--radius-lg); display: block; margin-top: 4px; cursor: zoom-in; }
.attach-media { margin-top: 4px; max-width: min(480px, 100%); }
.attach-video { max-width: 100%; max-height: 360px; border-radius: var(--radius-lg); background: var(--stream-bg); display: block; }
.attach-audio { width: min(360px, 100%); display: block; }
.file-caption { color: var(--muted); font-size: 12px; margin-top: 2px; }
.file-chip { display: inline-block; background: var(--side); border: 1px solid var(--dark); padding: 8px 12px; border-radius: var(--radius-lg); margin-top: 4px; color: var(--link); text-decoration: none; }
.file-size { color: var(--muted); font-size: 12px; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction { display: inline-flex; align-items: center; gap: 4px; background: var(--side); border: 1px solid transparent; border-radius: var(--radius-lg); padding: 1px 8px; cursor: pointer; }
.reaction:hover { border-color: var(--muted); }
.reaction.mine { background: color-mix(in srgb, var(--accent) 25%, transparent); border-color: var(--accent); }
.reaction-count { font-size: 13px; font-weight: 600; }
.msg-toolbar { display: none; position: absolute; right: 16px; top: -14px; background: var(--side); border: 1px solid var(--dark); border-radius: var(--radius); box-shadow: 0 2px 6px var(--shadow); }
.msg.show-tools .msg-toolbar { display: flex; }
.tb-btn .ic { width: 15px; height: 15px; vertical-align: middle; }
.tb-btn { background: none; border: 0; cursor: pointer; padding: 4px 8px; border-radius: var(--radius); }
.tb-btn:hover { background: var(--hover); }
.divider { display: flex; align-items: center; margin: 16px 16px 0; color: var(--muted); font-size: 12px; font-weight: 600; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--active); }
.divider span { padding: 0 8px; }
.divider.new { color: var(--red); }
.divider.new::before, .divider.new::after { border-color: var(--red); }
#jump-bar { background: var(--accent); color: var(--accent-text); padding: 6px 16px; cursor: pointer; font-size: 14px; }
#typing { height: 20px; padding: 0 16px; font-size: 13px; color: var(--muted); }
#reply-bar { margin: 0 16px; background: var(--side); border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: 6px 12px; display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; }
#composer { margin: 0 16px 24px; background: var(--input); border-radius: var(--radius-lg); display: flex; align-items: flex-end; }
#reply-bar:not(.hidden) ~ #composer, #attach-tray:not(.hidden) ~ #composer, #link-tray:not(.hidden) ~ #composer { border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
#text { flex: 1; background: none; border: 0; padding: 12px 8px; outline: none; resize: none; max-height: 220px; line-height: 1.4; }
.attach { cursor: pointer; font-size: 24px; color: var(--muted); padding: 6px 14px; }
.attach:hover { color: var(--text); }
#composer .icon { font-size: 22px; padding: 8px 12px; }
#drop-overlay { position: absolute; inset: 0; background: var(--overlay); color: var(--accent-text); display: grid; place-items: center; font-size: 24px; font-weight: 700; z-index: 5; border: 3px dashed var(--accent); pointer-events: none; }
#autocomplete { margin: 0 16px; background: var(--dark); border-radius: var(--radius-lg); box-shadow: 0 -4px 12px var(--shadow); overflow: hidden; }
.ac-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 12px; background: none; border: 0; text-align: left; cursor: pointer; }
.ac-item.active, .ac-item:hover { background: var(--hover); }
.ac-emoji { width: 24px; text-align: center; font-size: 18px; }
.ac-hint { color: var(--muted); font-size: 12px; margin-left: auto; }

/* ---------- link previews ---------- */
.embeds { display: grid; gap: 6px; }
.embed { margin-top: 6px; background: var(--side); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 8px 12px 12px; max-width: min(440px, 100%); display: grid; gap: 4px; }
.embed.image-only { background: none; border: 0; padding: 0; }
.embed-site { color: var(--muted); font-size: 12px; }
.embed-title { font-weight: 600; color: var(--link); text-decoration: none; }
.embed-title:hover { text-decoration: underline; }
.embed-desc { font-size: 14px; color: var(--text); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.embed-image { position: relative; margin-top: 4px; }
.embed-thumb { max-width: 100%; max-height: 260px; border-radius: var(--radius); display: block; cursor: zoom-in; }
.play-btn .ic { width: 22px; height: 22px; }
.play-btn { display: grid; place-items: center; position: absolute; inset: 0; margin: auto; width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--overlay); color: var(--accent-text); font-size: 24px; cursor: pointer; }
.embed-frame { width: min(420px, 100%); aspect-ratio: 16 / 9; border: 0; border-radius: var(--radius); display: block; }
.embed.has-player { max-width: min(440px, 100%); }

/* ---------- members and side panel ---------- */
#member-list li { display: flex; align-items: center; gap: 10px; padding: 4px 8px; border-radius: var(--radius); cursor: pointer; }
#member-list li:hover { background: var(--hover); }
#member-list li.offline { opacity: .45; }
.member-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.invite-opts { display: grid; gap: 6px; margin-bottom: 6px; }
#new-invite { width: 100%; margin: 4px 0 8px; }
#invite-list li { font-size: 13px; padding: 6px 0; word-break: break-all; }
#invite-list code { color: var(--text); }
#panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(380px, 100vw); background: var(--side); box-shadow: -4px 0 12px var(--shadow); z-index: 10; display: flex; flex-direction: column; }
#panel header { padding: 12px 16px; display: flex; justify-content: space-between; box-shadow: 0 1px 0 var(--shadow); }
#panel-body { overflow-y: auto; flex: 1; padding: 8px; }
.result { background: var(--bg); border-radius: var(--radius-lg); padding: 8px 12px; margin-bottom: 8px; cursor: pointer; }
.result:hover { background: var(--hover); }
.result-chan, .panel-empty { color: var(--muted); font-size: 13px; }
.panel-empty { padding: 16px; text-align: center; }

/* ---------- dialogs, menus, toasts ---------- */
.modal-backdrop { position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; z-index: 20; overflow: auto; padding: 16px 0; height: 100vh; height: 100dvh; }
.modal-panel { background: var(--bg); border-radius: var(--radius-lg); padding: 20px; max-height: 92vh; max-height: 92dvh; overflow-y: auto; box-shadow: 0 8px 24px var(--shadow); }
.modal-panel h2 { margin: 0 0 12px; font-size: 20px; color: var(--header-text); }
.dialog { display: grid; gap: 10px; }
.dialog-text { margin: 0; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 6px; }
.field-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.form-error { color: var(--red); font-size: 14px; min-height: 1em; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checklist { display: grid; gap: 6px; max-height: 240px; overflow-y: auto; }
.ctx-menu { position: fixed; z-index: 40; background: var(--dark); border-radius: var(--radius); padding: 6px; min-width: 190px; box-shadow: 0 8px 16px var(--shadow); }
.ctx-item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 6px 8px; border-radius: var(--radius); cursor: pointer; }
.ctx-item:hover:not(:disabled) { background: var(--accent); color: var(--accent-text); }
.ctx-item.danger { color: var(--red); }
.ctx-item.danger:hover:not(:disabled) { background: var(--red); color: var(--accent-text); }
.ctx-sep { border-top: 1px solid var(--active); margin: 4px 0; }
.ctx-custom { padding: 4px 8px; }
#toasts { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; }
.toast { background: var(--dark); color: var(--text); padding: 10px 16px; border-radius: var(--radius-lg); box-shadow: 0 4px 12px var(--shadow); }
.lightbox { background: none; box-shadow: none; padding: 0; }
.lightbox-img { max-width: 94vw; max-height: 90vh; display: block; border-radius: var(--radius); cursor: zoom-out; }
.qs-results { display: grid; max-height: 50vh; overflow-y: auto; }
.qs-item { text-align: left; background: none; border: 0; padding: 8px 12px; border-radius: var(--radius); cursor: pointer; }
.qs-item.active, .qs-item:hover { background: var(--hover); }
.peer-controls { display: grid; gap: 8px; min-width: 210px; }
.vol-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.vol-row { display: flex; align-items: center; gap: 8px; }
.vol-slider { flex: 1; accent-color: var(--accent); }
.card-head { display: flex; gap: 12px; align-items: center; padding: 4px 0 8px; }
.card-name { font-weight: 700; font-size: 18px; color: var(--header-text); }

/* ---------- settings ---------- */
.settings-modal { padding: 0; position: relative; }
.settings-close { position: absolute; top: 8px; right: 8px; z-index: 2; }
.settings-nav .settings-close-m { display: none; }
.settings-layout { display: grid; grid-template-columns: 200px 1fr; grid-template-rows: auto; min-height: min(640px, 80vh); }
.settings-nav { background: var(--side); padding: 24px 8px; display: flex; flex-direction: column; border-radius: var(--radius-lg) 0 0 var(--radius-lg); }
.settings-tabs { display: flex; flex-direction: column; gap: 2px; }
.nav-item { white-space: nowrap; flex: none; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: var(--radius); cursor: pointer; color: var(--muted); }
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--active); color: var(--header-text); }
.settings-content { padding: 24px 32px; overflow-y: auto; max-height: 85vh; }
.settings-content h3 { margin: 20px 0 8px; font-size: 12px; text-transform: uppercase; color: var(--muted); }
.settings-content h3:first-child { margin-top: 0; font-size: 20px; text-transform: none; color: var(--header-text); }
.settings-content h4 { margin: 16px 0 4px; color: var(--header-text); }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 8px 0; }
.set-row > :last-child { flex: 0 0 min(280px, 50%); }
.set-row > .switch { flex: 0 0 40px; }
.set-label { flex: 1; }
.set-hint { color: var(--muted); font-size: 13px; }
.btn-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.slider-row { display: flex; align-items: center; gap: 8px; }
.slider-value { min-width: 56px; text-align: right; color: var(--muted); font-size: 13px; }
.switch { position: relative; width: 40px; height: 22px; flex: none; display: inline-block; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch .slider { position: absolute; inset: 0; background: var(--btn2); border-radius: 11px; transition: background .15s; }
.switch .slider::after { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; border-radius: 50%; background: var(--accent-text); transition: transform .15s; }
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::after { transform: translateX(18px); }
.switch input:disabled { cursor: default; }
.meter { position: relative; height: 12px; background: var(--dark); border-radius: 6px; margin: 8px 0; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--muted); transition: width .05s; }
.meter-fill.open { background: var(--green); }
.meter-thresh { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--red); }
.acct { display: flex; gap: 16px; align-items: center; padding: 8px 0 16px; }
.acct-name { font-size: 22px; font-weight: 700; color: var(--header-text); }
.feat-head, .feat-row { display: grid; grid-template-columns: 1fr auto auto; gap: 16px; align-items: center; }
.feat-head { color: var(--muted); font-size: 12px; font-weight: 700; justify-items: center; }
.feat-row { padding: 6px 0; }
.feat-name { font-weight: 600; }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(190px, 100%), 1fr)); gap: 10px 16px; }
.theme-grid label, #theme-editor > label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); min-width: 0; }
.theme-grid input, #theme-editor select, #theme-editor textarea { min-width: 0; max-width: 100%; }
.theme-grid input[type=color] { width: 100%; height: 30px; border: 0; padding: 0; background: none; }
#theme-editor { display: grid; gap: 12px; }
#theme-editor select { background: var(--dark); border: 0; border-radius: var(--radius); padding: 8px; }
#settings textarea, #theme-editor textarea { font-family: monospace; font-size: 13px; }
.avatar-editor { display: grid; gap: 12px; }
.avatar-now { display: flex; align-items: center; gap: 12px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--active); }
.tab { background: none; border: 0; padding: 8px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--header-text); border-bottom-color: var(--accent); }
.crop-canvas { width: 280px; height: 280px; border-radius: var(--radius-lg); touch-action: none; cursor: grab; margin: 0 auto; display: block; max-width: 100%; }
.preset-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.preset-btn { aspect-ratio: 1; border: 0; border-radius: var(--avatar-radius); font-size: 26px; cursor: pointer; color: var(--accent-text); display: grid; place-items: center; }
.preset-btn:hover { outline: 3px solid var(--accent); }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  /* members becomes an overlay; app.js hides it by default on small screens */
  #app { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  #members { position: absolute; right: 0; top: var(--header-h); bottom: 0; width: min(280px, 80vw); z-index: 7; box-shadow: -4px 0 12px var(--shadow); }
}
@media (max-width: 700px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(300px, 84vw); z-index: 12; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open #sidebar { transform: none; }
  body.nav-open #nav-backdrop { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 11; }
  #nav-toggle { display: inline-block; }
  body.no-mobile-nav #nav-toggle { display: none; }
  #search { flex: 1 1 60px; }
  #channel-topic { display: none; }
  .settings-modal { width: 100vw !important; max-height: none; height: 100vh; height: 100dvh; border-radius: 0; }
  .settings-layout { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); height: 100%; min-height: 0; }
  .settings-nav { flex-direction: row; align-items: center; padding: 8px; border-radius: 0; gap: 4px; min-width: 0; }
  .settings-tabs { flex-direction: row; overflow-x: auto; flex: 1; min-width: 0; gap: 4px; scrollbar-width: none; }
  .settings-modal .settings-close { display: none; }
  .settings-nav .settings-close-m { display: inline-grid; place-items: center; flex: none; }
  .settings-content { padding: 16px; max-height: none; overflow-y: auto; }
  .set-row:not(.inline) { flex-direction: column; align-items: stretch; gap: 8px; }
  .set-row:not(.inline) > :last-child { flex: none; }
  .msg { gap: 10px; padding-left: 10px; padding-right: 10px; }
  .msg-toolbar { right: 8px; }
  #composer { margin: 0 8px calc(12px + env(safe-area-inset-bottom)); }
}

/* ---------- touch screens: bigger targets, and 16px inputs so iOS Safari does not zoom on focus ---------- */
@media (pointer: coarse) {
  .icon, .tb-btn { min-width: 40px; min-height: 40px; display: inline-grid; place-items: center; }
  .icon .ic { width: 20px; height: 20px; }
  .btn, .ctx-item, .qs-item, .nav-item, .tab { min-height: 44px; }
  .btn.small { min-height: 36px; padding: 6px 14px; }
  .chan { min-height: 44px; }
  .vmember { min-height: 40px; }
  #member-list li { min-height: 48px; }
  .vbtn { min-height: 44px; }
  .md-copy { min-height: 32px; min-width: 52px; }
  .reaction { min-height: 36px; padding: 2px 12px; }
  .file-caption a, .embed-title { display: inline-block; padding: 8px 4px; }
  .result { padding: 12px; }
  #auth-toggle { display: inline-block; padding: 12px 0; font-size: 15px; }
  .chan-gear { display: none; }
  .chan.active .chan-gear { display: inline-grid; }
  input, select, textarea { font-size: 16px; }
  .set-row { padding: 12px 0; }
  .modal-backdrop:has(.settings-modal) { padding: 0; }
  .switch, .set-row > .switch { width: 52px; height: 32px; flex: 0 0 52px; }
  .switch .slider { border-radius: 16px; }
  .switch .slider::after { width: 26px; height: 26px; }
  .switch input:checked + .slider::after { transform: translateX(20px); }
}

@media (max-width: 480px) {
  #search { display: none; }
  #search-btn { display: inline-grid; place-items: center; }
  #channel-header { gap: 4px; padding: 0 8px; }
  .msg-toolbar { top: -18px; }
}

/* Hover effects that reveal things: only where a real pointer exists. On touch screens iOS would swallow the first tap. */
@media (hover: hover) {
  .chan:hover .chan-gear { display: inline; }
  .chan:hover .chan-del { display: inline-grid; place-items: center; }
  .msg:hover .msg-gutter { visibility: visible; }
  .msg:hover .msg-toolbar { display: flex; }
}

/* ---------- attachment tray (files waiting above the message box) ---------- */
#attach-tray { margin: 0 16px; background: var(--input); border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: 10px 10px 0; border-bottom: 1px solid var(--active); }
#reply-bar:not(.hidden) ~ #attach-tray { border-radius: 0; }
.att-list { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 10px; }
.att-queued { font-size: 13px; color: var(--muted); padding: 0 2px 8px; }
.att-card { position: relative; flex: none; width: 128px; background: var(--side); border-radius: var(--radius-lg); padding: 8px; display: grid; gap: 4px; border: 1px solid transparent; }
.att-card.error { border-color: var(--red); }
.att-thumb { height: 84px; border-radius: var(--radius); background: var(--dark); display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: 34px; }
.att-thumb img { width: 100%; height: 100%; object-fit: cover; }
.att-remove { position: absolute; top: 2px; right: 2px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: var(--overlay); color: var(--accent-text); cursor: pointer; display: grid; place-items: center; font-size: 13px; padding: 0; }
.att-remove:hover { background: var(--red); }
.att-bar { height: 4px; border-radius: 2px; background: var(--dark); overflow: hidden; }
.att-fill { height: 100%; width: 0; background: var(--accent); transition: width .12s linear; }
.att-card.done .att-fill { background: var(--green); }
.att-card.error .att-fill { background: var(--red); }
.att-name { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-meta { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); min-width: 0; }
.att-status { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-card.error .att-status { color: var(--red); }
.att-retry { background: none; border: 0; color: var(--text); cursor: pointer; padding: 0 2px; }
@media (pointer: coarse) { .att-remove { width: 32px; height: 32px; } .att-retry { min-width: 32px; min-height: 28px; } }
@media (max-width: 480px) { #attach-tray { margin: 0 8px; } .att-card { width: 112px; } }

/* ---------- hover cards (formatting cheat sheet, supported file types) ---------- */
.hover-card { position: fixed; z-index: 45; max-width: min(420px, 92vw); background: var(--dark); color: var(--text); border-radius: var(--radius-lg); padding: 12px 14px; box-shadow: 0 8px 20px var(--shadow); font-size: 13px; pointer-events: none; }
.hover-title { font-weight: 700; color: var(--header-text); margin-bottom: 6px; text-transform: uppercase; font-size: 11px; letter-spacing: .04em; }
.cheat { border-collapse: collapse; }
.cheat td { padding: 3px 6px 3px 0; vertical-align: top; }
.cheat code { background: var(--bg); padding: 1px 6px; border-radius: var(--radius); font-family: ui-monospace, Menlo, Consolas, monospace; white-space: pre; }
.cheat .md { margin: 0; }
.cheat .md-codeblock { margin: 0; padding: 2px 6px; }
.cheat .md-copy { display: none; }
.cheat-arrow, .cheat-label { color: var(--muted); }
.hover-keys { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--active); display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); }
.hover-keys kbd { background: var(--bg); border: 1px solid var(--active); border-bottom-width: 2px; border-radius: var(--radius); padding: 0 5px; color: var(--text); font: inherit; font-size: 12px; }
.fmt-row { display: grid; grid-template-columns: 92px 1fr; gap: 8px; padding: 3px 0; }
.fmt-row b { color: var(--header-text); font-weight: 600; }

.dl-card { background: var(--side); border: 1px solid transparent; border-radius: var(--radius-lg); padding: 14px 16px; margin: 10px 0; display: grid; gap: 8px; }
.dl-card.mine { border-color: var(--accent); }
.dl-head { display: flex; align-items: center; gap: 10px; font-size: 17px; color: var(--header-text); }
.dl-tag { background: var(--accent); color: var(--accent-text); border-radius: var(--radius); padding: 0 8px; font-size: 12px; font-weight: 600; }
.btn { text-decoration: none; display: inline-block; }

/* link previews shown above the message box before posting */
#link-tray { margin: 0 16px; background: var(--input); border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: 10px 10px 4px; border-bottom: 1px solid var(--active); max-height: 36vh; overflow-y: auto; display: grid; gap: 4px; }
#reply-bar:not(.hidden) ~ #link-tray, #attach-tray:not(.hidden) ~ #link-tray { border-radius: 0; }
.lp-item { position: relative; }
.lp-item .embed { margin-top: 0; margin-bottom: 6px; }
.lp-item .att-remove { top: 6px; right: 6px; }
@media (max-width: 480px) { #link-tray { margin: 0 8px; } }

.role-tag { font-size: 10px; font-weight: 700; padding: 0 6px; border-radius: var(--radius); background: var(--btn2); color: var(--btn2-text); text-transform: uppercase; letter-spacing: .03em; flex: none; }
.role-admin { background: var(--accent); color: var(--accent-text); }
.role-mod { background: var(--green); color: var(--accent-text); }
.role-visitor { background: var(--dark); color: var(--muted); }

.chan.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--hover); }
.vmember[draggable="true"] { cursor: grab; }
.srv-muted { color: var(--red); }
.role-choice { align-items: flex-start; padding: 6px 0; }
.role-choice input { margin-top: 3px; }
.invite-only select { margin-bottom: 6px; }
#auth-hint { margin: 0; color: var(--muted); font-size: 13px; text-align: center; min-height: 1em; }
