/* One-Time Call — shared styles
   Design direction: "secure instrument, not a SaaS dashboard."
   Two accent colors carry the whole story: a cool signal-turquoise for a
   link that's armed and shareable, and an ember-to-ash pair for the moment
   it's spent. Three type roles: a display face for identity/headings, plain
   system sans for anything meant to be read as prose, and a monospace face
   for anything that is data — the code itself, timestamps, status, tags. */

@font-face {
  font-family: "Space Grotesk";
  src: url("/fonts/SpaceGrotesk-Variable.woff2") format("woff2");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/fonts/JetBrainsMono-Variable.woff2") format("woff2");
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #0a0c0f;
  --panel: #12151a;
  --panel-raised: #171b21;
  --panel-input: #1b1f26;
  --line: #262b33;
  --line-strong: #383f4b;

  --text: #edf0f3;
  --text-dim: #9aa3b0;
  --text-faint: #57606c;

  /* signal — a link that's armed and ready to be used */
  --signal: #4fd7c4;
  --signal-strong: #82ebdd;
  --signal-dim: rgba(79, 215, 196, 0.14);
  --signal-ink: #04201c;

  /* a call actually in progress */
  --ok: #5fd68f;
  --ok-dim: rgba(95, 214, 143, 0.14);

  /* the moment a link is spent: hot ember cooling to ash */
  --ember: #e8794f;
  --ember-dim: rgba(232, 121, 79, 0.18);
  --ash: #756f68;
  --ash-dim: rgba(117, 111, 104, 0.14);
  --ash-text: #a39d95;

  --danger: #ff6b6b;
  --danger-dim: rgba(255, 107, 107, 0.12);

  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 14px 32px rgba(0, 0, 0, 0.28);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);

  --display: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--sans);
  background: var(--ink);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--signal);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* ---- Layout ---- */
.page {
  max-width: 460px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}
.page-wide {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: 1.05rem;
}
.brand .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 0 4px var(--signal-dim);
  flex: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 32px;
}
.topbar .brand { flex-shrink: 0; }

/* ---- Cards ---- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 20px; }

h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}
h2 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  margin: 0 0 14px;
}
.subtitle {
  color: var(--text-dim);
  margin: 0 0 24px;
  font-size: 0.95rem;
}
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }

/* ---- Forms ---- */
.field { margin-bottom: 16px; }
label {
  display: block;
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  margin-bottom: 7px;
  font-weight: 500;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
select {
  width: 100%;
  background: var(--panel-input);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: var(--sans);
}
input[type="datetime-local"] { color-scheme: dark; }
select { appearance: none; cursor: pointer; }
input:focus,
select:focus {
  outline: none;
  border-color: var(--signal);
  box-shadow: 0 0 0 3px var(--signal-dim);
}
input::placeholder { color: var(--text-faint); }
/* Some browsers (notably Safari) apply a very low-contrast native look to
   disabled inputs that nearly disappears on a dark background — pin the
   colors so a disabled field (e.g. chat before the call connects) still
   reads clearly instead of looking blank. */
input:disabled {
  opacity: 1;
  background: var(--panel-input);
  color: var(--text-faint);
  border-color: var(--line);
  -webkit-text-fill-color: var(--text-faint);
}

/* ---- Buttons ---- */
button, .btn {
  font-family: var(--display);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
button:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--signal-dim);
  border-color: var(--signal);
}
.btn-primary {
  background: var(--signal);
  color: var(--signal-ink);
  width: 100%;
}
.btn-primary:hover { background: var(--signal-strong); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--line-strong);
}
.btn-secondary:hover { border-color: var(--text-dim); }

.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.35);
}
.btn-danger:hover { background: rgba(255, 107, 107, 0.2); }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  font-family: var(--sans);
  font-weight: 500;
  padding: 8px 12px;
}
.btn-ghost:hover { color: var(--text); }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---- Messages ---- */
.msg {
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 16px;
}
.msg-error {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(255, 107, 107, 0.3);
}
.msg-ok {
  background: var(--ok-dim);
  color: var(--ok);
  border: 1px solid rgba(95, 214, 143, 0.3);
}
.hidden { display: none !important; }

.form-footer {
  text-align: center;
  margin-top: 20px;
  color: var(--text-dim);
  font-size: 0.9rem;
}

/* ---- The link / code — the signature element ----
   Two states, seen at two different moments in the same story: freshly
   created and armed (cool signal turquoise, breathing gently — it's live
   and waiting to be used), and, once a call ends, burned (the block ignites
   into ember for an instant, then cools to ash — it can never be used
   again). The card is never toggled between them client-side; each state
   is its own page, so the "transition" is the animation that plays the
   instant the burned state is first painted. */
