:root {
  color-scheme: light;
  --page: #f6fbfa;
  --surface: #ffffff;
  --ink: #172220;
  --muted: #667572;
  --line: #dce7e4;
  --assistant: #ffffff;
  --user: #e9f7f2;
  --accent: #168b77;
  --accent-hover: #117361;
  --blue: #4f77d4;
  --shadow-soft: 0 8px 30px rgba(33, 73, 66, 0.08);
  --shadow-composer: 0 14px 38px rgba(33, 73, 66, 0.13);
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--page);
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button,
textarea,
input {
  font: inherit;
}

button,
.upload-button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(14px + env(safe-area-inset-top)) 30px 14px;
  border-bottom: 1px solid #e6efed;
  background: rgba(255, 255, 255, 0.96);
  position: relative;
  z-index: 2;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.35;
  font-weight: 720;
  letter-spacing: 0.015em;
}

.child-selector {
  position: absolute;
  right: max(24px, calc((100vw - 1120px) / 2));
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid #dce9e6;
  border-radius: 999px;
  background: #f4f9f8;
  box-shadow: 0 4px 16px rgba(33, 73, 66, 0.06);
}

.child-select-button {
  min-height: 32px;
  padding: 5px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #60706c;
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease, box-shadow 150ms ease;
}

.child-select-button:hover:not(:disabled) {
  color: #147c70;
  background: #eaf6f3;
}

.child-select-button.is-selected,
.child-select-button[aria-pressed="true"] {
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 4px 12px rgba(22, 139, 119, 0.2);
}

.child-select-button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 34px max(24px, calc((100vw - 1120px) / 2)) 42px;
  scroll-behavior: smooth;
}

.welcome-panel {
  width: min(1040px, 100%);
  min-height: calc(100% - 20px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 12px 0 28px;
  text-align: left;
}

.welcome-panel.is-hidden {
  display: none;
}

.welcome-greeting,
.source-row {
  display: flex;
  align-items: center;
  gap: 24px;
}

.welcome-mark {
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  flex: 0 0 60px;
  border-radius: 999px;
  background: #159d9c;
  box-shadow: 0 8px 22px rgba(22, 139, 119, 0.12);
}

.welcome-mark img {
  width: 29px;
  height: 29px;
  filter: brightness(0) invert(1);
}

.welcome-mark.owner-avatar {
  overflow: hidden;
  background: #ffffff;
}

.welcome-mark.owner-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: none;
}

.welcome-mark.owner-avatar.fallback {
  background: #159d9c;
}

