/* ------------------------------------------------------------------
 * tunnel — calm editorial · fraunces + geist + jetbrains mono
 * state-driven: one obvious action at every step
 * ------------------------------------------------------------------ */

:root {
  --bg: #0c1014;
  --bg-1: #11161e;
  --bg-2: #161c25;
  --line: #1e252f;
  --line-2: #2a3340;
  --ink: #ece8dc;
  --ink-2: #a8a395;
  --ink-3: #6c6859;
  --accent: #f6821f;
  --accent-soft: rgba(246, 130, 31, 0.12);
  --good: #7fb583;
  --good-soft: rgba(127, 181, 131, 0.14);
  --warn: #d8a657;

  --serif: "Fraunces", Georgia, serif;
  --sans: "Geist", -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at top, #131a24 0%, transparent 60%),
    var(--bg);
}

code, .mono { font-family: var(--mono); }
.italic { font-style: italic; }
.accent { color: var(--accent); }
.hidden { display: none !important; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------
 * topbar
 * ------------------------------------------------------------------ */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 14px;
  animation: pulse 2.6s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
.brand-word {
  font-family: var(--serif);
  font-style: italic;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }

/* trust pill — the single connection signal */
.trust-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  color: var(--ink-2);
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.18s;
}
.trust-pill .trust-ico {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ink-3);
  flex-shrink: 0;
}
.trust-pill[data-trust="connecting"] {
  border-color: var(--warn);
  color: var(--warn);
}
.trust-pill[data-trust="connecting"] .trust-ico {
  background: var(--warn);
  animation: blink 1s ease-in-out infinite;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }
.trust-pill[data-trust="secure"] {
  border-color: rgba(127, 181, 131, 0.5);
  color: var(--good);
  background: var(--good-soft);
}
/* lock glyph drawn in css (no icon font / emoji) */
.trust-pill[data-trust="secure"] .trust-ico {
  background: transparent;
  position: relative;
  width: 9px; height: 8px;
  border: 1.5px solid var(--good);
  border-radius: 1.5px;
  margin-top: 3px;
}
.trust-pill[data-trust="secure"] .trust-ico::before {
  content: "";
  position: absolute;
  top: -5px; left: 50%;
  transform: translateX(-50%);
  width: 5px; height: 5px;
  border: 1.5px solid var(--good);
  border-bottom: none;
  border-radius: 3px 3px 0 0;
}
.trust-pill:hover { border-color: var(--accent); }

/* identity chip */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.chip-name { font-size: 12px; color: var(--ink); }
.chip-tag {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* avatar — deterministic colour from peer id */
.avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: hsl(var(--hue, 30) 42% 52%);
  color: #0c0c0c;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
}
.avatar-lg { width: 38px; height: 38px; font-size: 14px; }

