/* Xenon web client — mobile first, with a static sidebar from 760px up. */

:root {
  --bg: #15181d;
  --panel: #1b1f26;
  --panel-2: #21262f;
  --line: #2f3641;
  --text: #e7eaef;
  --dim: #98a2b3;
  --accent: #4f8cff;
  --danger: #e5484d;
  --radius: 10px;
  --tap: 44px; /* Minimum comfortable touch target */
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --panel: #f6f7f9;
    --panel-2: #eceef2;
    --line: #d3d7de;
    --text: #14171c;
    --dim: #5c6572;
    --accent: #1c62e8;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

/* The script shows and hides with the hidden attribute, and several of those
   elements also carry a display rule below. A display rule beats the browser's
   own [hidden] style, so without this the auth screen and the app would both
   render at once and every message would offer Edit and Delete. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; font-size: 1rem; }

/* Controls */

.btn {
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: transparent; color: #fff; font-weight: 600; }
.btn-danger { color: var(--danger); }
.btn-quiet { background: transparent; }
.btn-sm { min-height: 34px; padding: 0 10px; font-size: .9rem; }

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-size: 1.15rem;
  cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); }

.link-btn {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--dim);
  font: inherit;
  font-size: .82rem;
  text-decoration: underline;
  cursor: pointer;
}
.link-btn:hover { color: var(--text); }

input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
textarea { resize: none; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 6px; font-size: .85rem; color: var(--dim); }
.form label input, .form label select { color: var(--text); font-size: 1rem; }
.form small { color: var(--dim); font-size: .76rem; }
.row { display: flex; gap: 8px; }
.row .btn { flex: 1; }
.hint { margin: 0; color: var(--dim); font-size: .85rem; }
.error {
  margin: 4px 0 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  color: var(--danger);
  font-size: .88rem;
}

/* Auth */

.auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh; /* Discounts mobile browser chrome where supported */
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
.auth-card {
  width: 100%;
  max-width: 380px;
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}
.auth-logo { justify-self: center; border-radius: 16px; }
.auth-card h1 { text-align: center; font-size: 1.3rem; letter-spacing: .04em; }

.tabs { display: flex; gap: 4px; padding: 4px; border-radius: var(--radius); background: var(--panel-2); }
.tab {
  flex: 1;
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--dim);
  font: inherit;
  cursor: pointer;
}
.tab.is-active { background: var(--bg); color: var(--text); font-weight: 600; }

.server-box { border-top: 1px solid var(--line); padding-top: 10px; }
.server-box summary { color: var(--dim); font-size: .85rem; cursor: pointer; }
.server-box .btn { margin-top: 10px; width: 100%; }
.server-box label { display: grid; gap: 6px; margin-top: 10px; font-size: .85rem; color: var(--dim); }

/* Shell */

.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

.drawer {
  position: fixed;
  z-index: 3;
  inset: 0 auto 0 0;
  width: min(82vw, 300px);
  display: flex;
  flex-direction: column;
  padding: 0 0 env(safe-area-inset-bottom);
  border-right: 1px solid var(--line);
  background: var(--panel);
  transform: translateX(-100%);
  transition: transform .18s ease-out;
}
.drawer.is-open { transform: none; }

