:root {
  --ink: #111111;
  --muted: #737373;
  --faint: #a1a1a1;
  --line: #e5e5e5;
  --line-dark: #cfcfcf;
  --paper: #ffffff;
  --soft: #f7f7f7;
  --soft-2: #f1f1f1;
  --shadow: 0 12px 36px rgba(0, 0, 0, 0.07);
}

* { box-sizing: border-box; }
html, body { height: 100%; min-height: 100%; overflow: hidden; }

body {
  margin: 0;
  color: var(--ink);
  background: #f5f5f5;
  font-family: "Songti SC", "STSong", "SimSun", serif;
  -webkit-font-smoothing: antialiased;
}

button, textarea, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
[hidden] { display: none !important; }

.consult-shell {
  height: 100dvh;
  min-height: 100dvh;
  max-width: 1440px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 70px minmax(0, 1fr);
  overflow: hidden;
  background: var(--paper);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.consult-header {
  grid-column: 1 / -1;
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand-lockup { grid-column: 2; padding: 0; color: inherit; background: transparent; border: 0; text-align: center; cursor: pointer; transition: opacity 180ms ease; }
.header-brand-mark { width: 180px; height: 60px; position: relative; overflow: hidden; }
.header-brand-mark img { width: 100%; height: 100%; display: block; object-fit: contain; }
.brand-hint { display: block; margin-top: -2px; color: #999; font-size: 9px; font-weight: 400; letter-spacing: .06em; opacity: 0; transition: opacity 180ms ease; }
.brand-lockup:hover .brand-hint, .brand-lockup:focus-visible .brand-hint, .brand-lockup.show-hint .brand-hint { opacity: 1; }
body.is-welcome .brand-lockup { opacity: 0; pointer-events: none; }

.round-action {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  background: transparent;
  border: 1px solid var(--line-dark);
  border-radius: 50%;
  cursor: pointer;
}
.round-action:hover, .account-trigger:hover { background: var(--soft); border-color: #999; }
.view-switch { font: 400 19px/1 Arial, sans-serif; }
.header-actions { grid-column: 3; justify-self: end; display: flex; align-items: center; gap: 9px; }
.account-trigger {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 13px;
  background: transparent;
  border: 1px solid var(--line-dark);
  border-radius: 999px;
  cursor: pointer;
}
.account-dot { width: 6px; height: 6px; border-radius: 50%; background: #999; }
.account-trigger.is-signed .account-dot { background: #111; box-shadow: 0 0 0 3px #e2e2e2; }

.conversation-column { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: #fff; }
.welcome-hero {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 22px 24px 10px;
  text-align: center;
}
.welcome-mark {
  width: min(590px, 88%);
  height: auto;
  max-height: 210px;
  aspect-ratio: 2.55 / 1;
  position: relative;
  overflow: hidden;
}
.welcome-mark img { position: absolute; top: -80%; left: 0; width: 100%; height: auto; display: block; }
.welcome-hero h2 { margin: 48px 0 10px; font-size: clamp(24px, 3vw, 34px); font-weight: 400; letter-spacing: 0.08em; }
.welcome-hero p { max-width: 620px; margin: 0; color: var(--muted); font-size: 14px; line-height: 1.9; letter-spacing: 0.04em; }

.chat-stream {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 34px max(24px, calc((100% - 790px) / 2)) 26px;
  scroll-behavior: smooth;
}
.message { display: flex; gap: 12px; margin: 0 0 24px; animation: message-in 240ms ease both; }
.message.user { justify-content: flex-end; }
.avatar {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: #111;
  background: #fff;
  border: 1px solid #111;
  border-radius: 50%;
  font-size: 13px;
}
.message.user .avatar { order: 2; color: #fff; background: #111; }
.bubble { max-width: min(690px, 84%); }
.bubble-body {
  padding: 14px 17px;
  line-height: 1.85;
  white-space: pre-wrap;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 16px 16px 16px 4px;
}
.message.user .bubble-body { color: #fff; background: #111; border-color: #111; border-radius: 16px 16px 4px 16px; }
.bubble small { display: block; margin-top: 7px; color: var(--faint); font-size: 10px; }
.message.user .bubble small { text-align: right; }
.edit-message-actions { display: none; margin-top: 8px; }
.message.is-editable .edit-message-actions { display: block; }
.edit-message-actions button { padding: 5px 10px; color: #555; background: #fff; border: 1px solid var(--line-dark); border-radius: 999px; cursor: pointer; font-size: 10px; }
.edit-message-actions button:hover { color: #fff; background: #111; border-color: #111; }
.message.user.long-pressing .bubble-body { outline: 2px solid #d6d6d6; outline-offset: 2px; }
.edit-help { margin: 0 5px 8px; color: #888; text-align: center; font-size: 10px; }

.choice-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 11px; }
.choice-row button, .quick-topics button {
  padding: 8px 14px;
  color: #222;
  background: #fff;
  border: 1px solid var(--line-dark);
  border-radius: 999px;
  cursor: pointer;
}
.choice-row button:hover, .quick-topics button:hover { color: #fff; background: #111; border-color: #111; }
.choice-row button:nth-last-child(1) { border-style: dashed; }
.typing .bubble-body { color: var(--muted); }
.typing-dots span { display: inline-block; animation: dot 1.2s infinite; }
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
.stream-label { margin-bottom: 8px; color: #555; font-size: 11px; }
.stream-text { color: var(--ink); white-space: pre-wrap; }

.quick-topics { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; padding: 0 20px 14px; }
.quick-topics button { font-size: 12px; }
.composer { padding: 0 max(24px, calc((100% - 790px) / 2)) 18px; background: #fff; }
.composer-field {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 9px 9px 9px 17px;
  background: #fff;
  border: 1px solid #c9c9c9;
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.composer textarea { flex: 1; min-height: 30px; max-height: 130px; resize: none; color: #111; background: transparent; border: 0; outline: 0; line-height: 1.7; }
.composer textarea::placeholder { color: #999; }
.composer button {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  color: #fff;
  background: #111;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  font: 500 21px/1 Arial, sans-serif;
}
.composer #voice-button { flex-basis: 34px; width: 34px; height: 34px; color: #555; background: #f5f5f5; border: 1px solid var(--line); font-size: 14px; }
.composer #voice-button:hover, .composer #voice-button.is-listening { color: #fff; background: #111; border-color: #111; }
.composer button:disabled { opacity: .3; cursor: wait; }
.voice-status { margin: 5px 5px 0; color: #777; font-size: 10px; }
.composer > p { margin: 8px 5px 0; color: #999; text-align: center; font-size: 9px; }

.result-card { margin-top: 12px; overflow: hidden; background: #fff; border: 1px solid var(--line-dark); border-radius: 2px; }
.result-card header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 15px; color: #fff; background: #111; }
.result-card header strong { font-size: 18px; font-weight: 400; letter-spacing: .06em; }
.result-card header span { color: #cfcfcf; font-size: 10px; text-align: right; }
.chart-preview { width: 100%; height: auto; display: block; object-fit: contain; object-position: top; background: #fff; border-bottom: 1px solid var(--line); }
.digest-grid { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }
.digest-grid div { padding: 10px 8px; text-align: center; border-right: 1px solid var(--line); }
.digest-grid div:last-child { border: 0; }
.digest-grid span { display: block; color: #888; font-size: 9px; }
.digest-grid strong { display: block; margin-top: 4px; font-size: 11px; line-height: 1.5; }
.report-tabs { display: flex; padding: 10px 12px 0; gap: 8px; }
.report-tabs button { flex: 1; padding: 9px; color: #777; background: transparent; border: 0; border-bottom: 1px solid var(--line-dark); cursor: pointer; }
.report-tabs button.active { color: #111; border-color: #111; font-weight: 700; }
.report-tabs button.locked { color: #999; background: #f6f6f6; cursor: help; }
.report-content { padding: 16px 17px 19px; white-space: pre-wrap; line-height: 1.95; font-size: 13px; }
.report-heading { color: #111; font-weight: 700; line-height: 1.45; white-space: normal; }
.report-heading-1 { margin: 4px 0 12px; font-size: 1.34em; }
.report-heading-2 { margin: 3px 0 10px; font-size: 1.2em; }
.report-heading-3 { margin: 2px 0 8px; font-size: 1.08em; }
.teacher-lock { margin: 0 15px 15px; padding: 12px 14px; color: #555; background: #f5f5f5; border-left: 2px solid #111; font-size: 11px; line-height: 1.8; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 15px 15px; }
.result-actions a, .result-actions button { flex: 1 1 140px; padding: 9px; color: #222; text-align: center; text-decoration: none; background: #fff; border: 1px solid var(--line-dark); cursor: pointer; }
.result-actions a:hover, .result-actions button:hover { color: #fff; background: #111; border-color: #111; }
.result-next { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 15px 15px; }
.result-next button { padding: 10px; color: #fff; background: #111; border: 1px solid #111; cursor: pointer; }
.result-next button:last-child { color: #111; background: #fff; }

.account-dialog {
  width: min(420px, calc(100vw - 28px));
  padding: 26px;
  color: #111;
  background: #fff;
  border: 1px solid #d0d0d0;
  border-radius: 16px;
  box-shadow: 0 28px 90px rgba(0, 0, 0, .18);
}
.account-dialog::backdrop { background: rgba(255, 255, 255, .78); backdrop-filter: blur(8px); }
.dialog-close-row { position: absolute; top: 9px; right: 11px; }
.dialog-close-row button { width: 32px; height: 32px; color: #555; background: transparent; border: 0; font-size: 24px; cursor: pointer; }
.account-dialog-title { display: flex; align-items: center; gap: 12px; margin: 4px 0 21px; }
.brand-seal { width: 40px; height: 40px; display: grid; place-items: center; color: #fff; background: #111; border-radius: 50%; font-size: 12px; }
.account-dialog-title h2, .account-signed-view h2 { margin: 0; font-size: 24px; font-weight: 400; }
.account-dialog-title p { margin: 3px 0 0; color: #888; font-size: 11px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 17px; border-bottom: 1px solid var(--line); }
.auth-tabs button { padding: 10px; color: #888; background: transparent; border: 0; border-bottom: 1px solid transparent; cursor: pointer; }
.auth-tabs button.active { color: #111; border-color: #111; font-weight: 700; }
.auth-field { display: grid; gap: 7px; margin-top: 14px; }
.auth-field span { color: #777; font-size: 11px; }
.auth-field input { width: 100%; min-height: 44px; padding: 0 13px; color: #111; background: #fff; border: 1px solid #d0d0d0; border-radius: 7px; outline: 0; }
.auth-field input:focus { border-color: #111; box-shadow: 0 0 0 3px #eee; }
.auth-status { min-height: 20px; margin: 10px 0 4px; color: #333; font-size: 11px; }
.auth-submit, .account-signed-view button { width: 100%; min-height: 44px; color: #fff; background: #111; border: 0; border-radius: 7px; cursor: pointer; }
.auth-submit:disabled { opacity: .45; cursor: wait; }
.auth-tip { margin: 13px 0 0; color: #888; font-size: 10px; line-height: 1.7; }
.account-signed-view { padding: 24px 5px 6px; text-align: center; }
.signed-seal, .signed-membership-label { display: inline-block; padding: 5px 11px; color: #111; background: #f3f3f3; border: 1px solid #ddd; border-radius: 999px; font-size: 10px; }
.account-signed-view h2 { margin-top: 15px; }
.signed-membership-label { margin-top: 9px; }
.account-signed-view p { margin: 10px 0 22px; color: #777; line-height: 1.8; font-size: 12px; }

.idle-dialog {
  width: min(390px, calc(100vw - 30px));
  padding: 27px 25px 23px;
  color: #111;
  background: #fff;
  border: 1px solid #d0d0d0;
  border-radius: 14px;
  box-shadow: 0 28px 90px rgba(0, 0, 0, .18);
  text-align: center;
}
.idle-dialog::backdrop { background: rgba(255,255,255,.82); backdrop-filter: blur(8px); }
.idle-dialog-mark { width: 38px; height: 38px; display: grid; place-items: center; margin: 0 auto 14px; color: #fff; background: #111; border-radius: 50%; font-size: 11px; }
.idle-dialog h2 { margin: 0; font-size: 22px; font-weight: 400; }
.idle-dialog p { margin: 12px 0 20px; color: #666; font-size: 12px; line-height: 1.8; }
.idle-dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.idle-dialog-actions button { min-height: 42px; color: #fff; background: #111; border: 1px solid #111; border-radius: 6px; cursor: pointer; }
.idle-dialog-actions button:last-child { color: #111; background: #fff; }
.idle-dialog-ended .idle-dialog-actions { grid-template-columns: 1fr; }

@keyframes message-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes dot { 0%, 70%, 100% { opacity: .2; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-2px); } }

@media (max-width: 880px) {
  body { background: #fff; }
  .consult-shell { display: flex; flex-direction: column; width: 100%; min-height: 100dvh; border: 0; }
  .consult-header { flex: 0 0 62px; min-height: 62px; padding: 0 12px; }
  .header-brand-mark { width: 148px; height: 50px; }
  .brand-hint { font-size: 8px; }
  .round-action { width: 34px; height: 34px; }
  .account-trigger { width: auto; min-width: 58px; max-width: 112px; min-height: 34px; padding: 0 10px; justify-content: center; gap: 6px; font-size: 12px; white-space: nowrap; }
  .account-trigger #account-label { display: block; max-width: 76px; overflow: hidden; text-overflow: ellipsis; }
  .header-actions { gap: 7px; }
  .conversation-column { flex: 1; min-height: 0; }
  .welcome-hero { padding: 10px 18px 6px; }
  .welcome-mark { width: min(410px, 100%); max-height: 160px; }
  .welcome-hero h2 { margin-top: 36px; font-size: 24px; }
  .welcome-hero p { max-width: 330px; font-size: 12px; line-height: 1.8; }
  .chat-stream { padding: 22px 13px 18px; }
  .message { gap: 8px; margin-bottom: 19px; }
  .avatar { width: 30px; height: 30px; flex-basis: 30px; font-size: 11px; }
  .bubble { max-width: calc(100% - 38px); }
  .bubble-body { padding: 12px 14px; font-size: 14px; line-height: 1.75; }
  .quick-topics { justify-content: flex-start; overflow-x: auto; flex-wrap: nowrap; padding: 0 13px 10px; scrollbar-width: none; }
  .quick-topics button { flex: 0 0 auto; padding: 7px 12px; font-size: 11px; }
  .composer { padding: 6px 11px max(11px, env(safe-area-inset-bottom)); }
  .composer > p { display: none; }
  .composer > .voice-status { display: block; }
  .composer > .edit-help { display: block; }
  .composer-field { border-radius: 16px; box-shadow: 0 7px 24px rgba(0, 0, 0, .08); }
  .digest-grid { grid-template-columns: repeat(2, 1fr); }
  .digest-grid div:nth-child(2) { border-right: 0; }
  .digest-grid div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .result-card header { align-items: flex-start; flex-direction: column; gap: 4px; }
}

body[data-consult-view-mode="mobile"] { background: #ececec; }
body[data-consult-view-mode="mobile"] .consult-shell { display: flex; flex-direction: column; width: min(100%, 460px); min-height: 100dvh; margin: 0 auto; border: 0; box-shadow: 0 0 48px rgba(0, 0, 0, .1); }
body[data-consult-view-mode="mobile"] .consult-header { flex: 0 0 62px; min-height: 62px; padding: 0 12px; }
body[data-consult-view-mode="mobile"] .header-brand-mark { width: 148px; height: 50px; }
body[data-consult-view-mode="mobile"] .brand-hint { font-size: 8px; }
body[data-consult-view-mode="mobile"] .round-action { width: 34px; height: 34px; }
body[data-consult-view-mode="mobile"] .account-trigger { width: auto; min-width: 58px; max-width: 112px; min-height: 34px; padding: 0 10px; justify-content: center; gap: 6px; font-size: 12px; white-space: nowrap; }
body[data-consult-view-mode="mobile"] .account-trigger #account-label { display: block; max-width: 76px; overflow: hidden; text-overflow: ellipsis; }
body[data-consult-view-mode="mobile"] .header-actions { gap: 7px; }
body[data-consult-view-mode="mobile"] .conversation-column { flex: 1; min-height: 0; }
body[data-consult-view-mode="mobile"] .welcome-hero { padding: 10px 18px 6px; }
body[data-consult-view-mode="mobile"] .welcome-mark { width: min(410px, 100%); max-height: 160px; }
body[data-consult-view-mode="mobile"] .welcome-hero h2 { margin-top: 36px; font-size: 24px; }
body[data-consult-view-mode="mobile"] .welcome-hero p { max-width: 330px; font-size: 12px; line-height: 1.8; }
body[data-consult-view-mode="mobile"] .chat-stream { padding: 22px 13px 18px; }
body[data-consult-view-mode="mobile"] .message { gap: 8px; margin-bottom: 19px; }
body[data-consult-view-mode="mobile"] .avatar { width: 30px; height: 30px; flex-basis: 30px; font-size: 11px; }
body[data-consult-view-mode="mobile"] .bubble { max-width: calc(100% - 38px); }
body[data-consult-view-mode="mobile"] .bubble-body { padding: 12px 14px; font-size: 14px; line-height: 1.75; }
body[data-consult-view-mode="mobile"] .quick-topics { justify-content: flex-start; overflow-x: auto; flex-wrap: nowrap; padding: 0 13px 10px; scrollbar-width: none; }
body[data-consult-view-mode="mobile"] .quick-topics button { flex: 0 0 auto; padding: 7px 12px; font-size: 11px; }
body[data-consult-view-mode="mobile"] .composer { padding: 6px 11px max(11px, env(safe-area-inset-bottom)); }
body[data-consult-view-mode="mobile"] .composer > p { display: none; }
body[data-consult-view-mode="mobile"] .composer > .voice-status { display: block; }
body[data-consult-view-mode="mobile"] .composer > .edit-help { display: block; }
body[data-consult-view-mode="mobile"] .composer-field { border-radius: 16px; }
body[data-consult-view-mode="mobile"] .digest-grid { grid-template-columns: repeat(2, 1fr); }
body[data-consult-view-mode="mobile"] .digest-grid div:nth-child(2) { border-right: 0; }
body[data-consult-view-mode="mobile"] .digest-grid div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }

body[data-consult-view-mode="desktop"] .consult-shell { max-width: 1440px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; scroll-behavior: auto !important; }
}
