:root {
  --bg: #0a0e0d;
  --surface: #0e1412;
  --surface-2: #141c19;
  --text: #c6e0d4;
  --text-muted: #5f7d70;
  --border: #1e2b26;
  --accent: #00e676;
  --accent-dim: #0c3a27;
  --ok: #00e676;
  --warn: #e3b341;
  --err: #ff5c57;
  --glow: 0 0 6px rgba(0, 230, 118, .45);
  --radius: 4px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

/* The [hidden] attribute must win over the display set on view classes. */
[hidden] { display: none !important; }

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

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Subtle CRT scanlines. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, .13) 0, rgba(0, 0, 0, .13) 1px, transparent 1px, transparent 3px);
  opacity: .5;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

::selection { background: var(--accent); color: var(--bg); }

/* ---------- Top bar ---------- */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand__prompt { color: var(--text-muted); }
.brand__name { color: var(--accent); text-shadow: var(--glow); letter-spacing: 1px; }
.cursor {
  width: 9px; height: 17px;
  background: var(--accent);
  box-shadow: var(--glow);
  margin-left: -3px;
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 12px;
  letter-spacing: 1.5px;
  color: var(--text-muted);
}
.status__dot { width: 8px; height: 8px; background: var(--text-muted); }
.status__text::before { content: "["; margin-right: 6px; opacity: .6; }
.status__text::after { content: "]"; margin-left: 6px; opacity: .6; }
.status[data-state="waiting"] .status__dot,
.status[data-state="connecting"] .status__dot { background: var(--warn); animation: blink 1s steps(1) infinite; }
.status[data-state="connected"] { color: var(--accent); border-color: var(--accent-dim); }
.status[data-state="connected"] .status__dot { background: var(--accent); box-shadow: var(--glow); }
.status[data-state="error"] { color: var(--err); border-color: var(--err); }
.status[data-state="error"] .status__dot { background: var(--err); }

/* ---------- Layout ---------- */
.main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.pair, .connecting, .notice { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }

/* ---------- Pairing ---------- */
.pair__card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 24px;
  text-align: center;
  box-shadow: 0 0 0 1px rgba(0, 230, 118, .04), 0 0 40px rgba(0, 230, 118, .05);
}

.ascii {
  margin: 0 0 14px;
  color: var(--accent);
  text-shadow: var(--glow);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.15;
  white-space: pre;
  overflow-x: auto;
}
.pair__subtitle { margin: 0 0 22px; color: var(--text-muted); font-size: 13px; }

.qr {
  display: inline-flex;
  padding: 12px;
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--accent-dim);
  min-height: 200px; min-width: 200px;
  align-items: center; justify-content: center;
}
.qr img, .qr canvas, .qr svg { display: block; }
.qr svg { width: 200px; height: 200px; }

.linkrow { display: flex; align-items: center; gap: 8px; margin: 22px 0 18px; }
.linkrow__sigil { color: var(--accent); }
.linkrow__input {
  flex: 1; min-width: 0;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
}
.linkrow__input:focus { outline: none; border-color: var(--accent); box-shadow: var(--glow); }

.pair__hint { margin: 0; font-size: 12px; color: var(--text-muted); line-height: 1.6; }

/* ---------- Connecting ---------- */
.connecting { flex-direction: column; gap: 18px; color: var(--text-muted); }
.spinner {
  width: 40px; height: 40px;
  border: 2px solid var(--surface-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  box-shadow: var(--glow);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 16px;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 700; }
.btn--primary:hover { box-shadow: var(--glow); }
.btn--ghost { background: transparent; color: var(--text); }
.btn--ghost:hover { border-color: var(--accent); color: var(--accent); box-shadow: var(--glow); }

/* ---------- Chat ---------- */
.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.chat__feed {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overscroll-behavior: contain;
}
.chat__welcome { margin: auto; text-align: center; color: var(--text-muted); font-size: 13px; max-width: 340px; }

/* Bubbles */
.msg {
  position: relative;
  max-width: min(82%, 540px);
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 2px solid var(--text-muted);
  border-radius: var(--radius);
  padding: 9px 13px;
  word-break: break-word;
  animation: rise .16s ease-out;
}
.msg::before {
  display: block;
  font-size: 9px;
  letter-spacing: 2px;
  margin-bottom: 5px;
  opacity: .75;
}
.msg--in::before { content: "RX <<"; color: var(--text-muted); }
.msg--out {
  align-self: flex-end;
  border-left: 1px solid var(--border);
  border-right: 2px solid var(--accent);
}
.msg--out::before { content: ">> TX"; color: var(--accent); text-align: right; }
@keyframes rise { from { opacity: 0; transform: translateY(5px); } }

.msg__text { white-space: pre-wrap; margin: 0; }

.msg__meta { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.msg--out .msg__meta { justify-content: flex-end; }

.msg__act {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: var(--radius);
  cursor: pointer;
}
.msg__act:hover { color: var(--accent); border-color: var(--accent); box-shadow: var(--glow); }

/* File bubble */
.file { display: flex; align-items: center; gap: 12px; min-width: 220px; }
.file__icon {
  flex: none;
  width: 42px; height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
}
.file__thumb { flex: none; width: 44px; height: 44px; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--border); }

/* Message contents are hidden (blurred) by default -- reveal per bubble. */
.is-masked { filter: blur(9px); cursor: pointer; user-select: none; -webkit-user-select: none; transition: filter .12s; }
.msg__text.is-masked { color: var(--text-muted); }
.file__info { min-width: 0; flex: 1; }
.file__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file__sub { font-size: 11px; color: var(--text-muted); letter-spacing: .5px; margin-top: 2px; }

.progress { margin-top: 9px; height: 4px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.progress__bar { height: 100%; width: 0; background: var(--accent); box-shadow: var(--glow); transition: width .12s linear; }
.msg--done .progress { display: none; }

/* ---------- Composer ---------- */
.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.composer__input {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.4;
}
.composer__input::placeholder { color: var(--text-muted); }
.composer__input:focus { outline: none; border-color: var(--accent); box-shadow: var(--glow); }

.composer__btn {
  flex: none;
  width: 44px; height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 20px;
  cursor: pointer;
  transition: color .12s, border-color .12s, background .12s, box-shadow .12s;
}
.composer__attach:hover { color: var(--accent); border-color: var(--accent); }
.composer__send { color: var(--accent); border-color: var(--accent-dim); font-weight: 700; }
.composer__send:hover:not(:disabled) { background: var(--accent); color: var(--bg); box-shadow: var(--glow); }
.composer__send:disabled { opacity: .35; cursor: default; }

/* ---------- Drop overlay ---------- */
.dropzone-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: rgba(10, 14, 13, .82);
  display: grid;
  place-items: center;
  padding: 24px;
}
.dropzone-overlay__inner {
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  padding: 38px 54px;
  font-size: 16px;
  letter-spacing: 1px;
  color: var(--accent);
  text-shadow: var(--glow);
}

/* ---------- Notice ---------- */
.notice__card {
  width: 100%;
  max-width: 400px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--err);
  border-radius: var(--radius);
  padding: 26px 24px;
}
.notice__title { margin: 0 0 10px; font-size: 16px; letter-spacing: 1px; color: var(--err); }
.notice__text { margin: 0 0 20px; color: var(--text-muted); font-size: 13px; line-height: 1.6; }

.toast {
  position: fixed;
  left: 50%; bottom: 84px;
  transform: translateX(-50%) translateY(10px);
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 8px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  letter-spacing: 1px;
  box-shadow: var(--glow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 20;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
