:root {
  /* Brand */
  --bg: #0a0a0b;
  --bg2: #121214;
  --bg3: #1a1a1e;
  --border: #2a2a30;
  --text: #f2f2f4;
  --muted: #9a9aa3;
  --dim: #6a6a74;
  --yellow: #f5c518;
  --yellow-dim: #c9a012;
  --green: #3dd68c;
  --red: #ff5c5c;
  --radius: 12px;
  --font: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Spacing scale: 0.25 / 0.5 / 0.75 / 1 / 1.25 / 1.5 / 2rem */
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.25rem;
  --s6: 1.5rem;
  --s7: 2rem;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--yellow); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--s7) var(--s5) calc(var(--s7) * 2);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -.02em;
}
.logo-link {
  display: flex;
  align-items: center;
  gap: var(--s2);
  color: inherit;
  text-decoration: none;
}
.logo-link:hover { text-decoration: none; }
.logo-centered {
  justify-content: center;
  margin-bottom: var(--s4);
}
.logo-mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: block;
  border-radius: 8px;
}
.tagline {
  color: var(--muted);
  margin: var(--s1) 0 0;
  font-size: .95rem;
}

/* Home */
.hero { margin-top: calc(var(--s7) + var(--s4)); }
.hero-narrow { max-width: 420px; }
.hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  letter-spacing: -.03em;
  margin: 0 0 var(--s2);
  line-height: 1.15;
}
.hero h1 span { color: var(--yellow); }
.hero p { color: var(--muted); max-width: 36rem; margin: 0 0 var(--s7); }

.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s6);
  max-width: 420px;
}
.card-center { text-align: center; }

.field { margin-bottom: var(--s4); }
.field label {
  display: block;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--dim);
  margin-bottom: var(--s2);
}
.field input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: var(--s3) var(--s4);
  font-size: 1rem;
  outline: none;
  transition: border-color .15s;
}
.field input:focus { border-color: var(--yellow); }
.row { display: flex; gap: var(--s2); align-items: stretch; }
.row input { flex: 1; }

.btn {
  appearance: none;
  border: none;
  border-radius: 8px;
  padding: var(--s3) var(--s5);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .08s, background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--yellow); color: #111; }
.btn-primary:hover:not(:disabled) { background: #ffd84a; }
.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--muted); background: var(--bg3); }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: var(--s2) var(--s3);
  font-size: .85rem;
}
.btn-ghost:hover { color: var(--text); background: var(--bg3); }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: var(--s2) var(--s3); font-size: .8rem; }
.btn-block {
  display: inline-block;
  text-align: center;
  text-decoration: none;
}
.btn-block:hover { text-decoration: none; }

.actions { display: flex; gap: var(--s2); margin-top: var(--s5); flex-wrap: wrap; }
.hint { color: var(--dim); font-size: .8rem; margin-top: var(--s3); }
.hint-flush { margin: 0; }
.hint-spaced { margin: 0 0 var(--s5); }
.hint-pull { margin-top: calc(var(--s2) * -1); }

/* Joining gate — only while connecting; must not sit over room shell */
.joining-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
}
#joiningGate[hidden],
.joining-gate[hidden] {
  display: none !important;
}
/* Author display:grid must not defeat the hidden attribute */
.room-shell[hidden],
#roomShell[hidden] {
  display: none !important;
}

/* Room layout */
.room-shell {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: var(--s4);
  min-height: calc(100vh - var(--s7));
  padding: var(--s4);
  max-width: 1100px;
  margin: 0 auto;
}
@media (max-width: 800px) {
  .room-shell { grid-template-columns: 1fr; }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  margin-bottom: var(--s4);
  flex-wrap: wrap;
}
.topbar-meta {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
}
.room-code {
  font-family: var(--mono);
  color: var(--yellow);
  font-size: .9rem;
  background: var(--bg3);
  padding: var(--s1) var(--s2);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.status-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  display: inline-block;
  background: var(--dim);
  margin-right: var(--s2);
  vertical-align: middle;
}
.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(61, 214, 140, .6);
  animation: pulse 1.6s infinite;
}
.status-dot.offline { background: var(--red); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(61, 214, 140, .55); }
  70% { box-shadow: 0 0 0 8px rgba(61, 214, 140, 0); }
  100% { box-shadow: 0 0 0 0 rgba(61, 214, 140, 0); }
}

.seats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s3);
  margin-bottom: var(--s4);
}
.seat {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s4);
  display: flex;
  gap: var(--s3);
  align-items: center;
  min-height: 72px;
}
.seat.empty {
  border-style: dashed;
  color: var(--dim);
  justify-content: center;
}
.avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--bg3);
  border: 2px solid var(--border);
  object-fit: cover;
  flex-shrink: 0;
  display: grid; place-items: center;
  font-weight: 700; color: var(--yellow);
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.seat-meta { min-width: 0; flex: 1; }
.seat-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seat-role { font-size: .75rem; color: var(--dim); }

.alone-banner {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s4) var(--s5);
  margin-bottom: var(--s4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  flex-wrap: wrap;
}
.alone-banner p { margin: 0; color: var(--muted); }
.banner-actions { display: flex; gap: var(--s2); flex-wrap: wrap; }