.link-block {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 18px;
  margin-top: 4px;
}
.link-block .link-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  margin-bottom: 12px;
}
.link-status .pip {
  width: 8px; height: 8px; border-radius: 50%;
}

/* active / armed state */
.link-block.is-active {
  background: var(--signal-dim);
  border-color: var(--signal);
}
.link-block.is-active .link-status { color: var(--signal); }
.link-block.is-active .pip {
  background: var(--signal);
  box-shadow: 0 0 0 4px var(--signal-dim);
  animation: breathe 2.6s ease-in-out infinite;
}

/* burned state — plays once, the instant this markup is first painted */
.link-block.is-burned {
  background: var(--ash-dim);
  border-color: var(--ash);
  animation: burn-out 1.8s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.link-block.is-burned .link-status { color: var(--ash-text); }
.link-block.is-burned .pip {
  background: var(--ash);
  animation: pip-cool 1.8s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.link-block.is-burned .link-value {
  text-decoration: line-through;
  color: var(--text-faint);
}

@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 4px var(--signal-dim); }
  50% { box-shadow: 0 0 0 8px rgba(79, 215, 196, 0.05); }
}

@keyframes burn-out {
  0% {
    background: var(--ember-dim);
    border-color: var(--ember);
    box-shadow: 0 0 0 5px var(--ember-dim), 0 0 26px rgba(232, 121, 79, 0.22);
  }
  35% {
    background: var(--ember-dim);
    border-color: var(--ember);
    box-shadow: 0 0 0 5px var(--ember-dim), 0 0 26px rgba(232, 121, 79, 0.22);
  }
  100% {
    background: var(--ash-dim);
    border-color: var(--ash);
    box-shadow: 0 0 0 0 transparent;
  }
}
@keyframes pip-cool {
  0%, 35% {
    background: var(--ember);
    box-shadow: 0 0 0 4px var(--ember-dim);
  }
  100% {
    background: var(--ash);
    box-shadow: 0 0 0 0 transparent;
  }
}

.link-value {
  font-family: var(--mono);
  font-size: 0.95rem;
  word-break: break-all;
  color: var(--text);
  display: block;
  margin-bottom: 12px;
}

.copy-row { display: flex; gap: 8px; }
.copy-row input {
  font-family: var(--mono);
  font-size: 0.9rem;
}

/* ---- Link list (dashboard) ---- */
.link-list { list-style: none; padding: 0; margin: 0; }
.link-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}
.link-list li:first-child { border-top: none; }
.link-list .code {
  font-family: var(--mono);
  font-size: 0.95rem;
}
.link-list .meta {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-faint);
  margin-top: 3px;
  letter-spacing: 0.01em;
}

.tag {
  font-family: var(--mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 20px;
}
.tag-pending { background: var(--signal-dim); color: var(--signal); }
.tag-active { background: var(--ok-dim); color: var(--ok); }
.tag-ended { background: var(--ash-dim); color: var(--text-dim); }

/* ---- Dashboard: room settings + management ---- */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 14px;
  margin-bottom: 4px;
}
.settings-grid .span-2 { grid-column: 1 / -1; }
.settings-grid label .faint { text-transform: none; letter-spacing: 0; }

.btn-small { padding: 7px 12px; font-size: 0.85rem; }
a.btn-small { text-decoration: none; }
.btn-primary.btn-small { width: auto; display: inline-flex; align-items: center; }

.room-list { list-style: none; padding: 0; margin: 0; }
.room-item {
  padding: 14px 0;
  border-top: 1px solid var(--line);
}
.room-item:first-child { border-top: none; }
.room-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.room-item .code {
  font-family: var(--mono);
  font-size: 0.95rem;
  color: var(--text);
}
.room-item .meta {
  font-size: 0.8rem;
  color: var(--text-faint);
  margin-top: 3px;
}
.room-panel:not(:empty) {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-raised);
}
.panel-title {
  font-size: 0.95rem;
  margin: 0 0 6px;
}
.panel-title + .panel-note { margin-top: 0; }
.room-panel .panel-title:not(:first-of-type) { margin-top: 20px; }
.panel-note { font-size: 0.8rem; margin: 8px 0 12px; }
.panel-row { margin-top: 18px; }
.panel-row .panel-note { margin: 0; }
.invite-list { list-style: none; padding: 0; margin: 0 0 12px; }
.invite-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.invite-list li:first-child { border-top: none; }
.invite-name { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.invite-form { display: flex; gap: 8px; }
.invite-form input { flex: 1; min-width: 0; }
.settings-form { margin-top: 8px; }

@media (max-width: 560px) {
  .settings-grid { grid-template-columns: 1fr; }
  .invite-form { flex-direction: column; }
}

.empty-state {
  text-align: center;
  padding: 28px 0;
  color: var(--text-faint);
  font-size: 0.9rem;
}

/* ============ Call room ============ */
.room {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  gap: 12px;
  flex-wrap: wrap;
}
.room-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.room-status .pip {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint);
}
.room-status.live .pip { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-dim); }
.room-status.waiting .pip { background: var(--signal); animation: breathe 2.6s ease-in-out infinite; }

