/*
 * Dark is the default, unconditionally. It does not follow the visitor's
 * operating system preference, so a laptop set to light mode still gets the
 * dark page. Light is opt in: put data-theme="light" on the <html> element.
 */
:root {
  color-scheme: dark;

  --sw-blue: #044EF4;
  --sw-fuchsia: #F72A72;
  --sw-turquoise: #40E0D0;

  --bg-page: #0e0e18;
  --bg-surface: #181a28;
  --bg-surface-raised: #222436;

  --fg-default: #f0f0f4;
  --fg-secondary: #e8e8ec;
  --fg-muted: #a0a0aa;
  --fg-headings: #f0f0f4;

  --border-default: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.15);
  --row-hover: rgba(255, 255, 255, 0.03);

  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);

  --font-body: 'Lexend', system-ui, sans-serif;
  --font-code: 'JetBrains Mono', ui-monospace, monospace;

  --radius-md: 8px;
  --radius-full: 100px;
}

/* Light mode, applied only when explicitly requested. */
:root[data-theme="light"] {
  color-scheme: light;

  --bg-page: #FAFBFC;
  --bg-surface: #F3F4F6;
  --bg-surface-raised: #E8EAF0;

  --fg-default: #1A1A18;
  --fg-secondary: #3A3A38;
  --fg-muted: #737371;
  --fg-headings: #070c2d;

  --border-default: rgba(0, 0, 0, 0.1);
  --border-strong: rgba(0, 0, 0, 0.18);
  --row-hover: rgba(0, 0, 0, 0.02);

  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg-page);
  color: var(--fg-default);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
}

/* The number is the page heading, so h1 carries no styling of its own. */
h1 {
  margin: 0;
  font: inherit;
}

.fallback-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--fg-headings);
}

/* ---------- masthead ---------- */

.masthead {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 1.25rem 1rem 1rem;
  background: var(--bg-page);
  border-bottom: 1px solid var(--border-default);
}

.masthead__inner {
  max-width: 1080px;
  margin-inline: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  align-items: flex-start;
  justify-content: space-between;
}

.masthead__identity {
  flex: 1 1 20rem;
  min-width: 0;
}

/* Status pinned to the top right, QR justified to the same right edge. */
.masthead__aside {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.85rem;
  flex-shrink: 0;
}

.dial {
  display: inline-block;
  font-family: var(--font-code);
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--fg-default);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: border-color 0.2s ease;
  white-space: nowrap;
}

.dial:hover { border-bottom-color: var(--sw-fuchsia); }

.vanity__word {
  color: var(--sw-fuchsia);
  font-weight: 600;
}

.dial__full {
  margin: 0.2rem 0 0;
  font-family: var(--font-code);
  font-size: 15px;
  color: var(--fg-muted);
}

.dial__hint {
  margin: 0.4rem 0 0;
  font-size: 14px;
  color: var(--fg-muted);
}

/* Deliberately light in both themes: inverted QR codes scan unreliably. */
.qr {
  display: block;
  width: 172px;
  height: 172px;
  padding: 8px;
  background: #FAFBFC;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  flex-shrink: 0;
}

.qr svg { display: block; width: 100%; height: 100%; }

.qr:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(4, 78, 244, 0.3);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.85rem;
  background: var(--bg-surface-raised);
  border-radius: var(--radius-full);
  font-size: 13px;
  color: var(--fg-secondary);
}

.status__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fg-muted);
  flex-shrink: 0;
}

.status[data-state="live"] .status__dot {
  background: var(--sw-turquoise);
  box-shadow: 0 0 0 0 rgba(64, 224, 208, 0.5);
  animation: pulse 2.4s ease-out infinite;
}

.status[data-state="down"] .status__dot { background: var(--sw-fuchsia); }

@keyframes pulse {
  70% { box-shadow: 0 0 0 7px rgba(64, 224, 208, 0); }
  100% { box-shadow: 0 0 0 0 rgba(64, 224, 208, 0); }
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 0.6rem;
  margin-top: 1.1rem;
}

.input {
  flex: 0 1 auto;
  width: 15rem;
  max-width: 100%;
  padding: 0.5rem 0.85rem;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--fg-default);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
}

.input::placeholder { color: var(--fg-muted); }

.input:focus-visible,
.btn:focus-visible {
  outline: none;
  border-color: var(--sw-blue);
  box-shadow: 0 0 0 3px rgba(4, 78, 244, 0.3);
}

.btn {
  padding: 0.5rem 0.9rem;
  min-height: 40px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  color: var(--fg-secondary);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.btn:hover { background: var(--row-hover); color: var(--fg-default); }

/* ---------- message bubbles ---------- */

main { padding: 2rem 1rem 4rem; }

.feed {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Every message here is inbound, so bubbles are centered rather than sided. */
.msg { text-align: center; }

.msg[hidden] { display: none; }

.bubble {
  display: inline-block;
  position: relative;
  max-width: 100%;
  padding: 1.05rem 1.5rem;
  text-align: left;
  background: var(--sw-blue);
  border-radius: 27px;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.bubble:hover { transform: translateY(-2px); }

.bubble[aria-expanded="true"] {
  box-shadow: 0 0 0 3px rgba(247, 42, 114, 0.5), var(--shadow-md);
}

.bubble:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(247, 42, 114, 0.5), var(--shadow-md);
}

/* The tail, centered beneath the bubble. */
.bubble::after {
  content: "";
  position: absolute;
  bottom: -11px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 12px solid var(--sw-blue);
}

.bubble__text {
  margin: 0;
  color: #fff;
  font-weight: 600;
  font-size: 21px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble__text--empty { opacity: 0.75; font-style: italic; font-weight: 400; }

.bubble__media {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.85rem;
}

.bubble__media:empty { display: none; }

.thumb {
  display: block;
  max-width: 275px;
  max-height: 275px;
  border-radius: 17px;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.bubble__media a {
  font-family: var(--font-code);
  font-size: 14px;
  color: #fff;
  text-decoration: underline;
}

.msg__meta {
  margin: 1.1rem 0 0;
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 0.4rem;
  font-family: var(--font-code);
  font-size: 14px;
}

.msg__from { color: var(--fg-secondary); }
.msg__time { color: var(--fg-muted); font-size: 13px; }
.msg__time::before { content: "\00b7\00a0"; }

.msg--new { animation: pop 0.42s cubic-bezier(0.18, 1.3, 0.4, 1); }

@keyframes pop {
  from { opacity: 0; transform: translateY(14px) scale(0.88); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.msg--leaving {
  animation: vanish 0.2s ease-in forwards;
  pointer-events: none;
}

@keyframes vanish {
  to { opacity: 0; transform: scale(0.9); }
}

/* ---------- remove popover ---------- */

.popover {
  position: fixed;
  z-index: 200;
  padding: 0.3rem;
  background: var(--bg-surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.popover[hidden] { display: none; }

.popover__btn {
  display: block;
  padding: 0.45rem 1.1rem;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  color: var(--sw-fuchsia);
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}

.popover__btn:hover { background: rgba(247, 42, 114, 0.12); }

.popover__btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(247, 42, 114, 0.6);
}

@media (prefers-reduced-motion: reduce) {
  .msg--new,
  .msg--leaving { animation: none; }
  .bubble:hover { transform: none; }
  .status[data-state="live"] .status__dot { animation: none; }
}

@media (min-width: 768px) {
  .masthead { padding: 1.5rem 2rem 1.15rem; }
  main { padding: 2.5rem 2rem 5rem; }
}
