/* OwnComms default theme — everything themeable via CSS variables. */
:root {
  --oc-bg: #0c111e;
  --oc-surface: #161d2e;
  --oc-text: #e8ecf4;          /* WCAG AA+ on --oc-bg */
  --oc-text-dim: #b3bccb;      /* still >= 4.5:1 on bg */
  --oc-accent: #4da3ff;
  --oc-accent-text: #06101f;
  --oc-danger: #ff6b6b;
  --oc-speaking: #4dd88a;
  --oc-border: #2b3550;
  --oc-radius: 10px;
  --oc-font: system-ui, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--oc-bg);
  color: var(--oc-text);
  font-family: var(--oc-font);
  min-height: 100vh;
}
#app { max-width: 900px; margin: 0 auto; padding: 1rem; }

:focus-visible {
  outline: 3px solid var(--oc-accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

/* join screen */
#join-screen { max-width: 380px; margin: 10vh auto 0; }
.tagline { color: var(--oc-text-dim); }
#join-form { display: grid; gap: .4rem; }
label { font-size: .9rem; color: var(--oc-text-dim); }
input {
  background: var(--oc-surface);
  border: 1px solid var(--oc-border);
  border-radius: var(--oc-radius);
  color: var(--oc-text);
  padding: .65rem .8rem;
  font-size: 1rem;
}
button {
  background: var(--oc-accent);
  color: var(--oc-accent-text);
  border: 0;
  border-radius: var(--oc-radius);
  padding: .65rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: .5rem;
}
button.danger { background: var(--oc-danger); }
#gate-btn[aria-pressed="true"] { background: var(--oc-speaking); }
.error { color: var(--oc-danger); }

/* room screen */
.room-header { display: flex; gap: .5rem; align-items: center; }
.room-header h1 { flex: 1; font-size: 1.2rem; margin: .3rem 0; }
.room-body {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 1rem;
  min-height: 60vh;
}
@media (max-width: 640px) { .room-body { grid-template-columns: 1fr; } }

#roster {
  list-style: none; margin: 0; padding: .5rem;
  background: var(--oc-surface); border-radius: var(--oc-radius);
}
#roster li {
  padding: .45rem .55rem; border-radius: var(--oc-radius);
  border-left: 4px solid transparent;
}
#roster li.speaking {
  border-left-color: var(--oc-speaking);
  background: color-mix(in srgb, var(--oc-speaking) 12%, transparent);
}

.chat-pane { display: flex; flex-direction: column; }
#chat-log {
  flex: 1; overflow-y: auto; list-style: none; margin: 0;
  padding: .6rem; background: var(--oc-surface);
  border-radius: var(--oc-radius);
}
#chat-log li { padding: .15rem 0; overflow-wrap: anywhere; }
#chat-log li.system { color: var(--oc-text-dim); font-style: italic; }
#chat-log li.self b { color: var(--oc-accent); }
#chat-log li.history { opacity: .55; }
#chat-form { display: flex; gap: .5rem; margin-top: .5rem; }
#chat-form input { flex: 1; }
#chat-form button { margin-top: 0; }

.controls { display: flex; gap: 1rem; align-items: center; margin-top: .8rem; }
#status { color: var(--oc-text-dim); }

@media (prefers-reduced-motion: no-preference) {
  #roster li { transition: background .2s, border-color .2s; }
}

#qr-box {
  background: #ffffff; border-radius: var(--oc-radius);
  padding: .8rem; margin: .6rem 0; width: fit-content; text-align: center;
}
#qr-box .qr-hint { color: #06101f; margin: .4rem 0 0; font-size: .9rem; }

#active-rooms { margin-top: 1.4rem; }
#active-rooms h2 { font-size: 1rem; color: var(--oc-text-dim); }
#room-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
button.room-pick {
  width: 100%; text-align: left; margin: 0;
  background: var(--oc-surface); color: var(--oc-text);
  border: 1px solid var(--oc-border);
}

#roster li { display: flex; align-items: center; gap: .3rem; }
#roster li span:first-child { flex: 1; }
button.mod-btn {
  margin: 0; padding: .1rem .45rem; font-size: .75rem; font-weight: 500;
  background: transparent; color: var(--oc-text-dim);
  border: 1px solid var(--oc-border); border-radius: 6px;
}
button.mod-btn:hover { color: var(--oc-danger); border-color: var(--oc-danger); }

.master-vol { display: flex; gap: .4rem; align-items: center;
  color: var(--oc-text-dim); font-size: .85rem; }
input[type="range"] { accent-color: var(--oc-accent); }
#roster li .vol { width: 64px; }

/* identity fingerprint badge (SHA-256 of the peer's session pubkey —
 * see README "Identity"); themeable via the --oc-* vars above */
#roster li { flex-wrap: wrap; }
#roster li code.fp {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .68rem;
  color: var(--oc-text-dim);
  background: color-mix(in srgb, var(--oc-accent) 10%, transparent);
  border: 1px solid #2b3550;
  border-radius: 6px;
  padding: .08rem .32rem;
  white-space: nowrap;
  letter-spacing: .02em;
}

/* TURN relay pill (footer) — shown when config has a turn:/turns: entry */
#relay-dot {
  font-size: .78rem; color: var(--oc-text-dim); white-space: nowrap;
  border: 1px solid #2b3550; border-radius: 999px; padding: .15rem .55rem;
}
#relay-dot::before { /* decorative dot; empty content = not announced */
  content: ""; display: inline-block; width: .5em; height: .5em;
  border-radius: 50%; background: var(--oc-speaking); margin-right: .35em;
}