.lost-banner {
  display: none;
  background: rgba(255, 92, 92, .12);
  border: 1px solid var(--red);
  color: #ffb4b4;
  border-radius: var(--radius);
  padding: var(--s3) var(--s4);
  margin-bottom: var(--s4);
  font-weight: 500;
}
.lost-banner.show { display: block; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg2);
  padding: var(--s7) var(--s5);
  text-align: center;
  transition: border-color .15s, background .15s;
  cursor: pointer;
  margin-bottom: var(--s4);
}
.dropzone.dragover {
  border-color: var(--yellow);
  background: rgba(245, 197, 24, .06);
}
.dropzone.disabled {
  opacity: .4;
  pointer-events: none;
}
.dropzone h3 { margin: 0 0 var(--s1); font-size: 1.05rem; }
.dropzone p { margin: 0; color: var(--muted); font-size: .9rem; }

.queue-status {
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: var(--s3);
  min-height: 1.2em;
}

.transfer-card, .offer-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s4);
  margin-bottom: var(--s3);
}
.offer-card {
  border-color: var(--yellow-dim);
  background: rgba(245, 197, 24, .06);
}
.offer-card .title { font-weight: 600; margin-bottom: var(--s1); }
.offer-card .meta { color: var(--muted); font-size: .85rem; margin-bottom: var(--s3); }

.progress {
  height: 6px;
  background: var(--bg3);
  border-radius: 99px;
  overflow: hidden;
  margin: var(--s2) 0;
}
.progress > i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--yellow), #ff8a00);
  border-radius: 99px;
  transition: width .12s linear;
}
.xfer-meta {
  display: flex;
  justify-content: space-between;
  font-size: .8rem;
  color: var(--muted);
  gap: var(--s2);
  flex-wrap: wrap;
}

/* Side panel */
.side {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 420px;
  max-height: calc(100vh - var(--s7));
}
.side-head {
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: .9rem;
}
.side-sub {
  font-weight: 400;
  color: var(--dim);
  font-size: .75rem;
}
.log {
  flex: 1;
  overflow-y: auto;
  padding: var(--s3) var(--s4);
  font-size: .8rem;
  font-family: var(--mono);
}
.log-line { margin-bottom: var(--s2); color: var(--muted); word-break: break-word; }
.log-line .ts { color: var(--dim); margin-right: var(--s1); }
.log-line.chat { color: var(--text); }
.log-line.chat .who { color: var(--yellow); }

.chat-form {
  display: flex;
  gap: var(--s2);
  padding: var(--s3);
  border-top: 1px solid var(--border);
}
.chat-form input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: var(--s2) var(--s3);
  outline: none;
}
.chat-form input:focus { border-color: var(--yellow); }

.identity-bar {
  display: flex;
  gap: var(--s2);
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: var(--s4);
}
.identity-bar input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: var(--s2) var(--s3);
  outline: none;
  width: 140px;
}
.identity-bar input:focus { border-color: var(--yellow); }
.file-label {
  cursor: pointer;
  margin: 0;
}

/* Toasts */
#toasts {
  position: fixed;
  right: var(--s4);
  bottom: var(--s4);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  max-width: min(360px, calc(100vw - var(--s7)));
}
.toast {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--yellow);
  border-radius: 8px;
  padding: var(--s3) var(--s4);
  font-size: .88rem;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  animation: slideIn .2s ease;
}
.toast.error { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }
@keyframes slideIn {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.footer-note {
  margin-top: calc(var(--s7) + var(--s2));
  color: var(--dim);
  font-size: .8rem;
}
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

/* Practical limit badge under nickname */
.seat-limit {
  font-size: .72rem;
  margin-top: 2px;
  color: var(--dim);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  position: relative;
  cursor: help;
}
.seat-limit.warn {
  color: var(--yellow);
  font-weight: 600;
}
.seat-limit .limit-tip {
  display: none;
  position: absolute;
  left: 0;
  bottom: calc(100% + 6px);
  z-index: 20;
  width: min(260px, 70vw);
  padding: var(--s3);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-weight: 400;
  font-size: .75rem;
  line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  white-space: normal;
  pointer-events: none;
}
.seat-limit:hover .limit-tip,
.seat-limit:focus-within .limit-tip {
  display: block;
}

.offer-card.queued {
  border-color: var(--border);
  background: var(--bg2);
  opacity: .9;
}
.offer-card .status-pill {
  display: inline-block;
  font-size: .7rem;
  padding: 1px 6px;
  border-radius: 99px;
  background: var(--bg3);
  color: var(--muted);
  margin-left: var(--s2);
  vertical-align: middle;
}
.offer-card.queued .status-pill {
  color: var(--yellow);
  border: 1px solid var(--yellow-dim);
}

.outbound-queue {
  margin-bottom: var(--s3);
}
.outbound-queue .oq-item {
  display: flex;
  justify-content: space-between;
  gap: var(--s2);
  font-size: .8rem;
  color: var(--muted);
  padding: var(--s2) 0;
  border-bottom: 1px solid var(--border);
}
.outbound-queue .oq-item:last-child { border-bottom: none; }
.outbound-queue .oq-state {
  color: var(--yellow);
  white-space: nowrap;
}

.dropzone .limits-line {
  margin-top: var(--s2);
  font-size: .8rem;
  color: var(--dim);
}
.lost-banner.resume {
  background: rgba(245, 197, 24, .1);
  border-color: var(--yellow-dim);
  color: #ffe08a;
}
