/*
 * Layout: the play column (output, combat dock, input) on the left; status (vitals, room,
 * compass, map) and conversations on the right. Narrower screens fold the right side into
 * tabs; phones show one view at a time with tabs at the bottom.
 */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font-family: var(--f-ui); font-size: var(--fs-body); overflow: hidden; text-shadow: var(--glowtext); }
:root[data-size="s"] body { font-size: 13.5px; }
:root[data-size="l"] body { font-size: 17px; }
:root[data-size="xl"] body { font-size: 19.5px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app {
    height: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 292px 340px;
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "top top top" "play status chats";
    gap: 12px;
    padding: max(10px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(14px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.top { grid-area: top; }
.play { grid-area: play; }
.status { grid-area: status; }
.chats { grid-area: chats; }
.side-switch, .tabs, .play-vitals { display: none; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.btn { background: var(--raise); border: 1px solid var(--line); border-radius: 7px; padding: 6px 12px; font-weight: 500; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.warn { color: var(--m-hurt); }
.eyebrow { font-size: .7rem; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); font-weight: 600; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; min-width: 18px; padding: 0 5px; text-align: center; font-weight: 700; font-size: .72rem; line-height: 18px; text-shadow: none; }

/* ---------- Top bar ---------- */
.top { display: flex; align-items: center; gap: 18px; min-width: 0; }
.brand { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.wordmark { font-family: var(--f-display); font-weight: 700; font-size: 1.55rem; letter-spacing: .04em; color: var(--accent); line-height: 1; white-space: nowrap; }
.brand small { font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); white-space: nowrap; }
.whoami { display: flex; align-items: baseline; gap: 10px; min-width: 0; padding-left: 18px; border-left: 1px solid var(--line); }
.ply { font-weight: 600; white-space: nowrap; }
.where { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .spacer { flex: 1; }
.conn { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .88rem; white-space: nowrap; background: none; border: 0; padding: 4px 6px; border-radius: 7px; }
.conn:hover { background: var(--raise); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.conn[data-state="open"] .dot { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent); }
.conn[data-state="connecting"] .dot { background: var(--accent); animation: pulse 1s infinite; }
.conn[data-state="closed"] .dot { background: var(--bad); }
.iconbtn { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.iconbtn:hover { color: var(--fg); border-color: var(--accent); }

/* ---------- Play column ---------- */
.play { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.out-wrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.output {
    flex: 1; min-width: 0; overflow-y: auto; overscroll-behavior: contain;
    font-family: var(--f-out); font-size: var(--fs-out); line-height: var(--lh-out);
    padding: 14px 18px 14px 64px;
    scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
:root[data-stamps="off"] .output { padding-left: 18px; }
.seg { position: relative; white-space: pre-wrap; overflow-wrap: anywhere; }
.seg::before {
    content: attr(data-t); position: absolute; left: -54px; top: 0; width: 44px; text-align: right;
    font-family: var(--f-ui); font-size: .72rem; color: var(--faint); opacity: 0; transition: opacity .15s;
    font-variant-numeric: tabular-nums; line-height: 2.1; white-space: nowrap;
}
.seg:hover::before { opacity: 1; }
:root[data-stamps="off"] .seg::before { display: none; }
.gap { height: .7em; }
.echo { color: var(--accent); opacity: .85; margin-top: .45em; }
.echo .gt { color: var(--faint); margin-right: 6px; }
.sys { color: var(--muted); font-style: italic; }
.sys.err { color: var(--bad); font-style: normal; }
.seg img { max-width: 100%; height: auto; }
.seg table { border-collapse: collapse; max-width: 100%; }
.seg td, .seg th { padding: 0 1.2em 0 0; vertical-align: top; text-align: left; }
.seg pre { margin: 0; white-space: pre; overflow-x: auto; font-family: inherit; }
.seg ul, .seg ol { margin: .2em 0; padding-left: 1.6em; }
.seg p { margin: .4em 0; white-space: normal; }
.seg h1, .seg h2, .seg h3 { font-family: var(--f-display); font-weight: 700; margin: .3em 0 .1em; line-height: 1.25; white-space: normal; }
.seg h1 { font-size: 1.32rem; color: var(--m-room); }
.seg h2 { font-size: 1.12rem; }
.seg h3 { font-size: 1rem; }

/* Server message classes (semantic) */
/* Server HTML sits in .srv. The server uses <div class='x'> as inline colour spans, as the
   old client styled them; unclassed divs and the column classes stay blocks. */
.srv div[class] { display: inline; }
.srv div.twocol, .srv div.threecol, .srv div.threecolhor, .srv div.fourcol { display: block; }
.room_title { font-family: var(--f-out); font-weight: 700; font-size: 1.05em; color: var(--m-room); }
.seg h1.room_title { margin: .2em 0 0; }
.room_descr { opacity: .92; }
.exit { color: var(--muted); }
.npc_title, .npc_descr { color: var(--m-npc); }
.obj_title, .obj_descr, .worn { color: var(--m-obj); }
.pc_title, .pc_descr, .immort_title, .immort_descr { color: var(--m-pc); }
.say_other, .ask_other, .shout_other { color: var(--m-say); }
.say_self, .ask_self, .shout_self, .tell_self, .social_self { color: var(--m-self); }
.tell_other, .whisper { color: var(--m-tell); }
.comm_say, .comm_emote, .comm_join, .comm_leave, .clan, .wiz { color: var(--m-chan); }
.social_other, .emote_other { color: var(--fg); }
.hit_me { color: var(--m-hit); }
.hit_opponent { color: var(--m-hurt); font-weight: 600; }
.hit_other { color: var(--muted); }
.miss_me, .miss_opponent, .miss_other, .nodam_me, .nodam_opponent, .nodam_other, .shield_me, .shield_opponent, .shield_other { color: var(--m-miss); }
.xpgain { color: var(--m-xp); font-weight: 600; }
.death { color: var(--m-death); font-weight: 600; }
.prompt { color: var(--accent); }
.spells, .spell { color: var(--m-spell); }
.score { color: var(--m-npc); }
.who, .who_name { color: var(--m-who); }
.who_title { color: var(--accent); }
.hint { color: var(--m-hint); }
.log { color: var(--fg); }
.mail { color: var(--m-tell); }
.default, .DEFAULT { color: var(--fg); }
.twocol { column-count: 2; column-gap: 20px; }
.threecol, .threecolhor { column-count: 3; column-gap: 20px; }
.fourcol { column-count: 4; column-gap: 20px; }
/* Old MUD colour codes */
.cr { color: var(--a-r); } .cpr { color: var(--a-R); } .cg { color: var(--a-g); } .cpg { color: var(--a-G); }
.cy { color: var(--a-y); } .cpy { color: var(--a-Y); } .cb { color: var(--a-b); } .cpb { color: var(--a-B); }
.cm { color: var(--a-m); } .cpm { color: var(--a-M); } .cc { color: var(--a-c); } .cpc { color: var(--a-C); }
.cw { color: var(--a-w); } .cpw { color: var(--a-W); } .cn { color: var(--a-n); } .cpn { color: var(--a-N); } .ca { color: var(--a-N); }
.br { background: color-mix(in srgb, var(--a-r) 35%, transparent); } .bg { background: color-mix(in srgb, var(--a-g) 35%, transparent); }
.by { background: color-mix(in srgb, var(--a-y) 35%, transparent); } .bb { background: color-mix(in srgb, var(--a-b) 35%, transparent); }
.bm { background: color-mix(in srgb, var(--a-m) 35%, transparent); } .bc { background: color-mix(in srgb, var(--a-c) 35%, transparent); }
.bw { background: color-mix(in srgb, var(--a-w) 35%, transparent); } .bn { background: transparent; }

.output a, .reader a { color: inherit; text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 40%, transparent); text-underline-offset: 3px; cursor: pointer; }
.output a:hover, .reader a:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* Paged text (help, who, score...) shown in the log, long ones folded */
.paged { border-left: 2px solid var(--line); padding-left: 12px; margin: .4em 0; }
.paged.long .paged-body { max-height: 22em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.paged-tools { display: flex; gap: 8px; margin-top: 6px; font-family: var(--f-ui); }
.paged-tools .btn { padding: 3px 10px; font-size: .82rem; }

/* Combat folded into one line per fight */
details.cgroup { margin: .3em 0; border-left: 2px solid color-mix(in srgb, var(--m-hurt) 50%, var(--line)); padding-left: 10px; }
details.cgroup summary { cursor: pointer; color: var(--muted); list-style: none; display: flex; gap: 12px; flex-wrap: wrap; align-items: baseline; font-family: var(--f-ui); font-size: .88rem; }
details.cgroup summary::-webkit-details-marker { display: none; }
details.cgroup summary::before { content: "▸"; color: var(--faint); display: inline-block; transition: transform .15s; }
details.cgroup[open] summary::before { transform: rotate(90deg); }
.ctag { font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--m-hurt); font-weight: 600; }
.cfoes { color: var(--fg); font-weight: 500; }
.t-hit { color: var(--m-hit); } .t-hurt { color: var(--m-hurt); } .t-miss { color: var(--faint); }

.newlines {
    position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
    background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px; padding: 6px 14px;
    font-weight: 600; font-size: .85rem; box-shadow: 0 6px 20px rgb(0 0 0 / .35); text-shadow: none;
}
.banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bad) 10%, var(--panel)); border-radius: var(--radius) var(--radius) 0 0; }
.banner span { flex: 1; min-width: 12em; }

/* ---------- Combat dock: your vitals, then one card per being (Summary) or the fight's log (Scroll) ---------- */
.combat { padding: 10px 12px 12px; display: grid; gap: 10px; border-color: color-mix(in srgb, var(--m-hurt) 45%, var(--line)); animation: rise .25s ease-out; max-height: 46%; overflow-y: auto; scrollbar-width: thin; }
.combat[data-view="scroll"] { display: flex; flex-direction: column; height: 42%; max-height: none; overflow: hidden; }
.play:has(> .combat:not([hidden])) > .play-vitals { display: none; } /* the dock shows them */
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pulse { 50% { opacity: .25; } }
.cb-head { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; }
.cb-tag { font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--m-hurt); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.cb-tag i { width: 7px; height: 7px; border-radius: 50%; background: var(--m-hurt); animation: pulse 1.2s infinite; }
.combat.over .cb-tag { color: var(--good); }
.combat.over .cb-tag i { background: var(--good); animation: none; }
.cb-round { color: var(--faint); font-size: .82rem; font-variant-numeric: tabular-nums; }
.cb-round:empty { display: none; }
.cb-vitals { flex-basis: 100%; order: 5; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; min-width: 0; }
.cb-vitals .vital { grid-template-columns: auto minmax(0, 1fr) auto; gap: 6px; }
.cb-vitals .vital label { font-size: .68rem; }
.cb-vitals .vital .num { min-width: 0; font-size: .8rem; }
.cb-vitals .delta { right: 0; }
.cb-hide { padding: 4px 9px; }
.cb-view { margin-left: auto; display: flex; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: var(--raise); }
.cb-view button { border: 0; background: transparent; border-radius: 5px; padding: 3px 10px; font-size: .78rem; font-weight: 600; color: var(--muted); }
.cb-view button[aria-pressed="true"] { background: var(--panel); color: var(--fg); box-shadow: 0 0 0 1px var(--line); }
.cb-log { flex: 1 1 auto; min-height: 4em; overflow-y: auto; scrollbar-width: thin; border-top: 1px solid var(--line); padding-top: 6px; font-family: var(--f-out); font-size: var(--fs-out); line-height: var(--lh-out); text-shadow: var(--glowtext); }
.cb-strip { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.cb-chip { display: flex; gap: 6px; align-items: center; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 0; }
.cb-chip .life > i { width: 9px; height: 7px; }
.cb-chip .cb-hits { margin-left: 0; }
.cb-chip b { color: var(--fg); font-weight: 600; max-width: 12em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cb-chip.at-me b { color: var(--m-hurt); }
.cb-chip.dead { opacity: .45; }
.cb-chip.dead b { text-decoration: line-through; }
.cb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }
.cb-row { background: var(--raise); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: grid; gap: 5px; min-width: 0; transition: opacity .4s, border-color .3s; }
.cb-row.at-me { border-color: color-mix(in srgb, var(--m-hurt) 55%, var(--line)); }
.cb-row.ally { border-style: dashed; }
.cb-row.dead { opacity: .45; }
.cb-row.dead .cb-name b { text-decoration: line-through; }
.cb-name { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; min-width: 0; }
.cb-name b { font-family: var(--f-display); font-weight: 700; font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.cb-target { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.cb-row.at-me .cb-target { color: var(--m-hurt); font-weight: 600; }
.cb-hp { display: flex; gap: 8px; align-items: center; font-size: .78rem; color: var(--muted); min-width: 0; }
/* Life in 5 boxes: the server says no more than that */
.life { display: flex; gap: 2px; flex: none; }
.life > i { width: 14px; height: 8px; border-radius: 2px; background: color-mix(in srgb, var(--fg) 12%, transparent); }
.life > i.on { background: var(--m-hurt); }
.ally .life > i.on { background: var(--frost); }
.life > i.lost { animation: lost .9s ease-out; }
@keyframes lost { from { background: var(--m-hit); } to { background: color-mix(in srgb, var(--fg) 12%, transparent); } }
/* This round's hits: ⚔×3, and 💥 for each big blow */
.cb-hits { display: flex; gap: 8px; margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.blows { font-weight: 600; display: inline-block; }
.blows.by-you { color: var(--m-hit); }
.blows.by-others { color: var(--muted); font-weight: 500; }
.blows.took-hits { color: var(--m-hurt); }
.blows.pop { animation: pop .45s ease-out; }
@keyframes pop { from { transform: scale(1.5); } to { transform: none; } }
.cb-took { font-size: .86rem; }
.cb-last { font-family: var(--f-out); font-size: .8rem; line-height: 1.4; color: var(--muted); min-height: 1.4em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cb-last.flash { color: var(--fg); }
.cb-lines { font-family: var(--f-out); font-size: .86rem; line-height: 1.5; display: grid; gap: 2px; }

/* ---------- Quick bar + input ---------- */
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 3px 11px; font-size: .84rem; color: var(--muted); }
.chip:hover { color: var(--fg); border-color: var(--accent); }
.cmdbar { display: flex; align-items: center; gap: 10px; padding: 4px 6px 4px 14px; transition: box-shadow .2s, border-color .2s; }
.cmdbar:focus-within { border-color: var(--accent); box-shadow: var(--glow); }
.ptext { color: var(--accent); font-family: var(--f-out); font-weight: 600; white-space: nowrap; max-width: 40%; overflow: hidden; text-overflow: ellipsis; }
.cmdbar input { flex: 1; min-width: 0; background: transparent; border: 0; outline: 0; padding: 10px 0; font-family: var(--f-out); font-size: var(--fs-input); }
.cmdbar input::placeholder { color: var(--faint); }
.send { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 7px; padding: 8px 14px; font-weight: 600; text-shadow: none; }

/* ---------- Status column ---------- */
.status { display: flex; flex-direction: column; gap: 12px; min-height: 0; overflow-y: auto; scrollbar-width: none; }
.card { padding: 14px; }
.vitals { display: grid; gap: 10px; }
.vital { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; align-items: center; gap: 10px; position: relative; }
.vital label { font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.vital .num { font-variant-numeric: tabular-nums; font-size: .9rem; min-width: 64px; text-align: right; }
.vital .num small { color: var(--faint); }
.bar { height: 10px; border-radius: 5px; background: var(--raise); position: relative; overflow: hidden; }
.bar::after { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 1px), color-mix(in srgb, var(--bg) 70%, transparent) calc(10% - 1px) 10%); pointer-events: none; }
.bar > i { position: absolute; inset: 0 auto 0 0; border-radius: 5px; transition: width .45s cubic-bezier(.2, .8, .2, 1); }
.bar > .ghost { background: color-mix(in srgb, var(--fg) 30%, transparent); transition: width .9s .35s ease; }
[data-vital="hp"] .bar > .fill { background: var(--hp); }
[data-vital="ep"] .bar > .fill { background: var(--ep); }
[data-vital="mp"] .bar > .fill { background: var(--mp); }
[data-vital="hp"].low .bar > .fill { animation: pulse 1s infinite; }
.delta { position: absolute; right: 76px; top: -6px; font-weight: 700; font-size: .85rem; color: var(--m-hurt); pointer-events: none; animation: floatup 1.1s ease-out forwards; font-variant-numeric: tabular-nums; }
.delta.plus { color: var(--good); }
@keyframes floatup { from { transform: translateY(4px); opacity: 1; } to { transform: translateY(-14px); opacity: 0; } }
.empty { color: var(--faint); font-size: .88rem; }

.roomcard { display: grid; gap: 12px; }
.rc-title { font-family: var(--f-display); font-weight: 700; font-size: 1.15rem; line-height: 1.2; color: var(--m-room); text-wrap: balance; }
.rc-sub { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.compass { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 1fr); gap: 10px; }
.rose, .updn { display: grid; gap: 5px; grid-auto-rows: 38px; }
.rose { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.updn { grid-template-rows: 38px 38px 38px; }
.updn .dir.d { grid-row: 3; }
.dir { border: 1px solid var(--line); background: var(--raise); border-radius: 8px; font-weight: 600; font-size: .82rem; letter-spacing: .04em; color: var(--faint); opacity: .5; transition: background .15s, color .15s, border-color .15s, opacity .15s; }
.dir.open { opacity: 1; color: var(--fg); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.dir.open:hover { background: var(--accent); color: var(--accent-ink); }
.dir:disabled { cursor: default; }
.dir.hub { opacity: 1; border-style: dashed; color: var(--muted); font-weight: 500; }
.dir.hub:hover { color: var(--fg); border-color: var(--accent); }
.mapcard { padding: 0; overflow: hidden; display: grid; }
.mapcard .eyebrow { padding: 12px 14px 8px; }
.mapview { position: relative; height: 210px; overflow: hidden; cursor: zoom-in; background: var(--raise); border: 0; padding: 0; display: block; width: 100%; }
.mapview img { position: absolute; left: 0; top: 0; max-width: none; filter: var(--map-filter); transform-origin: 0 0; transition: transform .7s cubic-bezier(.3, .7, .2, 1); }
.mapview .nomap { position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint); font-size: .88rem; padding: 12px; text-align: center; }
.you { position: absolute; left: 50%; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 30%, transparent); }
.you::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--accent); animation: ping 2s infinite; }
@keyframes ping { from { transform: scale(1); opacity: .8; } to { transform: scale(2.6); opacity: 0; } }
.whocard { display: grid; gap: 8px; }
.wholist { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.wholist button { border: 1px solid var(--line); background: var(--raise); border-radius: 999px; padding: 3px 10px; font-size: .84rem; color: var(--fg); display: flex; gap: 6px; align-items: baseline; }
.wholist button:hover { border-color: var(--accent); }
.wholist small { color: var(--accent); font-size: .7rem; letter-spacing: .04em; }
.mapzone { padding: 8px 14px 12px; color: var(--muted); font-size: .82rem; display: flex; justify-content: space-between; gap: 8px; font-variant-numeric: tabular-nums; }

/* ---------- Conversations ---------- */
.chats { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.chats > header { padding: 14px 14px 8px; display: flex; justify-content: space-between; align-items: baseline; }
.chats h2 { font-family: var(--f-display); font-size: 1.15rem; margin: 0; font-weight: 700; }
.threads { list-style: none; margin: 0; padding: 0 6px 8px; display: grid; gap: 2px; border-bottom: 1px solid var(--line); max-height: 44%; overflow-y: auto; scrollbar-width: thin; align-content: start; }
.threads .empty { padding: 4px 8px 8px; }
.thr { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 7px 8px; border-radius: 8px; border: 0; background: transparent; width: 100%; text-align: left; }
.thr:hover { background: var(--raise); }
.thr[aria-current="true"] { background: var(--raise); box-shadow: inset 2px 0 0 var(--accent); }
.av { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: .85rem; color: #10141c; text-shadow: none; }
.av.grp { border-radius: 8px; background: var(--line); color: var(--fg); font-size: .75rem; }
.thr-main { min-width: 0; display: grid; }
.thr-name { font-weight: 600; display: flex; gap: 6px; align-items: baseline; min-width: 0; white-space: nowrap; overflow: hidden; }
.thr-name small { font-weight: 400; color: var(--faint); font-size: .74rem; }
.thr-prev { display: block; color: var(--muted); font-size: .84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thr-meta { display: grid; justify-items: end; gap: 3px; font-size: .74rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.thread { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.thread-head { padding: 10px 14px 6px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.thread-head b { font-family: var(--f-display); font-size: 1.05rem; }
.thread-head small { color: var(--faint); font-size: .78rem; }
.msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 14px 10px; display: flex; flex-direction: column; gap: 9px; scrollbar-width: thin; }
.msg { display: grid; gap: 1px; }
.msg .meta { display: flex; gap: 8px; align-items: baseline; font-size: .78rem; }
.msg .meta b { color: var(--m-tell); font-weight: 600; }
.msg.self .meta b { color: var(--accent); }
.msg .meta time { color: var(--faint); font-variant-numeric: tabular-nums; }
.msg p { margin: 0; font-family: var(--f-out); font-size: .88rem; line-height: 1.45; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.self p { color: var(--muted); }
.msg.system p { color: var(--faint); font-style: italic; }
.reply { margin: 0 10px 10px; display: flex; align-items: center; gap: 8px; padding: 3px 4px 3px 8px; }
.reply:focus-within { border-color: var(--accent); box-shadow: var(--glow); }
.prefix { font-family: var(--f-out); font-size: .78rem; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); padding: 2px 7px; border-radius: 5px; white-space: nowrap; }
.reply input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 8px 2px; font-family: var(--f-out); font-size: .9rem; }

/* ---------- Overlays: reader, big map, connect, settings ---------- */
.scrim { position: fixed; inset: 0; background: rgb(5 8 12 / .55); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 10; padding: 16px; }
.reader { width: min(760px, 100%); max-height: 86vh; overflow-y: auto; padding: 18px 26px 24px; box-shadow: var(--shadow); animation: rise .2s ease-out; font-family: var(--f-out); font-size: .93rem; line-height: 1.55; }
/* Close in a sticky bar: in view while reading, and above the text (a help page's <h1> covered it) */
.reader-bar { position: sticky; top: -18px; z-index: 1; display: flex; justify-content: flex-end; margin: -18px -26px 4px; padding: 12px 14px 6px; background: var(--panel); border-bottom: 1px solid var(--line); }
.reader .close { font-family: var(--f-ui); }
.reader .seg h1 { font-size: 1.6rem; }
.mapbig { position: relative; max-width: 100%; max-height: 86vh; border-radius: var(--radius); overflow: hidden; background: var(--raise); box-shadow: var(--shadow); }
.mapbig img { display: block; max-width: 100%; max-height: 86vh; filter: var(--map-filter); }
.mapbig .you { transition: left .5s, top .5s; }
.connect { width: min(460px, 100%); padding: 26px 28px; box-shadow: var(--shadow); display: grid; gap: 16px; animation: rise .2s ease-out; }
.connect h1 { font-family: var(--f-display); color: var(--accent); margin: 0; font-size: 1.9rem; }
.connect p { margin: 0; color: var(--muted); line-height: 1.5; }
.pwdlg .said { display: grid; gap: 4px; padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--raise); border-radius: 6px; }
.pwdlg .said p { color: var(--fg); }
.presets { display: grid; gap: 8px; }
.preset { display: grid; gap: 2px; text-align: left; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--raise); }
.preset:hover, .preset[aria-pressed="true"] { border-color: var(--accent); }
.preset small { color: var(--muted); font-family: var(--f-out); font-size: .78rem; }
.fields { display: grid; grid-template-columns: 90px minmax(0, 1fr) 80px; gap: 8px; }
.fields label { display: grid; gap: 4px; font-size: .74rem; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.fields label.wide { grid-column: 1 / -1; }
.fields input, .fields select, .settings select { background: var(--raise); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; min-width: 0; text-transform: none; letter-spacing: 0; font-size: .95rem; color: var(--fg); }
.connect .row { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.connect .row a { color: var(--muted); font-size: .88rem; }
.settings { position: fixed; z-index: 11; top: 56px; right: max(16px, env(safe-area-inset-right, 0px)); width: min(320px, calc(100vw - 32px)); padding: 16px; box-shadow: var(--shadow); display: grid; gap: 14px; animation: rise .15s ease-out; }
.settings h2 { margin: 0; font-family: var(--f-display); font-size: 1.1rem; }
.settings label.opt { display: flex; gap: 10px; align-items: center; }
.settings .seg-ctl { display: flex; gap: 4px; }
.settings .seg-ctl button { flex: 1; border: 1px solid var(--line); background: var(--raise); border-radius: 6px; padding: 4px; }
.settings .seg-ctl button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.settings .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Medium widths: one side column with a switch ---------- */
@media (max-width: 1279px) {
    .app { grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: auto auto minmax(0, 1fr); grid-template-areas: "top top" "play switch" "play side"; }
    .status, .chats { grid-area: side; }
    .side-switch { grid-area: switch; display: flex; gap: 4px; padding: 4px; }
    .side-switch button { flex: 1; border: 0; background: transparent; border-radius: 7px; padding: 7px; color: var(--muted); font-weight: 600; display: flex; justify-content: center; gap: 6px; align-items: center; }
    .side-switch button[aria-pressed="true"] { background: var(--raise); color: var(--fg); }
    .app[data-side="status"] .chats, .app[data-side="chats"] .status { display: none; }
    .status .vitals { display: none; }
    .play-vitals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; padding: 10px 14px; }
    .play-vitals .vital { grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; }
    .play-vitals .vital .num { min-width: 0; font-size: .82rem; }
    .play-vitals .delta { right: 0; }
}

/* ---------- Phones: one view at a time, tabs at the bottom ---------- */
@media (max-width: 820px) {
    :root { --fs-body: 14px; --fs-out: .88rem; }
    .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "top" "view" "nav"; gap: 10px; padding-bottom: 0; }
    .side-switch { display: none; }
    .app[data-view] .play, .app[data-view] .status, .app[data-view] .chats { grid-area: view; display: none; }
    .app[data-view="play"] .play, .app[data-view="status"] .status, .app[data-view="chats"] .chats { display: flex; }
    .whoami, .conn .host, .brand small, .iconbtn span { display: none; }
    .wordmark { font-size: 1.3rem; }
    .output { padding: 10px 12px; }
    .seg::before { display: none; }
    .play-vitals { gap: 10px; padding: 8px 10px; }
    .play-vitals .vital { grid-template-columns: minmax(0, 1fr); gap: 3px; }
    .play-vitals .vital label { font-size: .68rem; }
    .play-vitals .vital .num { text-align: left; }
    .cb-grid { grid-template-columns: minmax(0, 1fr); }
    .combat { max-height: 40%; }
    .combat[data-view="scroll"] { height: 45%; }
    .cb-vitals { gap: 10px; }
    .quick { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
    .chip { white-space: nowrap; }
    .tabs { grid-area: nav; display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); margin: 0 calc(-1 * max(16px, env(safe-area-inset-right, 0px))) 0 calc(-1 * max(16px, env(safe-area-inset-left, 0px))); padding-bottom: env(safe-area-inset-bottom, 0px); background: var(--panel); }
    .tabs button { border: 0; background: transparent; padding: 11px 4px 12px; color: var(--muted); font-weight: 600; display: flex; justify-content: center; align-items: center; gap: 6px; }
    .tabs button[aria-pressed="true"] { color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); }
    .status .vitals { display: grid; }
    .threads { max-height: 40%; }
    .fields { grid-template-columns: 80px minmax(0, 1fr) 70px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
