:root {
  --bg: #1f2129;
  --panel: #272a33;
  --raised: #333744;
  --line: #3b3f4c;
  --text: #e3e5eb;
  --muted: #8b90a0;
  --accent: #5b7cfa;
  --accent-soft: #9fb2ff;
  --danger: #f2616b;
  --live: #eb4b55;
  --fs: 14px;
  --emote: 28px;
  color-scheme: dark;
  font-family: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); display: flex; flex-direction: column; overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
button:disabled { opacity: .4; cursor: default; }
input, textarea, select { font: inherit; color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* top bar */
.topbar { display: flex; align-items: stretch; height: 30px; flex-shrink: 0; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 13px; }
.tabs { display: flex; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.tab { display: flex; align-items: center; gap: 5px; padding: 0 6px 0 12px; color: var(--muted); border-right: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; }
.tab.active { color: var(--text); background: var(--bg); box-shadow: inset 0 2px var(--accent); }
.tab.unread { color: var(--text); }
.tab.mentioned { color: var(--accent-soft); }
.tab .x { width: 18px; height: 18px; border-radius: 3px; opacity: 0; }
.tab:hover .x, .tab.active .x { opacity: .55; }
.tab .x:hover { opacity: 1; background: var(--raised); }
.tab input { width: 110px; background: var(--bg); border: 1px solid var(--accent); border-radius: 3px; padding: 1px 4px; }
.spacer { flex: 1; }
.icon-btn { display: grid; place-items: center; min-width: 28px; padding: 0 7px; color: var(--muted); }
.icon-btn:hover { color: var(--text); background: var(--raised); }
.icon-btn svg { width: 14px; height: 14px; }
.account { padding: 0 12px; color: var(--muted); }
.account:hover { color: var(--text); background: var(--raised); }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--live); flex-shrink: 0; }
body.dock .tabs, body.dock #new-tab { display: none; }

