.continue-arrow {
  display: inline-block;
  margin-left: 10px;
  transition: transform 0.22s cubic-bezier(.4,1.4,.6,1), opacity 0.22s cubic-bezier(.4,1.4,.6,1);
  opacity: 0.7;
  font-size: 1.2em;
  position: relative;
  top: 1px;
}
.minimal-welcome-actions button:hover .continue-arrow {
  transform: translateX(8px);
  opacity: 1;
}
:root {
  color-scheme: light;
  --bg: #f4f4f4;
  --surface: #ffffff;
  --surface-soft: #f8f8f8;
  --border: #d9d9d9;
  --border-strong: #bdbdbd;
  --text: #101010;
  --muted: #5f5f5f;
  --black: #111111;
  --white: #ffffff;
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow-soft: 0 10px 28px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body,
input,
textarea,
button,
select {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  min-height: 100vh;
}

.main {
  max-width: 980px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: 58px;
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: min(980px, 100%);
  height: 58px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
  box-sizing: border-box;
}

.topbar-title {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 18px 180px;
  display: flex;
  flex-direction: column;
}


/* Minimal Welcome Overlay Styles */
#welcomeOverlay {
  position: fixed;
  z-index: 2000;
  inset: 0;
  background: rgba(244,244,244,0.98);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.minimal-welcome-sheet {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-soft);
  padding: 48px 80px 32px 80px;
  max-width: 1000px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 32px;
}

.minimal-welcome-center {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 18px;
  width: 100%;
}

.simon-big {
  font-size: clamp(44px, 10vw, 64px);
  font-weight: 800;
  letter-spacing: -0.04em;
  margin: 0 0 8px 0;
  color: var(--black);
  text-align: left;
}

.simon-desc {
  font-size: 22px;
  font-weight: 600;
  background: linear-gradient(90deg, #4f8cff 0%, #7f53ff 50%, #ff6ec4 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: left;
  margin-bottom: 0;
  letter-spacing: -0.01em;
  line-height: 1.4;
  filter: drop-shadow(0 2px 8px rgba(127,83,255,0.08));
  transition: background 0.3s;
}

.minimal-welcome-actions {
  width: 100%;
  display: flex;
  justify-content: flex-start;
}

.minimal-welcome-actions button {
  font-size: 17px;
  font-weight: 600;
  padding: 14px 0;
  border-radius: 999px;
  border: none;
  background: var(--black);
  color: var(--white);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  transition: background 0.15s, box-shadow 0.18s cubic-bezier(.4,1.4,.6,1), transform 0.18s cubic-bezier(.4,1.4,.6,1);
  width: 100%;
  display: block;
}
.minimal-welcome-actions button:hover {
  background: #222;
  box-shadow: 0 8px 24px rgba(0,0,0,0.13);
  transform: translateY(-3px) scale(1.03);
}

.minimal-welcome-legal {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  z-index: 2100;
  pointer-events: none;
  max-width: 480px;
  width: 92vw;
}
.minimal-welcome-legal small {
  pointer-events: auto;
  display: block;
}
.minimal-welcome-legal a {
  color: var(--muted);
  text-decoration: underline;
}

.messages {
  width: min(760px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.message.user {
  align-items: flex-end;
}

.message .role {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.bubble {
  max-width: min(78ch, 88%);
  width: fit-content;
  padding: 13px 15px;
  border-radius: 20px;
  line-height: 1.56;
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.message.user .bubble {
  background: #efefef;
  border: 1px solid var(--border);
  border-bottom-right-radius: 10px;
}

.message.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 10px;
}

.bubble p {
  margin: 0 0 0.66em;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble h1,
.bubble h2,
.bubble h3,
.bubble h4,
.bubble h5,
.bubble h6 {
  margin: 0.9em 0 0.45em;
  line-height: 1.25;
}

.bubble h1,
.bubble h2 {
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3em;
}

.bubble ul,
.bubble ol {
  margin: 0.4em 0 0.7em 1.2em;
  padding: 0;
}

.bubble li {
  margin: 0.28em 0;
}

.bubble pre {
  margin: 0.65em 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-soft);
  overflow: auto;
}

.bubble code {
  font-size: 0.92em;
}

.bubble blockquote {
  margin: 0.75em 0;
  padding: 0.5em 0.9em;
  border-left: 3px solid var(--border-strong);
  color: var(--muted);
}

.bubble hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1em 0;
}

.message.assistant.loading .bubble {
  min-width: 220px;
  background: var(--surface-soft);
}

.message.assistant.loading .bubble .loading-status {
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
  margin-bottom: 10px;
}

.message.assistant.loading .bubble .loading-lines {
  display: grid;
  gap: 8px;
}

.message.assistant.loading .bubble .loading-line {
  display: block;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #e4e4e4 0%, #f2f2f2 45%, #e4e4e4 100%);
  background-size: 220% 100%;
  animation: neutralShimmer 1.1s linear infinite;
}

.message.assistant.loading .bubble .loading-line.line-1 {
  width: 74%;
}

.message.assistant.loading .bubble .loading-line.line-2 {
  width: 56%;
}

.composer-wrap {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 1100;
  width: min(860px, calc(100% - 24px));
}

.composer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.composer textarea {
  flex: 1 1 240px;
  min-height: 46px;
  max-height: 260px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text);
  outline: none;
  resize: none;
  padding: 11px 14px;
  line-height: 1.45;
  font-size: 15px;
}

/* Hide native scrollbars for the message input while keeping scroll functionality */
.composer textarea,
#messageInput {
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE 10+ */
}
.composer textarea::-webkit-scrollbar,
#messageInput::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.composer textarea:focus {
  border-color: #8f8f8f;
  background: var(--white);
}

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

.composer button {
  width: 46px;
  height: 46px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--black);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  padding: 0;
}

.composer button:hover {
  background: #ececec;
}

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

.composer .send-btn {
  background: var(--black);
  border-color: var(--black);
  color: var(--white);
}

.composer .send-btn:hover {
  background: #000;
}

