/* Flisk on the web (/play/): the screen, and Flisk's chat or the tree beside it (below it, on a phone). Flisk purple
   on night (the brand pack's tokens: brand-assets/flisk/tokens), its raised surfaces a purple-tinted dark. */
:root {
  color-scheme: dark;
  --bg: #07060b;
  --panel: #110e1a;
  --raised: #1a1528;
  --line: #2c2440;
  --ink: #f4f2ff;
  --soft: #8d8a99;
  --accent: #864dff;
  --accent-deep: #672de7;
  --accent-light: #a97cff;
  --on-accent: #ffffff;
  --problem: #ff8a7a;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* The screen at 16:9, as large as it fits, as a TV's would be (black either side). */
#stage {
  position: relative;
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-width: 0;
  background: #000;
  container-type: size;
}

#screen {
  display: block;
  width: min(100cqw, calc(100cqh * 16 / 9));
  height: min(100cqh, calc(100cqw * 9 / 16));
  outline: none;
}

#status {
  position: absolute;
  left: 12px;
  bottom: 12px;
  margin: 0;
  padding: 4px 9px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--soft);
  font-size: 12px;
  pointer-events: none;
}

#status.on { color: #9fd8a8; }

/* A newer Flisk than this page (RELEASES.md): said calmly, at the top, until it's reloaded. */
#updated {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 8px 6px 14px;
  border-radius: 8px;
  background: rgba(17, 14, 26, 0.92);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 14px;
  white-space: nowrap;
}

#updated button {
  margin-left: 6px;
  padding: 3px 12px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

#updated[hidden] { display: none; }

#side {
  display: flex;
  flex-direction: column;
  width: min(420px, 40vw);
  border-left: 1px solid var(--line);
  background: var(--panel);
}

#side header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

/* The wordmark: white letters, the portal in the L (inline: no font). */
#side .brand { display: flex; flex: none; align-items: center; }
.flisk-wordmark { display: block; width: auto; }
#side .brand .flisk-wordmark { height: 18px; }  /* (80 px wide at the least: the pack's smallest) */

#who {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--soft);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button {
  font: inherit;
  cursor: pointer;
}

#profiles { color: var(--accent-light); font-size: 13px; white-space: nowrap; }

#sign-out {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--soft);
  font-size: 13px;
}

#sign-out:hover { color: var(--ink); }

#chat {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

#chat > * { flex: 1; min-height: 0; }

#chat[hidden], #browse[hidden], #settings[hidden] { display: none; }

/* Talk (the chat) or Browse (the tree), beside the screen. */
#tabs {
  display: flex;
  gap: 4px;
  padding: 6px 10px 0;
  border-bottom: 1px solid var(--line);
}

#tabs button {
  padding: 7px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--soft);
  font-size: 14px;
}

#tabs button:hover { color: var(--ink); }
#tabs button[aria-selected=true] { border-bottom-color: var(--accent); color: var(--ink); }

/* The tree: every scene by its address, as browse/services.py has them. A row puts its place on the
   screen; a folder's arrow opens it here, without going there. */
#browse {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

#browse .browse-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 6px;
  color: var(--soft);
  font-size: 13px;
}

#browse-refresh {
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--soft);
  font-size: 12px;
}

#browse-refresh:hover { color: var(--ink); }

#tree, #tree ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

#tree {
  flex: 1;
  min-height: 0;
  padding: 0 6px 12px;
  overflow-y: auto;
}

#tree ul { padding-left: 16px; }
#tree ul[hidden] { display: none; }

#tree .row {
  display: flex;
  align-items: flex-start;
  border-radius: 7px;
}

#tree .row:hover { background: rgba(255, 255, 255, 0.04); }
#tree .row.here { background: rgba(134, 77, 255, 0.16); }

#tree .toggle, #tree .spacer {
  flex: none;
  width: 24px;
  height: 34px;
}

#tree .toggle {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--soft);
  font-size: 11px;
}

#tree .toggle::before { content: "\25B6"; display: inline-block; transition: transform 0.12s; }
#tree .toggle[aria-expanded=true]::before { transform: rotate(90deg); }

#tree .go {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  padding: 6px 8px 6px 2px;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

#tree .go .title { font-size: 14px; }
#tree .row.here .go .title { color: var(--accent-light); font-weight: 600; }

