/* A Brainy Chat look (TASK 007, Huy 2026-10-24). Palette + font: abrainychat brainy-spec/brand/README.md
   - outside the call (home, pre-join, left): cream canvas, white cards, hairline borders, navy text
   - in the call: deep navy surfaces so faces stand out, same accent
   Logo navy #2c3479 is for the mark/headings only; buttons use the web accent #3b5cb8. */
:root {
  --navy: #2c3479; --navy-deep: #161b3f; --accent: #3b5cb8; --accent-hover: #34529f;
  --vanilla: #eddfd4; --cream: #faf8f5; --teal: #3db0b7; --gold: #e1b74f;
  --bg: var(--cream); --panel: #ffffff; --tile: #f1f5f9; --line: #e2e8f0;
  --text: #1e293b; --muted: #64748b; --danger: #d64545; --ok: var(--teal);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
#meeting, dialog.in-call {
  --bg: var(--navy-deep); --panel: #1f2552; --tile: #262d63; --line: #353d78;
  --text: #f4f5fb; --muted: #a9b0d6; --danger: #ef6b6b;
  color-scheme: dark;
  background: var(--bg); color: var(--text); /* inherited colour is body's computed value, so set it here */
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 "Be Vietnam Pro", Roboto, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1 { font-size: 24px; margin: 0 0 16px; color: var(--navy); font-weight: 600; }
h2 { font-size: 18px; margin: 0 0 8px; font-weight: 600; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; font-size: 14px; }
.link { color: var(--accent); display: block; text-align: center; margin-top: 12px; }

.screen { min-height: 100%; }
.center { display: grid; place-items: center; padding: 16px; }
.card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 24px; box-shadow: 0 1px 2px rgba(15,23,42,.04), 0 8px 24px rgba(44,52,121,.06); }
.card.wide { max-width: 560px; }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.brand img { height: 32px; width: auto; }
.brand h1 { margin: 0; }

