:root {
  color-scheme: light;
  font: 16px/1.5 system-ui, sans-serif;
  --bg: #f5f6fa;
  --surface: #fff;
  --ink: #242638;
  --muted: #626579;
  --line: #dedfee;
  --accent: #5148b5;
  background: var(--bg);
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
header {
  padding: calc(12px + env(safe-area-inset-top)) max(16px, calc((100% - 830px)/2)) 12px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.brand, .actions { display: flex; align-items: center; gap: 8px; }
.brand { font-weight: 750; white-space: nowrap; }
.mark, .hero-mark {
  display: inline-grid; place-items: center; background: var(--accent); color: white;
  border-radius: 35%; width: 32px; height: 32px;
}
button, select, input, textarea { font: inherit; color: inherit; }
button, select {
  min-height: 44px; padding: 7px 12px; border: 1px solid var(--line);
  background: var(--surface); border-radius: 12px; cursor: pointer; font-size: .875rem;
}
select { min-width: 0; max-width: 65%; }
.primary { background: var(--accent); color: white; border-color: var(--accent); font-weight: 650; }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
main { overflow-y: auto; padding: 20px 16px; }
#welcome { text-align: center; margin: min(16vh, 120px) auto 0; }
.hero-mark { width: 66px; height: 66px; font-size: 34px; transform: rotate(-10deg); }
h1 { font-size: clamp(1.7rem, 6vw, 2.4rem); letter-spacing: -.04em; margin-bottom: 0; }
p { color: var(--muted); }
#messages { max-width: 760px; margin: auto; display: grid; gap: 20px; }
.message { min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user { justify-self: end; max-width: 88%; background: #ebe9fa; padding: 10px 15px; border-radius: 18px 18px 4px 18px; }
.message.assistant { padding: 0 4px 12px; }
.message.assistant::before { content: 'DeepSeek'; display: block; color: var(--accent); font-weight: 700; margin-bottom: 8px; }
footer { padding: 8px 16px calc(12px + env(safe-area-inset-bottom)); }
#compose { max-width: 760px; margin: auto; padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; }
textarea { width: 100%; resize: vertical; max-height: 28dvh; padding: 8px; border: 0; background: transparent; }
.composer-actions { justify-content: flex-end; }
.composer-actions select { margin-right: auto; }
#status { max-width: 760px; margin: 4px auto 0; font-size: .875rem; }
#status:empty { display: none; }
dialog { width: min(420px, calc(100% - 28px)); border: 1px solid var(--line); border-radius: 22px; padding: 22px; color: var(--ink); background: var(--surface); }
dialog::backdrop { background: #20203966; }
h2 { margin-top: 0; }
input { width: 100%; margin-top: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; }
.hint, #balance { font-size: .875rem; }
#balance { white-space: pre-line; }
a { color: var(--accent); }
.key-actions { justify-content: flex-end; margin-top: 12px; }
#balance-area { border-top: 1px solid var(--line); margin-top: 16px; }

.topbar {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  padding-block: calc(6px + env(safe-area-inset-top)) 6px;
  background: var(--surface);
}
#chat-title {
  text-align: center;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-button {
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 1.4rem;
}
.menu-icon {
  width: 18px;
  height: 12px;
  border-block: 2px solid currentColor;
  position: relative;
}
.menu-icon::after {
  content: '';
  position: absolute;
  inset: 3px 4px auto 0;
  border-top: 2px solid currentColor;
}
#drawer {
  margin: 0 auto 0 0;
  width: min(310px, 85vw);
  height: 100%;
  max-height: none;
  max-width: none;
  border: 0;
  border-radius: 0;
  background: var(--bg);
  padding: calc(12px + env(safe-area-inset-top)) 14px calc(12px + env(safe-area-inset-bottom));
}
#drawer[open] {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 12px;
}
.drawer-top { display: flex; align-items: center; justify-content: space-between; }
.drawer-top .icon-button { width: 44px; }
#drawer-new { color: var(--accent); font-weight: 700; }
#history-list {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  overflow: auto;
  color: var(--muted);
  font-size: .875rem;
}
#history-list button {
  text-align: start;
  background: transparent;
  border-color: transparent;
  flex-shrink: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
#history-list button[aria-current] { background: #ebe9fa; color: var(--accent); }
@media (max-width: 540px) {
  main { background: var(--surface); }
  footer { padding-inline: 12px; }
  #compose { border-radius: 16px; }
  #welcome { margin-top: min(20vh, 140px); }
}