button.ghost-btn {
  background: transparent;
  border: 1px solid var(--line-2);
  color: var(--ink-2);
  padding: 6px 12px;
  font-family: var(--sans);
  font-size: 12px;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s;
}
button.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }
button.link-btn {
  background: none; border: none;
  color: var(--accent);
  font: inherit; cursor: pointer; padding: 0;
  border-bottom: 1px dotted var(--accent);
}
button.link-btn:hover { color: #ff8e2a; }

.send-btn {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #1a0c00;
  padding: 11px 20px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s;
  white-space: nowrap;
}
.send-btn:hover { background: #ff8e2a; }
.send-btn.copied { background: var(--good); border-color: var(--good); }

/* ------------------------------------------------------------------
 * trust details popover
 * ------------------------------------------------------------------ */
.trust-details {
  position: absolute;
  top: 60px; right: 28px;
  z-index: 40;
  width: 320px;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 16px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.5);
  animation: pop 0.16s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
.td-grid { display: flex; flex-direction: column; gap: 1px; }
.kv {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 10px; font-size: 12px; padding: 3px 0;
}
.kv > span { color: var(--ink-3); }
.kv > code {
  font-family: var(--mono); font-size: 11.5px; color: var(--ink);
  text-align: right; word-break: break-all; max-width: 62%;
}
.fp-block {
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 6px;
}
.fp-row { display: flex; flex-direction: column; gap: 2px; }
.fp-row > span {
  font-family: var(--mono); font-size: 9.5px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--ink-3);
}
.fp-row > code { font-family: var(--mono); font-size: 10px; color: var(--ink-2); word-break: break-all; line-height: 1.4; }
.fp-note { margin: 4px 0 0; font-family: var(--serif); font-style: italic; font-size: 11.5px; color: var(--ink-3); }
.log-wrap { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.log-wrap summary {
  cursor: pointer; list-style: none; color: var(--ink-3); font-size: 11px;
  display: flex; justify-content: space-between; align-items: center;
}
.log-wrap summary::-webkit-details-marker { display: none; }
.log-wrap summary::before { content: "▸ "; color: var(--ink-3); }
.log-wrap[open] summary::before { content: "▾ "; }

/* ------------------------------------------------------------------
 * layout shell
 * ------------------------------------------------------------------ */
.layout {
  flex: 1;
  display: flex;
  padding: 32px;
  max-width: 1180px;
  margin: 0 auto;
  width: 100%;
  min-height: 0;
}

/* state visibility: invite OR conversation, never both */
#invite-screen, #conversation { width: 100%; }
body[data-state="boot"] #conversation,
body[data-state="waiting"] #conversation { display: none; }
body[data-state="connecting"] #invite-screen,
body[data-state="connected"] #invite-screen { display: none; }

/* ------------------------------------------------------------------
 * invite screen (waiting state)
 * ------------------------------------------------------------------ */
.invite {
  display: flex;
  align-items: center;
  justify-content: center;
}
.invite-inner {
  max-width: 540px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}
.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 18px;
  opacity: 0; animation: rise 0.5s 0.05s ease-out forwards;
}
.invite-title {
  font-family: var(--serif);
  font-weight: 300;
  font-size: clamp(32px, 5vw, 52px);
  line-height: 1.08;
  letter-spacing: -0.02em;
  margin: 0 0 18px;
  font-variation-settings: "opsz" 144;
  opacity: 0; animation: rise 0.5s 0.12s ease-out forwards;
}
.invite-title .accent { display: block; font-style: italic; }
.invite-tagline {
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  color: var(--ink-2);
  margin: 0 0 32px;
  opacity: 0; animation: rise 0.5s 0.19s ease-out forwards;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.invite-link {
  display: flex;
  width: 100%;
  gap: 8px;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  padding: 6px 6px 6px 14px;
  align-items: center;
  opacity: 0; animation: rise 0.5s 0.26s ease-out forwards;
}
#invite-url {
  flex: 1;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink);
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.invite-qr {
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  opacity: 0; animation: rise 0.5s 0.33s ease-out forwards;
}
.qr-frame {
  width: 168px; height: 168px;
  background: var(--ink);
  border-radius: 6px;
  padding: 12px;
  display: flex; align-items: center; justify-content: center;
}
.qr-frame img, .qr-frame canvas, .qr-frame svg {
  width: 100%; height: 100%; image-rendering: pixelated; display: block;
}
.qr-cap {
  font-family: var(--serif);
  font-style: italic;
  font-size: 12.5px;
  color: var(--ink-3);
}
.waiting-status {
  margin-top: 30px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: var(--ink-2);
  opacity: 0; animation: rise 0.5s 0.4s ease-out forwards;
}
.pulse-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 var(--accent-soft);
  animation: ping 1.8s ease-out infinite;
}
@keyframes ping {
  0% { box-shadow: 0 0 0 0 rgba(246,130,31,0.4); }
  70% { box-shadow: 0 0 0 10px rgba(246,130,31,0); }
  100% { box-shadow: 0 0 0 0 rgba(246,130,31,0); }
}

/* ------------------------------------------------------------------
 * conversation (connecting / connected state)
 * ------------------------------------------------------------------ */