.icon {
  width: 20px;
  height: 20px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.attachments-preview {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
  font-size: 13px;
}

.attachment-chip img {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  object-fit: cover;
}

.remove-attach {
  border: 0;
  background: transparent;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  line-height: 1;
}

.remove-attach:hover {
  background: #ececec;
  color: var(--text);
}

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.generated-images {
  margin-top: 8px;
  width: min(420px, 92vw);
  display: grid;
  gap: 8px;
}

.generated-image {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
}

.disclaimer {
  margin: 8px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.command-confirmation {
  position: absolute;
  right: 12px;
  top: -34px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #0a84ff;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: 0 6px 16px rgba(10, 132, 255, 0.28);
  opacity: 0;
  transform: translateY(6px) scale(0.96);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 120;
}

.command-confirmation.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.composer .command-autocomplete {
  position: absolute;
  left: 8px;
  bottom: calc(100% + 8px);
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #ffffff !important;
  color: #111827;
  display: none;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  min-width: 272px;
  width: auto !important;
  height: auto !important;
  min-height: 0 !important;
  font-size: 12px;
  line-height: 1.1;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
  cursor: pointer;
  z-index: 140;
}

.composer .image-mode-pill {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  min-width: 92px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  height: 24px;
  cursor: pointer;
  z-index: 145;
}

.image-mode-pill-icon {
  font-size: 12px;
  line-height: 1;
}

.image-mode-pill-close {
  font-size: 13px;
  line-height: 1;
  color: #2563eb;
}

.composer.image-command-active .composer-input-wrap textarea {
  padding-left: 112px !important;
}

.command-autocomplete-icon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid #dbe4ff;
  background: #eef4ff;
  display: inline-grid;
  place-items: center;
  flex: none;
}

.command-autocomplete-icon svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: #1d4ed8;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.command-autocomplete-content {
  display: grid;
  gap: 2px;
  text-align: left;
}

.command-autocomplete-name {
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #0f172a;
}

.command-autocomplete-desc {
  color: #64748b;
  font-weight: 500;
  font-size: 11px;
}

.command-autocomplete-hint {
  margin-left: auto;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  background: #f8fafc;
  color: #475569;
  padding: 3px 7px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

body.imessage-mode .composer.image-command-active textarea {
  border-color: #86efac !important;
  box-shadow: none !important;
}

body.imessage-mode .composer.image-command-active .command-autocomplete {
  background: #ffffff !important;
  border-color: #86efac;
  box-shadow: 0 8px 20px rgba(22, 163, 74, 0.16);
}

.scroll-indicator {
  position: fixed;
  right: 16px;
  bottom: 94px;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid #2a2a2a;
  background: #1a1a1a;
  color: #fff;
  box-shadow: var(--shadow-soft);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1200;
}

.scroll-indicator.visible {
  display: inline-grid;
}

#authOverlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.72);
}

.auth-sheet {
  width: min(460px, calc(100% - 28px));
  padding: 28px;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.2);
}

.auth-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 12px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--border);
}

.auth-sheet h2 {
  margin: 0 0 14px;
  font-size: 20px;
  line-height: 1.25;
}


.auth-actions {
  margin-top: 18px;
}

.auth-actions button {
  min-width: 128px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--black);
  background: var(--black);
  color: var(--white);
  font-weight: 600;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.18s;
}
.auth-actions button:hover {
  background: #222;
}

/* Welcome/terms overlay */
#welcomeOverlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #fff;
  z-index: 2000;
  animation: fadeInBg 0.5s;
}
@keyframes fadeInBg {
  from { background: rgba(255,255,255,0.7); }
  to { background: #fff; }
}
.auth-sheet {
  background: #fff !important;
  border: 2px solid #e5e7eb;
  border-radius: 22px;
  padding: 48px 0 48px 0;
  max-width: 1100px;
  min-width: 700px;
  margin: 0 auto;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 48px;
}
.auth-icon {
  background: #e0e7ef;
  color: #2563eb;
  border: none;
  margin-bottom: 0;
  margin-left: 48px;
  margin-right: 0;
  width: 110px;
  height: 110px;
  min-width: 110px;
  min-height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.welcome-content {
  flex: 1 1 0%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding-right: 48px;
}
.auth-sheet h2 {
  font-size: 2.2rem;
  font-weight: 700;
  color: #23272f;
  margin-bottom: 10px;
  margin-top: 0;
}
.auth-sub {
  color: #6b7280;
  font-size: 1.1rem;
  margin-bottom: 22px;
}
.welcome-terms {
  list-style: none;
  padding: 0;
  margin: 18px 0 0 0;
  text-align: left;
  width: 100%;
  max-width: 420px;
}
.welcome-terms li {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 1.13rem;
  margin-bottom: 12px;
  color: #23272f;
  background: none;
  border-radius: 0;
  padding: 0 0 0 0;
}
.term-icon {
  font-size: 1.5rem;
  width: 2.2em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #e0e7ef;
  border-radius: 7px;
  height: 2.2em;
  margin-right: 8px;
}
.auth-actions {
  width: 100%;
  max-width: 420px;
  margin-left: 0;
  margin-right: 0;
  display: flex;
  justify-content: flex-start;
  margin-top: 24px;
}
.auth-actions button {
  background: #2563eb;
  color: #fff;
  border: none;
  font-weight: 600;
  font-size: 1.13rem;
  transition: background 0.18s;
  width: 100%;
  padding: 15px 0;
  border-radius: 8px;
  letter-spacing: 0.01em;
  margin-top: 0;
}
.auth-actions button:hover {
  background: #1d4ed8;
}

.shake {
  animation: shake 420ms cubic-bezier(.36, .07, .19, .97);
}

.stagger-char {
  display: inline-block;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 80ms ease, transform 120ms cubic-bezier(.2, .8, .2, 1);
}

.stagger-char.visible {
  opacity: 1;
  transform: translateY(0);
}

@keyframes neutralShimmer {
  0% {
    background-position: 120% 0;
  }
  100% {
    background-position: -120% 0;
  }
}

@keyframes shake {
  0% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
  100% { transform: translateX(0); }
}

@media (max-width: 700px) {
  .main {
    max-width: 100%;
  }

  .topbar {
    width: 100%;
    padding: 0 12px;
  }

  .chat-area {
    padding: 16px 10px 172px;
  }

  .messages {
    width: 100%;
    gap: 12px;
  }

  .message .role {
    font-size: 10px;
  }

  .bubble {
    max-width: 94%;
    border-radius: 18px;
    padding: 12px 13px;
    font-size: 14px;
  }

  .composer-wrap {
    width: calc(100% - 12px);
    bottom: max(8px, env(safe-area-inset-bottom));
  }

  .composer {
    gap: 8px;
    padding: 8px;
    border-radius: 20px;
  }

  .composer textarea {
    flex-basis: 100%;
    min-height: 44px;
  }

  .composer-actions {
    margin-left: auto;
  }

  .composer button {
    width: 44px;
    height: 44px;
  }

  .scroll-indicator {
    right: 10px;
    bottom: 90px;
  }

  .auth-sheet {
    padding: 22px 18px;
    border-radius: 20px;
  }
}:root {
  color-scheme: light;
  --bg: #f7f7f8; /* very light grey page bg */
  --panel: #ffffff; /* panels */
  --panel-border: #e6e6e9; /* subtle neutral border */
  --text: #0f1720; /* near-black text */
  --muted: #6b7280; /* grey muted */
  --hover: #f1f3f5; /* subtle hover */
  --bubble-user: #f3f4f6; /* light grey bubble */
  --bubble-assistant: #ffffff; /* assistant white */
  --input-bg: #ffffff;
  --input-border: #e6e6e9;
  --accent: #0b1220; /* dark accent for primary actions */
  --radius-lg: 32px;
  --radius-md: 20px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Force consistent sans-serif across all controls to avoid monospace fallbacks */
html, body, input, textarea, button, select {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  padding: 18px;
  gap: 14px;
  transition: transform 0.2s ease;
  box-shadow: 0 18px 48px rgba(12, 14, 16, 0.06);
  border-radius: calc(var(--radius-lg) - 6px);
}

.sidebar-top {
  display: flex;
}

.sidebar-btn {
  width: 100%;
  background: transparent;
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  border: 0;
}

.sidebar-btn:hover,
.history-item:hover {
  background: var(--hover);
}

/* Minimal new chat button */
.new-chat-btn {
  width: 100%;
  padding: 8px 12px; /* slightly smaller vertical size */
  border-radius: 999px;
  background: #0b1220; /* dark pill */
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  color: #fff;
  font-size: 14px;
}

.new-chat-icon {
  display: inline-grid;
  place-items: center;
  width: 28px; /* smaller icon */
  height: 28px;
  border-radius: 999px;
  background: transparent;
}

.new-chat-icon svg {
  display: block;
  width: 12px;
  height: 12px;
  stroke: #fff;
}

.new-chat-text {
  display: inline-block;
  font-weight: 600;
  color: #fff;
  font-size: 14px;
}

.new-chat-btn:hover {
  background: #0d0f14;
}

/* History section */
.history {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  flex: 1;
}

.history-item {
  border: 0;
  border-radius: calc(var(--radius-md));
  color: var(--text);
  background: transparent;
  text-align: left;
  padding: 10px 14px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 15px; /* slightly larger to match button text scale */
}

.history-item.active {
  background: var(--hover);
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: #0b1220;
  display: inline-grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-top: 52px; /* leave space for fixed topbar */
}

.topbar {
  height: 52px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--panel);
  z-index: 1100;
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
}

.icon-btn {
  border: 1px solid var(--panel-border);
  background: var(--hover);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.mobile-only {
  display: none;
}

.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 8px;
  display: flex;
  flex-direction: column;
}

.welcome {
  margin: auto;
  text-align: center;
}

.welcome h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 34px);
  line-height: 1.2;
}

