:root {
  --bg: #1a1d21;
  --panel: rgba(255, 255, 255, 0.06);
  --panel2: rgba(255, 255, 255, 0.04);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.62);
  --accent: #6ea8fe;
  --danger: #ff5a6a;
  --border: rgba(255, 255, 255, 0.10);
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
  --radius: 14px;
  --radius2: 18px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Arial, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --bg-pattern: none;
  --surface: rgba(255, 255, 255, 0.06);
  --surface2: rgba(255, 255, 255, 0.09);
  --bubble: rgba(255, 255, 255, 0.07);
  --bubble-me: color-mix(in srgb, var(--accent) 22%, transparent);
  --input: rgba(255, 255, 255, 0.08);
}

html[data-theme="night"] {
  --bg: #1a1d21;
  --panel: rgba(255, 255, 255, 0.06);
  --panel2: rgba(255, 255, 255, 0.04);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.62);
  --accent: #6ea8fe;
  --border: rgba(255, 255, 255, 0.10);
  --bg-pattern: none;
  --surface: rgba(255, 255, 255, 0.06);
  --surface2: rgba(255, 255, 255, 0.09);
  --bubble: rgba(255, 255, 255, 0.07);
  --bubble-me: color-mix(in srgb, var(--accent) 22%, transparent);
  --input: rgba(255, 255, 255, 0.08);
}

html[data-theme="day"] {
  --bg: #f6f7fb;
  --panel: rgba(15, 23, 42, 0.04);
  --panel2: rgba(15, 23, 42, 0.03);
  --text: rgba(15, 23, 42, 0.92);
  --muted: rgba(15, 23, 42, 0.62);
  --accent: #2563eb;
  --border: rgba(15, 23, 42, 0.12);
  --shadow: 0 22px 60px rgba(2, 6, 23, 0.10);
  --surface: rgba(15, 23, 42, 0.04);
  --surface2: rgba(15, 23, 42, 0.06);
  --bubble: rgba(15, 23, 42, 0.05);
  --bubble-me: color-mix(in srgb, var(--accent) 14%, transparent);
  --input: rgba(15, 23, 42, 0.05);
}

html[data-theme="cli"] {
  --bg: #0f1115;
  --panel: rgba(255, 255, 255, 0.06);
  --panel2: rgba(255, 255, 255, 0.04);
  --text: rgba(211, 255, 230, 0.92);
  --muted: rgba(211, 255, 230, 0.56);
  --accent: #19f07a;
  --danger: #ff5c7a;
  --border: rgba(25, 240, 122, 0.18);
  --shadow: none;
  --bg-pattern: radial-gradient(circle at 10% 15%, rgba(25, 240, 122, 0.05), transparent 46%),
    radial-gradient(circle at 80% 10%, rgba(25, 240, 122, 0.035), transparent 50%);
  --surface: rgba(255, 255, 255, 0.06);
  --surface2: rgba(255, 255, 255, 0.09);
  --bubble: #262626;
  --bubble-me: #004d40;
  --input: #1e2229;
}

html[data-theme="cli"] body {
  font-family: var(--font-mono);
}

html[data-theme="cli"] .topbar {
  background: transparent;
}

html[data-theme="cli"] .panel {
  background: transparent;
}

html[data-theme="cli"] .msg.message.me .bubble {
  color: rgba(255, 255, 255, 0.92);
}

html[data-theme="cli"] .name {
  color: rgba(211, 255, 230, 0.62);
}

html[data-theme="cli"] .time {
  color: rgba(211, 255, 230, 0.42);
}