label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
input {
  display: block; width: 100%; margin-top: 6px; padding: 12px; border-radius: 12px; font: inherit;
  border: 1px solid var(--line); background: #fff; color: var(--text); font-size: 16px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
button {
  font: inherit; color: var(--text); background: var(--tile); border: 0; border-radius: 12px;
  padding: 12px 16px; cursor: pointer;
}
button.primary { background: var(--accent); color: #fff; width: 100%; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* pre-join preview */
.preview { position: relative; aspect-ratio: 16/9; background: var(--navy-deep); border-radius: 12px; overflow: hidden; margin: 8px 0 16px; }
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview-off { position: absolute; inset: 0; display: grid; place-items: center; color: #a9b0d6; }
.preview-controls { position: absolute; bottom: 10px; left: 0; right: 0; display: flex; gap: 12px; justify-content: center; }
.round { width: 48px; height: 48px; border-radius: 50%; padding: 0; color: #fff; background: color-mix(in srgb, var(--navy-deep) 75%, transparent); display: grid; place-items: center; }
.round[aria-pressed="false"] { background: var(--danger); }

/* icons (CSS masks keep the page script-free of SVG strings) */
.round::before, .tool .ico { content: ""; width: 22px; height: 22px; background: currentColor; display: block;
  -webkit-mask: var(--i) center/contain no-repeat; mask: var(--i) center/contain no-repeat; }
#preMic, #tMic { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 15a3 3 0 0 0 3-3V6a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.9V21h2v-2.1a7 7 0 0 0 6-6.9z'/%3E%3C/svg%3E"); }
#preMic[aria-pressed="false"], #tMic[aria-pressed="false"] { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M15 10.6V6a3 3 0 0 0-5.9-.8zM19 12h-2c0 .7-.2 1.4-.4 2l1.5 1.5c.6-1 .9-2.2.9-3.5zM4.3 3 3 4.3l6 6V12a3 3 0 0 0 4.5 2.6l1.6 1.6A5 5 0 0 1 7 12H5a7 7 0 0 0 6 6.9V21h2v-2.1c1-.1 2-.5 2.8-1l3.9 3.9 1.3-1.3z'/%3E%3C/svg%3E"); }
#preCam, #tCam { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M17 10.5V7a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-3.5l4 4v-11z'/%3E%3C/svg%3E"); }
#preCam[aria-pressed="false"], #tCam[aria-pressed="false"] { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M21 6.5l-4 4V7a1 1 0 0 0-1-1H9.8L21 17.2zM3.3 2 2 3.3 4.7 6H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h12c.2 0 .4-.1.5-.2l3.2 3.2 1.3-1.3z'/%3E%3C/svg%3E"); }
#tShare { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M20 18a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2H0v2h24v-2zM13 14.2V12c-3 0-5 1-6.5 3 .6-3 2.4-6 6.5-6.6V7l4 3.6z'/%3E%3C/svg%3E"); }
#tInvite { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M15 12a4 4 0 1 0-4-4 4 4 0 0 0 4 4zm-9-2V7H4v3H1v2h3v3h2v-3h3v-2zm9 4c-2.7 0-8 1.3-8 4v2h16v-2c0-2.7-5.3-4-8-4z'/%3E%3C/svg%3E"); }
#tStats { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 9h3v11H5zm5.5-5h3v16h-3zM16 13h3v7h-3z'/%3E%3C/svg%3E"); }
#tLeave { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 9c-1.6 0-3.1.3-4.6.7v3.1c0 .4-.2.7-.6.9-1 .5-1.9 1.1-2.6 1.8-.2.2-.4.3-.7.3s-.5-.1-.7-.3L.3 13.1a1 1 0 0 1 0-1.4C3.3 8.8 7.5 7 12 7s8.7 1.8 11.7 4.7a1 1 0 0 1 0 1.4l-2.5 2.5c-.2.2-.4.3-.7.3s-.5-.1-.7-.3c-.8-.7-1.6-1.3-2.6-1.8a1 1 0 0 1-.6-.9V9.7C15.1 9.3 13.6 9 12 9z'/%3E%3C/svg%3E"); }

/* meeting */
#meeting { position: fixed; inset: 0; display: flex; flex-direction: column; min-height: 0; }
.bar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--bg); }
.bar.top { font-size: 14px; }
.code { font-weight: 600; letter-spacing: .5px; }
.status { margin-left: auto; font-size: 13px; color: var(--muted); }
.status.warn { color: #f5a524; }
#grid { flex: 1; min-height: 0; display: grid; gap: 8px; padding: 8px; place-content: center; }
#stage { flex: 3; min-height: 0; position: relative; background: #000; margin: 8px 8px 0; border-radius: 12px; overflow: hidden; }
#stage video { width: 100%; height: 100%; object-fit: contain; }
#meeting.has-stage #grid { flex: 1; grid-auto-flow: column; }
.tile { position: relative; background: var(--tile); border-radius: 10px; overflow: hidden; border: 2px solid transparent; transition: border-color .15s; }
.tile.speaking { border-color: var(--ok); }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile.fit-contain video { object-fit: contain; background: #000; }
.tile.self video { transform: scaleX(-1); }
.tile .avatar { position: absolute; inset: 0; display: grid; place-items: center; }
.tile .avatar span { width: 25%; aspect-ratio: 1; max-width: 72px; min-width: 32px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: clamp(12px, 3vw, 22px); }
.tile.has-video .avatar { display: none; }
.label { position: absolute; left: 6px; bottom: 6px; max-width: calc(100% - 12px); background: color-mix(in srgb, var(--navy-deep) 70%, transparent); border-radius: 6px; padding: 2px 8px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.label .muted-mic { color: var(--danger); margin-left: 4px; }
.tile .info { position: absolute; right: 6px; top: 6px; font: 11px/1.3 ui-monospace, monospace; background: rgba(0,0,0,.6); padding: 2px 6px; border-radius: 6px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 4px; font-size: 13px; }
.pager button { padding: 4px 14px; }
.bar.bottom { justify-content: center; gap: 4px; padding: 8px 8px calc(8px + var(--safe-b)); flex-wrap: nowrap; }
.tool { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 10px; min-width: 56px; background: transparent; font-size: 12px; white-space: nowrap; }
.tool:hover { background: var(--tile); }
.tool[aria-pressed="false"] .ico { color: var(--danger); }
.tool.active .ico { color: var(--ok); }
.tool.leave .ico { color: var(--danger); }
#stats { position: absolute; top: 44px; right: 8px; max-width: min(360px, calc(100% - 16px)); background: color-mix(in srgb, var(--navy-deep) 94%, transparent); border-radius: 10px; padding: 8px 12px; z-index: 5; }
#stats pre { margin: 0; font: 12px/1.45 ui-monospace, monospace; white-space: pre-wrap; }
dialog { background: var(--panel); color: var(--text); border: 0; border-radius: 16px; padding: 20px; width: min(420px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog .row { display: flex; gap: 8px; margin-top: 12px; }
dialog .row button { flex: 1; }
#toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: var(--navy); color: #fff; max-width: calc(100% - 32px); text-align: center; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 10; }
#toast.show { opacity: 1; }

@media (max-width: 420px) {
  .tool { min-width: 0; padding: 6px 2px; font-size: 11px; flex: 1 1 0; }
  .tool span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .bar.top { gap: 8px; font-size: 13px; }
}

/* camera effects picker (pre-join strip + in-call dialog) */
.fx { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; margin: -6px 0 14px; scrollbar-width: none; }
.fx::-webkit-scrollbar { display: none; }
.fx-chip { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 0; background: none; color: var(--muted); font-size: 12px; border-radius: 10px; }
.fx-thumb { width: 68px; height: 42px; border-radius: 10px; border: 2px solid var(--line); overflow: hidden; display: grid; place-items: center; background: var(--tile); color: var(--text); }
.fx-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fx-chip[aria-pressed="true"] { color: var(--text); font-weight: 600; }
.fx-chip[aria-pressed="true"] .fx-thumb { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.fx-thumb { position: relative; font-size: 20px; }
.fx-art { position: absolute; inset: -6px; background: radial-gradient(circle at 22% 32%, var(--gold) 0 13%, transparent 14%), radial-gradient(circle at 80% 26%, var(--teal) 0 11%, transparent 12%), linear-gradient(135deg, #adcee7, var(--vanilla)); }
.fx-art.light { filter: blur(2px); }
.fx-art.strong { filter: blur(4px); }
.fx-person { position: absolute; inset: 0; background: radial-gradient(ellipse 24% 34% at 50% 100%, var(--navy) 0 98%, transparent 100%), radial-gradient(circle at 50% 46%, var(--navy) 0 13%, transparent 14%); }
.fx-note { font-size: 12px; color: var(--muted); margin: -8px 0 12px; min-height: 1em; }
#fxDialog { width: min(540px, calc(100% - 32px)); }
#fxDialog .fx { margin: 8px 0 4px; flex-wrap: wrap; overflow: visible; }
#tFx, #preSettings { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M19.4 13a7.5 7.5 0 0 0 0-2l2.1-1.6a.5.5 0 0 0 .1-.6l-2-3.5a.5.5 0 0 0-.6-.2l-2.5 1a7.3 7.3 0 0 0-1.7-1L14.4 2.4A.5.5 0 0 0 14 2h-4a.5.5 0 0 0-.5.4L9.2 5a7.3 7.3 0 0 0-1.7 1l-2.5-1a.5.5 0 0 0-.6.2l-2 3.5a.5.5 0 0 0 .1.6L4.6 11a7.5 7.5 0 0 0 0 2l-2.1 1.6a.5.5 0 0 0-.1.6l2 3.5c.1.2.4.3.6.2l2.5-1c.5.4 1.1.7 1.7 1l.4 2.7c0 .2.2.4.5.4h4c.2 0 .5-.2.5-.4l.4-2.7c.6-.3 1.2-.6 1.7-1l2.5 1c.2.1.5 0 .6-.2l2-3.5a.5.5 0 0 0-.1-.6zM12 15.5a3.5 3.5 0 1 1 0-7 3.5 3.5 0 0 1 0 7z'/%3E%3C/svg%3E"); }
#tChat { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 3h16a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H8l-5 4V5a2 2 0 0 1 1-2zm3 6v2h10V9zm0 4v2h7v-2z'/%3E%3C/svg%3E"); }
@media (max-width: 340px) {
  .tool { font-size: 10px; letter-spacing: -.3px; padding: 6px 0; } /* SE: 7 tools x ~45 px ("Settings" is the widest) */
}

/* AI notes (TASK 013) */
.notes-note { font-size: 13px; line-height: 1.45; color: var(--text); background: color-mix(in srgb, var(--teal) 12%, var(--panel)); border: 1px solid color-mix(in srgb, var(--teal) 35%, transparent); border-radius: 10px; padding: 10px 12px; margin: 0 0 14px; }
/* in-app browser warning (TASK 030) */
.inapp-note { display: flex; align-items: center; gap: 10px; font-size: 13px; line-height: 1.45; color: var(--text); background: color-mix(in srgb, #e8a33d 16%, var(--panel)); border: 1px solid color-mix(in srgb, #e8a33d 55%, transparent); border-radius: 10px; padding: 10px 12px; margin: 0 0 14px; text-align: left; }
.inapp-note[hidden] { display: none; }
.inapp-note p { margin: 0; flex: 1; }
.inapp-note button { flex: none; min-height: 36px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.notes-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 4px 10px; min-height: 28px; border-radius: 999px; background: color-mix(in srgb, var(--teal) 22%, transparent); color: var(--text); border: 1px solid color-mix(in srgb, var(--teal) 55%, transparent); cursor: pointer; white-space: nowrap; }
.notes-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 30%, transparent); }
.notes-pill.off { background: transparent; border-color: var(--line); color: var(--muted); }
.notes-pill.off .dot { background: var(--muted); box-shadow: none; }
@media (max-width: 420px) { .notes-pill { padding: 3px 8px; } }

/* self view: like a mirror, except a phone's back camera (TASK 025) */
.no-mirror .preview video, .no-mirror .tile.self video { transform: none; }

/* settings dialog: devices (TASK 025) */
#fxDialog h3 { font-size: 14px; font-weight: 600; color: var(--muted); margin: 14px 0 0; }
label.dev { margin: 10px 0 0; }
select { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: 12px; font: inherit; font-size: 15px;
  border: 1px solid var(--line); background: var(--tile); color: var(--text); }
.meter { display: block; height: 6px; margin-top: 8px; border-radius: 3px; background: var(--line); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--teal); transition: width .08s linear; }

/* chat (TASK 024) */
.tool { position: relative; }
.tool .badge { position: absolute; top: 2px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 600; line-height: 18px; text-align: center; }
#tChat[aria-pressed="true"] .ico { color: var(--ok); }
#chat { position: fixed; top: 0; right: 0; bottom: 0; width: 340px; z-index: 6; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); }
#meeting.chat-open { padding-right: 340px; }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 6px 16px; }
.chat-head h2 { margin: 0; }
.chat-close { background: transparent; padding: 8px 10px; font-size: 16px; color: var(--muted); }
.chat-empty { font-size: 13px; color: var(--muted); margin: 0 16px 8px; }
#chatList { flex: 1; min-height: 0; overflow-y: auto; list-style: none; margin: 0; padding: 4px 16px 12px; overscroll-behavior: contain; }
.msg { margin-top: 12px; }
.msg.cont { margin-top: 2px; }
.msg.cont .meta { display: none; }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg .meta b { color: var(--text); font-weight: 600; margin-right: 6px; }
.msg .text { font-size: 14px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .text a { color: #9fb6ff; text-decoration: underline; }
.msg.mine .meta b { color: var(--teal); }
#chatForm { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px calc(10px + var(--safe-b)); border-top: 1px solid var(--line); }
#chatInput { flex: 1; resize: none; max-height: 120px; padding: 10px 12px; border-radius: 12px; font: inherit; font-size: 16px; line-height: 1.35;
  border: 1px solid var(--line); background: var(--tile); color: var(--text); }
#chatInput:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
#chatSend { width: auto; padding: 10px 14px; }
@media (max-width: 760px) {
  #chat { left: 0; width: auto; border-left: 0; height: 100dvh; bottom: auto; }
  #meeting.chat-open { padding-right: 0; }
}
@media (max-width: 420px) {
  #tStats { display: none; } /* 8 tools don't fit an SE; stats live in Settings on phones */
}

/* ---------- Looks per domain (TASK 032). The Worker sets <html data-theme> from the domain:
   abc = A Brainy Chat (the :root values above), huddee = meet.huddee.com, vnn = meet.vietneuropsy.org.
   Each look overrides the same variables, light surface and in-call surface. ---------- */
html[data-theme="huddee"] {   /* huddee.com: paper + ink, no colour accent */
  --navy: #242424; --navy-deep: #161616; --accent: #363737; --accent-hover: #1f1f1f;
  --vanilla: #f7f7f7; --cream: #faf9f6; --teal: #3d8b6e; --gold: #b0b0b0;
  --tile: #f2f2f0; --line: #e6e6e6; --text: #242424; --muted: #6b6b6b;
}
html[data-theme="huddee"] #meeting, html[data-theme="huddee"] dialog.in-call {
  --bg: #161616; --panel: #1e1e1e; --tile: #262626; --line: #333333; --text: #ecebe7; --muted: #9a9a9a;
}
html[data-theme="vnn"] {      /* vietneuropsy.org: teal science colour, gold heritage accent */
  --navy: #115e59; --navy-deep: #042f2e; --accent: #0f766e; --accent-hover: #115e59;
  --vanilla: #ccfbf1; --cream: #fafcfb; --teal: #14b8a6; --gold: #d4a017;
  --tile: #eef6f4; --line: #d9e7e4; --text: #1a2e2a; --muted: #5b6f6b;
}
html[data-theme="vnn"] #meeting, html[data-theme="vnn"] dialog.in-call {
  --bg: #042f2e; --panel: #0b3d3a; --tile: #134e4a; --line: #1f5f5a; --text: #f0fdfa; --muted: #9cc7c0;
}