.conversation {
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}
.conv-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.conv-peer { display: flex; align-items: center; gap: 12px; }
.conv-peer-meta { display: flex; flex-direction: column; gap: 1px; }
.conv-peer-name { font-family: var(--serif); font-size: 19px; letter-spacing: -0.01em; }
.conv-peer-sub { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
body[data-state="connected"] .conv-peer-sub { color: var(--good); }
.conv-actions { display: flex; align-items: center; gap: 12px; }

.seg {
  display: inline-flex;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}
.seg-btn {
  background: none; border: none;
  color: var(--ink-3);
  font-family: var(--sans); font-size: 12px;
  padding: 6px 14px; border-radius: 999px;
  cursor: pointer; transition: all 0.15s;
}
.seg-btn:hover { color: var(--ink-2); }
.seg-btn.active { background: var(--bg-2); color: var(--ink); }

.view { flex: 1; display: flex; flex-direction: column; min-height: 0; gap: 14px; }

/* unified message stream */
.stream {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 6px;
  scroll-behavior: smooth;
  min-height: 240px;
}
.stream::-webkit-scrollbar { width: 6px; }
.stream::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }

.msg { display: flex; flex-direction: column; gap: 3px; max-width: 74%; animation: msgin 0.22s ease-out; }
@keyframes msgin { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg .who-row { display: flex; align-items: baseline; gap: 8px; padding: 0 2px; }
.msg .who { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); }
.msg.me .who { color: var(--accent); }
.msg .ts { font-family: var(--mono); font-size: 9.5px; color: var(--ink-3); }
.msg .body {
  font-size: 14px; color: var(--ink);
  background: var(--bg-1);
  border: 1px solid var(--line);
  padding: 9px 13px;
  border-radius: 12px 12px 12px 3px;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.me .body {
  background: var(--accent-soft);
  border-color: rgba(246,130,31,0.25);
  border-radius: 12px 12px 3px 12px;
}

/* system + connected event lines, centered */
.event { align-self: center; text-align: center; max-width: 88%; }
.event.sys {
  font-family: var(--serif); font-style: italic;
  font-size: 12.5px; color: var(--ink-3);
  padding: 2px 0;
}
.event.secure {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--good-soft);
  border: 1px solid rgba(127,181,131,0.3);
  border-radius: 10px;
  padding: 14px 20px;
  margin: 6px 0;
  animation: securein 0.4s ease-out;
}
@keyframes securein { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
.event.secure .lock {
  width: 16px; height: 13px; position: relative; margin-top: 6px;
  border: 2px solid var(--good); border-radius: 2px;
}
.event.secure .lock::before {
  content: ""; position: absolute; top: -8px; left: 50%; transform: translateX(-50%);
  width: 9px; height: 9px; border: 2px solid var(--good); border-bottom: none; border-radius: 5px 5px 0 0;
}
.event.secure .secure-title { font-family: var(--sans); font-size: 13px; color: var(--good); font-weight: 500; }
.event.secure .secure-sub { font-family: var(--mono); font-size: 10.5px; color: var(--ink-2); }

/* inline file transfer bubble */
.transfer {
  align-self: flex-start;
  max-width: 74%;
  min-width: 220px;
  border: 1px solid var(--line);
  background: var(--bg-1);
  padding: 11px 13px;
  border-radius: 12px 12px 12px 3px;
}
.transfer.out { align-self: flex-end; background: var(--accent-soft); border-color: rgba(246,130,31,0.22); border-radius: 12px 12px 3px 12px; }
.transfer-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.transfer-ico {
  width: 26px; height: 26px; flex-shrink: 0;
  border: 1px solid var(--line-2); border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 11px; color: var(--ink-2);
}
.transfer-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.transfer-name { color: var(--ink); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transfer-meta { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); }
.bar { height: 3px; background: var(--line); position: relative; overflow: hidden; border-radius: 2px; }
.bar > span { display: block; height: 100%; background: var(--accent); width: 0%; transition: width 0.15s linear; }
.transfer.done .bar > span { background: var(--good); }
.transfer a.download {
  display: inline-block; margin-top: 8px;
  color: var(--accent); font-size: 12px; text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}

/* composer */
.composer {
  display: flex;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.attach-btn {
  width: 38px; height: 38px; flex-shrink: 0;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  color: var(--ink-2);
  font-size: 22px; line-height: 1;
  border-radius: 3px; cursor: pointer;
  transition: all 0.15s;
}
.attach-btn:hover { border-color: var(--accent); color: var(--accent); }
.composer input[type="text"] {
  flex: 1;
  background: var(--bg-1);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 11px 14px;
  font-family: var(--sans); font-size: 14px;
  border-radius: 3px; transition: border-color 0.15s;
}
.composer input:focus { outline: none; border-color: var(--line-2); }
.composer input::placeholder { color: var(--ink-3); }

/* drop overlay */
.drop-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(12,16,20,0.86);
  border: 2px dashed var(--accent);
  border-radius: 8px;
  z-index: 30;
  pointer-events: none;
}
body.dragging .drop-overlay { display: flex; }
.drop-overlay span {
  font-family: var(--serif); font-style: italic; font-size: 22px; color: var(--accent);
}

/* screen share */
.screen-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px; flex: 1; align-content: start;
}
.video-tile {
  background: #000; border: 1px solid var(--line);
  position: relative; aspect-ratio: 16 / 9; border-radius: 4px; overflow: hidden;
}
.video-tile video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.video-tile .label {
  position: absolute; top: 8px; left: 8px;
  font-family: var(--mono); font-size: 11px; color: var(--accent);
  background: rgba(0,0,0,0.6); padding: 3px 7px; border-radius: 2px;
}
.empty-state {
  font-family: var(--serif); font-style: italic; color: var(--ink-3);
  font-size: 16px; padding: 48px 20px; text-align: center;
  border: 1px dashed var(--line); border-radius: 4px;
  grid-column: 1 / -1;
}