#tree .go .about {
  overflow: hidden;
  color: var(--soft);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#tree .go .by { color: var(--soft); font-size: 12px; opacity: 0.8; }

#tree .note { padding: 6px 8px 6px 26px; color: var(--soft); font-size: 13px; }
#tree .note.problem { color: var(--problem); }

#sign-in {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(7, 6, 11, 0.84);
}

#sign-in[hidden] { display: none; }

#sign-in form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 340px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

#sign-in h1 { margin: 2px 0 4px; }
#sign-in h1 .flisk-wordmark { height: 26px; }
#qr-sign-in { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
#qr-sign-in[hidden], #qr-or[hidden] { display: none; }
#qr { width: 180px; height: 180px; border-radius: 10px; image-rendering: pixelated; }
#sign-in .or { text-align: center; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }
#sign-in p { margin: 0; color: var(--soft); }

#sign-in label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--soft);
}

#sign-in input {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}

#sign-in input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
#sign-in label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
#sign-in label.check input { padding: 0; accent-color: var(--accent); }
#by-email, #by-code { display: flex; flex-direction: column; gap: 10px; }
#by-email[hidden], #by-code[hidden] { display: none; }
#sign-in input[name=code] { font-size: 22px; letter-spacing: 0.2em; text-align: center; }
#code-again { align-self: center; padding: 2px 9px; border: 0; background: none; color: var(--soft); font-size: 12px; text-decoration: underline; }
#sign-in p.soft { font-size: 12px; text-align: center; }
#sign-in p.soft a { color: var(--soft); }

#sign-in .problem { min-height: 1.2em; color: var(--problem); font-size: 13px; }

#sign-in button[type=submit] {
  padding: 10px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

#sign-in button[type=submit]:hover { background: var(--accent-deep); }

#sign-in button[disabled] { opacity: 0.6; cursor: default; }

/* A phone, or a narrow window: the screen above, the chat below. */
@media (max-width: 760px) {
  body { flex-direction: column; }
  #stage { flex: none; width: 100%; aspect-ratio: 16 / 9; }
  #side { flex: 1; width: auto; min-height: 0; border-left: 0; border-top: 1px solid var(--line); }
}

/* This screen (the Screen tab): its name, its id to copy, whether it's connected. */
#settings {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px 20px;
}
#settings h2 { margin: 4px 0 12px; font-size: 17px; font-weight: 600; }
#settings label { display: block; margin-bottom: 6px; color: var(--soft); font-size: 13px; }
#settings .row { display: flex; gap: 8px; }
#settings input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}
#settings button {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
}
#settings button:hover { border-color: var(--accent); }
#settings button.small { padding: 2px 9px; font-size: 12px; color: var(--soft); }
#settings button.problem { color: var(--problem); }
#settings button.problem:hover { border-color: var(--problem); }
#screens-list li > button + button { margin-left: -4px; }
#settings dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 16px 0; }
#settings dt { color: var(--soft); font-size: 13px; }
#settings dd { margin: 0; overflow-wrap: anywhere; }
#settings code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
#settings .soft { color: var(--soft); font-size: 13px; }
#settings h2.next { margin-top: 24px; }
#screens-list { list-style: none; margin: 0; padding: 0; }
#screens-list li { display: flex; align-items: flex-start; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
#screens-list li > div { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
#screens-list strong { font-weight: 600; }
#screens-list small { color: var(--soft); font-size: 12px; }
#screens-list code { color: var(--soft); font-size: 11px; }
#screens-list .dot { flex: none; width: 8px; height: 8px; margin-top: 7px; border-radius: 50%; background: var(--line); }
#screens-list .dot.on { background: #6fd18b; box-shadow: 0 0 6px rgba(111, 209, 139, 0.6); }

#settings .switch { display: flex; gap: 8px; align-items: flex-start; margin: 10px 0; font-size: 13px; color: var(--soft); line-height: 1.4; }
#settings .switch input { margin-top: 2px; accent-color: var(--accent, #864dff); }

/* The chat widget (agent-frontend, dark): in the page's colours, not its own greys. */
#chat .cw-container.cw-dark {
  --cw-bg: var(--panel);
  --cw-bg-muted: var(--raised);
  --cw-text: var(--ink);
  --cw-text-muted: var(--soft);
  --cw-border: var(--line);
}