.drawer-head {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 56px;
  padding: 0 8px 0 16px;
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.drawer-head h2 { flex: 1; font-size: 1.05rem; }

.room-list { flex: 1; margin: 0; padding: 8px; overflow-y: auto; list-style: none; }
.room-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: var(--tap);
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.room-btn:hover { background: var(--panel-2); }
.room-btn.is-active { background: var(--accent); color: #fff; font-weight: 600; }
.room-tag {
  margin-left: auto;
  padding: 1px 6px;
  border-radius: 99px;
  background: var(--panel-2);
  color: var(--dim);
  font-size: .68rem;
  text-transform: uppercase;
}
.room-btn.is-active .room-tag { background: rgba(255, 255, 255, .22); color: #fff; }
.room-empty { padding: 12px; color: var(--dim); font-size: .88rem; }

/* Reused inside a dialog (Discover rooms): bounded height instead of the
   drawer's flex: 1, so a long list scrolls within the sheet rather than
   growing it past the viewport */
.sheet .room-list { max-height: 50vh; margin: 12px 0; overflow-y: auto; }

.drawer-actions { display: grid; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); }
.drawer-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
}
.whoami { flex: 1; color: var(--dim); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; }

.scrim { position: fixed; inset: 0; z-index: 2; background: rgba(0, 0, 0, .5); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 56px;
  padding: env(safe-area-inset-top) 8px 0;
  border-bottom: 2px solid var(--line);
  background: var(--panel);
}
.topbar h1 {
  flex: 1;
  min-width: 0;
  font-size: 1.05rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Messages */

.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.empty { margin: auto; color: var(--dim); font-size: .9rem; }
.load-older {
  align-self: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--panel);
  color: var(--dim);
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}

.msg {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.msg.is-mine { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }

.avatar {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .02em;
}

.msg-body { flex: 1; min-width: 0; }
.msg-head { display: flex; align-items: center; gap: 8px; }
.author { font-weight: 700; font-size: .92rem; }
.badge-edited { color: var(--dim); font-size: .72rem; }

.text {
  margin: 4px 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.files { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.shot { margin: 0; max-width: min(100%, 320px); }
.shot img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 320px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}
/* Attachments carry no src until their bytes are fetched (they need an auth
   header), and until then an auto-height image is zero tall. Standing in with a
   rough shape means the page only nudges as pictures land instead of growing by
   a screenful. The real aspect ratio takes over the moment src is set. */
.shot img:not([src]) { aspect-ratio: 4 / 3; }
.player {
  position: relative;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #000;
  overflow: hidden;
}
/* Loaded clips size to their own frame instead of the placeholder's guess */
.player.ready { aspect-ratio: auto; }
.player-audio, .player-audio.ready { aspect-ratio: auto; min-height: 44px; background: var(--panel-2); }
.player-play {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 52px;
  height: 52px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.player-play:disabled { opacity: .6; cursor: default; }
.shot video {
  display: block;
  width: 100%;
  height: auto;
  max-height: 320px;
  object-fit: contain;
  background: #000;
}
.shot audio { display: block; width: 100%; }

.embeds { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.embed-yt { max-width: min(100%, 400px); flex: 1 1 320px; }
/* Thumbnail and iframe both fill the 16:9 frame the player class sets up */
.embed-yt .embed-thumb,
.embed-yt iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.embed-yt .embed-thumb { object-fit: cover; }
.embed-yt figcaption a { color: var(--dim); }
.shot figcaption { padding-top: 4px; color: var(--dim); font-size: .74rem; overflow-wrap: anywhere; }
.file-chip {
  max-width: 100%;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: .82rem;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.msg-foot { display: flex; align-items: center; gap: 12px; }
.msg-actions { display: flex; gap: 12px; }
.stamp { margin-left: auto; color: var(--dim); font-size: .74rem; font-weight: 600; white-space: nowrap; }
.edit-box { display: grid; gap: 8px; margin: 6px 0; }
.edit-box .row { justify-content: flex-end; }
.edit-box .row .btn { flex: 0 0 auto; }

/* Composer */

.attach-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--panel-2);
  font-size: .8rem;
  overflow-wrap: anywhere;
}
.chip-x {
  width: 20px;
  height: 20px;
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--line);
  color: var(--text);
  font-size: .9rem;
  line-height: 1;
  cursor: pointer;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 2px solid var(--line);
  background: var(--panel);
}
.composer textarea { flex: 1; max-height: 140px; }
.composer .btn-primary { flex: none; }

/* Dialogs */

.sheet {
  width: min(440px, calc(100vw - 24px));
  /* The room dialog outgrew the viewport once every permission got a box */
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  margin: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, .55); }
.sheet h3 { margin-bottom: 12px; font-size: 1.05rem; }
.sheet > .btn { width: 100%; margin-top: 8px; }
.perms { display: grid; gap: 6px; margin: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); }
.perms legend { padding: 0 6px; color: var(--dim); font-size: .78rem; }
.check { display: flex !important; align-items: center; gap: 10px; color: var(--text) !important; font-size: .9rem !important; }
.check input { width: 20px; min-height: 20px; height: 20px; margin: 0; flex: none; }
.code-out {
  display: block;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.25rem;
  letter-spacing: .12em;
  text-align: center;
  overflow-wrap: anywhere;
}

/* Toast */

.toast {
  position: fixed;
  z-index: 9;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 99px;
  background: #000;
  color: #fff;
  font-size: .88rem;
  text-align: center;
  transform: translateX(-50%);
}

/* Desktop: the drawer becomes a permanent column */

@media (min-width: 760px) {
  .drawer { position: static; width: 280px; transform: none; transition: none; }
  #drawerClose, #menuBtn, .scrim { display: none; }
  .messages { padding: 16px 20px; }
  .msg { max-width: 760px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
