/* Root palette */
:root {
  --bg: #ececec;
  --panel: #ffffff;
  --card: rgb(204, 204, 204);
  --text: #e7e7e7;
  --muted: #a6aab3;
  --accent: #6da7ff;
  --accent-2: #4ddc8b;
  --border: #ffffff;

  /* AI bubble dynamic colors (updated via JS) */
  --ai-bubble-bg: var(--card);
  --ai-bubble-text: var(--text);

  /* Chatbox fill color (drives masked bg) */
  --chatbox-color: #ffffff;

  /* Visitor */
  --visitor-gray-light: #f8f2f2;
  --visitor-gray-dark: #504c49;

  /* Char 1 */
  --char1-yellow-light: #f0e0c5;
  --char1-yellow-dark: #f6bd4b;

  /* Char 2 */
  --char2-purple-light: #e4cbd9;
  --char2-purple-dark: #9c4771;

  /* Char 3 */
  --char3-blue-light: #d2deee;
  --char3-blue-dark: #389fc7;

  /* Char 4 */
  --char4-green-light: #d0cea0;
  --char4-green-dark: #595c2f;

  /* Char 5 */
  --char5-red-light: #f3cdc0;
  --char5-red-dark: #c66363;

  --chat-vpad: clamp(12px, 2.5vh, 24px);
}

/* Reset-ish */
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  overflow: hidden;
}
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto,
    Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Character name */
#char_name {
  margin: 0 0 12px;
  text-align: center;
  font-weight: bold;
  color: var(--char-name-color, var(--text));
  transition: color 180ms ease;
}

/* Layout */
.container {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
}

/* Avatar header */
.app-header.avatars {
  min-height: 70px; /* enforce min height */
  height: 10vh;
  padding: 8px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.avatar {
  height: 100%;
  aspect-ratio: 1 / 1;
  width: auto;
  object-fit: contain;
  display: block;
}
@media (max-width: 480px) {
  .avatar {
    height: 70px;
  }
}
/* Make avatars clickable & focus-visible */
.avatar.is-clickable {
  cursor: pointer;
}
.avatar.is-clickable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Chat area */
.chat {
  position: relative;
  flex: 1 1 auto;
  min-height: 0; /* critical for flex scroll */
  width: 100%;
  padding: var(--chat-vpad);
  padding-bottom: max(var(--chat-vpad), env(safe-area-inset-bottom));
  overflow: hidden; /* keep bg layer tidy */
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
}
.chat > * {
  position: relative;
  z-index: 1;
}

/* Masked background layer */
.chat::before {
  content: "";
  position: absolute;
  inset: 0;
  background-color: var(--chatbox-color);
  z-index: 0;
  pointer-events: none;

  -webkit-mask-image: url("assets/ui_chatBG.svg");
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: top center;
  -webkit-mask-size: 100% auto;

  mask-image: url("assets/ui_chatBG.svg");
  mask-repeat: no-repeat;
  mask-position: top center;
  mask-size: 100% auto;

  transition: background-color 180ms ease;
}
/* Desktop / large screens: let mask flex to fill */
@media (min-width: 992px) and (orientation: landscape) {
  .chat::before {
    -webkit-mask-size: 100% auto;
    mask-size: 100% auto;
  }
}

/* Messages list */
#messages.messages {
  flex: 1 1 auto;
  min-height: 0; /* critical */
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
  display: flex;
  flex-direction: column;
}

/* Bubbles */
.msg {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 12px;
  margin-bottom: 10px;
  line-height: 1.3;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg.user {
  background: var(--visitor-gray-light);
  color: var(--visitor-gray-dark);
  margin-left: auto;
  border-bottom-right-radius: 4px;
}
.msg.ai {
  background: var(--ai-bubble-bg);
  color: var(--ai-bubble-text);
  margin-right: auto;
  border-bottom-left-radius: 4px;
  border: none;
  transition: background-color 180ms ease, color 180ms ease;
}
.msg.system {
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  margin-left: auto;
  margin-right: auto;
  width: fit-content;
  max-width: 100%;
}

/* Composer (chat form) */
form#chatForm.composer {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  border-radius: 10px;

  background: var(--ai-bubble-bg);
  background: color-mix(in srgb, var(--ai-bubble-bg) 50%, transparent);
}

/* Input box (borderless) */
input#chatInput.input {
  flex: 1;
  font-size: 16px;
  border: none;
  background: var(--chatbox-color);
  color: rgb(100, 100, 100);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
}
input#chatInput.input::placeholder {
  color: rgba(100, 100, 100, 0.7);
}

/* Send button */
form#chatForm .send {
  border: none;
  background: var(--visitor-gray-dark);
  color: var(--visitor-gray-light);
  padding: 0 16px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}
form#chatForm .send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Scrollbar */
#messages.messages::-webkit-scrollbar {
  width: 10px;
}
#messages.messages::-webkit-scrollbar-thumb {
  background: #2b2f36;
  border-radius: 6px;
}
#messages.messages::-webkit-scrollbar-track {
  background: transparent;
}

/* Intro screen */
.intro-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 99999;
  cursor: pointer;
  pointer-events: auto;
  overflow: hidden;
}

.intro-screen * {
  pointer-events: auto;
}

/* Desktop / landscape ticket sizing */
.intro-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

/* Mobile / portrait ticket sizing */
@media (orientation: portrait) {
  .intro-img {
    width: 100vw;
    height: auto;
  }
}

.intro-note {
  margin-top: 16px;
  color: var(--muted);
  font-size: 14px;
}

.hidden {
  display: none !important;
}
