/* Intercom panel.
   Read in a dim gallery, at arm's length, on a phone, by someone whose
   attention is mostly elsewhere. So: high contrast, large targets, state
   carried by an illuminated edge rather than by text.

   No web fonts on purpose -- this runs on a festival network, and a panel that
   waits on fonts.googleapis.com is a panel that renders late when it matters.

   Colour is the whole language, so it is spent carefully:
     green   subscribed, hearing it
     amber   called
     cyan    someone is talking on it     (deliberately not red)
     red     YOU are transmitting          (red means "me, live", nothing else)
*/

:root {
  --bg:        #0b0f14;
  --surface:   #151c25;
  --key:       #1c2531;
  --key-edge:  #2b3745;
  --ink:       #dde4ec;
  --ink-dim:   #7c8896;
  --ink-faint: #4c5766;

  --subscribed: #2fbf71;
  --called:     #f2a03d;
  --incoming:   #35b8d6;
  --transmit:   #e5484d;

  --legend: 600 0.72rem/1 ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  --radius: 10px;
  --tap: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
}

body { display: flex; flex-direction: column; }

[hidden] { display: none !important; }

/* ------------------------------------------------------------------ veils */

.veil {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: radial-gradient(120% 80% at 50% 0%, #131c26 0%, var(--bg) 70%);
}

.veil-card {
  width: min(380px, 100%);
  display: flex; flex-direction: column; gap: 14px;
}

.mark {
  font: 700 0.78rem/1.25 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.32em;
  color: var(--ink-dim);
  margin-bottom: 10px;
}
.mark span { display: block; color: var(--ink); letter-spacing: 0.18em; font-size: 1.5rem; }

.lede { color: var(--ink-dim); margin: 0 0 4px; font-size: 0.95rem; }

label {
  font: var(--legend);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

input[type="password"], input[type="text"] {
  width: 100%;
  min-height: var(--tap);
  padding: 0 16px;
  background: var(--key);
  border: 1px solid var(--key-edge);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 1.05rem;
  letter-spacing: 0.06em;
}
input:focus-visible, button:focus-visible {
  outline: 2px solid var(--incoming);
  outline-offset: 2px;
}

button {
  font-family: inherit;
  border: none;
  border-radius: var(--radius);
  color: var(--ink);
  cursor: pointer;
}

.primary {
  min-height: var(--tap);
  background: var(--subscribed);
  color: #06210f;
  font: 600 1rem/1 inherit;
  letter-spacing: 0.04em;
}
.primary:disabled { opacity: 0.5; cursor: default; }

.danger {
  min-height: var(--tap);
  width: 100%;
  background: transparent;
  border: 1px solid var(--transmit);
  color: var(--transmit);
  font-size: 1rem;
}

.ghost { background: transparent; color: var(--ink-dim); font-size: 1.1rem; padding: 8px 12px; }

.msg { min-height: 1.2em; margin: 0; font-size: 0.9rem; color: var(--called); }

.venue-list { display: flex; flex-direction: column; gap: 10px; }
.venue-list button {
  min-height: var(--tap);
  background: var(--key);
  border: 1px solid var(--key-edge);
  text-align: left;
  padding: 0 18px;
  font-size: 1.05rem;
}

/* ----------------------------------------------------------------- header */

.bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--key-edge);
}
.who { display: flex; flex-direction: column; min-width: 0; }
.venue {
  font: var(--legend); letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ink-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user { font-size: 1.02rem; font-weight: 600; }
.right { display: flex; align-items: center; gap: 6px; }

.link {
  font: var(--legend); letter-spacing: 0.12em; text-transform: uppercase;
  padding: 5px 9px; border-radius: 999px;
  border: 1px solid var(--key-edge); color: var(--ink-dim);
}
.link[data-state="live"]       { color: var(--subscribed); border-color: var(--subscribed); }
.link[data-state="connecting"] { color: var(--called);     border-color: var(--called); }
.link[data-state="lost"]       { color: var(--transmit);   border-color: var(--transmit); }

/* ------------------------------------------------------------------- keys */

.keys {
  list-style: none; margin: 0;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
}

/* The signature element: a key that reads like a panel key rather than a
   list row. A lamp strip runs down the left edge and carries the state, the
   legend sits top-left the way a panel legend strip does, and the talk key is
   physically separate on the right so it can never be hit by a subscribe tap. */
.key {
  position: relative;
  display: grid;
  grid-template-columns: 6px 1fr auto;
  align-items: stretch;
  gap: 0;
  background: var(--key);
  border: 1px solid var(--key-edge);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 120ms ease, background 120ms ease;
}

.lamp {
  background: var(--ink-faint);
  opacity: 0.35;
  transition: background 100ms ease, opacity 100ms ease, box-shadow 100ms ease;
}

.key[data-sub="on"]                { border-color: color-mix(in srgb, var(--subscribed) 45%, var(--key-edge)); }
.key[data-sub="on"] .lamp          { background: var(--subscribed); opacity: 1; }
.key[data-called="1"] .lamp        { background: var(--called); opacity: 1;
                                     animation: pulse 900ms ease-in-out infinite; }
.key[data-live="1"] .lamp          { background: var(--incoming); opacity: 1;
                                     box-shadow: 0 0 14px color-mix(in srgb, var(--incoming) 60%, transparent); }
/* Own transmit outranks everything: if the lamp is red, you are open. */
.key[data-tx="1"]                  { border-color: var(--transmit); }
.key[data-tx="1"] .lamp            { background: var(--transmit); opacity: 1;
                                     box-shadow: 0 0 16px color-mix(in srgb, var(--transmit) 70%, transparent); }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) {
  .key[data-called="1"] .lamp { animation: none; }
}

