:root {
  --paper: #eef0f3;
  --paper-soft: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #d8dee8;
  --gold: #94a3b8;
  --black: #111827;
  --white: #ffffff;
  --user-bg: #2563eb;
  --user-text: #ffffff;
  --assistant-bg: #ffffff;
  --assistant-text: #1f2937;
  --assistant-border: #d1d9e6;
  --accent: #2563eb;
  --shadow: 0 10px 28px rgba(15, 23, 42, .08);
  --pixel-shadow: 2px 2px 0 rgba(15, 23, 42, .12);
  --pixel-shadow-soft: 1px 1px 0 rgba(15, 23, 42, .08);
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --app-height: 100dvh;
}

* {
  box-sizing: border-box;
}

html {
  height: var(--app-height, 100dvh);
  max-height: var(--app-height, 100dvh);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  width: 100%;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  touch-action: manipulation;
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(15, 23, 42, .028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 42, .028) 1px, transparent 1px);
  background-size: 8px 8px;
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  position: relative;
  isolation: isolate;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.grid-accents {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.grid-accent-cell {
  position: absolute;
  width: 8px;
  height: 8px;
  opacity: .52;
}

.grid-accent-cell.is-double {
  width: 16px;
  height: 16px;
  opacity: .38;
}

.app-topbar {
  flex: 0 0 auto;
  flex-shrink: 0;
  z-index: 20;
  position: relative;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 10px;
  padding: 12px clamp(16px, 4vw, 34px);
}

.topbar-center {
  justify-self: center;
  min-width: 0;
  max-width: calc(100vw - 132px);
  text-align: center;
}

.app-brand {
  color: var(--ink);
  text-decoration: none;
  font-size: 17px;
  font-weight: 850;
  letter-spacing: 0;
}

.app-brand-link {
  display: inline-block;
}

.session-topic {
  min-width: 0;
}

.session-topic-label {
  margin: 0;
  font-size: 11px;
  line-height: 1.2;
  color: var(--muted);
  font-weight: 650;
  letter-spacing: .12em;
}

.session-topic-text {
  margin: 2px 0 0;
  font-size: 15px;
  line-height: 1.35;
  font-weight: 800;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell.is-chatting .app-brand-link {
  display: none;
}

.app-shell.is-chatting .session-topic {
  display: block;
}

.app-shell.is-chatting .session-topic[hidden] {
  display: none;
}

.icon-button,
.mode-button,
.drawer-close,
.sheet-close {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-soft);
  color: var(--ink);
  box-shadow: var(--pixel-shadow-soft);
  cursor: pointer;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 12px;
}

.icon-button span {
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: var(--ink);
}

.mode-button {
  width: 44px;
  height: 44px;
  font-size: 12px;
  font-weight: 850;
}

.chat-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 clamp(18px, 4vw, 36px);
  position: relative;
  z-index: 1;
}

.welcome-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  width: min(760px, 100%);
  margin: 0 auto;
  display: grid;
  justify-items: center;
  align-content: center;
  text-align: center;
  padding: 0 0 16px;
  transition: opacity .24s ease, transform .24s ease, max-height .24s ease;
}

.mascot {
  width: clamp(180px, 42vw, 240px);
  max-height: 240px;
  object-fit: contain;
  filter: drop-shadow(0 28px 44px rgba(43, 31, 20, .15));
}

.welcome-panel h1 {
  margin: 20px 0 0;
  font-size: clamp(34px, 8vw, 58px);
  line-height: 1.08;
  font-weight: 850;
  letter-spacing: 0;
}

.welcome-panel p {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: clamp(16px, 3.8vw, 20px);
  font-weight: 780;
}

.prompt-chips,
.related-questions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.prompt-chips {
  width: min(560px, 100%);
  margin-top: 34px;
}

.prompt-chips button,
.related-question {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-soft);
  color: var(--assistant-text);
  padding: 0 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--pixel-shadow-soft);
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  width: min(820px, 100%);
  margin: 0 auto;
  display: none;
  flex-direction: column;
  gap: 14px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 2px 16px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(38, 30, 20, .18) transparent;
}

.messages::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(38, 30, 20, .16);
}

.message-row {
  display: flex;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.assistant {
  justify-content: flex-start;
}

.message {
  max-width: min(78%, 560px);
  padding: 12px 15px;
  border-radius: var(--radius-lg);
  font-weight: 600;
  line-height: 1.65;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.message.user {
  border-bottom-right-radius: 4px;
  background: var(--user-bg);
  color: var(--user-text);
  box-shadow: var(--pixel-shadow);
}

.message.assistant {
  border-bottom-left-radius: 4px;
  background: var(--assistant-bg);
  color: var(--assistant-text);
  border: 1px solid var(--assistant-border);
  box-shadow: var(--pixel-shadow-soft);
}

.message.typing {
  min-width: 72px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
}

.typing-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 1px;
  background: #64748b;
  opacity: .5;
  animation: typing 1.05s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: .14s;
}

.typing-dot:nth-child(3) {
  animation-delay: .28s;
}

@keyframes typing {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: .32;
  }

  40% {
    transform: translateY(-4px);
    opacity: .86;
  }
}

