:root {
  --bg: #0b0f14;
  --panel: #111820;
  --panel-2: #16202b;
  --line: #1f2b38;
  --text: #e7edf3;
  --muted: #8698a9;
  --mine: #1f6feb;
  --theirs: #1b2836;
  --accent: #4ade80;
  --danger: #f87171;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

/* Must outrank the class-based `display` rules below, or an element carrying
   the hidden attribute (the media viewer, the typing dots) stays on screen. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

button {
  font: inherit;
  cursor: pointer;
}

/* ------------------------------------------------------------------ login */

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% 0%, #16202b 0%, var(--bg) 55%);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 32px 26px 24px;
  text-align: center;
  box-shadow: 0 24px 60px rgb(0 0 0 / 45%);
}

.login-mark {
  color: var(--mine);
  margin-bottom: 6px;
}

.login-card h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.4px;
}

.login-sub {
  margin: 4px 0 24px;
  color: var(--muted);
  font-size: 13px;
}

.login-card form {
  text-align: left;
  display: grid;
  gap: 6px;
}

.login-card label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

.login-card input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}

.login-card input:focus {
  outline: 2px solid var(--mine);
  outline-offset: 1px;
}

button.primary {
  margin-top: 18px;
  padding: 13px 16px;
  border: 0;
  border-radius: 12px;
  background: var(--mine);
  color: #fff;
  font-weight: 600;
}

button.primary:active {
  transform: translateY(1px);
}

.login-error {
  margin: 16px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.login-foot {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
}

/* ------------------------------------------------------------------- shell */

.shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.who {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.who strong {
  display: block;
  font-size: 15px;
}

.who small {
  color: var(--muted);
  font-size: 11.5px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #46586a;
  flex: 0 0 auto;
}

.dot[data-online="true"] {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgb(74 222 128 / 18%);
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline {
  margin: 0;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 7px 11px;
  border-radius: 10px;
  font-size: 12.5px;
}

button.ghost:hover {
  color: var(--text);
  border-color: #2c3d4f;
}

#wipeBtn:hover {
  color: var(--danger);
  border-color: rgb(248 113 113 / 45%);
}

.banner {
  padding: 8px 14px;
  font-size: 12.5px;
  text-align: center;
  background: rgb(248 113 113 / 12%);
  color: var(--danger);
  border-bottom: 1px solid rgb(248 113 113 / 25%);
}

/* ------------------------------------------------------------------ thread */

.thread {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.empty {
  margin: auto;
  max-width: 260px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.row {
  display: flex;
  animation: pop 0.18s ease-out;
}

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

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.bubble {
  position: relative;
  /* Column flow, so the meta row below counts towards the bubble's width. A
     two-letter message still has to be wide enough for its own timestamp. */
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: min(78%, 460px);
  padding: 8px 11px 8px;
  border-radius: var(--radius);
  background: var(--theirs);
  overflow: hidden;
  transition: opacity 0.35s ease, transform 0.35s ease, filter 0.35s ease;
}

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

.bubble.media {
  padding: 4px 4px 6px;
}

.bubble p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble img,
.bubble video {
  display: block;
  max-width: 100%;
  max-height: 60dvh;
  border-radius: 14px;
  background: #000;
}

.bubble .thumb {
  cursor: zoom-in;
}

.meta {
  align-self: flex-end;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  line-height: 1;
  /* Never let the clock wrap under the status - the pair sets the floor for how
     narrow a bubble can get. */
  white-space: nowrap;
  color: rgb(231 237 243 / 62%);
}

.meta .status:empty {
  display: none;
}

.bubble.media .meta {
  padding: 0 6px 2px;
}

.fuse {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: var(--accent);
  transform-origin: left center;
  opacity: 0;
}

.bubble.dying .fuse {
  opacity: 1;
  animation: burn linear forwards;
  animation-duration: var(--fuse, 15s);
}

@keyframes burn {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

.bubble.dying .meta {
  color: var(--accent);
}

.bubble.gone {
  opacity: 0;
  transform: scale(0.9);
  filter: blur(6px);
}

.hint {
  margin: 2px 0 0;
  font-size: 10.5px;
  color: var(--muted);
  text-align: center;
}

/* ----------------------------------------------------------------- typing */

.typing {
  display: flex;
  gap: 4px;
  padding: 0 20px 6px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes blink {
  0%,
  60%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* --------------------------------------------------------------- composer */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.attach {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
}

.attach:hover {
  color: var(--text);
}

#input {
  flex: 1;
  resize: none;
  max-height: 30dvh;
  padding: 11px 14px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}

#input:focus {
  outline: none;
  border-color: #2c3d4f;
}

.send {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 50%;
  background: var(--mine);
  color: #fff;
}

.send:disabled {
  opacity: 0.45;
  cursor: default;
}

.upload {
  padding: 0 14px 10px;
  background: var(--panel);
}

.upload-bar {
  height: 3px;
  border-radius: 3px;
  background: var(--panel-2);
  overflow: hidden;
}

.upload-bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--mine);
  transition: width 0.15s linear;
}

.upload small {
  color: var(--muted);
  font-size: 11px;
}

/* ----------------------------------------------------------------- viewer */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgb(0 0 0 / 92%);
  display: grid;
  grid-template-rows: auto 1fr;
}

.viewer-close {
  justify-self: end;
  margin: 12px 14px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid #2c3d4f;
  background: transparent;
  color: var(--text);
}

.viewer-stage {
  display: grid;
  place-items: center;
  padding: 0 12px calc(18px + var(--safe-b));
  min-height: 0;
}

.viewer-stage img,
.viewer-stage video {
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
}