/* splits */
#splits { flex: 1; display: flex; min-height: 0; overflow-x: auto; }
.page { flex: 1; display: flex; min-width: 0; }
.split { flex: 1 1 0; min-width: 220px; display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.split:last-child { border-right: 0; }
.split-head { display: flex; align-items: center; gap: 6px; height: 30px; flex-shrink: 0; padding-left: 10px; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 13px; }
.split.focused .split-head { box-shadow: inset 0 -2px var(--accent); }
.split-head .name { font-weight: 700; }
.split-head .name:hover { color: var(--accent-soft); }
.split-head .modes { flex: 1; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-input { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--accent); border-radius: 3px; padding: 2px 6px; }

.log-wrap { flex: 1; position: relative; display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; overflow-x: hidden; overflow-anchor: none; padding: 4px 0; font-size: var(--fs); line-height: 1.5; overscroll-behavior: contain; }
.empty { margin: 0; padding: 14px 12px; color: var(--muted); font-size: 13px; }
.jump { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: none; padding: 4px 14px; border-radius: 14px; background: var(--accent); color: #fff; font-size: 12px; box-shadow: 0 2px 10px rgba(0, 0, 0, .4); z-index: 2; }
body.newest-top .jump { top: 10px; bottom: auto; }
.split.paused .jump { display: block; }
.search { display: flex; gap: 4px; padding: 5px 6px; background: var(--panel); border-bottom: 1px solid var(--line); }
.search input { flex: 1; min-width: 0; padding: 3px 8px; background: var(--bg); border: 1px solid var(--accent); border-radius: 3px; font-size: 13px; }
.search button { width: 26px; color: var(--muted); }
.filtered-out { display: none; }
.last-read { height: 0; border-top: 2px solid var(--live); margin: 2px 0; opacity: .8; }

/* messages */
.msg { padding: 1px 10px; overflow-wrap: anywhere; }
.msg:hover { background: rgba(255, 255, 255, .035); }
body.alt-rows .messages .msg:nth-child(even) { background-color: rgba(255, 255, 255, .025); }
.msg .ts { margin-right: 6px; color: var(--muted); font-size: .85em; font-variant-numeric: tabular-nums; }
.msg .origin { color: var(--muted); font-weight: 700; }
.msg .badge { height: 1.15em; margin-right: 3px; vertical-align: -.2em; }
.msg .user { font-weight: 700; cursor: pointer; }
.msg .user:hover { text-decoration: underline; }
.msg a { color: var(--accent-soft); }
.msg .mention-tag { font-weight: 700; cursor: pointer; }
.msg .sys { font-weight: 700; color: #d2bfff; }
.msg .reply-ctx { display: block; color: var(--muted); font-size: .85em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.msg .reply-ctx:hover { color: var(--text); }
.msg .cheer-amount { font-weight: 700; margin: 0 2px; }
.msg.notice { color: var(--muted); font-size: .9em; }
.msg.mention { background: rgba(91, 124, 250, .15); box-shadow: inset 3px 0 var(--accent); }
.msg.hl-user { background: rgba(232, 176, 74, .1); box-shadow: inset 3px 0 #e8b04a; }
.msg.first { background: rgba(63, 191, 143, .09); box-shadow: inset 3px 0 #3fbf8f; }
.msg.sub { background: rgba(169, 120, 255, .11); box-shadow: inset 3px 0 #a978ff; }
.msg.redemption { background: rgba(61, 180, 230, .09); box-shadow: inset 3px 0 #3db4e6; }
.msg.redemption .sys { color: #8fd6f5; }
.msg.highlighted-msg { background: rgba(117, 94, 188, .3); box-shadow: inset 3px 0 #9b7bff; }
.msg.whisper { background: rgba(232, 112, 172, .08); box-shadow: inset 3px 0 #e870ac; }
.msg.automod { background: rgba(242, 97, 107, .08); box-shadow: inset 3px 0 var(--danger); }
.msg.automod .sys { color: #ffb3b8; }
.am-actions { display: inline-flex; gap: 4px; margin-left: 8px; }
.am-actions button { padding: 0 8px; border-radius: 3px; background: var(--raised); font-size: .85em; }
.am-actions .allow:hover { background: #2f6b4f; }
.am-actions .deny:hover { background: #7a3238; }
.am-state { margin-left: 8px; color: var(--muted); font-size: .85em; }
.msg.deleted .body { text-decoration: line-through; opacity: .45; }
.msg.historical { opacity: .6; }
.msg.long { max-height: calc(var(--fs) * 1.5 * 6); overflow: hidden; cursor: pointer; -webkit-mask-image: linear-gradient(#000 65%, transparent); mask-image: linear-gradient(#000 65%, transparent); }

.emote-stack { position: relative; display: inline-flex; align-items: center; justify-content: center; vertical-align: middle; margin: -4px 1px; }
.emote { height: var(--emote); width: auto; }
.emote.zw { position: absolute; }

.tools { display: inline-flex; gap: 1px; margin-right: 4px; vertical-align: -3px; }
.tools button, .reply-btn { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 3px; color: var(--muted); }
.tools button:hover, .reply-btn:hover { background: var(--raised); color: var(--text); }
.tools [data-act="ban"]:hover { color: var(--danger); }
.tools svg, .reply-btn svg { width: 12px; height: 12px; }
.reply-btn { float: right; opacity: 0; }
.msg:hover .reply-btn { opacity: 1; }

/* composer */
.composer { flex-shrink: 0; padding: 6px; background: var(--panel); border-top: 1px solid var(--line); }
body.readonly .composer { display: none; }
.reply-bar { display: none; align-items: center; gap: 6px; padding: 0 2px 5px; color: var(--muted); font-size: 12px; }
.reply-bar.on { display: flex; }
.reply-bar span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar button:hover { color: var(--text); }
.composer-row { display: flex; align-items: center; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding-right: 4px; }
.composer-row:focus-within { border-color: var(--accent); }
.composer textarea { flex: 1; min-width: 0; height: 32px; resize: none; padding: 6px 8px; background: none; border: 0; font-size: var(--fs); outline: none; }
.composer textarea:disabled { cursor: not-allowed; }
.count { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.count.near { color: var(--danger); }
.picker-btn { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 3px; color: var(--muted); }
.picker-btn:hover:not(:disabled) { color: var(--text); background: var(--raised); }
.picker-btn svg { width: 16px; height: 16px; }

/* popups */
.menu, .panel, .picker { position: fixed; z-index: 20; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); font-size: 13px; }
.menu { min-width: 190px; padding: 4px; display: flex; flex-direction: column; }
.menu button { text-align: left; padding: 5px 10px; border-radius: 4px; }
.menu button:hover, .menu button:focus-visible { background: var(--raised); }
.menu .danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; }

.panel { width: min(330px, calc(100vw - 16px)); max-height: min(500px, calc(100vh - 16px)); display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 8px 4px 8px 12px; border-bottom: 1px solid var(--line); }
.panel-head strong { flex: 1; }
.panel-filter, .nick-input { margin: 8px 12px; padding: 4px 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; }
.nick-input { margin: 0; width: 170px; }
.viewer-list { overflow-y: auto; padding: 0 6px 8px; }
.viewer { display: block; width: 100%; text-align: left; padding: 3px 6px; border-radius: 3px; }
.viewer:hover { background: var(--raised); }
.card-head { display: flex; gap: 10px; align-items: flex-start; padding: 12px 6px 10px 12px; }
.card-head .avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--raised); flex-shrink: 0; }
.card-info { flex: 1; min-width: 0; }
.card-name { font-size: 16px; font-weight: 700; text-decoration: none; }
.card-name:hover { text-decoration: underline; }
.card-meta { color: var(--muted); margin-top: 2px; }
.card-meta:empty { display: none; }
.card-actions { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 12px 10px; }
.card-actions button { padding: 3px 10px; border-radius: 4px; background: var(--raised); }
.card-actions button:hover { background: #3f4453; }
.card-actions .danger { color: var(--danger); }
.card-log { overflow-y: auto; border-top: 1px solid var(--line); padding: 4px 0; font-size: var(--fs); line-height: 1.5; }

.picker { width: min(340px, calc(100vw - 16px)); height: 360px; display: flex; flex-direction: column; }
.picker-search { margin: 8px; padding: 5px 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; }
.picker-body { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.picker-title { margin: 8px 2px 4px; color: var(--muted); font-weight: 700; font-size: 12px; }
.picker-grid { display: flex; flex-wrap: wrap; gap: 2px; }
.picker-grid button { display: grid; place-items: center; min-width: 36px; height: 36px; padding: 2px; border-radius: 4px; }
.picker-grid button:hover { background: var(--raised); }
.picker-grid .emote { height: 28px; }

.tooltip { position: fixed; z-index: 30; transform: translate(-50%, -100%); max-width: 180px; padding: 8px; background: #14151b; border: 1px solid var(--line); border-radius: 6px; text-align: center; font-size: 12px; white-space: pre-line; pointer-events: none; }
.tooltip.below { transform: translate(-50%, 0); }
.tooltip img { display: block; max-width: 112px; max-height: 112px; margin: 0 auto 6px; }

/* settings */
dialog { width: min(480px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; }
dialog::backdrop { background: rgba(10, 11, 15, .6); }
.settings-form { padding: 18px 20px; font-size: 14px; }
.settings-form h2 { margin: 0 0 12px; font-size: 18px; }
.settings-form h3 { margin: 20px 0 8px; font-size: 14px; color: var(--muted); }
.settings-form .row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.settings-form .row input[type="range"] { flex: 1; }
.settings-form output { min-width: 34px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.settings-form .check { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.settings-form .field { display: block; margin: 10px 0; }
.settings-form .field input, .settings-form select, #dock-url { display: block; width: 100%; margin-top: 4px; padding: 5px 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; }
.hint { display: block; color: var(--muted); font-size: 12px; margin: 2px 0 0; }
.note { padding: 8px 10px; border-radius: 4px; background: rgba(242, 97, 107, .12); color: #ffb3b8; font-size: 13px; }
.settings-form .actions { position: sticky; bottom: -18px; display: flex; justify-content: flex-end; gap: 8px; margin: 20px -20px -18px; padding: 12px 20px; background: var(--panel); border-top: 1px solid var(--line); }
.settings-form .actions button, #account-btn { padding: 6px 14px; border-radius: 4px; background: var(--raised); }
.settings-form .actions .primary { background: var(--accent); color: #fff; }
#account-status { flex: 1; }

body.transparent, body.transparent .messages { background: transparent; }
body.transparent .msg:hover { background: none; }

@media (max-width: 600px) {
  .split { min-width: 85vw; }
}