.room-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  min-height: 0;
}

.video-stage {
  position: relative;
  background: #050708;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  overflow: hidden;
}
/* Group call: every participant (including you) is a tile in the grid. */
.video-grid {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 8px;
  padding: 8px;
  grid-template-columns: 1fr;
  grid-auto-rows: 1fr;
  align-content: center;
}
.video-grid[data-count="2"] { grid-template-columns: repeat(2, 1fr); }
.video-grid[data-count="3"],
.video-grid[data-count="4"] { grid-template-columns: repeat(2, 1fr); }
.video-grid[data-count="5"],
.video-grid[data-count="6"] { grid-template-columns: repeat(3, 1fr); }

.tile {
  position: relative;
  min-height: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--line);
}
.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}
.tile-local video { transform: scaleX(-1); }
.tile-label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(5, 7, 8, 0.72);
  font-size: 0.8rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  pointer-events: none;
}
.tile-state:empty { display: none; }
.tile[data-state="failed"] { border-color: rgba(255, 107, 107, 0.35); }

.room-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.room-chip {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--text-dim);
}
.room-chip.chip-warn { color: var(--ember); border-color: var(--ember-dim); background: var(--ember-dim); }
.room-chip.chip-locked { color: var(--ash-text); background: var(--ash-dim); }

.room-banner {
  padding: 10px 18px;
  background: var(--ember-dim);
  color: var(--text);
  font-size: 0.88rem;
  border-bottom: 1px solid var(--line);
}

.lobby-countdown {
  font-family: var(--mono);
  font-size: 1.4rem;
  color: var(--signal);
  margin: 4px 0 16px;
}

.stage-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  gap: 10px;
}
.stage-overlay h2 { margin: 0; }
.stage-overlay p { color: var(--text-dim); margin: 0; max-width: 340px; }

.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--line-strong);
  border-top-color: var(--signal);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin-bottom: 4px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Chat panel */
.chat {
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel-raised);
}
.chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
.chat-msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.9rem;
  word-wrap: break-word;
}
.chat-name {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-dim);
  margin-bottom: 2px;
}
.chat-msg.me {
  align-self: flex-end;
  background: var(--signal);
  color: var(--signal-ink);
  border-bottom-right-radius: 3px;
}
.chat-msg.them {
  align-self: flex-start;
  background: var(--panel-input);
  color: var(--text);
  border-bottom-left-radius: 3px;
}
.chat-msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-faint);
  font-size: 0.78rem;
  font-style: italic;
}
.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}
.chat-form input { flex: 1; }

.control-bar {
  display: flex;
  gap: 10px;
  align-items: center;
}
.icon-btn {
  background: var(--panel-input);
  border: 1px solid var(--line);
  color: var(--text);
  width: 42px; height: 42px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 1rem;
}
.icon-btn:hover { border-color: var(--line-strong); }
.icon-btn.off { background: var(--danger-dim); color: var(--danger); border-color: rgba(255,107,107,0.35); }
.icon-btn svg { width: 19px; height: 19px; flex: none; }
.icon-btn svg[hidden] { display: none; }

/* Icon + label buttons (copy, end call) */
.btn-secondary, .btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.btn-secondary svg, .btn-danger svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.privacy-note {
  font-size: 0.78rem;
  color: var(--text-faint);
  margin-top: 24px;
  text-align: center;
  line-height: 1.5;
}
.privacy-note strong { color: var(--text-dim); font-weight: 600; }

/* Full-screen "ended" state for the room */
.ended-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.ended-screen .card {
  animation: settle 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes settle {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 720px) {
  .room-body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .chat {
    border-left: none;
    border-top: 1px solid var(--line);
    max-height: 42vh;
  }
  .video-grid[data-count="2"] { grid-template-columns: 1fr; }
  .video-grid[data-count="5"],
  .video-grid[data-count="6"] { grid-template-columns: repeat(2, 1fr); }
  .room-header { padding: 12px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
