:root {
  --bg: #0b141a;
  --bg-pattern-color: #1f2c33;
  --bubble-bot: #ffffff;
  --bubble-user: #66a06b;
  --text-bot: #1a1a1a;
  --text-user: #ffffff;
  --accent: #ff8c2a;
  --max-width: 520px;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: #fff;
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("assets/bg-pattern.svg");
  background-repeat: repeat;
  background-size: 360px 360px;
  opacity: .06;
  pointer-events: none;
  z-index: 0;
}

.chat {
  position: relative;
  z-index: 1;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 32px) 12px 96px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-left: 2px solid #c97d2b40;
  border-right: 2px solid #c97d2b40;
  min-height: 100vh;
}

.row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  opacity: 0;
  transform: translateY(8px);
  animation: in .28s ease forwards;
}

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

@keyframes in {
  to { opacity: 1; transform: none; }
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: #333;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.row.reply + .row:not(.reply) .avatar,
.row:not(.reply) + .row:not(.reply) .avatar {
  /* keep avatar visible always for simplicity */
}

.bubble {
  background: var(--bubble-bot);
  color: var(--text-bot);
  padding: 8px 12px;
  border-radius: var(--radius);
  border-top-left-radius: 4px;
  max-width: 78%;
  word-wrap: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 1px #0004;
  font-size: 14.5px;
}

.bubble.user {
  background: var(--bubble-user);
  color: var(--text-user);
  border-top-left-radius: var(--radius);
  border-top-right-radius: 4px;
}

.bubble.media {
  padding: 4px;
  background: #fff;
}

.bubble.media img {
  display: block;
  max-width: 100%;
  border-radius: 10px;
}

.bubble.typing {
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
}

.bubble.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #999;
  animation: blink 1.2s infinite ease-in-out;
}
.bubble.typing span:nth-child(2) { animation-delay: .15s; }
.bubble.typing span:nth-child(3) { animation-delay: .30s; }

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

.options {
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  width: 100%;
}

.options button {
  background: var(--bubble-user);
  color: var(--text-user);
  border: 0;
  padding: 10px 16px;
  border-radius: 22px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px #0006;
  transition: transform .08s, filter .15s;
  max-width: 85%;
  text-align: center;
}

.options button:hover { filter: brightness(1.05); }
.options button:active { transform: scale(.97); }
.options button:disabled { opacity: .4; cursor: default; }

.cta {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 14px 22px;
  border-radius: 28px;
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 2px 8px #0008;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.04); }
}

.vsl-row {
  justify-content: center;
}

.vsl {
  width: 100%;
  max-width: 480px;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}

.vsl iframe,
.vsl video {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* Form input bubble */
.form-row { width: 100%; }

.form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 340px;
}

.form input {
  background: #fff;
  border: 2px solid transparent;
  border-radius: 22px;
  padding: 10px 16px;
  font: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color .15s;
}

.form input:focus { border-color: var(--bubble-user); }
.form input.err  { border-color: #e64545; }

.form button {
  background: var(--bubble-user);
  color: #fff;
  border: 0;
  padding: 10px 16px;
  border-radius: 22px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px #0006;
}

.form button:hover { filter: brightness(1.05); }
.form button:disabled { opacity: .4; cursor: default; }

.err-msg {
  color: #ff8a8a;
  font-size: 12px;
  padding: 0 12px;
  min-height: 14px;
}

/* Timer bubble */
.bubble.timer {
  background: #c92a2a;
  color: #fff;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 16px;
}

.bubble.timer .timer-label {
  font-size: 12px;
  font-weight: 500;
  opacity: .9;
}

.bubble.timer .timer-val {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
}

.row.expired .bubble.timer { background: #555; }

@media (max-width: 520px) {
  .chat {
    border-left: 0;
    border-right: 0;
    padding: calc(env(safe-area-inset-top, 0px) + 56px) 8px 80px;
  }
  .bubble { max-width: 82%; }
}
