:root {
  --bg: #14181f;
  --panel: #1c222c;
  --line: #2c3442;
  --text: #e6e9ee;
  --dim: #98a2b3;
  --accent: #d97757;
  --owner: #2b4a3a;
  --system: #3b3524;
  --danger: #ff8f8f;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 1.1rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; margin-bottom: 0.4rem; }
button, input, select, textarea {
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
}
button { cursor: pointer; background: var(--accent); border-color: var(--accent); color: #1a1208; font-weight: 600; }
button.small { background: var(--panel); border-color: var(--line); color: var(--text); font-weight: 500; padding: 0.35rem 0.6rem; }
button.icon { background: transparent; border-color: transparent; color: var(--text); padding: 0.3rem 0.5rem; font-size: 1.2rem; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.error { color: var(--danger); min-height: 1.2em; margin: 0.3rem 0 0; }
.hint { color: var(--dim); font-size: 0.85rem; margin: 0.3rem 0; }
.spacer { flex: 1; }
.pill { background: var(--system); color: #f2d98a; border-radius: 99px; padding: 0.1rem 0.6rem; font-size: 0.8rem; }

.card { max-width: 24rem; margin: 12vh auto 0; padding: 1.5rem; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.card form { display: grid; gap: 0.8rem; margin-top: 1rem; }
.card label { display: grid; gap: 0.3rem; color: var(--dim); font-size: 0.9rem; }

#chat { display: flex; flex-direction: column; height: 100dvh; }
header { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--line); background: var(--panel); }
.banner { background: var(--system); color: #f2d98a; padding: 0.5rem 0.75rem; font-size: 0.9rem; }
.body { flex: 1; display: flex; min-height: 0; }

nav#rooms { width: 15rem; border-right: 1px solid var(--line); display: flex; flex-direction: column; background: var(--panel); }
#room-list { list-style: none; margin: 0; padding: 0.4rem; overflow-y: auto; flex: 1; }
#room-list button { width: 100%; text-align: left; background: transparent; border-color: transparent; color: var(--text); font-weight: 500; display: flex; gap: 0.5rem; align-items: center; }
#room-list button[aria-current="true"] { background: var(--bg); border-color: var(--line); }
#room-list .count { color: var(--dim); font-size: 0.8rem; margin-left: auto; }
#room-list .dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--accent); }
.helper { padding: 0.6rem 0.75rem; border-top: 1px solid var(--line); color: var(--dim); font-size: 0.8rem; }
.helper.bad { color: var(--danger); }

.room { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.people { display: flex; flex-wrap: wrap; gap: 0.35rem; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--line); font-size: 0.8rem; color: var(--dim); }
.people span { border: 1px solid var(--line); border-radius: 99px; padding: 0.05rem 0.55rem; }
.people span.gone { opacity: 0.5; }
#messages { list-style: none; margin: 0; padding: 0.75rem; overflow-y: auto; flex: 1; display: grid; gap: 0.55rem; align-content: start; }
#messages li { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0.5rem 0.7rem; max-width: 60rem; }
#messages li.owner { background: var(--owner); border-color: #3a6650; }
#messages li.system { background: var(--system); border-color: #5a5030; color: #f2d98a; }
#messages .meta { color: var(--dim); font-size: 0.78rem; display: flex; flex-wrap: wrap; gap: 0.5rem; }
#messages .meta b { color: var(--text); }
#messages .text { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 0.15rem; }
#messages .empty { background: transparent; border-style: dashed; color: var(--dim); }

#composer { border-top: 1px solid var(--line); padding: 0.6rem 0.75rem calc(0.6rem + env(safe-area-inset-bottom)); background: var(--panel); }
.to-row { display: flex; gap: 0.5rem; align-items: center; color: var(--dim); font-size: 0.85rem; margin-bottom: 0.4rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.chips label { border: 1px solid var(--line); border-radius: 99px; padding: 0.1rem 0.6rem; cursor: pointer; color: var(--text); }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: #1a1208; }
.chips label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.send-row { display: flex; gap: 0.5rem; align-items: flex-end; }
.send-row textarea { flex: 1; resize: vertical; min-height: 2.8rem; max-height: 40vh; background: var(--bg); }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; width: min(40rem, 94vw); max-height: 90dvh; padding: 1rem; }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog section { border-top: 1px solid var(--line); padding: 0.8rem 0; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.6rem; }
.dialog-head button { background: transparent; border-color: transparent; color: var(--text); }
.row { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin: 0.4rem 0; }
.row input[type="number"] { width: 5rem; }
#map-rows .row input { flex: 1; min-width: 8rem; }
#key-list { list-style: none; padding: 0; margin: 0 0 0.5rem; display: grid; gap: 0.3rem; font-size: 0.9rem; }
#key-list li { display: flex; gap: 0.5rem; align-items: center; }
#key-list .revoked { opacity: 0.5; text-decoration: line-through; }
.secret { background: var(--bg); border: 1px dashed var(--accent); border-radius: 8px; padding: 0.6rem; overflow-wrap: anywhere; font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }

@media (max-width: 760px) {
  nav#rooms { position: fixed; inset: 3.1rem auto 0 0; z-index: 5; width: min(18rem, 85vw); transform: translateX(-105%); transition: transform 0.15s; border-right: 1px solid var(--line); }
  nav#rooms.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.5); }
  #pause-room { font-size: 0.85rem; }
}
@media (min-width: 761px) {
  #rooms-toggle { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  nav#rooms { transition: none; }
}
