:root {
  color-scheme: light;
  --bg: #f5f5f2;
  --surface: #ffffff;
  --ink: #171816;
  --muted: #7c7e78;
  --line: #e5e6e1;
  --accent: #20211f;
  --assistant: #ffffff;
  --user: #252724;
  --success: #39795a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

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

.is-hidden {
  display: none !important;
}

.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(circle at 50% 0%, #fff 0, transparent 45%),
    var(--bg);
}

.login-box {
  width: min(360px, 100%);
  padding: 2.4rem 2rem;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 24px 80px rgba(20, 22, 18, 0.08);
  text-align: center;
}

.brand-mark,
.avatar,
.message-avatar {
  display: grid;
  place-items: center;
  color: white;
  background: var(--accent);
  font-family: Georgia, serif;
}

.brand-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 1.2rem;
  border-radius: 18px;
  font-size: 1.8rem;
}

.login-box h1 {
  margin: 0;
  font-family: Georgia, serif;
  font-size: 2rem;
  letter-spacing: 0.04em;
}

.login-box > p {
  margin: 0.5rem 0 2.2rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.login-box label {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.8rem;
  text-align: left;
}

.login-box label span {
  color: var(--muted);
  font-size: 0.72rem;
}

.login-box input {
  width: 100%;
  height: 52px;
  padding: 0 0.9rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  background: #fafaf8;
}

.login-box input:focus {
  border-color: var(--ink);
}

.login-box button {
  width: 100%;
  height: 52px;
  margin-top: 0.8rem;
  border: 0;
  border-radius: 14px;
  color: white;
  background: var(--accent);
  cursor: pointer;
}

.error-text {
  min-height: 1.2rem;
  margin: 0.7rem 0 0 !important;
  color: #a9342e !important;
  font-size: 0.76rem !important;
}

.app-view {
  width: min(760px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(229, 230, 225, 0.85);
  background: rgba(245, 245, 242, 0.92);
  backdrop-filter: blur(18px);
}

.identity,
.header-actions {
  display: flex;
  align-items: center;
}

.identity {
  gap: 0.7rem;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  font-size: 1.2rem;
}

.identity div:last-child {
  display: grid;
  gap: 0.15rem;
}

.identity strong {
  font-family: Georgia, serif;
  font-size: 1.05rem;
}

.identity span {
  color: var(--success);
  font-size: 0.68rem;
}

.header-actions {
  gap: 0.5rem;
}

.header-actions > button:not(.round-button) {
  height: 38px;
  padding: 0 0.85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 0.75rem;
  cursor: pointer;
}

.history-drawer,
.settings-drawer,
.tasks-drawer {
  position: fixed;
  z-index: 60;
  inset: 0;
}

.history-backdrop,
.settings-backdrop,
.tasks-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 21, 19, 0.3);
  backdrop-filter: blur(3px);
}

.history-panel,
.settings-panel,
.tasks-panel {
  position: absolute;
  top: 0;
  right: max(0px, calc((100vw - 760px) / 2));
  width: min(360px, 88vw);
  height: 100dvh;
  padding: max(1rem, env(safe-area-inset-top)) 1rem 1rem;
  overflow-y: auto;
  background: var(--bg);
  box-shadow: -18px 0 50px rgba(20, 22, 18, 0.15);
}

.history-panel > header,
.settings-panel > header,
.tasks-panel > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.history-panel > header div,
.settings-panel > header div,
.tasks-panel > header div {
  display: grid;
  gap: 0.2rem;
}

.history-panel > header strong,
.settings-panel > header strong,
.tasks-panel > header strong {
  font-family: Georgia, serif;
  font-size: 1.15rem;
}

.history-panel > header span,
.settings-panel > header span,
.tasks-panel > header span,
.history-empty,
.tasks-empty {
  color: var(--muted);
  font-size: 0.7rem;
}

.history-panel > header button,
.settings-panel > header button,
.tasks-panel > header button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  font-size: 1.2rem;
  cursor: pointer;
}

.settings-group {
  display: grid;
  margin-bottom: 0.8rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
}