/* ------------------------------------------------------------------
 * footer + about sheet
 * ------------------------------------------------------------------ */
.footer {
  display: flex; justify-content: center; align-items: center; gap: 14px;
  padding: 14px 28px;
  font-family: var(--mono); font-size: 10.5px; color: var(--ink-3);
  letter-spacing: 0.04em;
  border-top: 1px solid var(--line);
}
.about-sheet {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 50; width: min(560px, calc(100% - 32px));
  background: var(--bg-1); border: 1px solid var(--line-2);
  border-radius: 8px; padding: 20px 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.55);
  animation: pop 0.18s ease-out;
}
.about-sheet p {
  margin: 0 0 14px; font-size: 13.5px; color: var(--ink-2); line-height: 1.6;
}

/* ------------------------------------------------------------------
 * signaling log (inside trust details)
 * ------------------------------------------------------------------ */
.log {
  font-family: var(--mono); font-size: 10px; color: var(--ink-2);
  display: flex; flex-direction: column;
  max-height: 180px; overflow-y: auto; margin-top: 8px;
}
.log::-webkit-scrollbar { width: 4px; }
.log::-webkit-scrollbar-thumb { background: var(--line-2); }
.log .line {
  display: grid; grid-template-columns: 52px 12px 1fr;
  align-items: baseline; column-gap: 8px; padding: 2px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.log .t { color: var(--ink-3); font-size: 9.5px; font-variant-numeric: tabular-nums; }
.log .d { font-size: 10px; text-align: center; }
.log .d.in { color: #7fb3d5; }
.log .d.out { color: var(--accent); }
.log .d.sys { color: var(--ink-3); }
.log .m { font-size: 10px; color: var(--ink-2); word-break: break-word; line-height: 1.35; }

/* ------------------------------------------------------------------
 * responsive
 * ------------------------------------------------------------------ */
@media (max-width: 720px) {
  .layout { padding: 20px; }
  .topbar { padding: 14px 18px; }
  .chip .chip-tag { display: none; }
  .trust-details { right: 12px; left: 12px; width: auto; }
  .conv-head { gap: 12px; }
  .msg { max-width: 86%; }
  .invite-title { font-size: clamp(28px, 8vw, 40px); }
}
