*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0f14;
  --surface: rgba(255,255,255,0.04);
  --surface-strong: rgba(255,255,255,0.06);
  --border: rgba(255,255,255,0.07);
  --text: #c8cdd6;
  --text-bright: #dde2ec;
  --muted: #5a6070;
  --accent: #b39ddb;
  --accent-dim: rgba(179,157,219,0.15);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 15px;
  font-weight: 300;
  line-height: 1.7;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#rain { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
#splashes { position: fixed; inset: 0; pointer-events: none; z-index: 2; }

.screen {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
}
.hidden { display: none !important; }

.card {
  width: 100%;
  max-width: 420px;
  opacity: 0;
  transform: translateY(-20px);
  animation: rise 0.9s cubic-bezier(0.215,0.61,0.355,1) forwards;
}

@keyframes rise { to { opacity: 1; transform: translateY(0); } }

.heading {
  font-size: clamp(1.6rem, 5vw, 2.1rem);
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--text-bright);
  margin-bottom: 0.2em;
}
.heading .accent-word { color: var(--accent); font-weight: 500; }

.sub { color: var(--muted); font-size: 0.85rem; margin-bottom: 2rem; letter-spacing: 0.01em; }
.section-label { font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin-bottom: 0.6rem; }

.code-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6em 0.9em;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 0.9rem;
  transition: border-color 0.18s, background 0.18s;
}
.code-pill span { font-size: 1.05rem; letter-spacing: 0.14em; color: var(--accent); font-weight: 400; }

.pill-row { display: flex; gap: 0.4rem; }
.spacer { flex: 1; }

.pill-btn {
  display: inline-flex; align-items: center; gap: 0.35em; padding: 0.3em 0.85em;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-family: inherit; font-size: 0.78rem; cursor: pointer;
  transition: border-color 0.18s, color 0.18s, background 0.18s;
}
.pill-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

button.wide {
  width: 100%; display: block; text-align: center; padding: 0.65em 1em; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 0.88rem; cursor: pointer; transition: border-color 0.18s, color 0.18s, background 0.18s;
}
button.wide:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
button.wide:disabled { opacity: 0.4; cursor: default; }

.divider {
  display: flex; align-items: center; gap: 0.9em; margin: 1.8rem 0;
  color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.12em;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

input[type="text"], input[type="password"] {
  width: 100%; background: var(--surface); border: 1px solid var(--border); color: var(--text);
  font-family: inherit; font-size: 0.9rem; padding: 0.65em 0.9em; border-radius: 12px;
  outline: none; margin-bottom: 0.9rem; transition: border-color 0.18s;
}
input[type="text"]:focus, input[type="password"]:focus { border-color: var(--accent); }
input[type="text"]::placeholder, input[type="password"]::placeholder { color: var(--muted); }
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px #14161d inset;
  caret-color: var(--text);
  transition: background-color 9999s ease-out 0s;
}

.status-line { margin-top: 1.1rem; font-size: 0.8rem; color: var(--muted); min-height: 1.2em; }
.status-line.error { color: #d68fa0; }
.status-line.ok { color: var(--accent); }

.clock-row { display: flex; align-items: center; gap: 0.5em; }

.status-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  flex-shrink: 0; transition: background 0.3s;
}
.status-dot.live { background: var(--accent); animation: pulse 2.4s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50% { opacity: 0.3; transform: scale(0.8); }
}

#chatScreen { flex-direction: column; align-items: stretch; justify-content: stretch; padding: 0; }

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.6rem; border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02); font-size: 0.82rem;
}
.chat-header .room-tag { color: var(--muted); }
.chat-header .room-tag b { color: var(--accent); font-weight: 500; letter-spacing: 0.08em; }

#messages {
  flex: 1; overflow-y: auto; overflow-x: visible; padding: 1.5rem 1.6rem;
  display: flex; flex-direction: column; gap: 0.4rem;
}

#messageList { display: flex; flex-direction: column; gap: 0.4rem; width: 100%; }

.msg-container { display: flex; flex-direction: column; margin-bottom: 0.3rem; }
.msg-container.me { align-items: flex-end; }
.msg-container.them { align-items: flex-start; }
.msg-container.system { align-items: center; margin: 0.8rem 0; }

.timestamp { font-size: 0.65rem; color: var(--muted); margin-bottom: 0.2rem; margin-inline: 0.4rem; }