.face {
  padding: 10px 12px;
  min-height: 76px;
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
  background: none; border: none; text-align: left; color: inherit;
  min-width: 0;
}
.face:disabled { cursor: default; }

.legend {
  font: var(--legend);
  letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ink-dim);
  display: flex; align-items: center; gap: 7px;
}
.name {
  font-size: 1.1rem; font-weight: 600; line-height: 1.15;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sub {
  font-size: 0.82rem; color: var(--ink-dim); min-height: 1.1em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.key[data-live="1"] .sub { color: var(--incoming); }

.tag {
  font: var(--legend); letter-spacing: 0.1em;
  padding: 2px 6px; border-radius: 4px;
  border: 1px solid var(--key-edge); color: var(--ink-faint);
}
.tag.locked { color: var(--called); border-color: color-mix(in srgb, var(--called) 50%, transparent); }
.tag.delay  { color: var(--ink-dim); }

.talk {
  width: 92px;
  background: var(--key-edge);
  border-left: 1px solid var(--key-edge);
  color: var(--ink-dim);
  font: 700 0.78rem/1 inherit;
  letter-spacing: 0.14em;
  border-radius: 0;
  display: flex; align-items: center; justify-content: center;
  touch-action: none;
}
.talk[data-on="1"] { background: var(--transmit); color: #fff; }
.talk:disabled     { opacity: 0.25; cursor: default; }

.volume {
  grid-column: 2 / 4;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px 10px;
}
.volume input[type="range"] { flex: 1; accent-color: var(--incoming); height: 28px; }
.volume .pct { font: var(--legend); color: var(--ink-faint); width: 3ch; text-align: right; }

/* ------------------------------------------------------------------- foot */

.foot {
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--key-edge);
}

/* ALL is momentary only -- never latching -- so a forgotten key cannot put a
   private conversation onto every line. Held open, it is unmistakable. */
.allkey {
  width: 100%; min-height: 68px;
  background: var(--key);
  border: 1px solid var(--key-edge);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  touch-action: none;
  transition: background 80ms ease, border-color 80ms ease;
}
.allkey-label { font: 700 1.1rem/1 inherit; letter-spacing: 0.3em; }
.allkey-hint  { font: var(--legend); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); }
.allkey[data-on="1"] {
  background: var(--transmit); border-color: var(--transmit); color: #fff;
  box-shadow: 0 0 24px color-mix(in srgb, var(--transmit) 45%, transparent);
}
.allkey[data-on="1"] .allkey-hint { color: #ffd9da; }
.allkey:disabled { opacity: 0.3; cursor: default; }

/* ------------------------------------------------------------------ sheet */

.sheet {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  background: var(--surface);
  border-top: 1px solid var(--key-edge);
  border-radius: 16px 16px 0 0;
  padding: 18px 18px calc(22px + env(safe-area-inset-bottom));
  max-height: 72vh; overflow-y: auto;
}
.sheet h2 { margin: 0 0 14px; font-size: 1.05rem; }
.sheet .close { position: absolute; top: 10px; right: 10px; }
.diag { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 18px; font-size: 0.9rem; }
.diag dt { color: var(--ink-dim); }
.diag dd { margin: 0; font-variant-numeric: tabular-nums; }

@media (min-width: 700px) {
  .keys { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); align-content: start; }
  .foot { max-width: 700px; margin: 0 auto; width: 100%; }
}
