:root {
  --bg-color: #814e39; /* Dark Chocolate Brown */
  --chat-bg: #5d4037; /* Slightly lighter brown */
  --header-bg: #814e39; /* Very dark brown */
  --user-bubble: #d4a373; /* Milk Tea Color */
  --partner-bubble: #814e39; /* Dark Coffee */
  --text-user: #ffffff;
  --text-partner: #ffecb3; /* Creamy text */
  --green: #34c759;
  --accent: #ffb74d;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  padding: 0;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  background-color: var(--bg-color);
  height: 100vh; /* Fallback for older browsers */
  height: 100dvh; /* Dynamic viewport height for mobile browsers */
  display: flex;
  justify-content: center;
  overflow: hidden;
}

.phone-frame {
  width: 100%;
  max-width: 450px; /* Max width for desktop viewing */
  height: 100%;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

.chat-header {
  height: 60px;
  background: var(--header-bg);
  color: white;
  border-bottom: 1px solid #5d4037;
  display: flex;
  align-items: center;
  padding: 0 15px;
  /* Safe Area Support */
  padding-top: env(safe-area-inset-top);
  height: calc(60px + env(safe-area-inset-top));
  z-index: 10;
  position: absolute;
  top: 0;
  width: 100%;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  position: relative;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.avatar::after {
  content: "";
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background: var(--green);
  border: 2px solid white;
  border-radius: 50%;
}

.header-info {
  display: flex;
  flex-direction: column;
}

.name {
  font-weight: 600;
  font-size: 16px;
}

.status {
  font-size: 12px;
  color: #d7ccc8;
  opacity: 0.8;
}

.chat-area {
  flex: 1;
  padding: calc(70px + env(safe-area-inset-top)) 15px 100px 15px; /* Top padding adjusts for header+notch */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: var(--chat-bg);
  /* Custom Boba Pattern Background */
  background-image: url("data:image/svg+xml,%3Csvg width='200' height='200' viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cstyle%3E.cup%7Bfill:%23D4A373;stroke:%233E2723;stroke-width:2%7D.lid%7Bfill:%23EFEBE9;stroke:%233E2723;stroke-width:2%7D.pearl%7Bfill:%233E2723%7D.straw%7Bstroke:%233E2723;stroke-width:3;fill:none%7D.face%7Bfill:%233E2723%7D%3C/style%3E%3C/defs%3E%3Cg transform='translate(40 40) rotate(-10)' opacity='0.3'%3E%3Cline x1='25' y1='5' x2='35' y2='-15' class='straw'/%3E%3Cpath d='M10 5h30l-5 40H15z' class='cup'/%3E%3Cpath d='M10 5Q25 0 40 5' class='lid' fill='none'/%3E%3Ccircle cx='20' cy='38' r='2.5' class='pearl'/%3E%3Ccircle cx='30' cy='38' r='2.5' class='pearl'/%3E%3Ccircle cx='25' cy='35' r='2.5' class='pearl'/%3E%3Ccircle cx='18' cy='20' r='1.5' class='face'/%3E%3Ccircle cx='32' cy='20' r='1.5' class='face'/%3E%3Cpath d='M22 22q3 3 6 0' stroke='%233E2723' fill='none' stroke-width='1.5'/%3E%3C/g%3E%3Cpath d='M140 40l5 15h15l-12 10 4 15-12-10-12 10 4-15-12-10h15z' fill='%23FFB74D' transform='scale(.8) translate(20 0)' opacity='0.3'/%3E%3Cpath d='M40 140q0-10 10-15 10-5 20 15 10-20 20-15 10 5 10 15 0 15-30 35-30-20-30-35z' fill='%23EF5350' transform='scale(.6) translate(-20 50)' opacity='0.3'/%3E%3Cg transform='translate(140 140) rotate(10)' opacity='0.3'%3E%3Cline x1='25' y1='5' x2='15' y2='-15' class='straw'/%3E%3Cpath d='M10 5h30l-5 40H15z' class='cup'/%3E%3Ccircle cx='20' cy='38' r='2.5' class='pearl'/%3E%3Ccircle cx='30' cy='38' r='2.5' class='pearl'/%3E%3Ccircle cx='25' cy='35' r='2.5' class='pearl'/%3E%3Ccircle cx='18' cy='20' r='1.5' class='face'/%3E%3Ccircle cx='32' cy='20' r='1.5' class='face'/%3E%3Cpath d='M22 22q3 3 6 0' stroke='%233E2723' fill='none' stroke-width='1.5'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 150px 150px;

  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch; /* smooth scrolling iOS */
}

.message {
  max-width: 75%;
  padding: 10px 16px;
  border-radius: 18px;
  font-size: 16px;
  line-height: 1.4;
  position: relative;
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  transform-origin: bottom left;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.message.received {
  background-color: var(--partner-bubble);
  color: var(--text-partner);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border: 1px solid #6d4c41;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.message.sent {
  background-color: var(--user-bubble);
  color: var(--text-user);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  transform-origin: bottom right;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.message.media {
  padding: 0;
  background: transparent;
  border-radius: 12px;
  overflow: hidden;
  border: none;
}
.message.media img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 200px;
}

.timestamp {
  font-size: 10px;
  margin-top: 4px;
  opacity: 0.7;
  text-align: right;
  color: inherit;
}

.typing-indicator {
  background-color: var(--partner-bubble);
  width: fit-content;
  padding: 12px 16px;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  display: none; /* Hidden by default */
  gap: 4px;
  align-self: flex-start;
  margin-bottom: 5px;
}

.dot {
  width: 8px;
  height: 8px;
  background: #d7ccc8;
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) {
  animation-delay: -0.32s;
}
.dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

.input-area {
  position: absolute;
  bottom: 0;
  width: 100%;
  /* width: 100%; */ /* Duplicate removed */
  background: var(--header-bg);
  border-top: 1px solid #5d4037;
  padding: 15px;
  /* Safe Area Support */
  padding-bottom: calc(15px + env(safe-area-inset-bottom));
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.options-container {
  display: flex;
  gap: 10px;
  width: 100%;
  justify-content: center;
  flex-wrap: wrap; /* Allow wrapping on small screens */
}

.reply-btn {
  background: var(--user-bubble);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 25px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition:
    transform 0.2s,
    background 0.2s;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  /* Improve touch target */
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.reply-btn:active {
  transform: scale(0.95);
}

.btn-no {
  background: #5d4037;
  color: #ffecb3;
  transition: all 0.3s ease;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  background-color: #f00;
  animation: fall linear forwards;
  top: -10px;
  z-index: 50;
  pointer-events: none; /* Prevent blocking clicks */
}

@keyframes fall {
  to {
    transform: translateY(100vh) rotate(720deg);
  }
}
