:root {
  --sky-0: #f4fbff;
  --sky-1: #dff3ff;
  --sky-2: #bfe6ff;
  --sky-3: #7ec8f0;
  --sky-4: #4aa8de;
  --sky-5: #2d86c4;
  --ink: #1c4d6e;
  --ink-soft: #4d7a97;
  --white: #ffffff;
  --bubble-prem: #ffffff;
  --bubble-phing: linear-gradient(160deg, #6ec4f2 0%, #3ea3dd 100%);
  --shadow: 0 12px 40px rgba(61, 140, 186, 0.18);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* JS overrides this with the visual viewport height so the mobile keyboard
     shrinks the chat instead of pushing the composer off screen. */
  --app-h: 100dvh;

  --pad-x: clamp(10px, 3.4vw, 18px);
  --row-gap: clamp(8px, 2.4vw, 13px);
  --fs-msg: clamp(14.5px, 3.9vw, 16.5px);
  --fs-meta: clamp(9.5px, 2.6vw, 11px);
  --fs-title: clamp(16px, 4.6vw, 20px);
  --fs-status: clamp(11px, 3vw, 13px);
  --avatar-lg: clamp(34px, 10vw, 42px);
  --avatar-sm: clamp(24px, 7.2vw, 30px);
  --control: clamp(42px, 12vw, 48px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
  height: 100%;
}

body {
  font-family: "Sarabun", "Mali", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 10% -10%, #c9ecff 0%, transparent 55%),
    radial-gradient(900px 600px at 110% 0%, #9ad6f7 0%, transparent 50%),
    linear-gradient(180deg, #eaf7ff 0%, #cfefff 48%, #b7e4fb 100%);
  overflow: hidden;
}

.sky {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.72);
  border-radius: 40px;
  filter: blur(0.2px);
  animation: drift 22s linear infinite;
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  background: inherit;
  border-radius: 50%;
}

.cloud.c1 {
  width: 120px;
  height: 38px;
  top: 8%;
  left: -20%;
  animation-duration: 28s;
}

.cloud.c1::before {
  width: 50px;
  height: 50px;
  top: -24px;
  left: 18px;
}

.cloud.c1::after {
  width: 70px;
  height: 70px;
  top: -36px;
  left: 48px;
}

.cloud.c2 {
  width: 90px;
  height: 30px;
  top: 22%;
  left: -30%;
  animation-duration: 34s;
  animation-delay: -8s;
  opacity: 0.7;
}

.cloud.c2::before {
  width: 40px;
  height: 40px;
  top: -18px;
  left: 12px;
}

.cloud.c2::after {
  width: 52px;
  height: 52px;
  top: -26px;
  left: 36px;
}

.cloud.c3 {
  width: 140px;
  height: 42px;
  top: 70%;
  left: -25%;
  animation-duration: 40s;
  animation-delay: -18s;
  opacity: 0.55;
}

.cloud.c3::before {
  width: 56px;
  height: 56px;
  top: -26px;
  left: 20px;
}

.cloud.c3::after {
  width: 74px;
  height: 74px;
  top: -38px;
  left: 56px;
}

.sparkle {
  position: absolute;
  color: #ffffff;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
  animation: twinkle 3.6s ease-in-out infinite;
  font-size: 14px;
}

.s1 { top: 12%; right: 12%; animation-delay: 0s; }
.s2 { top: 28%; left: 8%; color: #ffd6e7; animation-delay: 0.8s; }
.s3 { bottom: 18%; right: 10%; animation-delay: 1.4s; }
.s4 { bottom: 30%; left: 14%; color: #ffd6e7; animation-delay: 2s; }

.phone {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: var(--app-h);
  max-height: var(--app-h);
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.18));
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(8px, 2.4vw, 12px);
  padding: calc(clamp(9px, 2.6vw, 13px) + var(--safe-top)) var(--pad-x)
    clamp(9px, 2.6vw, 13px);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(255, 255, 255, 0.55));
  border-bottom: 1px solid rgba(126, 200, 240, 0.45);
}

.avatars {
  position: relative;
  flex: none;
  width: calc(var(--avatar-lg) * 1.45);
  height: var(--avatar-lg);
}

.avatar {
  position: absolute;
  width: var(--avatar-lg);
  height: var(--avatar-lg);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: "Mali", sans-serif;
  font-size: calc(var(--avatar-lg) * 0.42);
  font-weight: 700;
  color: white;
  border: 2px solid white;
  box-shadow: 0 6px 14px rgba(46, 122, 168, 0.22);
}

.avatar.prem {
  left: 0;
  background: linear-gradient(160deg, #7ed0f7, #3ea3dd);
  z-index: 1;
}

.avatar.phing {
  left: calc(var(--avatar-lg) * 0.45);
  background: linear-gradient(160deg, #9ad8f8, #67b7ea);
}

/* photo sits above the letter fallback, so only the photo shows when it loads */
.avatar::after,
.mini::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.avatar.prem::after,
.row.prem .mini::after {
  background-image: url("/img/prem.jpg");
}

.avatar.phing::after,
.row.phing .mini::after {
  background-image: url("/img/phing.jpg");
}

.who {
  min-width: 0;
}

.who h1 {
  font-family: "Mali", sans-serif;
  font-size: var(--fs-title);
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.who p {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-size: var(--fs-status);
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #45d09a;
  box-shadow: 0 0 0 4px rgba(69, 208, 154, 0.18);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ghost {
  border: 0;
  background: rgba(126, 200, 240, 0.22);
  color: var(--sky-5);
  font-family: inherit;
  font-size: clamp(12px, 3.2vw, 14px);
  font-weight: 600;
  padding: clamp(6px, 2vw, 9px) clamp(9px, 3vw, 13px);
  border-radius: 999px;
}

.cake-btn {
  font-size: clamp(14px, 4vw, 17px);
  padding: clamp(5px, 1.8vw, 8px) clamp(7px, 2.4vw, 10px);
}

.hidden {
  display: none !important;
}

.thread {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(12px, 3.6vw, 20px) var(--pad-x) clamp(6px, 2vw, 10px);
  display: flex;
  flex-direction: column;
  gap: var(--row-gap);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(126, 200, 240, 0.6) transparent;
}

.thread::-webkit-scrollbar {
  width: 6px;
}

.thread::-webkit-scrollbar-thumb {
  background: rgba(126, 200, 240, 0.55);
  border-radius: 999px;
}

/* keeps a short conversation resting at the bottom of the scroll area */
.thread > :first-child {
  margin-top: auto;
}

.day {
  align-self: center;
  font-size: var(--fs-meta);
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.55);
  padding: 4px 10px;
  border-radius: 999px;
}

.row {
  display: flex;
  align-items: flex-end;
  gap: clamp(6px, 1.8vw, 9px);
  max-width: min(86%, 30rem);
  animation: pop 0.28s ease;
}

.row.prem {
  align-self: flex-start;
}

.row.phing {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.mini {
  position: relative;
  flex: none;
  width: var(--avatar-sm);
  height: var(--avatar-sm);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  font-family: "Mali", sans-serif;
  font-size: calc(var(--avatar-sm) * 0.44);
  font-weight: 700;
}

.row.prem .mini {
  background: linear-gradient(160deg, #7ed0f7, #3ea3dd);
}

.row.phing .mini {
  background: linear-gradient(160deg, #9ad8f8, #67b7ea);
}

.bubble {
  position: relative;
  min-width: 0;
  padding: clamp(8px, 2.4vw, 12px) clamp(11px, 3.2vw, 15px);
  border-radius: clamp(15px, 4.6vw, 20px);
  font-size: var(--fs-msg);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.bubble .text {
  white-space: pre-wrap;
}

.bubble .gift {
  display: block;
  width: min(240px, 58vw);
  aspect-ratio: 1 / 1;
  object-fit: cover;
  margin-bottom: 8px;
  border-radius: clamp(12px, 3.4vw, 16px);
  background: linear-gradient(140deg, #eaf7ff, #cfeafb);
  box-shadow: 0 6px 14px rgba(46, 122, 168, 0.18);
  animation: gift-in 0.5s ease;
  cursor: zoom-in;
}

@keyframes gift-in {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: none; }
}

.row.prem .bubble {
  background: var(--bubble-prem);
  color: var(--ink);
  border-bottom-left-radius: 6px;
  box-shadow: 0 8px 18px rgba(80, 150, 190, 0.12);
}

.row.phing .bubble {
  background: var(--bubble-phing);
  color: white;
  border-bottom-right-radius: 6px;
  box-shadow: 0 8px 18px rgba(46, 134, 186, 0.22);
}

.time {
  margin-top: 4px;
  font-size: var(--fs-meta);
  opacity: 0.62;
}

.typing {
  display: flex;
  gap: 5px;
  padding: 12px 14px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7eb9d8;
  animation: bounce 1s infinite;
}

.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: clamp(6px, 2vw, 10px);
  padding: clamp(8px, 2.4vw, 12px) var(--pad-x)
    calc(clamp(10px, 2.8vw, 14px) + var(--safe-bottom));
  background: rgba(255, 255, 255, 0.78);
  border-top: 1px solid rgba(126, 200, 240, 0.4);
}

textarea {
  flex: 1 1 auto;
  min-width: 0;
  resize: none;
  border: 0;
  outline: none;
  min-height: var(--control);
  max-height: min(140px, 28vh);
  padding: clamp(10px, 2.8vw, 13px) clamp(13px, 3.6vw, 16px);
  border-radius: calc(var(--control) / 2);
  background: #eef8ff;
  color: var(--ink);
  font-family: inherit;
  /* keep at 16px+ so iOS Safari never zooms in on focus */
  font-size: max(16px, var(--fs-msg));
  line-height: 1.4;
}

textarea::placeholder {
  color: #7aa3bb;
}

#sendBtn {
  flex: none;
  width: var(--control);
  height: var(--control);
  border: 0;
  border-radius: 50%;
  color: white;
  background: linear-gradient(160deg, #6ec4f2, #2f95d0);
  box-shadow: 0 8px 16px rgba(47, 149, 208, 0.35);
  display: grid;
  place-items: center;
}

#sendBtn svg {
  width: calc(var(--control) * 0.4);
  height: calc(var(--control) * 0.4);
  margin-left: 2px;
}

#sendBtn:disabled,
.ghost:disabled {
  opacity: 0.45;
}

button {
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

@keyframes drift {
  from { transform: translateX(0); }
  to { transform: translateX(140vw); }
}

@keyframes twinkle {
  0%, 100% { opacity: 0.25; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.15); }
}

@keyframes pop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-5px); }
}

.bday {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 20%, rgba(255, 214, 232, 0.35), transparent 42%),
    rgba(28, 77, 110, 0.38);
  backdrop-filter: blur(10px);
}

.bday[hidden] {
  display: none;
}

.bday-card {
  position: relative;
  width: min(360px, 100%);
  max-height: calc(var(--app-h) - 36px);
  overflow: hidden auto;
  text-align: center;
  padding: 28px 22px 22px;
  border-radius: 28px;
  background:
    radial-gradient(circle at 20% 0%, #fff7fb 0%, transparent 40%),
    linear-gradient(180deg, #ffffff 0%, #eef8ff 100%);
  box-shadow: 0 24px 60px rgba(28, 77, 110, 0.28);
  animation: pop 0.45s ease;
}

.bday-confetti {
  pointer-events: none;
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.bday-confetti i {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  animation: fall 2.8s linear infinite;
}

.bday-kicker {
  font-family: "Mali", sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--sky-5);
}

.cake {
  position: relative;
  width: 180px;
  height: 168px;
  margin: 18px auto 10px;
}

.candles {
  position: absolute;
  left: 50%;
  top: 4px;
  z-index: 4;
  display: flex;
  gap: 18px;
  transform: translateX(-50%);
}

.candle {
  position: relative;
  width: 8px;
  height: 28px;
  border-radius: 3px 3px 2px 2px;
  background: linear-gradient(180deg, #fff 0 6px, #7ed0f7 6px 100%);
  box-shadow: 0 4px 0 #3ea3dd;
}

.candle.c-a { transform: translateY(4px); }
.candle.c-c { transform: translateY(4px); }

.flame {
  position: absolute;
  left: 50%;
  top: -14px;
  width: 10px;
  height: 16px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: radial-gradient(circle at 50% 70%, #fff6c8 0 28%, #ffb347 55%, #ff7a59 100%);
  transform: translateX(-50%);
  filter: drop-shadow(0 0 6px rgba(255, 170, 70, 0.85));
  animation: flicker 0.7s ease-in-out infinite alternate;
}

.bday.blown .flame {
  animation: none;
  opacity: 0;
  transform: translateX(-50%) scale(0.2);
  transition: 0.35s ease;
}

.layer {
  position: absolute;
  left: 50%;
  border-radius: 18px 18px 10px 10px;
  transform: translateX(-50%);
}

.layer.top {
  top: 34px;
  z-index: 3;
  width: 92px;
  height: 28px;
  background: linear-gradient(180deg, #fff 0%, #d9f1ff 100%);
  box-shadow:
    inset 0 -8px 0 rgba(126, 200, 240, 0.25),
    0 8px 0 #9ad6f7;
}

.layer.top::before {
  content: "♡";
  position: absolute;
  left: 50%;
  top: 4px;
  color: #ff8fab;
  font-size: 14px;
  transform: translateX(-50%);
}

.layer.top::after,
.layer.mid::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -7px;
  height: 10px;
  background:
    radial-gradient(circle at 12px 0, #fff 8px, transparent 9px),
    radial-gradient(circle at 32px 0, #fff 8px, transparent 9px),
    radial-gradient(circle at 52px 0, #fff 8px, transparent 9px);
}

.layer.mid {
  top: 58px;
  z-index: 2;
  width: 124px;
  height: 34px;
  background: linear-gradient(180deg, #c9ecff 0%, #7ec8f0 100%);
  box-shadow: 0 8px 0 #4aa8de;
}

.layer.mid::after {
  background:
    radial-gradient(circle at 16px 0, #c9ecff 9px, transparent 10px),
    radial-gradient(circle at 42px 0, #c9ecff 9px, transparent 10px),
    radial-gradient(circle at 70px 0, #c9ecff 9px, transparent 10px),
    radial-gradient(circle at 96px 0, #c9ecff 9px, transparent 10px);
}

.layer.base {
  top: 88px;
  z-index: 1;
  width: 156px;
  height: 40px;
  background: linear-gradient(180deg, #8fd4f6 0%, #3ea3dd 100%);
  box-shadow: 0 10px 0 #2d86c4;
}

.plate {
  position: absolute;
  left: 50%;
  bottom: 8px;
  width: 176px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffffff 0%, #d7ecf8 100%);
  transform: translateX(-50%);
  box-shadow: 0 10px 16px rgba(45, 134, 196, 0.22);
}

.bday-card h2 {
  font-family: "Mali", sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: var(--ink);
  margin-top: 4px;
}

.bday-sub {
  margin-top: 6px;
  font-weight: 600;
  color: var(--sky-5);
}

.bday-note {
  margin: 10px 0 16px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-soft);
}

#bdayClose {
  border: 0;
  width: 100%;
  padding: 12px 16px;
  border-radius: 999px;
  color: white;
  font-family: "Mali", sans-serif;
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(160deg, #6ec4f2, #2f95d0);
  box-shadow: 0 10px 18px rgba(47, 149, 208, 0.32);
}

@keyframes flicker {
  from { transform: translateX(-50%) scale(0.92) rotate(-6deg); }
  to { transform: translateX(-50%) scale(1.08) rotate(6deg); }
}

@keyframes fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(220px) rotate(220deg); opacity: 0; }
}

/* very narrow phones: keep the header from crowding the chat */
@media (max-width: 340px) {
  .avatars {
    display: none;
  }

  .row {
    max-width: 92%;
  }
}

/* landscape phones: reclaim vertical space for messages */
@media (max-height: 520px) and (orientation: landscape) {
  :root {
    --avatar-lg: 30px;
    --control: 40px;
  }

  .topbar {
    padding-top: calc(6px + var(--safe-top));
    padding-bottom: 6px;
  }

  .who p {
    display: none;
  }

  .thread {
    padding-top: 10px;
  }
}

@media (min-width: 720px) {
  :root {
    --fs-msg: 16px;
    --fs-title: 20px;
    --pad-x: 20px;
  }

  body {
    padding: 18px 0;
  }

  .phone {
    height: min(880px, calc(var(--app-h) - 36px));
    max-height: none;
    border-radius: 28px;
    border: 1px solid rgba(255, 255, 255, 0.7);
  }
}