.settings-row {
  display: flex;
  min-height: 66px;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.8rem 0.9rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  text-decoration: none;
}

button.settings-row {
  cursor: pointer;
}

.settings-link {
  cursor: pointer;
}

.brand-mark.has-image,
.avatar.has-image,
.message-avatar.has-image {
  background-color: white;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  color: transparent;
}

.settings-row:last-child {
  border-bottom: 0;
}

.settings-row > span {
  display: grid;
  gap: 0.22rem;
}

.settings-row strong {
  font-size: 0.82rem;
}

.settings-row small {
  color: var(--muted);
  font-size: 0.66rem;
  line-height: 1.4;
}

.settings-row b {
  color: var(--muted);
  font-size: 1.25rem;
  font-weight: 400;
}

.settings-toggle input {
  position: relative;
  flex: 0 0 auto;
  width: 42px;
  height: 24px;
  appearance: none;
  border-radius: 999px;
  outline: none;
  background: #d5d6d1;
  cursor: pointer;
  transition: background 160ms ease;
}

.settings-toggle input::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 4px rgba(20, 22, 18, 0.24);
  content: "";
  transition: transform 160ms ease;
}

.settings-toggle input:checked {
  background: var(--accent);
}

.settings-toggle input:checked::after {
  transform: translateX(18px);
}

.settings-row.danger-soft strong {
  color: #9a5b34;
}

.settings-row.danger strong {
  color: #a9342e;
}

.settings-note {
  margin: 1rem 0;
  color: var(--muted);
  font-size: 0.66rem;
  line-height: 1.6;
  text-align: center;
}

.history-list {
  display: grid;
  gap: 0.55rem;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr 32px;
  gap: 0.5rem;
  align-items: center;
  padding: 0.75rem 0.65rem 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.history-item.is-active {
  border-color: #959790;
}

.history-open {
  display: grid;
  gap: 0.3rem;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.history-open strong,
.history-open span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-open strong {
  font-size: 0.82rem;
}

.history-open span {
  color: var(--muted);
  font-size: 0.66rem;
}

.history-delete {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  color: #9a3f38;
  background: #faf4f3;
  cursor: pointer;
}

.history-empty {
  padding: 2rem 0;
  text-align: center;
}

.tasks-list {
  display: grid;
  gap: 0.65rem;
}

.task-item {
  display: grid;
  gap: 0.55rem;
  padding: 0.78rem;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
}

.task-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}

.task-item-header strong {
  min-width: 0;
  overflow: hidden;
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-item-header span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.66rem;
}

.task-progress {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #ecede8;
}

.task-progress i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 240ms ease;
}

.task-meta,
.task-error,
.task-result p,
.tasks-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.55;
}

.task-error {
  color: #a9342e;
}

.task-result {
  display: grid;
  gap: 0.55rem;
}

.task-result img {
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  border-radius: 12px;
  background: #efefeb;
}

.task-result button,
.task-result a {
  justify-self: start;
  padding: 0.5rem 0.72rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafaf8;
  color: var(--ink);
  font-size: 0.7rem;
  cursor: pointer;
  text-decoration: none;
}

.tasks-empty {
  padding: 2rem 0;
  text-align: center;
}

.round-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
}

