/* Chinese typography includes the original HarmonyOS Sans SC, © Huawei Device Co., Ltd. */
@font-face {
  font-family: "HarmonyOS Sans SC Web";
  src: url("/web-fonts/HarmonyOS_Sans_SC_Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
:root {
  color-scheme: light;
  --ink: #1d1d1f;
  --muted: #606472;
  --surface: #f6f7fa;
  --blue: #0066df;
  --glass: linear-gradient(155deg, #ffffffc7, #f3f6ff8f 54%, #e0e8fb9c);
  --glass-edge: #ffffffd6;
  --glass-shadow: inset 0 1px 1px #fff, inset 0 -1px 1px #8aa0c222, 0 4px 14px #33487218;
  font-family: "PingFang SC", "HarmonyOS Sans SC", "HarmonyOS Sans SC Web",
    -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; color: var(--ink);
  background: radial-gradient(ellipse at 19% 21%, #dceaff 0, transparent 43%),
    radial-gradient(ellipse at 83% 62%, #e8e3fb 0, transparent 45%),
    radial-gradient(ellipse at 51% 0%, #fef5dc 0, transparent 35%), var(--surface);
  background-attachment: fixed;
}
button, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.topbar {
  position: sticky; top: 0; z-index: 2;
  background: #f7f9fd93;
  -webkit-backdrop-filter: saturate(160%) blur(22px);
  backdrop-filter: saturate(160%) blur(22px);
  border-bottom: 1px solid #ffffffce;
}
.topbar-inner {
  max-width: 1120px; margin: auto; padding: 0 28px; height: 60px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { display: inline-flex; align-items: center; gap: 11px; font-size: 15px; font-weight: 650; white-space: nowrap; }
.brand-mark, .orb img { display: block; object-fit: cover; object-position: 50% 42%; }
.brand-mark { width: 29px; height: 29px; border-radius: 10px; border: 1px solid #fff; box-shadow: 0 2px 6px #27334c20; }
.topbar-actions { position: relative; display: flex; align-items: center; gap: 8px; }
.new-chat { display: inline-flex; align-items: center; gap: 5px; min-height: 36px; padding: 8px 13px; border-radius: 99px; color: var(--ink); font-size: 13px; white-space: nowrap; }
.new-chat svg { width: 15px; height: 15px; }
.history-panel { position: absolute; z-index: 3; top: calc(100% + 10px); right: 0; width: min(294px, calc(100vw - 32px)); padding: 10px; border-radius: 21px; animation: enter .2s ease-out both; }
.history-title { padding: 6px 9px 9px; font-size: 13px; font-weight: 650; }
.history-panel ul { list-style: none; padding: 0; margin: 0; max-height: min(48vh, 320px); overflow: auto; }
.history-panel button { display: block; width: 100%; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 0; border-radius: 12px; padding: 9px; color: #263248; background: transparent; font-size: 13px; }
.history-panel button:hover, .history-panel button[aria-current="true"] { background: #d8e8fbdc; }

.chat { width: min(100% - 48px, 764px); margin: auto; min-height: calc(100dvh - 61px); display: flex; flex-direction: column; }
.welcome { text-align: center; padding: clamp(52px, 12vh, 130px) 0 30px; animation: enter .55s ease-out both; }
.orb { margin: 0 auto 25px; width: 80px; height: 80px; border-radius: 25px; padding: 3px; background: #fffc; box-shadow: 0 12px 31px #715d3036; }
.orb img { width: 100%; height: 100%; border-radius: 22px; }
.welcome h1 { margin: 0; font-size: clamp(35px, 6vw, 64px); font-weight: 720; line-height: 1.22; letter-spacing: .045em; }
.welcome p { margin: 16px 0 0; color: var(--muted); font-size: clamp(15px, 2.6vw, 19px); line-height: 1.65; }
.dock { z-index: 1; padding: 8px 0 26px; }
.chat.active .dock {
  position: sticky; bottom: 0; margin-top: auto;
  padding: 20px 0 max(18px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, #f3f6fcce 29%, #f3f6fce8);
}
.composer {
  display: grid; gap: 5px; padding: 13px; border: 1px solid #ffffffec; border-radius: 27px;
  background: linear-gradient(145deg, #fffffff1, #f7f9ffcd 64%, #eaf0ffcf);
  box-shadow: var(--glass-shadow), 0 15px 44px #293d7018;
  -webkit-backdrop-filter: blur(24px) saturate(145%);
  backdrop-filter: blur(24px) saturate(145%);
  transition: border-color .18s, box-shadow .18s;
}
.composer:focus-within { border-color: #8cb4ee; box-shadow: 0 0 0 3px #0066df12, 0 15px 44px #222c4e0b; }
.composer textarea { width: 100%; min-height: 50px; max-height: 145px; padding: 12px 10px; border: 0; outline: 0; resize: none; line-height: 1.6; background: transparent; color: var(--ink); font-size: 16px; }
.composer textarea::placeholder { color: #646979; }
.composer-bar { display: flex; align-items: center; justify-content: space-between; }
.glass-control, .glass-surface, .suggestions button {
  border: 1px solid var(--glass-edge);
  background: var(--glass);
  box-shadow: var(--glass-shadow);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
}
.glass-control, .suggestions button { transition: transform .19s, box-shadow .19s, filter .19s; }
.glass-control:not(:disabled):hover, .suggestions button:hover { filter: brightness(1.045); transform: translateY(-1px); box-shadow: var(--glass-shadow), 0 5px 16px #5671a524; }
.glass-control:not(:disabled):active, .suggestions button:active { transform: scale(.96); }
.mode { position: relative; }
.mode-toggle { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 99px; color: #30394d; font-size: 13px; }
.mode-toggle svg { width: 15px; height: 15px; transition: transform .22s; }
.mode-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
.mode-menu {
  position: absolute; left: 0; bottom: calc(100% + 9px); z-index: 3;
  min-width: 156px; padding: 6px; border-radius: 21px;
  background: linear-gradient(150deg, #fcfdfff2, #e7efffee);
  box-shadow: var(--glass-shadow), 0 13px 34px #3f548d31;
  opacity: 0; visibility: hidden; pointer-events: none;
  transform: translateY(6px) scale(.96); transform-origin: bottom left;
  transition: opacity .18s ease, transform .18s ease, visibility 0s linear .18s;
}
.mode-menu[data-open] { opacity: 1; visibility: visible; pointer-events: auto; transform: none; transition-delay: 0s; }
.mode-menu button { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 8px 10px; min-height: 36px; border: 0; border-radius: 14px; color: #263248; background: none; font-size: 13px; white-space: nowrap; text-align: left; }
.mode-menu button[aria-checked="true"] { color: #0b4d9a; background: #d9e8fce8; }
.mode-menu button[aria-checked="true"]::after { content: "✓"; padding-left: 12px; }
.mode-menu button:hover, .mode-menu button:focus-visible { background: #cbdffbe8; outline: none; }
.send { display: grid; place-items: center; width: 42px; height: 42px; padding: 0; border-radius: 50%; color: white; background: linear-gradient(147deg, #66aef9, #126bde 62%, #3057bd); border-color: #bfdeff; box-shadow: inset 0 1px 3px #e6f5ff8f, 0 4px 12px #2561c946; }
.send:disabled { background: var(--glass); color: #65748b; cursor: default; box-shadow: var(--glass-shadow); }
.suggestions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 17px; }
.suggestions button { padding: 8px 13px; border-radius: 99px; color: #374258; font-size: 13px; }

.conversation { padding: 29px 0 16px; }
.chat-turns { display: grid; gap: 24px; }
.message { min-width: 0; animation: enter .23s ease-out both; }
.user { justify-self: end; max-width: min(87%, 620px); background: linear-gradient(145deg, #f0f7ffde, #dbe8ffde); border: 1px solid #f9fcff; box-shadow: 0 3px 10px #425d8e13; padding: 12px 17px; border-radius: 22px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.65; }
.assistant { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 12px; align-items: start; }
.assistant .brand-mark { margin-top: 3px; }
.reply { min-width: 0; background: #ffffffcf; border: 1px solid #fffffff4; box-shadow: 0 4px 15px #425d8e12; border-radius: 22px; padding: 16px 20px; }
.answer-text { font-size: 16px; line-height: 1.8; white-space: pre-wrap; overflow-wrap: anywhere; }
.answer-text .katex-display { max-width: 100%; overflow-x: auto; overflow-y: hidden; margin: .6em 0; padding: .18em 0; }
.answer-text .katex { white-space: nowrap; }
.typing { display: flex; align-items: center; gap: 5px; min-height: 24px; }
.typing span { display: block; width: 6px; height: 6px; background: #6d81ab; border-radius: 50%; animation: pulse .95s ease-in-out infinite alternate; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { from { opacity: .35; transform: translateY(0); } to { opacity: 1; transform: translateY(-3px); } }

@media (max-width: 560px) {
  .topbar-inner { padding: 0 16px; height: 54px; }
  .brand { gap: 7px; font-size: 13px; }
  .topbar-actions { gap: 5px; }
  .new-chat { padding: 7px 9px; }
  #history-toggle span { display: none; }
  .chat { width: calc(100% - 28px); min-height: calc(100dvh - 55px); }
  .welcome { padding-top: clamp(42px, 9vh, 76px); }
  .orb { width: 65px; height: 65px; border-radius: 20px; margin-bottom: 20px; }
  .orb img { border-radius: 17px; }
  .conversation { padding-top: 20px; }
  .chat-turns { gap: 18px; }
  .assistant { grid-template-columns: 24px minmax(0, 1fr); gap: 7px; }
  .assistant .brand-mark { width: 23px; height: 23px; border-radius: 8px; }
  .reply { padding: 12px; }
  .answer-text { font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
