:root {
  color-scheme: dark;
  --night: #151a2e;
  --deck: #1d2340;
  --rule: #2e3558;
  --paper: #ece7dc;
  --dim: #8f95b2;
  --ember: #ff8a3d;
  --ember-deep: #3a2419;
  --seen: #7fd6c4;
  --danger: #ff5d5d;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Ubuntu Mono", Menlo, Consolas, monospace;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
*, *::before, *::after { box-sizing: inherit; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--night);
  color: var(--paper);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ember); outline-offset: 2px; }

/* ---------- gate screens (home / join) ---------- */
.gate { min-height: 100%; display: grid; align-items: center; padding: 24px; }
.gate-inner { width: 100%; max-width: 30rem; margin: 0 auto; }
.mark {
  font-size: clamp(2.6rem, 9vw, 3.6rem);
  font-weight: 300;
  letter-spacing: -0.03em;
  margin: 0 0 4px;
  position: relative;
  padding-bottom: 14px;
}
.mark::after {
  content: ""; position: absolute; left: 0; bottom: 0; height: 3px; width: 62%;
  background: var(--ember); border-radius: 3px;
  box-shadow: 0 0 12px rgba(255, 138, 61, .55);
}
.lede { color: var(--dim); margin: 16px 0 28px; max-width: 34em; }
.field { display: block; margin-bottom: 18px; font-size: .9rem; color: var(--dim); }
.field input, .field select {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px;
  background: var(--deck); border: 1px solid var(--rule); border-radius: 10px;
  font-size: 1rem; color: var(--paper);
}
.field input:focus, .field select:focus { border-color: var(--ember); outline: none; }
.note { color: var(--dim); font-size: .88rem; margin: 14px 0 0; }
.note.err { color: var(--danger); }

.btn {
  appearance: none; border: 1px solid var(--rule); background: var(--deck);
  padding: 11px 18px; border-radius: 999px; cursor: pointer; font-weight: 500;
}
.btn:hover { border-color: var(--dim); }
.btn.primary { background: var(--ember); border-color: var(--ember); color: #1a0f08; width: 100%; }
.btn.primary:disabled { opacity: .55; cursor: progress; }
.sheet .btn.primary { width: auto; }
.btn.ghost { background: transparent; }
.btn.hot { color: var(--ember); border-color: rgba(255, 138, 61, .5); background: transparent; }
.btn.hot.solid { background: var(--danger); border-color: var(--danger); color: #1b0606; }

/* ---------- chat ---------- */
.chat { height: 100%; display: flex; flex-direction: column; }
.bar {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 12px 12px 16px; background: var(--night);
  border-bottom: 1px solid var(--rule);
}
.bar-id { min-width: 0; }
.room-code { font-family: var(--mono); font-size: .95rem; letter-spacing: .06em; }
.room-code.inline { font-size: .85rem; color: var(--paper); }
.burn-text { color: var(--dim); font-size: .8rem; }
.burn-text.close { color: var(--ember); }
.bar-actions { display: flex; gap: 4px; }
.fuse { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; }
.fuse-fill {
  height: 100%; width: 100%; background: var(--ember);
  box-shadow: 0 0 10px rgba(255, 138, 61, .7);
  transition: width 1s linear;
}

.icon-btn {
  position: relative; display: grid; place-items: center; width: 42px; height: 42px;
  border: 0; border-radius: 12px; background: transparent; cursor: pointer;
}
.icon-btn:hover { background: var(--deck); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--paper); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.hot svg { stroke: var(--ember); }
.count {
  position: absolute; top: 4px; right: 3px; min-width: 16px; padding: 0 4px;
  font-size: .68rem; line-height: 16px; border-radius: 8px; background: var(--rule); color: var(--paper);
}

.status { text-align: center; font-size: .82rem; padding: 6px; background: var(--ember-deep); color: var(--ember); }

.list { flex: 1; overflow-y: auto; padding: 16px 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.empty { margin: auto; text-align: center; color: var(--dim); max-width: 22rem; padding: 24px; }
.sys { align-self: center; color: var(--dim); font-size: .78rem; margin: 10px 0; }

.msg { max-width: min(78%, 34rem); align-self: flex-start; margin-top: 6px; }
.msg.mine { align-self: flex-end; }
.msg.cont { margin-top: 1px; }
.who { font-size: .76rem; color: var(--dim); margin: 0 0 2px 12px; }
.bubble {
  padding: 8px 12px; border-radius: 16px 16px 16px 5px; background: var(--deck);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.mine .bubble { background: var(--ember-deep); border-radius: 16px 16px 5px 16px; }
.bubble.media { padding: 4px; }
.bubble img { display: block; max-width: 100%; max-height: 60vh; border-radius: 12px; cursor: zoom-in; }
.bubble.warn { outline: 1px solid var(--danger); }
.file-card { display: flex; align-items: center; gap: 10px; padding: 4px; }
.file-card .fname { font-weight: 500; overflow-wrap: anywhere; }
.file-card .fsize { color: var(--dim); font-size: .8rem; }
.file-card .btn { padding: 6px 12px; font-size: .85rem; flex: none; }
.meta { font-size: .72rem; color: var(--dim); margin: 2px 10px 0; display: flex; gap: 6px; justify-content: flex-end; }
.msg:not(.mine) .meta { justify-content: flex-start; }
.tick { letter-spacing: -.2em; padding-right: .2em; }
.tick.read { color: var(--seen); }
.seen-by { color: var(--seen); }

.composer {
  display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px;
  border-top: 1px solid var(--rule); background: var(--night);
}
.composer textarea {
  flex: 1; resize: none; max-height: 9rem; padding: 10px 14px; border-radius: 20px;
  border: 1px solid var(--rule); background: var(--deck); line-height: 1.35; font-size: 1rem;
}
.composer textarea:focus { outline: none; border-color: var(--ember); }
.send-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--ember);
  display: grid; place-items: center; cursor: pointer; flex: none;
}
.send-btn svg { width: 20px; height: 20px; fill: #1a0f08; }
.chat.dragging .list { outline: 2px dashed var(--ember); outline-offset: -8px; }

/* ---------- dialogs ---------- */
.sheet {
  width: min(28rem, calc(100% - 24px)); border: 1px solid var(--rule); border-radius: 18px;
  background: var(--deck); color: var(--paper); padding: 22px;
}
.sheet::backdrop { background: rgba(8, 10, 20, .7); }
.sheet h2 { margin: 0 0 4px; font-weight: 500; font-size: 1.25rem; }
.row { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.stack { display: grid; gap: 10px; margin-top: 18px; }
.invite-out input {
  width: 100%; margin-top: 4px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--ember);
  background: var(--night); font-family: var(--mono); font-size: .8rem;
}
.people { list-style: none; padding: 0; margin: 14px 0; }
.people li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--rule); flex: none; }
.dot.on { background: var(--seen); }
.people .tag { margin-left: auto; color: var(--dim); font-size: .78rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--paper); color: var(--night); padding: 9px 16px; border-radius: 999px;
  font-size: .9rem; width: max-content; max-width: calc(100% - 32px); z-index: 50;
}

.viewer { position: fixed; inset: 0; background: rgba(5, 6, 12, .94); display: grid; place-items: center; z-index: 40; cursor: zoom-out; }
.viewer img { max-width: 96vw; max-height: 92vh; }

@media (prefers-reduced-motion: reduce) { .fuse-fill { transition: none; } }
