:root {
  --bg: #ffffff;
  --ink: #1a1a1a;
  --muted: #666666;
  --line: #dddddd;
  --mine: #e8f1fc;
  --theirs: #f2f2f2;
  --accent: #1f6feb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --ink: #e9e9e9;
    --muted: #9a9a9a;
    --line: #33363c;
    --mine: #1d3557;
    --theirs: #24272d;
    --accent: #6ea8fe;
  }
}

* { box-sizing: border-box; }

/* Anything marked hidden really is hidden, whatever else the rules below say. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

/* ---------- sign-in and password pages ---------- */

body.centered {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.card {
  width: 100%;
  max-width: 340px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 22px;
}

.card h1 { margin: 0 0 16px; font-size: 20px; }

.card label {
  display: block;
  margin-bottom: 14px;
  font-size: 14px;
  color: var(--muted);
}

.card input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 10px;
  font-size: 16px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.card button {
  width: 100%;
  padding: 11px;
  font-size: 16px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.error { color: #c0392b; font-size: 14px; margin: 0 0 14px; }
.ok    { color: #1e7d34; font-size: 14px; margin: 0 0 14px; }
.muted { color: var(--muted); font-size: 14px; text-align: center; margin: 16px 0 0; }
.muted a, .bar a { color: var(--accent); }

/* ---------- chat page ---------- */

body.chat-page {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.bar {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}

.bar-right { display: flex; align-items: center; gap: 12px; }
.inline { display: inline; margin: 0; }

.linkish {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.status {
  flex: 0 0 auto;
  padding: 7px 14px;
  font-size: 13px;
  background: #fff3cd;
  color: #6a4b00;
  border-bottom: 1px solid var(--line);
}

#messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px;
}

#load-older {
  display: block;
  margin: 0 auto 14px;
  padding: 6px 12px;
  font-size: 13px;
  background: none;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--muted);
  cursor: pointer;
}

.msg { margin-bottom: 12px; max-width: 78%; }
.msg.mine { margin-left: auto; }

.meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 3px;
}

.msg.mine .meta { text-align: right; }

.bubble {
  background: var(--theirs);
  padding: 8px 11px;
  border-radius: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.mine .bubble { background: var(--mine); }

.msg.pending { opacity: 0.55; }

.daymark {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin: 16px 0 12px;
}

#composer {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

#body {
  flex: 1 1 auto;
  resize: none;
  max-height: 140px;
  padding: 10px;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 18px;
}

#send {
  flex: 0 0 auto;
  padding: 0 18px;
  font-size: 15px;
  border: 0;
  border-radius: 18px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

#send:disabled { opacity: 0.5; cursor: default; }

/* ---------- replies ---------- */

.meta-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}

.msg.mine .meta-row { justify-content: flex-end; }

.meta-row .meta { margin-bottom: 0; }

.reply-btn {
  background: none;
  border: 0;
  padding: 0;
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s;
}

.msg:hover .reply-btn,
.msg:focus-within .reply-btn { opacity: 1; }

/* Phones have no hover, so keep it permanently visible there. */
@media (hover: none) {
  .reply-btn { opacity: 0.75; }
}

.quote {
  border-left: 3px solid var(--accent);
  padding: 3px 0 3px 9px;
  margin-bottom: 4px;
  font-size: 13.5px;
  color: var(--muted);
  cursor: pointer;
  overflow-wrap: anywhere;
}

.quote-name { font-weight: 600; display: block; }
.quote-body { display: block; }

.msg.flash .bubble {
  animation: flash 1.1s ease-out;
}

@keyframes flash {
  0%   { box-shadow: 0 0 0 3px var(--accent); }
  100% { box-shadow: 0 0 0 3px transparent; }
}

.replying {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  font-size: 13.5px;
  color: var(--muted);
}

.replying-text {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.replying-text strong { color: var(--ink); }

#replying-cancel {
  flex: 0 0 auto;
  background: none;
  border: 0;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
}