.welcome p {
  margin: 12px 0 0;
  color: var(--muted);
}

.messages {
  width: min(920px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 18px;
}

.message {
  display: grid;
  gap: 8px;
}

.message .role {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.bubble {
  border-radius: 18px;
  padding: 16px 18px;
  line-height: 1.5;
  font-size: 15px;
  /* Prevent mid-word breaks while allowing intentional newlines */
  word-break: normal;
  overflow-wrap: normal;
  hyphens: none;
  white-space: pre-wrap;
  color: var(--text);
  background-clip: padding-box;
}

.message.user .bubble {
  background: var(--bubble-user);
}

.message.assistant .bubble {
  background: var(--bubble-assistant);
  border: 1px solid var(--panel-border);
  white-space: normal;
}

/* Typing indicator: animated three dots */

.message.assistant.loading .bubble {
  min-width: 64px;
  color: var(--muted);
  padding-right: 20px;
}

.message.assistant.loading.math .bubble {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
}

.message.assistant.loading.math .bubble .math-prefix {
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Math symbols animation (horizontal, sequential) */
.math-symbols {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  margin-left: 8px;
}

.math-symbols {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  margin-left: 8px;
}

.math-symbols .symbol {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: linear-gradient(135deg, rgba(96,165,250,0.18), rgba(167,139,250,0.18));
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
  transform-origin: center;
  opacity: 0.9;
  animation: mathPop 1s infinite ease-in-out;
  padding: 2px;
}

.math-symbols .symbol:nth-child(1) { animation-delay: 0s }
.math-symbols .symbol:nth-child(2) { animation-delay: 0.08s }
.math-symbols .symbol:nth-child(3) { animation-delay: 0.16s }
.math-symbols .symbol:nth-child(4) { animation-delay: 0.24s }
.math-symbols .symbol:nth-child(5) { animation-delay: 0.32s }

@keyframes mathPop {
  0% { transform: translateY(0) scale(1); opacity: 0.6 }
  40% { transform: translateY(-4px) scale(1.08); opacity: 1 }
  100% { transform: translateY(0) scale(1); opacity: 0.9 }
}

/* Rotating gradient cube for math loader */
.math-cube {
  width: 30px;
  height: 30px;
  position: relative;
  transform-style: preserve-3d;
  perspective: 600px;
  margin-left: 8px;
  display: inline-block;
  animation: rotateCube 2.6s cubic-bezier(.2,.8,.2,1) infinite;
}

.math-cube .cube-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: white;
  border-radius: 6px;
  backface-visibility: hidden;
  font-size: 12px;
}

.math-cube .face-1 { transform: rotateY(0deg) translateZ(15px); background: linear-gradient(135deg,#60a5fa,#a78bfa); }
.math-cube .face-2 { transform: rotateY(90deg) translateZ(15px); background: linear-gradient(135deg,#34d399,#60a5fa); }
.math-cube .face-3 { transform: rotateY(180deg) translateZ(15px); background: linear-gradient(135deg,#f472b6,#fb7185); }
.math-cube .face-4 { transform: rotateY(-90deg) translateZ(15px); background: linear-gradient(135deg,#f59e0b,#f97316); }
.math-cube .face-5 { transform: rotateX(90deg) translateZ(15px); background: linear-gradient(135deg,#a3e635,#34d399); }
.math-cube .face-6 { transform: rotateX(-90deg) translateZ(15px); background: linear-gradient(135deg,#60a5fa,#3b82f6); }

@keyframes rotateCube {
  0% { transform: rotateX(0deg) rotateY(0deg); }
  25% { transform: rotateX(-10deg) rotateY(90deg); }
  50% { transform: rotateX(-10deg) rotateY(180deg); }
  75% { transform: rotateX(10deg) rotateY(270deg); }
  100% { transform: rotateX(0deg) rotateY(360deg); }
}

/* Dots laid out horizontally using flex so they don't stack */
.message.assistant.loading .bubble .dots {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.message.assistant.loading .bubble .dot {
  flex: none;
  width: 6px;
  height: 6px;
  background: var(--muted);
  border-radius: 50%;
  opacity: 0.2;
  transform: translateY(0);
  animation: dotPulse 1s infinite ease-in-out;
}

.message.assistant.loading .bubble .dot:nth-child(1) { animation-delay: 0s }
.message.assistant.loading .bubble .dot:nth-child(2) { animation-delay: 0.12s }
.message.assistant.loading .bubble .dot:nth-child(3) { animation-delay: 0.24s }

/* Messages are shown fully; removed truncation/show-more styles */

/* Scroll-to-bottom indicator */
.scroll-indicator {
  position: fixed;
  right: 20px;
  bottom: 110px; /* sits above composer */
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(11,18,32,0.95), rgba(17,24,39,0.95));
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(12,14,16,0.18);
  border: 1px solid rgba(255,255,255,0.06);
  z-index: 1200;
  cursor: pointer;
  transition: transform 160ms ease, opacity 160ms ease;
}
.scroll-indicator.visible { display: inline-grid; opacity: 1; transform: translateY(0); }
.scroll-indicator svg { color: #fff; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.2; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-6px); }
}

/* Staggered per-character reveal for assistant messages */
.stagger-char {
  display: inline-block;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 80ms ease, transform 120ms cubic-bezier(.2,.8,.2,1);
  will-change: opacity, transform;
}
.stagger-char.visible {
  opacity: 1;
  transform: translateY(0);
}

.composer-wrap {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 20px;
  z-index: 1000;
  width: min(720px, calc(100% - 48px));
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
}

.composer {
  width: 100%;
  margin: 0 auto;
  margin-bottom: 0;
  background: rgba(255,255,255,0.98);
  backdrop-filter: blur(6px) saturate(120%);
  -webkit-backdrop-filter: blur(6px) saturate(120%);
  border: 1px solid rgba(15,23,42,0.04);
  box-shadow: 0 10px 30px rgba(15,23,42,0.04);
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px; /* slightly larger for rounder feel */
}

/* Give the chat area bottom padding so messages aren't hidden by fixed composer */
.chat-area {
  padding-bottom: 180px; /* ensure space so messages never hide under composer */
}

.composer textarea {
  flex: 1;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  min-height: 44px; /* less tall input */
  max-height: 260px;
  line-height: 1.5;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(15,23,42,0.03);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.6);
}

.composer button {
  background: transparent;
  border: 0;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--muted);
  border-radius: 999px;
}

.composer button:focus { outline: none; box-shadow: 0 6px 18px rgba(11,18,32,0.06); }

.composer .send-btn {
  background: var(--accent);
  color: #fff;
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(11,18,32,0.08);
}

.icon { width: 20px; height: 20px; display: block; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* make icon buttons circular and subtly filled on hover */
.composer button { border-radius: 999px; }
.composer button:hover { background: rgba(15,23,42,0.04); }
.composer button:active { transform: translateY(1px); }

/* Slightly enlarge send icon for emphasis */
.composer .send-btn .icon { width: 18px; height: 18px; }

/* Make the textarea visually pill-shaped and inset */
.composer textarea {
  border-radius: 999px;
  padding: 10px 14px;
  background: transparent;
}

.disclaimer {
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  margin: 8px 0 0;
  width: 100%;
  max-width: calc(920px - 48px);
}

/* Fullscreen auth overlay */
#authOverlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6,10,15,0.6);
  backdrop-filter: blur(6px);
  z-index: 2000;
}
.auth-sheet {
  width: min(720px, calc(100% - 48px));
  background: rgba(255,255,255,0.72);
  -webkit-backdrop-filter: blur(12px) saturate(150%);
  backdrop-filter: blur(12px) saturate(150%);
  border-radius: 28px;
  padding: 48px 40px;
  border: 1px solid rgba(255,255,255,0.78);
  box-shadow: 0 18px 48px rgba(4,6,12,0.28);
  text-align: center;
  min-height: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.auth-sheet h2 {
  margin: 0 0 6px;
  font-size: 22px;
}
.auth-icon {
  width: 88px;
  height: 88px;
  margin-top: -6px;
  display: grid;
  place-items: center;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(11,18,32,0.06), rgba(11,18,32,0.03));
  color: var(--accent);
  box-shadow: 0 8px 22px rgba(11,18,32,0.08);
}
.auth-icon svg { width: 40px; height: 40px; }
.auth-sheet input[type="password"] {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--input-border);
  font-size: 16px;
  margin-bottom: 18px;
}
.auth-actions { display:flex; justify-content:center }
.auth-actions button {
  background: linear-gradient(180deg, rgba(11,18,32,0.95), rgba(17,24,39,0.95));
  color: #fff;
  border: 1px solid rgba(255,255,255,0.08);
  padding: 12px 20px;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(11,18,32,0.18);
  transition: transform 140ms ease, opacity 140ms ease;
}
.auth-actions button:active { transform: translateY(1px) }

.auth-sheet h2 { margin-bottom: 8px }
.auth-sheet .auth-sub { color: var(--muted); font-size: 13px; margin-bottom: 14px }
.auth-sheet input[type="password"] { transition: box-shadow 140ms ease, transform 140ms ease }
.auth-sheet input[type="password"]:focus { box-shadow: 0 8px 24px rgba(11,18,32,0.06); transform: translateY(-1px) }
.auth-error { color: #b91c1c; margin-top: 8px; font-size: 13px }

.auth-settings { width: 100%; margin-top: 6px; text-align: left; }
.auth-settings .direct-mode-label { display: inline-flex; gap: 10px; align-items: center; color: var(--muted); font-size: 13px; }
.auth-settings .settings-fields { margin-top: 8px; display: none; gap: 8px; }
.auth-settings .settings-fields input { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--input-border); font-size: 14px; }
.auth-settings.active .settings-fields { display: flex; flex-direction: column; }
/* small checkbox spacing */
.auth-settings input[type="checkbox"] { width: 16px; height: 16px; }

/* small shake for wrong password */
.shake { animation: shake 420ms cubic-bezier(.36,.07,.19,.97); }
@keyframes shake {
  0% { transform: translateX(0) }
  20% { transform: translateX(-6px) }
  40% { transform: translateX(6px) }
  60% { transform: translateX(-4px) }
  80% { transform: translateX(4px) }
  100% { transform: translateX(0) }
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 10;
    transform: translateX(-102%);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.12);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-only {
    display: inline-grid;
    place-items: center;
  }

  .topbar {
    padding-inline: 10px;
  }
}

/* ChatGPT-like renovation overrides */
body {
  background: #f8f9fb;
}

.main {
  padding-top: 56px;
}

.topbar {
  height: 56px;
  background: rgba(248, 249, 251, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  justify-content: center;
  border-bottom: 1px solid #e5e7eb;
}

.topbar-title {
  font-size: 14px;
  font-weight: 600;
  color: #6b7280;
}

.chat-area {
  padding: 24px 16px 170px;
}

.welcome {
  margin: 70px auto auto;
}

.messages {
  width: min(760px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
}

.message.user {
  align-items: flex-end;
}

.message .role {
  display: none;
}

.message-time {
  display: none;
}

.bubble {
  display: inline-block;
  width: fit-content;
  max-width: min(72ch, 84%);
  padding: 11px 14px;
  border-radius: 18px;
  line-height: 1.55;
  font-size: 15px;
  white-space: pre-wrap;
  overflow-wrap: normal;
  word-break: keep-all;
  hyphens: none;
  overflow: visible;
  position: relative;
  transition: transform 160ms cubic-bezier(.2,.8,.2,1), box-shadow 160ms ease, background-color 160ms ease;
  box-shadow: 0 6px 18px rgba(15,23,42,0.06);
}

.message.user .bubble {
  background: #e8edf9;
  border: 1px solid #d9e0f3;
  border-bottom-right-radius: 8px;
  color: #0b1220;
}

.message.assistant .bubble {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 8px;
  color: #0b1220;
  line-height: 1.62;
}

/* subtle hover/active feedback */
.message .bubble:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(15,23,42,0.08);
}

/* tails for bubbles */
.message.assistant .bubble::after {
  content: '';
  position: absolute;
  left: -8px;
  bottom: 12px;
  width: 14px;
  height: 14px;
  background: inherit;
  border-left: 1px solid rgba(0,0,0,0.02);
  transform: rotate(45deg);
  border-bottom-right-radius: 2px;
  box-shadow: -2px 2px 6px rgba(15,23,42,0.03);
}

.message.user .bubble::after {
  content: '';
  position: absolute;
  right: -8px;
  bottom: 12px;
  width: 14px;
  height: 14px;
  background: inherit;
  border-right: 1px solid rgba(0,0,0,0.02);
  transform: rotate(45deg);
  border-bottom-left-radius: 2px;
  box-shadow: 2px 2px 6px rgba(15,23,42,0.03);
}

/* ensure very long words still wrap gracefully without breaking mid-glyph */
.bubble { word-wrap: break-word; }

/* tighter rich-text spacing inside bubbles */
.bubble p {
  margin: 0 0 0.5em;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble ul,
.bubble ol {
  margin: 0.35em 0 0.45em 1.15em;
  padding: 0;
}

.bubble li {
  margin: 0.18em 0;
}

.bubble pre {
  margin: 0.25em 0;
  padding: 6px 8px;
  border-radius: 10px;
  overflow: auto;
  background: rgba(15, 23, 42, 0.04);
}

.bubble code {
  font-size: 0.92em;
}

/* enforce compact rhythm for rich text generated by markdown */
.bubble > *:first-child { margin-top: 0 !important; }
.bubble > *:last-child { margin-bottom: 0 !important; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4, .bubble h5, .bubble h6 {
  margin: 0.32em 0 0.28em;
  line-height: 1.2;
}

.message.assistant .bubble h1,
.message.assistant .bubble h2,
.message.assistant .bubble h3 {
  font-weight: 700;
  margin-top: 1.05em;
  margin-bottom: 0.55em;
  text-align: center;
  letter-spacing: -0.01em;
}

.message.assistant .bubble h1 {
  font-size: 1.36rem;
  line-height: 1.18;
}

.message.assistant .bubble h2 {
  font-size: 1.2rem;
  line-height: 1.22;
}

.message.assistant .bubble h1:not(:first-child),
.message.assistant .bubble h2:not(:first-child),
.message.assistant .bubble h3:not(:first-child) {
  margin-top: 1.35em;
}

.message.assistant .bubble p + h1,
.message.assistant .bubble p + h2,
.message.assistant .bubble p + h3,
.message.assistant .bubble ul + h1,
.message.assistant .bubble ul + h2,
.message.assistant .bubble ul + h3,
.message.assistant .bubble ol + h1,
.message.assistant .bubble ol + h2,
.message.assistant .bubble ol + h3,
.message.assistant .bubble blockquote + h1,
.message.assistant .bubble blockquote + h2,
.message.assistant .bubble blockquote + h3,
.message.assistant .bubble .katex-display + h1,
.message.assistant .bubble .katex-display + h2,
.message.assistant .bubble .katex-display + h3 {
  margin-top: 1.55em;
}

.message.assistant .bubble h3 {
  font-size: 1.1rem;
  line-height: 1.24;
}

.message.assistant .bubble h2 {
  padding-bottom: 0.26em;
  border-bottom: 1px solid var(--panel-border);
}

.message.assistant .bubble hr {
  border: 0;
  border-top: 1px solid var(--panel-border);
  width: 72%;
  margin: 1.05em auto;
}

.message.assistant .bubble blockquote {
  margin: 0.75em 0;
  padding: 0.45em 0.95em;
  border-left: 3px solid var(--panel-border);
  color: var(--muted);
}

.message.assistant .bubble ul,
.message.assistant .bubble ol {
  margin-top: 0.52em;
  margin-bottom: 0.72em;
  margin-left: 1.2em;
}

.message.assistant .bubble li {
  margin: 0.3em 0;
}

.message.assistant .bubble p {
  margin: 0 0 0.7em;
}

.message.assistant .bubble strong {
  font-weight: 700;
}

.message.assistant .bubble .katex-display {
  margin: 0.85em 0;
}

.message.assistant .bubble > * + * {
  margin-top: 0.22em;
}

.message.assistant.loading .bubble {
  min-width: 0;
}

.composer-wrap {
  bottom: 14px;
  width: min(860px, calc(100% - 28px));
  padding: 0;
}

.composer {
  border-radius: 22px;
  padding: 10px 12px;
  gap: 10px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #e5e7eb;
  box-shadow: 0 10px 30px rgba(15, 23, 32, 0.08);
}

.composer textarea {
  min-height: 46px;
  max-height: 260px;
  line-height: 1.45;
  font-size: 15px;
}

.composer button {
  width: 42px;
  height: 42px;
  min-width: 42px;
  font-size: 15px;
  background: #111827;
}

/* Attachments preview chips */
.attachments-preview {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.attachment-chip {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid rgba(15,23,42,0.06);
  padding: 6px 8px;
  border-radius: 12px;
  font-size: 13px;
}
.attachment-chip img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 8px;
}
.attachment-chip .remove-attach {
  margin-left: 6px;
  background: transparent;
  border: 0;
  cursor: pointer;
  color: #6b7280;
}

.disclaimer {
  margin-top: 7px;
}

.scroll-indicator {
  right: 18px;
  bottom: 88px;
}


/* Shimmer loader for focused physics/math solving */
.message.assistant.loading.shimmer-loading .bubble {
  position: relative;
  overflow: hidden;
}

.message.assistant.loading.shimmer-loading .bubble::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.12) 40%, rgba(255,255,255,0.2) 50%, rgba(255,255,255,0.12) 60%, rgba(255,255,255,0) 100%);
  transform: translateX(-110%);
  animation: shimmerMove 1.2s linear infinite;
  pointer-events: none;
  mix-blend-mode: screen;
}

@keyframes shimmerMove {
  to { transform: translateX(110%); }
}

/* Minimal neutral thinking indicator (applies to math + general prompts) */
.message.assistant.loading .bubble {
  position: relative;
  min-width: 220px;
  color: #6b7280;
  background: #f8f9fb;
  border: 1px solid #e5e7eb;
}

.message.assistant.loading .bubble .loading-status {
  font-size: 13px;
  font-weight: 500;
  color: #6b7280;
  margin-bottom: 8px;
}

.message.assistant.loading .bubble .loading-lines {
  display: grid;
  gap: 8px;
}

.message.assistant.loading .bubble .loading-line {
  display: block;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #eceff3 0%, #f6f7f9 45%, #eceff3 100%);
  background-size: 220% 100%;
  animation: neutralShimmer 1.2s linear infinite;
}

.message.assistant.loading .bubble .loading-line.line-1 { width: 76%; }
.message.assistant.loading .bubble .loading-line.line-2 { width: 58%; }

/* Hide older loader variants to keep UI minimal */
.message.assistant.loading .bubble .dots,
.message.assistant.loading .bubble .math-cube,
.message.assistant.loading .bubble .math-symbols {
  display: none !important;
}

@keyframes neutralShimmer {
  0% { background-position: 120% 0; }
  100% { background-position: -120% 0; }
}

/* =========================
   Exact iMessage replication
   ========================= */

.statusbar {
  display: none;
}

body.imessage-mode {
  background: #f3f4f6;
}

body.imessage-mode .app-shell {
  min-height: 100vh;
  display: block;
  padding: 0;
}

body.imessage-mode .main {
  width: 100%;
  height: 100vh;
  max-width: none;
  background: #fff;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  position: relative;
  padding-top: 0;
  margin: 0;
  box-shadow: none;
}

body.imessage-mode .main::before {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: 138px;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.2) 0%,
    rgba(0, 0, 0, 0.14) 34%,
    rgba(0, 0, 0, 0.08) 64%,
    rgba(0, 0, 0, 0) 100%
  );
  pointer-events: none;
  z-index: 40;
}

body.imessage-mode .main::after {
  content: '';
  position: absolute;
  inset: auto 0 0;
  height: 108px;
  background: linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.08) 0%,
    rgba(0, 0, 0, 0.05) 40%,
    rgba(0, 0, 0, 0.025) 68%,
    rgba(0, 0, 0, 0) 100%
  );
  pointer-events: none;
  z-index: 40;
}

body.imessage-mode .statusbar {
  position: absolute;
  inset: 0 0 auto;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 60;
}

body.imessage-mode .status-time {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  width: 64px;
  white-space: nowrap;
  line-height: 1;
}

body.imessage-mode .dynamic-island {
  display: none;
}

body.imessage-mode .status-icons {
  width: 62px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
}

body.imessage-mode .signal-bars {
  display: inline-flex;
  gap: 1px;
  align-items: flex-end;
}

body.imessage-mode .signal-bars i {
  display: block;
  width: 2px;
  border-radius: 2px;
  background: #111;
}

body.imessage-mode .signal-bars i:nth-child(1) { height: 5px; }
body.imessage-mode .signal-bars i:nth-child(2) { height: 7px; }
body.imessage-mode .signal-bars i:nth-child(3) { height: 9px; }
body.imessage-mode .signal-bars i:nth-child(4) { height: 11px; }

body.imessage-mode .wifi-icon {
  width: 13px;
  height: 9px;
  border: 2px solid #111;
  border-top-left-radius: 11px;
  border-top-right-radius: 11px;
  border-bottom: 0;
  transform: scaleX(0.95);
}

body.imessage-mode .battery-icon {
  width: 23px;
  height: 11px;
  border: 1.7px solid #111;
  border-radius: 3px;
  padding: 1px;
  position: relative;
}

body.imessage-mode .battery-icon::after {
  content: '';
  position: absolute;
  right: -3px;
  top: 3px;
  width: 2px;
  height: 4px;
  border-radius: 1px;
  background: #111;
}

body.imessage-mode .battery-level {
  display: block;
  width: 70%;
  height: 100%;
  border-radius: 1px;
  background: #111;
}

body.imessage-mode .topbar {
  position: absolute;
  inset: 0 0 auto;
  width: 100%;
  height: 110px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 16px 12px;
  border-bottom: 0;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: none;
  pointer-events: none;
  z-index: 50;
}

body.imessage-mode .topbar > * {
  pointer-events: auto;
}

body.imessage-mode .ios-header-btn {
  width: 36px;
  height: 36px;
  border: 1px solid #fff;
  border-radius: 999px;
  background: #fff;
  color: #111;
  display: inline-grid;
  place-items: center;
  padding: 0;
  transform: translateY(-10px);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.14);
}

body.imessage-mode .chevron-left {
  display: block;
  width: 18px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

body.imessage-mode .video-icon {
  width: 14px;
  height: 10px;
  border: 2px solid #111;
  border-radius: 3px;
  position: relative;
}

body.imessage-mode .video-icon::after {
  content: '';
  position: absolute;
  right: -5px;
  top: 1px;
  border-left: 5px solid #111;
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
}

body.imessage-mode .facetime-icon-image {
  width: 24px;
  height: 24px;
  display: block;
  object-fit: contain;
}

body.imessage-mode .ios-contact {
  position: absolute;
  left: 50%;
  bottom: 2px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  filter: drop-shadow(0 4px 10px rgba(15, 23, 42, 0.14));
}

body.imessage-mode .ios-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  z-index: 2;
  background: #a8d8ff;
  display: grid;
  place-items: center;
  font-size: 30px;
  border: 2px solid #fff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
}

body.imessage-mode .ios-contact-chip {
  margin-top: -4px;
  position: relative;
  z-index: 1;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #ececec;
  border-radius: 999px;
  padding: 2px 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.06);
}

body.imessage-mode .ios-contact-name {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

body.imessage-mode .ios-contact-caret {
  font-size: 13px;
  font-weight: 600;
  color: #9ca3af;
  transform: scaleY(1.14);
  display: inline-block;
}

body.imessage-mode .imessage-toggle {
  display: inline-flex;
  position: absolute;
  right: 12px;
  top: 52px;
  bottom: auto;
  transform: none;
  z-index: 80;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  padding: 4px 8px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.14);
}

body.imessage-mode .chat-area {
  width: 100%;
  padding: 104px 14px 96px;
}

body.imessage-mode .messages {
  width: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

body.imessage-mode .message {
  margin-top: 2px;
}

body.imessage-mode .message.is-first-in-group {
  margin-top: 12px;
}

body.imessage-mode .message .role {
  display: none;
}

body.imessage-mode .bubble {
  max-width: 72%;
  width: fit-content;
  border-radius: 18px;
  padding: 8px 14px;
  font-size: 15px;
  line-height: 1.3;
  border: 0;
  box-shadow: none;
  overflow-wrap: break-word;
  word-break: break-word;
}

body.imessage-mode .message.user .bubble {
  color: #fff;
  background: linear-gradient(180deg, #43a5ff 0%, #0a84ff 100%);
}

body.imessage-mode .message.assistant .bubble {
  color: #000;
  background: #e9e9eb;
}

body.imessage-mode .message.user.is-last-in-group .bubble {
  border-bottom-right-radius: 4px;
}

body.imessage-mode .message.assistant.is-last-in-group .bubble {
  border-bottom-left-radius: 4px;
}

body.imessage-mode .message .bubble:hover,
body.imessage-mode .message .bubble::after {
  transform: none;
  box-shadow: none;
  content: none;
}

body.imessage-mode .message-attachments {
  margin-top: 6px;
  max-width: 72%;
}

body.imessage-mode .generated-images {
  width: min(420px, 80vw);
  max-width: 72%;
  margin-top: 6px;
}

body.imessage-mode .generated-image {
  border: 0;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

body.imessage-mode .attachment-chip {
  border-radius: 18px;
  border: 0;
  background: #e9e9eb;
}

body.imessage-mode .read-receipt {
  display: inline-block;
  align-self: flex-end;
  margin-top: 4px;
  margin-right: 4px;
  font-size: 11px;
  font-weight: 500;
  color: #8e8e93;
}

body.imessage-mode .composer-wrap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  transform: none;
  width: 100%;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border-top: 0;
  z-index: 55;
}

body.imessage-mode .composer {
  position: relative;
  border: 0;
  box-shadow: none;
  border-radius: 0;
  background: transparent;
  padding: 0;
  gap: 10px;
  display: flex;
  align-items: center;
}

body.imessage-mode .composer textarea {
  order: 2;
  flex: 1;
  min-height: 36px;
  max-height: 120px;
  border: 1px solid #fff;
  border-radius: 999px;
  background: #fff;
  font-size: 15px;
  line-height: 1.35;
  padding: 8px 36px 8px 14px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.14);
}

body.imessage-mode .composer textarea:focus {
  border: 1px solid #fff;
  background: #fff;
}

body.imessage-mode .composer-actions {
  display: contents;
}

body.imessage-mode #attachBtn {
  order: 1;
  width: 32px;
  height: 32px;
  min-width: 32px;
  border: 1px solid #fff;
  border-radius: 999px;
  background: #fff;
  color: #111;
  position: relative;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.14);
}

body.imessage-mode #attachBtn .icon {
  display: none;
}

body.imessage-mode #attachBtn::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 1.6px;
  transform: translate(-50%, -50%);
  background: #111;
  border-radius: 999px;
}

body.imessage-mode #attachBtn::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1.6px;
  height: 12px;
  transform: translate(-50%, -50%);
  background: #111;
  border-radius: 999px;
}