.related-questions {
  justify-content: flex-start;
  max-width: 100%;
  margin: 0;
}

.lead-action {
  margin: 0;
}

.chat-footer {
  flex: 0 0 auto;
  flex-shrink: 0;
  position: relative;
  z-index: 30;
  width: 100%;
  padding-bottom: env(safe-area-inset-bottom);
  background: linear-gradient(180deg, rgba(238, 240, 243, 0) 0%, rgba(238, 240, 243, .94) 22%, #eef0f3 100%);
}

.app-shell.is-input-focused .suggestions-bar {
  display: none;
}

.suggestions-bar {
  width: min(820px, calc(100% - 20px));
  margin: 0 auto;
  padding: 8px 10px 0;
}

.suggestions-bar:not([hidden]) + .composer-wrap {
  padding-top: 4px;
}

.suggestions-bar .related-questions {
  justify-content: flex-start;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.suggestions-bar .related-question {
  flex: 0 0 auto;
  white-space: nowrap;
}

.suggestions-bar .lead-action {
  padding-bottom: 4px;
}

.composer-wrap {
  position: relative;
  z-index: 1;
  width: min(820px, calc(100% - 28px));
  margin: 0 auto;
  padding: 10px 0 12px;
}

.lead-action a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid #1d4ed8;
  background: var(--user-bg);
  color: var(--user-text);
  padding: 0 16px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--pixel-shadow-soft);
}

.composer {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--paper-soft);
  padding: 5px 6px;
  box-shadow: var(--pixel-shadow);
}

.input-mode-button {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  color: var(--user-bg);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--pixel-shadow-soft);
}

.composer-text-mode,
.composer-voice-mode {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.composer-voice-mode[hidden],
.composer-text-mode[hidden] {
  display: none !important;
}

.voice-hold-button {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--pixel-shadow-soft);
  user-select: none;
  touch-action: none;
}

.voice-hold-button.is-recording {
  background: #eff6ff;
  border-color: #93b4f6;
  color: var(--user-bg);
}

.app-shell.is-voice-mode .composer {
  padding-left: 6px;
}

.app-shell.is-voice-recording .composer {
  border-color: #93b4f6;
  box-shadow: var(--pixel-shadow), 0 0 0 2px rgba(37, 99, 235, .12);
}

.composer:focus-within {
  border-color: #93b4f6;
  box-shadow: var(--pixel-shadow), 0 0 0 2px rgba(37, 99, 235, .14);
}

.composer-input,
.composer input {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  height: 38px;
  border: 0;
  background: transparent;
  color: var(--ink);
  outline: none;
  font-size: 16px;
  font-weight: 600;
}

.attach-button {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--pixel-shadow-soft);
  transition: transform .18s ease, background .18s ease, border-color .18s ease;
}

.attach-button.is-open {
  transform: rotate(45deg);
  background: #eff6ff;
  border-color: #93b4f6;
  color: var(--user-bg);
}

.attach-panel {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--pixel-shadow-soft);
}

.attach-panel[hidden] {
  display: none !important;
}

.attach-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.attach-tile {
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  color: var(--ink);
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 8px;
  padding: 10px 6px;
  cursor: pointer;
  box-shadow: var(--pixel-shadow-soft);
}

.attach-tile:active {
  background: #eff6ff;
  border-color: #93b4f6;
}

.attach-tile-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  background: #eff6ff;
  color: var(--user-bg);
  font-size: 18px;
  font-weight: 700;
}

.attach-tile-label {
  font-size: 12px;
  font-weight: 650;
}

.attach-hint {
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.user-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-width: min(78%, 560px);
}

.message-image-card {
  overflow: hidden;
  border-radius: var(--radius-lg);
  border-bottom-right-radius: 4px;
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: var(--pixel-shadow-soft);
}

.message-image-card img {
  display: block;
  width: auto;
  max-width: min(240px, 72vw);
  max-height: 280px;
  object-fit: cover;
}

.user-stack .message.user {
  max-width: 100%;
}

.message-text {
  white-space: pre-wrap;
}

.message-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.message-speak {
  min-width: 34px;
  height: 28px;
  border: 1px solid #dbeafe;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--user-bg);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.message-speak:disabled {
  opacity: .6;
  cursor: wait;
}

.app-shell.is-attach-open .suggestions-bar {
  display: none;
}

.composer input::placeholder {
  color: #94a3b8;
}

.send-button {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border: 1px solid #1d4ed8;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  background: var(--user-bg);
  color: var(--user-text);
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--pixel-shadow-soft);
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: .74;
}

.send-button.is-loading span {
  display: none;
}

.send-button.is-loading::after {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid rgba(255, 254, 250, .38);
  border-top-color: var(--white);
  animation: spin .78s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.status {
  min-height: 20px;
  margin: 8px 18px 0;
  color: #8d473e;
  font-size: 13px;
  font-weight: 760;
}

.app-shell.is-chatting .welcome-panel {
  display: none;
}

.app-shell.is-chatting .chat-main {
  padding-bottom: 0;
}

.app-shell.is-chatting .messages {
  display: flex;
}

.drawer,
.mode-sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background: rgba(12, 10, 6, 0);
  transition: background .22s ease;
}