.speech-control {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  transition:
    color 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.speech-control svg {
  width: 19px;
  height: 19px;
  overflow: visible;
  fill: currentColor;
}

.speech-control path {
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.speech-control .speech-wave,
.speech-control .speech-slash {
  fill: none;
}

.speech-control .speech-wave {
  display: none;
}

.speech-control.is-active {
  border-color: var(--accent);
  color: white;
  background: var(--accent);
}

.speech-control.is-active .speech-wave {
  display: block;
}

.speech-control.is-active .speech-slash {
  display: none;
}

.conversation {
  flex: 1;
  padding: 1.2rem 1rem 9.5rem;
  overflow-y: auto;
}

.day-label {
  margin: 0.2rem 0 1.4rem;
  color: #a2a39f;
  font-size: 0.66rem;
  text-align: center;
}

.message {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

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

.message-avatar {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 11px;
  font-size: 0.86rem;
}

.bubble {
  max-width: min(82%, 560px);
  padding: 0.78rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 4px 16px 16px 16px;
  background: var(--assistant);
  box-shadow: 0 4px 18px rgba(20, 22, 18, 0.025);
}

.message.user .bubble {
  border-color: var(--user);
  border-radius: 16px 4px 16px 16px;
  color: white;
  background: var(--user);
}

.bubble p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.65;
  white-space: pre-wrap;
}

.bubble p + p {
  margin-top: 0.55rem;
}

.message-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.message-link.is-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  margin: 0.2rem 0.2rem 0.2rem 0;
  padding: 0.45rem 0.8rem;
  border: 1px solid #1d1e1a;
  border-radius: 999px;
  color: white;
  background: #1d1e1a;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
}

.message-link.is-preview {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  margin: 0.2rem 0.2rem 0.2rem 0;
  padding: 0.45rem 0.8rem;
  border: 1px solid #1d1e1a;
  border-radius: 999px;
  color: #1d1e1a;
  background: white;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
}

.bubble .message-image {
  display: block;
  width: min(100%, 440px);
  max-height: 70dvh;
  margin: -0.35rem -0.45rem 0.65rem;
  border-radius: 12px;
  object-fit: contain;
  background: #efefeb;
}

.image-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.image-actions button,
.image-actions a {
  padding: 0.52rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: #fafaf8;
  font-size: 0.7rem;
  text-decoration: none;
  cursor: pointer;
}

.starter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin: 1.2rem 0 0 2.55rem;
}

.starter-grid button {
  min-height: 48px;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.7);
  color: #62645f;
  font-size: 0.76rem;
  text-align: left;
  cursor: pointer;
}

.thinking {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 52px;
  min-height: 22px;
}

.thinking i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #858780;
  animation: bounce 700ms infinite alternate;
}

.thinking i:nth-child(2) {
  animation-delay: 140ms;
}

.thinking i:nth-child(3) {
  animation-delay: 280ms;
}

@keyframes bounce {
  to {
    transform: translateY(-5px);
    opacity: 0.45;
  }
}

.attachment-bar {
  position: fixed;
  z-index: 25;
  right: 0;
  bottom: calc(76px + env(safe-area-inset-bottom));
  left: 0;
  display: grid;
  width: min(728px, calc(100% - 2rem));
  grid-template-columns: 44px 1fr 30px;
  gap: 0.65rem;
  align-items: center;
  margin: auto;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 30px rgba(20, 22, 18, 0.1);
}

.attachment-bar img {
  width: 44px;
  height: 44px;
  border-radius: 9px;
  object-fit: cover;
}

.attachment-bar div {
  display: grid;
  gap: 0.12rem;
}

.attachment-bar strong {
  font-size: 0.75rem;
}

.attachment-bar span {
  color: var(--muted);
  font-size: 0.65rem;
}

.attachment-bar button {
  border: 0;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
}

.composer {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  width: min(760px, 100%);
  grid-template-columns: 44px minmax(0, 1fr) 44px 44px;
  gap: 0.55rem;
  align-items: end;
  margin: auto;
  padding: 0.7rem 1rem max(0.7rem, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(229, 230, 225, 0.86);
  background: rgba(245, 245, 242, 0.96);
  backdrop-filter: blur(18px);
}

.composer.is-voice-mode {
  grid-template-columns: 44px minmax(0, 1fr) 44px;
}

.composer.is-voice-mode .send-button {
  display: none;
}

.attach-button,
.send-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
  cursor: pointer;
}

.attach-button {
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 1.25rem;
}

.input-wrap {
  position: relative;
  display: flex;
  min-height: 44px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
}

.input-wrap textarea {
  width: 100%;
  max-height: 124px;
  padding: 0.68rem 2.8rem 0.68rem 0.9rem;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: 0;
  background: transparent;
  line-height: 1.45;
}

.voice-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
}