body.imessage-mode .send-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 26px;
  min-width: 34px;
  border: 1px solid #fff;
  border-radius: 7px;
  background: #fff;
  color: #0b79f8;
  padding: 0;
  display: inline-grid;
  place-items: center;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.14);
}

body.imessage-mode .send-btn .icon {
  display: block;
  width: 13px;
  height: 13px;
  stroke-width: 2.8;
}

body.imessage-mode .attachments-preview {
  order: 4;
  width: 100%;
  margin-top: 6px;
}

body.imessage-mode .disclaimer {
  display: none;
}

@media (max-width: 480px) {
  body.imessage-mode .main {
    width: 100vw;
    height: 100vh;
    border-width: 0;
    border-radius: 0;
    box-shadow: none;
  }
}

/* Keep iMessage-specific chrome out of normal mode */
.ios-header-btn,
.ios-contact {
  display: none;
}

.ios-avatar img {
  width: 70%;
  height: 70%;
  object-fit: contain;
  object-position: center;
  display: block;
  margin: auto;
}



.topbar-title {
  display: block;
}

body.imessage-mode .topbar-title {
  display: none !important;
}

body.imessage-mode .ios-header-btn {
  display: inline-grid;
}

body.imessage-mode .ios-contact {
  display: flex;
}

/* Header toggle for iMessage mode */
.topbar {
  justify-content: flex-end;
}