.drawer.is-open,
.mode-sheet.is-open {
  pointer-events: auto;
  background: rgba(12, 10, 6, .38);
}

.drawer-panel {
  width: min(318px, 86vw);
  height: 100%;
  overflow-y: auto;
  background: #f8fafc;
  border-right: 1px solid #dbeafe;
  box-shadow: 24px 0 70px rgba(37, 99, 235, .12);
  padding: 18px;
  transform: translateX(-102%);
  transition: transform .24s ease;
}

.drawer.is-open .drawer-panel {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.drawer-head strong {
  font-size: 18px;
  color: var(--user-bg);
}

#newChatButton {
  background: var(--user-bg);
  border-color: #1d4ed8;
  color: var(--user-text);
  box-shadow: var(--pixel-shadow-soft);
  font-weight: 700;
}

#newChatButton:active {
  background: #1d4ed8;
}

.drawer-close,
.sheet-close {
  width: 38px;
  height: 38px;
  font-size: 24px;
  line-height: 1;
}

.drawer-item,
.drawer-question {
  width: 100%;
  min-height: 44px;
  border: 1px solid #dbeafe;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  background: #ffffff;
  color: var(--ink);
  padding: 0 14px;
  text-align: left;
  text-decoration: none;
  font-weight: 650;
  cursor: pointer;
  box-shadow: var(--pixel-shadow-soft);
}

.drawer-question:active {
  background: #eff6ff;
  border-color: #93b4f6;
}

.drawer-group {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}

.drawer-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.drawer-group p {
  margin: 8px 0 2px;
  color: var(--user-bg);
  font-size: 13px;
  font-weight: 800;
}

.clear-history:active {
  color: var(--user-bg);
}

.clear-history {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 0 0;
  font-size: 12px;
  font-weight: 850;
  cursor: pointer;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  width: 100%;
  min-height: 54px;
  border: 1px solid #dbeafe;
  border-radius: var(--radius-sm);
  display: grid;
  gap: 4px;
  background: #ffffff;
  color: var(--ink);
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--pixel-shadow-soft);
}

.history-item:active {
  background: #eff6ff;
  border-color: #93b4f6;
}

.history-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 750;
  color: #1e3a8a;
}

.history-item small,
.empty-history {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.empty-history {
  padding: 6px 2px 2px;
}

.drawer-item + .drawer-item,
.drawer-group + .drawer-item {
  margin-top: 10px;
}

.mode-sheet {
  display: grid;
  align-items: end;
}

.mode-panel {
  width: min(560px, 100%);
  margin: 0 auto;
  border-radius: 28px 28px 0 0;
  background: var(--paper-soft);
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  transform: translateY(104%);
  transition: transform .24s ease;
}

.mode-sheet.is-open .mode-panel {
  transform: translateY(0);
}

.mode-panel h2 {
  margin: 0 0 16px;
  font-size: 24px;
}

.sheet-close {
  position: absolute;
  right: 18px;
  top: 18px;
}

.mode-option {
  position: relative;
  width: 100%;
  min-height: 74px;
  border: 1px solid rgba(38, 30, 20, .12);
  border-radius: 18px;
  display: grid;
  gap: 4px;
  background: rgba(255, 254, 250, .82);
  color: var(--ink);
  padding: 14px 48px 14px 16px;
  text-align: left;
  cursor: pointer;
}

.mode-option + .mode-option {
  margin-top: 10px;
}

.mode-option.active {
  border-color: rgba(78, 61, 41, .38);
  background: #f4ede1;
  box-shadow: 0 14px 34px rgba(45, 34, 21, .1);
}

.mode-option strong {
  font-size: 16px;
}

.mode-option span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
}

.mode-check {
  position: absolute;
  right: 17px;
  top: 50%;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--black);
  color: var(--white);
  font-style: normal;
  font-size: 14px;
  font-weight: 900;
  opacity: 0;
  transform: translateY(-50%) scale(.86);
  transition: opacity .18s ease, transform .18s ease;
}

.mode-option.active .mode-check {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

@media (min-width: 820px) {
  .app-topbar {
    grid-template-columns: 52px 1fr 52px;
  }

  .app-brand {
    justify-self: start;
  }
}

@media (max-width: 560px) {
  .app-topbar {
    padding-left: 14px;
    padding-right: 14px;
  }

  .chat-main {
    padding-left: 14px;
    padding-right: 14px;
  }

  .message {
    max-width: 86%;
  }

  .prompt-chips {
    justify-content: stretch;
  }

  .prompt-chips button {
    flex: 1 1 100%;
  }

  .chat-footer,
  .suggestions-bar,
  .composer-wrap {
    width: 100%;
  }

  .composer-wrap {
    width: calc(100% - 20px);
  }
}