.date-sep {
  display: flex; align-items: center; gap: 0.9em; margin: 1.1rem 0 0.3rem;
  color: var(--muted); font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase;
}
.date-sep::before, .date-sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.msg {
  max-width: min(75vw, 480px); padding: 0.55em 0.85em; border-radius: 14px;
  font-size: 0.88rem; line-height: 1.5; word-wrap: break-word;
  opacity: 0; animation: msgIn 0.25s ease forwards;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.me { background: var(--accent-dim); border: 1px solid rgba(179,157,219,0.3); color: var(--text-bright); border-bottom-right-radius: 4px; }
.msg.them { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.system { color: var(--muted); font-size: 0.75rem; background: none; border: none; letter-spacing: 0.03em; max-width: 100%; text-align: center; }

/* Markdown & Media styling */
.msg { white-space: pre-wrap; }
.msg b { font-weight: 500; color: #fff; }
.msg i { font-style: italic; opacity: 0.9; }
.msg img, .msg video {
  max-width: 100%;
  max-height: 280px; /* Caps the height so it doesn't take over the screen */
  width: auto;       /* Ensures the aspect ratio doesn't stretch */
  border-radius: 8px;
  margin-top: 4px;
  display: block;
  background: #000;
}
.msg audio { max-width: 100%; margin-top: 4px; display: block; outline: none; border-radius: 8px; }
.msg a { color: var(--accent); text-decoration: underline; word-break: break-all; }
.msg.system { white-space: normal; }
.file-caption { margin-top: 0.35em; }

/* Reply quoting */
.reply-quote {
  font-size: 0.75rem; color: var(--muted); border-left: 2px solid var(--accent);
  padding-left: 0.5em; margin-bottom: 0.35em; cursor: pointer; opacity: 0.85;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px;
}
.reply-quote:hover { color: var(--accent); }

.msg-highlight .msg { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Bubble row: message + hover actions. Actions are absolutely positioned so
   they overlay outside the bubble and never shift or resize the message. */
.bubble-row { position: relative; display: flex; max-width: 100%; }

.msg-actions {
  position: absolute; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; gap: 0.05rem; opacity: 0.55; z-index: 3;
}
.msg-container.me .msg-actions { right: 100%; margin-right: 4px; flex-direction: row-reverse; }
.msg-container.them .msg-actions { left: 100%; margin-left: 4px; }
@media (hover: hover) {
  .msg-actions { opacity: 0; pointer-events: none; transition: opacity 0.15s; }
  .msg-container:hover .msg-actions { opacity: 0.95; pointer-events: auto; }
}
/* Keep reply/react actions visible while the reaction picker is open, so
   moving the mouse from the react button to a reaction doesn't hide the
   menu (which would otherwise happen the instant the cursor leaves the
   hover area, before the click registers). */
.msg-container.picker-active .msg-actions { opacity: 0.95 !important; pointer-events: auto !important; }
.msg-actions button {
  background: none; border: none; color: var(--muted); font-size: 0.9rem; cursor: pointer;
  padding: 0.3rem; border-radius: 8px; line-height: 1; min-width: 30px; min-height: 30px;
}
.msg-actions button:hover, .msg-actions button:active { color: var(--accent); background: var(--accent-dim); }

/* Hover timestamp — same side as the reply/react buttons, sitting just above them */
.hover-time {
  position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%);
  font-size: 0.62rem; color: var(--muted); background: #12141b; border: 1px solid var(--border);
  padding: 0.15em 0.5em; border-radius: 6px; white-space: nowrap; pointer-events: none;
}

.react-wrap { position: relative; }
.emoji-picker {
  position: absolute; bottom: calc(100% + 6px); display: none; gap: 0.1rem; padding: 0.35rem;
  background: #12141b; border: 1px solid var(--border); border-radius: 12px; z-index: 10;
  box-shadow: 0 6px 18px rgba(0,0,0,0.4); white-space: nowrap;
}
.msg-container.me .emoji-picker { right: 0; }
.msg-container.them .emoji-picker { left: 0; }
.emoji-picker.open { display: flex; }
.emoji-picker button {
  background: none; border: none; font-size: 1.05rem; padding: 0.3rem; cursor: pointer;
  border-radius: 8px; min-width: 34px; min-height: 34px;
}
.emoji-picker button:hover { background: var(--accent-dim); }
.emoji-picker button.more-emoji { font-size: 0.8rem; color: var(--muted); }

/* Read receipts */
.read-receipt { font-size: 0.66rem; color: var(--muted); margin-top: 2px; margin-inline: 0.4rem; }

/* Full emoji picker (chat-bar + custom reactions) — phone-shaped, short, scrollable */
.emoji-full-picker {
  position: fixed; width: 280px; height: 300px; background: #12141b; border: 1px solid var(--border);
  border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); z-index: 50;
  display: flex; flex-direction: column; overflow: hidden;
}
.emoji-tabs {
  display: flex; gap: 2px; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02); flex-shrink: 0; overflow-x: auto;
}
.emoji-tabs button {
  background: none; border: none; font-size: 1rem; padding: 0.3rem 0.4rem; border-radius: 8px;
  cursor: pointer; opacity: 0.5; flex-shrink: 0;
}
.emoji-tabs button.active, .emoji-tabs button:hover { opacity: 1; background: var(--accent-dim); }
.emoji-grid-scroll { flex: 1; overflow-y: auto; padding: 0.3rem 0.5rem 0.6rem; }
.emoji-cat-label { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0.6rem 0.2rem 0.25rem; }
.emoji-cat-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1px; }
.emoji-cat-grid button { background: none; border: none; font-size: 1.3rem; padding: 0.25rem; border-radius: 8px; cursor: pointer; }
.emoji-cat-grid button:hover { background: var(--accent-dim); }