.topbar-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.imessage-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  cursor: pointer;
}

.imessage-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.imessage-toggle-track {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #d1d1d6;
  position: relative;
  transition: background-color 180ms ease;
}

.imessage-toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.24);
  transition: transform 180ms ease;
}

.composer-input-wrap {
  position: relative;
  flex: 1 1 240px;
  display: flex;
  min-width: 0;
}

.composer-input-wrap textarea {
  width: 100%;
  padding-right: 56px;
}

.composer-input-wrap .send-btn {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
}

.imessage-toggle input:checked + .imessage-toggle-track {
  background: #34c759;
}

.imessage-toggle input:checked + .imessage-toggle-track::after {
  transform: translateX(18px);
}

.imessage-toggle-label {
  font-size: 12px;
  color: #6b7280;
  font-weight: 600;
}

.welcome {
	flex: 1;
	display: grid;
	place-items: center;
	margin: 0;
	text-align: center;
	padding: 0 16px;
}

.welcome-card {
  width: min(700px, 100%);
  min-height: 260px;
  padding: 10px 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.welcome h1 {
  margin: 0;
  font-size: clamp(19px, 2.8vw, 24px);
  line-height: 1.2;
  letter-spacing: -0.015em;
  color: #1f2937;
  font-weight: 600;
}

.welcome p {
  margin: 7px 0 0;
  font-size: 13px;
  color: #9ca3af;
}

body.imessage-mode .welcome {
	padding-top: 12px;
}

body.imessage-mode .welcome-card {
  width: min(600px, 98%);
  min-height: 220px;
}

/* iMessage mode */
body.imessage-mode {
  background: #e5e5ea;
}

body.imessage-mode,
body.imessage-mode input,
body.imessage-mode textarea,
body.imessage-mode button,
body.imessage-mode select {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
}

body.imessage-mode .topbar {
  background: transparent;
  border-bottom: 0;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

body.imessage-mode .topbar-title {
  color: #111;
  font-size: 16px;
  font-weight: 600;
}

body.imessage-mode .chat-area {
  padding-bottom: 156px;
}

body.imessage-mode .messages {
  width: calc(100% - 24px);
  max-width: none;
  gap: 0;
}

body.imessage-mode .message {
  gap: 0;
  margin-top: 2px;
}

body.imessage-mode .message.is-first-in-group {
  margin-top: 12px;
}

body.imessage-mode .message .role {
  display: none;
}

body.imessage-mode .bubble {
  position: relative;
  max-width: 72%;
  width: fit-content;
  border-radius: 18px;
  padding: 8px 14px;
  line-height: 1.3;
  box-shadow: none;
  border: 0;
  font-size: 15px;
  overflow-wrap: break-word;
  word-break: break-word;
}

body.imessage-mode .message.assistant .bubble {
  background: #e9e9eb;
  color: #111;
}

body.imessage-mode .message.user .bubble {
  background: linear-gradient(180deg, #43a5ff 0%, #0a84ff 100%);
  color: #fff;
}

body.imessage-mode .message.user.is-last-in-group .bubble {
  border-bottom-right-radius: 5px;
}

body.imessage-mode .message.assistant.is-last-in-group .bubble {
  border-bottom-left-radius: 5px;
}

body.imessage-mode .message .bubble:hover {
  transform: none;
  box-shadow: none;
}

body.imessage-mode .message.assistant .bubble::after,
body.imessage-mode .message.user .bubble::after {
  content: none;
}

body.imessage-mode .message.assistant.loading .bubble {
  background: #e9e9eb;
  color: #6b7280;
  border-radius: 18px;
}

body.imessage-mode .message.user .bubble p,
body.imessage-mode .message.assistant .bubble p {
  margin: 0;
}

body.imessage-mode .message-time {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 500;
  color: #8e8e93;
}

body.imessage-mode .message.user .message-time {
  align-self: flex-end;
  margin-right: 4px;
}

body.imessage-mode .message.assistant .message-time {
  align-self: flex-start;
  margin-left: 4px;
}

body.imessage-mode .composer-wrap {
  width: min(700px, calc(100% - 16px));
  bottom: max(8px, env(safe-area-inset-bottom));
}

body.imessage-mode .composer {
  border-radius: 22px;
  border: 1px solid #d1d1d6;
  background: rgba(248, 248, 248, 0.92);
  box-shadow: none;
  padding: 8px;
}

body.imessage-mode .composer textarea {
  border: 1px solid #d1d1d6;
  background: #fff;
  border-radius: 18px;
  min-height: 40px;
  font-size: 17px;
}

body.imessage-mode .composer .send-btn {
  background: #0a84ff;
  color: #fff;
  width: 38px;
  height: 38px;
}

body.imessage-mode .composer #attachBtn {
  width: 36px;
  height: 36px;
  background: #fff;
  color: #111;
  border: 1px solid #fff;
  border-radius: 999px;
  box-shadow: none;
}

body.imessage-mode .disclaimer {
  display: none;
}

@media (max-width: 700px) {
  .imessage-toggle-label {
    display: none;
  }
}

/* Final iMessage composer corrections */
body.imessage-mode .composer-wrap {
  position: absolute !important;
  transform: none !important;
  width: 100% !important;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom)) !important;
  background: transparent !important;
  border-top: 0 !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

body.imessage-mode .composer {
  position: relative;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  padding: 0 !important;
  gap: 10px;
}

body.imessage-mode .composer-input-wrap {
  order: 2;
  flex: 1;
  min-width: 0;
}

body.imessage-mode .composer textarea {
  border: 1px solid #fff !important;
  background: #fff !important;
  border-radius: 999px;
  min-height: 36px;
  font-size: 15px;
  padding: 8px 40px 8px 14px;
  box-shadow: none !important;
}

body.imessage-mode .composer textarea::placeholder {
  color: rgba(17, 17, 17, 0.38);
}

body.imessage-mode .composer .send-btn {
  position: absolute !important;
  right: 7px;
  top: 50%;
  transform: translateY(-50%) !important;
  width: 34px;
  height: 26px;
  min-width: 34px;
  border-radius: 12px;
  background: #0a84ff;
  color: #fff;
  border: 0;
  padding: 0;
  display: inline-grid;
  place-items: center;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.14);
}