/* ---------- theme presets ----------
 * The :root block at the top IS the default "midnight" theme. Presets
 * override the same --oc-* contract via <html data-oc-theme="...">,
 * picked on the join screen (app.js) and persisted in
 * localStorage "owncomms.theme". Embedders can force one the same way
 * or define their own :root[data-oc-theme="x"] block. */
:root[data-oc-theme="light"] {
  --oc-bg: #f4f6fa;
  --oc-surface: #ffffff;
  --oc-text: #17202f;          /* 15:1 on --oc-bg */
  --oc-text-dim: #4c5668;      /* >= 6.9:1 */
  --oc-accent: #1c66c2;        /* 5.6:1 vs white (AA as text + button bg) */
  --oc-accent-text: #ffffff;
  --oc-danger: #b3261e;        /* 6.5:1 on white */
  --oc-speaking: #14783c;
  --oc-border: #c3cad8;
}

/* WCAG AAA: pure black/white palette, yellow accent = yellow focus ring
 * (:focus-visible uses --oc-accent). Text 21:1, accent buttons 19.6:1. */
:root[data-oc-theme="high-contrast"] {
  --oc-bg: #000000;
  --oc-surface: #000000;
  --oc-text: #ffffff;
  --oc-text-dim: #ffffff;
  --oc-accent: #ffff00;
  --oc-accent-text: #000000;
  --oc-danger: #ff8080;        /* 8.7:1 on black */
  --oc-speaking: #ffffff;
  --oc-border: #ffffff;
}
/* surface == bg in high-contrast; keep the panes delineated */
:root[data-oc-theme="high-contrast"] #roster,
:root[data-oc-theme="high-contrast"] #chat-log {
  border: 1px solid var(--oc-border);
}

/* true-black background (OLED pixel-off), midnight accents elsewhere */
:root[data-oc-theme="oled"] {
  --oc-bg: #000000;          /* true OLED black */
  --oc-surface: #0c0c0d;     /* near-black cards */
  --oc-text: #f6e58a;        /* warm yellow, readable on black */
  --oc-text-dim: #b3a253;    /* muted gold for secondary text */
  --oc-accent: #ffd60a;      /* bright yellow — buttons, highlights */
  --oc-accent-text: #000000; /* black label on yellow */
  --oc-border: #26220f;      /* subtle warm border */
  --oc-speaking: #4dd88a;    /* green speaking ring stands out on yellow */
}

/* theme picker (join screen, injected by app.js) */
.theme-row { margin-top: 1.2rem; display: grid; gap: .4rem; }
select {
  background: var(--oc-surface);
  border: 1px solid var(--oc-border);
  border-radius: var(--oc-radius);
  color: var(--oc-text);
  padding: .55rem .6rem;
  font-size: .95rem;
}

/* live captions */
#captions { display: grid; gap: .25rem; }
#captions:not(:empty) { margin-top: .5rem; }
.caption-line {
  margin: 0; padding: .3rem .6rem;
  background: var(--oc-surface);
  border-left: 3px solid var(--oc-accent);
  border-radius: var(--oc-radius);
  overflow-wrap: anywhere;
  opacity: 1;
}
.caption-line b { color: var(--oc-accent); }
.caption-line.fading { opacity: 0; }
@media (prefers-reduced-motion: no-preference) {
  .caption-line { transition: opacity .6s; }
}
#cc-btn[aria-pressed="true"] {
  background: var(--oc-speaking);
  color: var(--oc-accent-text);
}
button:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- in-VC channel bar (see + navigate all channels) ---------- */
#channel-bar { overflow-x: auto; margin: .2rem 0 .5rem; }
#channel-switch { list-style: none; display: flex; gap: .35rem;
  margin: 0; padding: 0; }
#channel-switch li { flex: none; }
.chan {
  background: var(--oc-surface); color: var(--oc-text-dim);
  border: 1px solid var(--oc-border); border-radius: 999px;
  padding: .3rem .7rem; font-size: .9rem; margin: 0; white-space: nowrap;
}
.chan:hover { border-color: var(--oc-accent); color: var(--oc-text); }
.chan.current {
  background: var(--oc-accent); color: var(--oc-accent-text);
  border-color: transparent; cursor: default; font-weight: 600;
}

/* per-user local mute (each listener controls who they hear) */
.peer-mute {
  background: transparent; border: 1px solid var(--oc-border);
  border-radius: var(--oc-radius); padding: .1rem .4rem; margin: 0 .3rem;
  font-size: .9rem; line-height: 1.4; cursor: pointer;
}
.peer-mute.on { border-color: var(--oc-danger); }

/* ---------- video grid (opt-in 512x512 tiles) ---------- */
#video-grid {
  display: grid; gap: .5rem; margin: 0 0 .8rem;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.vtile {
  position: relative; aspect-ratio: 1 / 1; max-width: 512px;
  background: #000; border: 1px solid var(--oc-border);
  border-radius: var(--oc-radius); overflow: hidden;
}
.vtile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.vtile .vcap {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: .15rem .45rem; font-size: .78rem; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.72));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#video-btn.on { background: var(--oc-danger); }