.emoji-toggle-btn {
  background: none; border: none; color: var(--muted); font-size: 1.3rem;
  cursor: pointer; transition: color 0.18s; padding: 0.4rem 0.4rem;
  min-width: 40px; min-height: 40px;
}
.emoji-toggle-btn:hover { color: var(--text-bright); }
.emoji-toggle-btn:disabled { opacity: 0.4; cursor: default; }

/* Multi-attachment modal preview */
.modal-preview.multi { flex-wrap: wrap; flex-direction: row; gap: 0.5rem; padding: 0.6rem; max-height: 340px; overflow-y: auto; }
.modal-preview-item { position: relative; }
.modal-preview.multi .modal-preview-item img,
.modal-preview.multi .modal-preview-item video { max-width: 120px; max-height: 120px; border-radius: 8px; display: block; }
.modal-preview.multi .modal-preview-item .file-chip { width: 120px; padding: 0.6em 0.4em; font-size: 0.7rem; }
.remove-attachment {
  position: absolute; top: 2px; right: 2px; background: rgba(5,6,10,0.75); color: #fff;
  border: none; border-radius: 50%; width: 20px; height: 20px; font-size: 0.65rem; cursor: pointer;
  line-height: 1;
}
.remove-attachment:hover { background: var(--accent); color: #12141b; }

/* Reactions */
.msg-reactions { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-top: 0.2rem; margin-inline: 0.3rem; }
.msg-container.me .msg-reactions { justify-content: flex-end; }
.reaction-pill {
  font-size: 0.72rem; padding: 0.15em 0.55em; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; line-height: 1.5;
}
.reaction-pill.active { border-color: var(--accent); background: var(--accent-dim); color: var(--accent); }

/* Reply bar above input */
.reply-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  padding: 0.5rem 1.6rem; background: rgba(255,255,255,0.03); border-top: 1px solid var(--border);
  font-size: 0.78rem;
}
.reply-bar-content { display: flex; flex-direction: column; overflow: hidden; }
.reply-bar-label { color: var(--accent); font-size: 0.68rem; letter-spacing: 0.03em; }
.reply-bar-text { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }

/* File preview modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(5,6,10,0.72); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 20; padding: 1.5rem;
}
.modal-card {
  width: 100%; max-width: 420px; background: #12141b; border: 1px solid var(--border);
  border-radius: 16px; padding: 1.2rem; display: flex; flex-direction: column; gap: 0.8rem;
}
.modal-title { font-size: 0.78rem; color: var(--muted); letter-spacing: 0.05em; }
.modal-preview {
  max-height: 340px; overflow: hidden; border-radius: 10px; display: flex;
  align-items: center; justify-content: center; background: rgba(255,255,255,0.02);
}
.modal-preview img, .modal-preview video { max-width: 100%; max-height: 340px; display: block; border-radius: 10px; }
.modal-preview audio { width: 100%; }
.file-chip { padding: 0.9em 1em; border: 1px solid var(--border); border-radius: 10px; font-size: 0.85rem; color: var(--text-bright); width: 100%; text-align: center; }
#modalCaption {
  width: 100%; background: var(--surface); border: 1px solid var(--border); color: var(--text);
  font-family: inherit; font-size: 0.88rem; padding: 0.6em 0.9em; border-radius: 12px; outline: none;
  resize: none; min-height: 2.6em; max-height: 100px; transition: border-color 0.18s;
}
#modalCaption:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 0.6rem; justify-content: flex-end; }
#modalSendBtn {
  padding: 0.55em 1.2em; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--accent); font-family: inherit; font-size: 0.85rem;
  cursor: pointer; transition: border-color 0.18s, background 0.18s; min-height: 40px;
}
#modalSendBtn:hover { border-color: var(--accent); background: var(--accent-dim); }
#modalSendBtn:disabled { opacity: 0.5; cursor: default; }

.input-bar {
  display: flex; align-items: flex-end; gap: 0.6rem; padding: 1.1rem 1.6rem;
  padding-bottom: calc(1.1rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: rgba(255,255,255,0.02);
}

.attach-btn {
  background: none; border: none; color: var(--muted); font-size: 1.4rem;
  cursor: pointer; transition: color 0.18s; padding: 0.4rem 0.5rem;
  min-width: 40px; min-height: 40px;
}
.attach-btn:hover { color: var(--text-bright); }
.attach-btn:disabled { opacity: 0.4; cursor: default; }

.input-bar input[type="text"] { flex: 1; margin-bottom: 0; }
.input-bar textarea {
  flex: 1; background: var(--surface); border: 1px solid var(--border); color: var(--text);
  font-family: inherit; font-size: 0.9rem; padding: 0.65em 0.9em; border-radius: 16px;
  outline: none; resize: none; max-height: 140px; line-height: 1.4;
  transition: border-color 0.18s;
}
.input-bar textarea:focus { border-color: var(--accent); }
.input-bar textarea::placeholder { color: var(--muted); }
.input-bar textarea:disabled { opacity: 0.5; }

.input-bar button:not(.attach-btn) {
  padding: 0.6em 1.3em; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--accent); font-family: inherit; font-size: 0.85rem;
  cursor: pointer; transition: border-color 0.18s, background 0.18s; white-space: nowrap;
  min-height: 40px;
}
.input-bar button:not(.attach-btn):hover { border-color: var(--accent); background: var(--accent-dim); }

/* Typing Indicator */
#typingIndicator { margin-bottom: 0.5rem; }
.typing-bubble {
  display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.5em 0.95em;
  border-radius: 14px; border-bottom-left-radius: 4px;
  background: var(--accent-dim); border: 1px solid rgba(179,157,219,0.4);
  box-shadow: 0 2px 10px rgba(179,157,219,0.08);
  animation: typingPop 0.25s ease;
}
@keyframes typingPop { from { opacity: 0; transform: translateY(4px) scale(0.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
.typing-label { font-size: 0.72rem; color: var(--accent); letter-spacing: 0.04em; }
.typing-dots { color: var(--accent); font-size: 1.5rem; line-height: 1; display: flex; gap: 3px; }
.dot { animation: blink 1.2s infinite both; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

#messages { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

@media (max-width: 600px) {
  .screen { padding: 1.5rem 1.2rem; }
  .chat-header {
    padding: 0.9rem 1.1rem;
    padding-top: calc(0.9rem + env(safe-area-inset-top));
  }
  #messages { padding: 1rem 0.9rem; }
  .input-bar { padding: 0.85rem 0.9rem; padding-bottom: calc(0.85rem + env(safe-area-inset-bottom)); gap: 0.45rem; }
  .reply-bar { padding: 0.5rem 0.9rem; }
  .msg { max-width: min(85vw, 340px); font-size: 0.9rem; }
  /* 16px prevents iOS Safari from auto-zooming the page on focus */
  .input-bar textarea, .input-bar input[type="text"], #modalCaption { font-size: 16px; }
  .modal-card { max-width: 100%; }
  .reply-bar-text { max-width: 50vw; }
}

/* ------------------------------------------------------------------ */
/* Admin panel (served only on the localhost-only admin port)          */
/* ------------------------------------------------------------------ */

.admin-card { max-width: 560px; }
.admin-card .sub { margin-bottom: 1.6rem; }

.admin-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.4rem; gap: 1rem; }
.admin-toolbar .heading { margin-bottom: 0; font-size: 1.35rem; }

.admin-account {
  border: 1px solid var(--border); background: var(--surface); border-radius: 14px;
  padding: 1rem 1.1rem; margin-bottom: 0.9rem;
}
.admin-account-head { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; margin-bottom: 0.7rem; }
.admin-name { color: var(--text-bright); font-weight: 500; font-size: 0.95rem; letter-spacing: 0.02em; }
.admin-status { display: flex; align-items: center; gap: 0.45rem; font-size: 0.68rem; color: var(--muted); letter-spacing: 0.1em; text-transform: uppercase; }
.admin-status .status-dot { width: 6px; height: 6px; }

.admin-row { display: flex; gap: 0.5rem; align-items: center; }
.admin-row input[type="password"] { flex: 1; margin-bottom: 0; }
.admin-meta { font-size: 0.72rem; color: var(--muted); margin-top: 0.55rem; }

.admin-sep { height: 1px; background: var(--border); margin: 0.9rem 0; }
.admin-hint { font-size: 0.75rem; color: var(--muted); line-height: 1.55; margin-bottom: 1.2rem; }
.admin-hint code { color: var(--accent); font-size: 0.72rem; }