body.imessage-mode .composer .send-btn .icon {
  display: block !important;
  width: 16px;
  height: 16px;
  stroke-width: 2.6;
}

body.imessage-mode .message.assistant.loading.shimmer-loading .bubble::after {
  content: none;
}

body.imessage-mode .message.assistant.loading .bubble {
  min-width: 58px;
  padding: 10px 12px;
  border: 0;
  background: #e9e9eb;
}

body.imessage-mode .message.assistant.loading .bubble .loading-status,
body.imessage-mode .message.assistant.loading .bubble .loading-lines,
body.imessage-mode .message.assistant.loading .bubble .loading-line {
  display: none !important;
}

body.imessage-mode .message.assistant.loading .bubble .dots {
  display: inline-flex !important;
  align-items: center;
  gap: 5px;
  margin-left: 2px;
}

body.imessage-mode .message.assistant.loading .bubble .dot {
  width: 6px;
  height: 6px;
  background: #8e8e93;
  opacity: 0.45;
}

/* Keep LaTeX fully contained inside chat bubbles */
.bubble .katex-display {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.bubble .katex-display .katex {
  max-width: none;
}

/* Remove blur effects entirely in iMessage mode */
body.imessage-mode .topbar,
body.imessage-mode .imessage-toggle,
body.imessage-mode .composer-wrap {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

body.imessage-mode .topbar {
  background: transparent !important;
  border-bottom: 0 !important;
  box-shadow: none !important;
}

body.imessage-mode .imessage-toggle {
  background: #ffffff !important;
}

.bubble .katex {
  max-width: 100%;
}

@media (max-width: 700px) {
  .main {
    padding-top: 52px;
    max-width: 100%;
    overflow-x: hidden;
  }

  .topbar {
    height: 52px;
    padding: 0 10px;
    width: 100%;
  }

  .topbar-title {
    font-size: 14px;
  }

  .ios-contact,
  .imessage-toggle-label {
    display: none;
  }

  .ios-header-btn {
    width: 34px;
    height: 34px;
  }

  .chat-area {
    padding: 12px 8px calc(168px + env(safe-area-inset-bottom));
  }

  .messages {
    width: 100%;
    min-width: 0;
  }

  .bubble {
    max-width: 95%;
  }

  .composer-wrap {
    width: calc(100% - 8px);
    bottom: max(6px, env(safe-area-inset-bottom));
  }

  .composer {
    padding: 8px;
    gap: 6px;
    border-radius: 18px;
  }

  .composer textarea {
    min-height: 42px;
    font-size: 16px;
  }

  .disclaimer {
    margin-top: 6px;
    padding: 0 8px;
    font-size: 11px;
  }
}