html[data-theme="sakura"] {
  --bg: #fff7fb;
  --panel: rgba(255, 255, 255, 0.66);
  --panel2: rgba(255, 255, 255, 0.50);
  --text: rgba(31, 41, 55, 0.92);
  --muted: rgba(31, 41, 55, 0.62);
  --accent: #ec4899;
  --danger: #ef4444;
  --border: rgba(31, 41, 55, 0.12);
  --shadow: 0 18px 50px rgba(2, 6, 23, 0.10);
  --bg-pattern: radial-gradient(900px 500px at 10% 20%, rgba(236, 72, 153, 0.12), transparent 55%),
    radial-gradient(900px 600px at 90% 10%, rgba(244, 114, 182, 0.12), transparent 55%);
  --surface: rgba(31, 41, 55, 0.04);
  --surface2: rgba(31, 41, 55, 0.06);
  --bubble: rgba(31, 41, 55, 0.05);
  --bubble-me: color-mix(in srgb, var(--accent) 14%, transparent);
  --input: rgba(31, 41, 55, 0.05);
}

html[data-theme="stars"] {
  --bg: #070b1a;
  --panel: rgba(255, 255, 255, 0.06);
  --panel2: rgba(255, 255, 255, 0.04);
  --text: rgba(237, 242, 255, 0.92);
  --muted: rgba(237, 242, 255, 0.70);
  --accent: #8ab4ff;
  --danger: #ff6b6b;
  --border: rgba(255, 255, 255, 0.10);
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  --bg-pattern: radial-gradient(circle at 15% 25%, rgba(138, 180, 255, 0.12), transparent 42%),
    radial-gradient(circle at 80% 10%, rgba(255, 107, 107, 0.10), transparent 42%),
    radial-gradient(circle at 20% 80%, rgba(255, 255, 255, 0.06), transparent 50%);
  --surface: rgba(255, 255, 255, 0.06);
  --surface2: rgba(255, 255, 255, 0.09);
  --bubble: rgba(255, 255, 255, 0.07);
  --bubble-me: color-mix(in srgb, var(--accent) 22%, transparent);
  --input: rgba(255, 255, 255, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg-pattern), var(--bg);
  color: var(--text);
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.22);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(245, 158, 11, 0.12);
  }
}

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--panel2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.5px;
}

.topbarRight {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status {
  font-size: 12px;
  color: var(--muted);
}

.statusPill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--panel);
}

.statusDot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
  box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
}

.statusDot[data-mode="online"] {
  background: #22c55e;
  box-shadow: 0 0 0 6px rgba(34, 197, 94, 0.12);
}

.statusDot[data-mode="connecting"] {
  background: #f59e0b;
  animation: pulse 1.2s ease-in-out infinite;
}

.statusDot[data-mode="offline"] {
  background: rgba(255, 255, 255, 0.28);
}

.panel {
  flex: 1;
  min-height: 0;
  background: var(--panel2);
  border-radius: var(--radius2);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

.login {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  width: min(520px, 100%);
  background: var(--panel2);
  border-radius: var(--radius2);
  padding: 18px;
}

.card h1 {
  margin: 0 0 8px;
  font-size: 22px;
}

.muted {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

form {
  display: flex;
  gap: 10px;
}

input {
  flex: 1;
  padding: 12px 12px;
  border-radius: 12px;
  border: 0;
  background: var(--input);
  color: var(--text);
  outline: none;
  min-width: 0;
}

input:focus {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}

button {
  padding: 12px 14px;
  border-radius: 12px;
  border: 0;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

.iconBtn {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 0;
  color: var(--text);
  transition: transform 100ms ease, background 120ms ease;
}

.iconBtn:hover {
  background: var(--surface2);
}

.iconBtn:active {
  transform: scale(0.97);
}

.ghostBtn {
  padding: 10px 12px;
  border-radius: 12px;
  background: transparent;
  border: 0;
  color: var(--muted);
  transition: transform 100ms ease, background 120ms ease, color 120ms ease;
}

.ghostBtn:active {
  transform: scale(0.98);
}

.ghostBtn:hover {
  background: var(--surface);
  color: var(--text);
}

.error {
  margin-top: 10px;
  color: var(--danger);
  min-height: 18px;
  font-size: 13px;
}

.cardActions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

.chat {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.messages {
  list-style: none;
  margin: 0;
  padding: 14px 14px 12px;
  overflow: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  scroll-padding-bottom: 90px;
}

.msg {
  padding: 0;
  border: 0;
  background: transparent;
  max-width: 100%;
  animation: pop 180ms ease-out both;
}

.msg.system {
  align-self: center;
}

.msg.message {
  align-self: flex-start;
}

.msg.message.me {
  align-self: flex-end;
}

.row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: min(78ch, 100%);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.92);
  flex: 0 0 auto;
  transform: translateY(-2px);
}

.bubble {
  padding: 10px 12px 8px;
  background: var(--bubble);
  border-radius: 18px 18px 18px 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

.msg.message.me .row {
  flex-direction: row-reverse;
}

.msg.message.me .bubble {
  background: var(--bubble-me);
  border-radius: 18px 18px 6px 18px;
}

.bubbleTop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 2px;
}

.name {
  font-size: 12px;
  color: var(--muted);
}

.text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  font-size: 14px;
}

.time {
  margin-top: 6px;
  font-size: 11px;
  color: color-mix(in srgb, var(--muted) 85%, transparent);
  text-align: right;
}

.msg.continued {
  margin-top: -6px;
}

.msg.continued .avatar {
  visibility: hidden;
}

.msg.continued .bubbleTop {
  display: none;
}

.sys {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  max-width: 92vw;
}

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

.sysTime {
  color: color-mix(in srgb, var(--muted) 80%, transparent);
  flex: 0 0 auto;
}

.composer {
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, color-mix(in srgb, var(--bg) 92%, transparent), transparent);
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 10px;
}