.welcome-mark.owner-avatar.fallback img {
  width: 29px;
  height: 29px;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

.greeting-bubble {
  min-height: 78px;
  display: flex;
  align-items: center;
  padding: 14px 30px;
  border: 1px solid #dce6e4;
  border-radius: 21px;
  background: #ffffff;
  box-shadow: var(--shadow-soft);
}

.greeting-bubble h2 {
  margin: 0;
  font-size: clamp(24px, 2.4vw, 34px);
  line-height: 1.25;
  font-weight: 640;
  letter-spacing: -0.018em;
}

.quick-actions {
  width: calc(100% - 84px);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin: 28px 0 0 84px;
}

.quick-action {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid #cddfdd;
  border-radius: 999px;
  background: #f3fbfa;
  color: #176f6b;
  font-size: 15px;
  font-weight: 680;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(33, 73, 66, 0.045);
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.quick-action:hover {
  border-color: #b7d8d1;
  box-shadow: 0 9px 24px rgba(33, 73, 66, 0.09);
  transform: translateY(-1px);
}

.quick-action:focus-visible,
.child-select-button:focus-visible,
.upload-button:focus-visible,
.send-button:focus-visible {
  outline: 3px solid rgba(79, 119, 212, 0.26);
  outline-offset: 2px;
}

.quick-icon {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  display: grid;
  place-items: center;
  border-radius: 9px;
}

.quick-icon img {
  width: 21px;
  height: 21px;
  opacity: 0.75;
}

.quick-icon.blue {
  background: #edf2ff;
}

.quick-icon.teal {
  background: #e5f6f2;
}

.quick-icon.amber {
  background: #fff4df;
}

.quick-icon.violet {
  background: #f2edff;
}

.source-row {
  margin-top: 48px;
}

.welcome-mark.compact {
  width: 54px;
  height: 54px;
  flex-basis: 54px;
}

.welcome-mark.compact img {
  width: 26px;
  height: 26px;
}

.source-card {
  width: 430px;
  display: flex;
  align-items: center;
  gap: 13px;
  min-height: 92px;
  padding: 17px 20px;
  border: 1px solid #dce9e6;
  border-radius: 20px;
  background: #ffffff;
  color: #35544d;
  text-align: left;
  box-shadow: var(--shadow-soft);
}

.source-icon {
  width: 54px;
  height: 54px;
  flex: 0 0 54px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: #edf8f6;
}

.source-icon img {
  width: 28px;
  height: 28px;
  opacity: 0.68;
}

.source-card strong,
.source-card small {
  display: block;
}

.source-card strong {
  font-size: 16px;
  line-height: 1.45;
}

.source-card small {
  margin-top: 3px;
  color: #6a7b77;
  font-size: 13px;
  line-height: 1.45;
}

.message-row {
  width: 100%;
  display: flex;
  gap: 13px;
  margin: 0 auto 24px;
  align-items: flex-start;
}

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

.avatar {
  width: 42px;
  height: 42px;
  border: 2px solid rgba(255, 255, 255, 0.96);
  border-radius: 999px;
  background: #e7f5f2;
  display: grid;
  place-items: center;
  flex: 0 0 42px;
  overflow: hidden;
  box-shadow: 0 7px 18px rgba(22, 139, 119, 0.18);
}

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

.avatar.fallback {
  background: var(--accent);
}

.avatar.fallback img {
  width: 21px;
  height: 21px;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

.bubble {
  max-width: min(760px, calc(100% - 55px));
  padding: 15px 18px;
  border-radius: 18px;
  background: var(--assistant);
  border: 1px solid var(--line);
  line-height: 1.72;
  font-size: 15px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 3px 12px rgba(33, 73, 66, 0.045);
}

.user .bubble {
  background: var(--user);
  border-color: #cee7df;
  border-bottom-right-radius: 7px;
}

.assistant .bubble {
  border-top-left-radius: 7px;
}

.file-badge {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  max-width: 100%;
}

.file-icon {
  width: 32px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(22, 139, 119, 0.12);
  color: var(--accent);
  font-size: 10px;
  font-weight: 780;
  flex: 0 0 auto;
}

.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thinking .bubble {
  display: flex;
  gap: 5px;
  align-items: center;
  min-height: 48px;
}

.thinking-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #6a8881;
  animation: bounce 1.15s infinite ease-in-out;
}

.thinking-dot:nth-child(2) {
  animation-delay: 0.14s;
}

.thinking-dot:nth-child(3) {
  animation-delay: 0.28s;
}

@keyframes bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

.composer-wrap {
  padding: 16px max(20px, calc((100vw - 1160px) / 2)) calc(12px + env(safe-area-inset-bottom));
  background: rgba(246, 251, 250, 0.97);
}

.composer {
  min-height: 78px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid #cedbd8;
  border-radius: 27px;
  box-shadow: var(--shadow-composer);
}

.composer:focus-within {
  border-color: #9fc7be;
  box-shadow: 0 0 0 3px rgba(22, 139, 119, 0.08), var(--shadow-composer);
}

.upload-button {
  width: 50px;
  height: 50px;
  border: 1px solid #dce7e4;
  border-radius: 15px;
  display: grid;
  place-items: center;
  flex: 0 0 50px;
  color: #4d625d;
  cursor: pointer;
  user-select: none;
  transition: background 140ms ease, transform 140ms ease;
}

.upload-button img {
  width: 28px;
  height: 28px;
  opacity: 0.72;
}

.upload-button:hover {
  background: #edf4f2;
}

.upload-button:active {
  transform: scale(0.96);
}

.upload-button.disabled {
  pointer-events: none;
  opacity: 0.4;
}

textarea {
  resize: none;
  flex: 1 1 auto;
  min-width: 0;
  max-height: 148px;
  padding: 11px 3px 10px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  line-height: 1.5;
  font-size: 16px;
}

textarea::placeholder {
  color: #899894;
}

.send-button {
  height: 50px;
  min-width: 102px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 16px;
  border-radius: 17px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 140ms ease, transform 140ms ease;
}

.send-button img {
  width: 16px;
  height: 16px;
  filter: brightness(0) invert(1);
}

.send-button:hover {
  background: var(--accent-hover);
}

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

.send-button:disabled {
  cursor: default;
  opacity: 0.5;
}

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

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

@media (max-width: 720px) {
  .topbar {
    min-height: 64px;
    padding-left: 18px;
    padding-right: 18px;
  }

  .topbar h1 {
    font-size: 18px;
  }

  .child-selector {
    right: 12px;
    gap: 3px;
    padding: 3px;
  }

  .child-select-button {
    min-height: 30px;
    padding: 4px 9px;
    font-size: 11px;
  }

  .messages {
    padding: 24px 15px 28px;
  }

  .welcome-panel {
    justify-content: flex-start;
    min-height: auto;
    padding-top: 5vh;
  }

  .welcome-mark {
    width: 46px;
    height: 46px;
    flex-basis: 46px;
  }

  .welcome-mark img {
    width: 23px;
    height: 23px;
  }

  .welcome-greeting,
  .source-row {
    width: 100%;
    gap: 12px;
  }

  .greeting-bubble {
    min-height: 64px;
    padding: 12px 16px;
    border-radius: 18px;
  }

  .greeting-bubble h2 {
    font-size: clamp(21px, 6vw, 27px);
  }

  .quick-actions {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 20px 0 0;
  }

  .quick-action {
    min-height: 58px;
    gap: 9px;
    padding: 8px 11px;
    border-radius: 16px;
    font-size: 13px;
  }

  .quick-icon {
    width: 30px;
    height: 30px;
    flex-basis: 30px;
    border-radius: 11px;
  }

  .quick-icon img {
    width: 19px;
    height: 19px;
  }

  .source-row {
    margin-top: 18px;
  }

  .welcome-mark.compact {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }

  .source-card {
    width: auto;
    min-height: 78px;
    flex: 1;
    padding: 11px 12px;
  }

  .source-icon {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  .source-icon img {
    width: 22px;
    height: 22px;
  }

  .source-card strong {
    font-size: 14px;
  }

  .message-row {
    gap: 9px;
    margin-bottom: 18px;
  }

  .avatar {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
    border-radius: 999px;
  }

  .avatar.fallback img {
    width: 18px;
    height: 18px;
  }

  .bubble {
    max-width: calc(100% - 45px);
    padding: 12px 14px;
    font-size: 14px;
    border-radius: 16px;
  }

  .composer-wrap {
    padding: 10px 10px calc(8px + env(safe-area-inset-bottom));
  }

  .composer {
    min-height: 60px;
    padding: 8px;
    gap: 6px;
    border-radius: 22px;
  }

  .upload-button {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }

  .send-button {
    min-width: 62px;
    height: 42px;
    padding: 0 15px;
  }

  .send-button img {
    display: none;
  }

  .privacy-note {
    margin-top: 6px;
    font-size: 10px;
  }
}

@media (max-width: 430px) {
  .topbar {
    justify-content: flex-start;
  }

  .topbar h1 {
    padding-left: 2px;
  }

  .child-select-button {
    padding-left: 8px;
    padding-right: 8px;
  }

  .source-card small {
    font-size: 11px;
  }
}

@media (max-height: 700px) and (min-width: 721px) {
  .welcome-panel {
    justify-content: flex-start;
    padding-top: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