.voice-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.voice-button .keyboard-mode-icon {
  display: none;
}

.voice-button.is-keyboard-mode .voice-mode-icon {
  display: none;
}

.voice-button.is-keyboard-mode .keyboard-mode-icon {
  display: block;
}

.hold-to-talk {
  width: 100%;
  min-height: 42px;
  padding: 0 1rem;
  border: 0;
  border-radius: 22px;
  color: var(--ink);
  background: transparent;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  cursor: pointer;
}

.hold-to-talk::selection {
  background: transparent;
}

.hold-to-talk.is-recording {
  color: var(--accent);
  background: #efefeb;
}

.hold-to-talk.is-processing {
  cursor: wait;
  color: var(--muted);
}

.voice-overlay {
  position: fixed;
  z-index: 80;
  right: 0;
  bottom: calc(88px + env(safe-area-inset-bottom));
  left: 0;
  display: grid;
  width: min(260px, calc(100% - 3rem));
  justify-items: center;
  gap: 0.4rem;
  margin: auto;
  padding: 1.4rem 1rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 24px;
  color: white;
  background: rgba(25, 27, 24, 0.92);
  box-shadow: 0 18px 60px rgba(20, 22, 18, 0.28);
  backdrop-filter: blur(16px);
  pointer-events: none;
}

.voice-overlay.is-canceling {
  background: rgba(145, 50, 43, 0.94);
}

.voice-overlay.is-processing {
  background: rgba(42, 64, 54, 0.94);
}

.voice-overlay strong {
  margin-top: 0.25rem;
  font-size: 0.9rem;
}

.voice-overlay span {
  color: rgba(255, 255, 255, 0.68);
  font-size: 0.68rem;
}

.voice-overlay time {
  color: rgba(255, 255, 255, 0.52);
  font-size: 0.65rem;
  font-variant-numeric: tabular-nums;
}

.voice-orb {
  display: flex;
  width: 74px;
  height: 74px;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
}

.voice-orb i {
  width: 4px;
  height: 16px;
  border-radius: 999px;
  background: white;
  transform: scaleY(var(--voice-level, 0.16));
  transform-origin: center;
  transition: transform 80ms linear, opacity 120ms ease;
}

.voice-orb i:nth-child(2),
.voice-orb i:nth-child(4) {
  height: 29px;
}

.voice-orb i:nth-child(3) {
  height: 40px;
}

.voice-orb i:nth-child(5) {
  height: 22px;
}

.voice-overlay.is-processing .voice-orb {
  animation: voice-processing 1s ease-in-out infinite alternate;
}

@keyframes voice-processing {
  to {
    transform: scale(0.88);
    opacity: 0.62;
  }
}

.send-button {
  border: 0;
  color: white;
  background: var(--accent);
  font-size: 1.15rem;
}

.send-button:disabled {
  opacity: 0.42;
}

@media (min-width: 761px) {
  body {
    background: #e9eae6;
  }

  .app-view {
    border-right: 1px solid var(--line);
    border-left: 1px solid var(--line);
    box-shadow: 0 0 60px rgba(20, 22, 18, 0.05);
  }
}

@media (max-width: 480px) {
  .app-header {
    padding-right: 0.75rem;
    padding-left: 0.75rem;
  }

  .header-actions {
    gap: 0.35rem;
  }

  #historyButton {
    display: none;
  }

  .header-actions > button:not(.round-button) {
    padding: 0 0.65rem;
  }

  .conversation {
    padding-right: 0.75rem;
    padding-left: 0.75rem;
  }

  .composer {
    grid-template-columns: 42px minmax(0, 1fr) 42px 42px;
    gap: 0.42rem;
    padding-right: 0.7rem;
    padding-left: 0.7rem;
  }

  .composer.is-voice-mode {
    grid-template-columns: 42px minmax(0, 1fr) 42px;
  }

  .attach-button,
  .voice-button,
  .send-button {
    width: 42px;
    height: 42px;
  }

  .starter-grid {
    margin-left: 2.3rem;
  }

  .bubble {
    max-width: 86%;
  }
}