.composer button {
  flex: 0 0 auto;
}

.composer input {
  border-radius: 999px;
  padding: 12px 14px;
}

.sendBtn {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--accent) 26%, transparent);
  transition: transform 100ms ease, background 120ms ease;
  position: relative;
}

.sendBtn:hover {
  background: color-mix(in srgb, var(--accent) 34%, transparent);
}

.sendBtn:active {
  transform: scale(0.95);
}

.sendIcon {
  width: 18px;
  height: 18px;
}

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

@supports (height: 100dvh) {
  html,
  body {
    height: 100dvh;
  }

  .app {
    min-height: 100dvh;
  }
}

@media (max-width: 640px) {
  .app {
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .topbar {
    padding: 10px 12px;
    border-radius: 12px;
  }

  .panel {
    border-radius: 14px;
  }

  .login {
    padding: 16px;
  }

  .card {
    padding: 16px;
  }

  .card h1 {
    font-size: 20px;
  }

  .card form {
    flex-direction: column;
  }

  .messages {
    padding: 12px 12px 12px;
  }

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

  button {
    padding: 12px;
  }

  input {
    font-size: 16px;
  }
}

.modal.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modalBackdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

html[data-theme="day"] .modalBackdrop,
html[data-theme="sakura"] .modalBackdrop {
  background: rgba(2, 6, 23, 0.35);
}

.modalCard {
  position: relative;
  width: min(560px, 100%);
  border-radius: var(--radius2);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modalHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}

.modalTitle {
  font-weight: 700;
}

.modalBody {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.field .label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.seg {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.segItem {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-radius: 12px;
  border: 0;
  background: var(--panel);
  cursor: pointer;
  user-select: none;
  transition: transform 100ms ease, background 120ms ease;
  position: relative;
}

.segItem:hover {
  background: var(--surface2);
}

.segItem:active {
  transform: scale(0.98);
}

.segItem input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}

.segItem[data-selected="true"] {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

.themeIcon {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.22);
}

.themeIcon[data-theme="cli"] {
  background: #19f07a;
}

.themeIcon[data-theme="sakura"] {
  background: #ec4899;
}

.themeIcon[data-theme="stars"] {
  background: #8ab4ff;
}

.themeIcon[data-theme="day"] {
  background: #2563eb;
}

.themeIcon[data-theme="night"] {
  background: #6ea8fe;
}

.hint {
  font-size: 12px;
  color: var(--muted);
}

.emptyState {
  margin: auto;
  padding: 28px 12px;
  text-align: center;
  color: var(--muted);
  opacity: 0.78;
  font-size: 13px;
}

@media (max-width: 420px) {
  .seg {
    grid-template-columns: 1fr;
  }

  .composer {
    flex-direction: column;
  }
}
