@font-face { font-family: Inter; src: url("/assets/inter-400.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: Inter; src: url("/assets/inter-500.ttf") format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: Inter; src: url("/assets/inter-600.ttf") format("truetype"); font-weight: 600; font-display: swap; }
@font-face { font-family: Outfit; src: url("/assets/outfit-500.ttf") format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: Outfit; src: url("/assets/outfit-700.ttf") format("truetype"); font-weight: 700; font-display: swap; }

*, *::before, *::after { box-sizing: border-box; }
:root {
  --bg-deep: #0f172a;
  --bg-elevated: #1e293b;
  --surface: rgba(30, 41, 59, 0.72);
  --surface-hover: rgba(51, 65, 85, 0.88);
  --stroke: rgba(148, 163, 184, 0.14);
  --stroke-strong: rgba(159, 134, 214, 0.42);
  --text: #e0f2fe;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent-from: #9f86d6;
  --accent-to: #4ebfcf;
  --accent-mid: #bbb0ea;
  --btn-primary: #7549d4;
  --btn-primary-hover: #663cc4;
  --btn-primary-shadow: rgba(117, 73, 212, 0.4);
  --ok: #35b890;
  --danger: #ef6f85;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --brand-gradient: linear-gradient(135deg, var(--accent-from) 0%, var(--accent-to) 100%);
  --cta-gradient: linear-gradient(135deg, var(--btn-primary) 0%, var(--accent-to) 100%);
  --shadow-glow: 0 0 80px rgba(159, 134, 214, 0.17);
  --font-display: "Outfit", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
}

html { scroll-behavior: auto; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
* { scrollbar-width: thin; scrollbar-color: rgba(187, 176, 234, 0.82) rgba(15, 23, 42, 0.28); }
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.28);
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.08);
}
*::-webkit-scrollbar-thumb {
  border: 2px solid rgba(15, 23, 42, 0.38);
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(187, 176, 234, 0.94), rgba(78, 191, 207, 0.86)),
    rgba(159, 134, 214, 0.78);
}
*::-webkit-scrollbar-thumb:hover {
  background:
    linear-gradient(180deg, rgba(224, 242, 254, 0.95), rgba(78, 191, 207, 0.98)),
    rgba(187, 176, 234, 0.95);
}

.bg-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(159, 134, 214, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(78, 191, 207, 0.08), transparent),
    radial-gradient(ellipse 50% 35% at 0% 80%, rgba(159, 134, 214, 0.07), transparent);
}
.bg-layer::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cg fill='none' stroke='%2394a3b8' stroke-opacity='0.06'%3E%3Cpath d='M0 24h48M24 0v48'/%3E%3C/g%3E%3C/svg%3E");
}

.shell {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: max(clamp(20px, 4vw, 40px), env(safe-area-inset-top, 0px)) max(clamp(18px, 4vw, 36px), env(safe-area-inset-right, 0px)) 28px max(clamp(18px, 4vw, 36px), env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
}
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; min-width: 0; }
.logo-img { width: 44px; height: 44px; border-radius: 14px; box-shadow: 0 0 32px rgba(159, 134, 214, 0.26); }
.brand-text { font-family: var(--font-display); font-size: 1.12rem; font-weight: 700; }
.header-nav { display: flex; align-items: center; gap: clamp(14px, 3vw, 28px); flex-wrap: wrap; }
.header-nav a { color: var(--text-muted); text-decoration: none; font-weight: 500; transition: color 160ms ease; }
.header-nav a:hover { color: var(--text); }

.llm-app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 18px;
  flex: 1;
  min-height: 0;
}
.app-head { display: flex; align-items: end; justify-content: space-between; gap: 18px; flex-shrink: 0; }
.hero-eyebrow { margin: 0 0 7px; color: var(--accent-mid); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
h1 { font-family: var(--font-display); line-height: 1.1; margin: 0; font-size: clamp(1.9rem, 4vw, 3rem); }
.status-strip { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.status-strip span {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.45);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
#connStatus::before {
  content: "";
  width: 8px; height: 8px; border-radius: 999px;
  background: var(--text-dim);
  box-shadow: 0 0 10px currentColor;
}
#connStatus.online::before { background: var(--ok); }
#connStatus.offline::before { background: var(--danger); }

.chat-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: min(calc(100dvh - 214px), 820px);
  min-height: min(420px, calc(100dvh - 240px));
  border: 1px solid var(--stroke);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.78), rgba(15, 23, 42, 0.62));
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-glow);
  overflow: hidden;
}
.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--stroke);
  flex-shrink: 0;
}
.chat-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.toolbar-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.toolbar-right { display: flex; align-items: center; gap: 8px; }
.model-chip, .caps-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}
.model-chip { color: var(--text); background: linear-gradient(135deg, rgba(117, 73, 212, 0.34), rgba(78, 191, 207, 0.2)); border: 1px solid rgba(159, 134, 214, 0.3); }
.caps-chip {
  min-width: 142px;
  justify-content: center;
  color: var(--text-muted);
  border: 1px solid var(--stroke);
  background: rgba(15, 23, 42, 0.45);
  font-variant-numeric: tabular-nums;
}

.settings-panel {
  display: grid;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--stroke);
  background: rgba(15, 23, 42, 0.32);
  flex-shrink: 0;
  max-height: none;
  overflow: visible;
}
.settings-panel[hidden] { display: none; }
.settings-panel:not([hidden]) + .messages { overflow-y: hidden; }
.settings-panel textarea { resize: vertical; min-height: 56px; max-height: 120px; }
.control-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
label { display: grid; gap: 7px; color: var(--text-muted); font-size: 0.82rem; font-weight: 600; }
label.full { grid-column: 1 / -1; }
input, select, textarea {
  width: 100%;
  border: 1px solid rgba(159, 134, 214, 0.3);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.82), rgba(15, 23, 42, 0.66)),
    rgba(15, 23, 42, 0.72);
  outline: none;
  font: 500 0.94rem var(--font-body);
  color-scheme: dark;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: rgba(148, 163, 184, 0.76); }
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--accent-mid) 50%), linear-gradient(135deg, var(--accent-mid) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 38px;
}
select option,
select optgroup {
  color: var(--text);
  background: #0f172a;
}
select.native-select-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
  padding-right: 40px;
  font-variant-numeric: tabular-nums;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  appearance: none;
  margin: 0;
  display: none;
}
.number-stepper {
  position: relative;
  width: 100%;
}
.number-stepper input[type="number"] {
  padding-right: 44px;
}
.number-stepper-controls {
  position: absolute;
  top: 50%;
  right: 12px;
  width: 14px;
  height: 30px;
  display: grid;
  grid-template-rows: 1fr 1fr;
  transform: translateY(-50%);
  pointer-events: none;
}
.number-stepper-btn {
  width: 14px;
  height: 15px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  cursor: pointer;
  pointer-events: auto;
}
.number-stepper-btn::before {
  content: "";
  display: block;
  width: 0;
  height: 0;
  margin: auto;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  opacity: 0.62;
  transition: opacity 140ms ease, border-color 140ms ease;
}
.number-stepper-btn.up::before {
  border-bottom: 6px solid var(--text-muted);
}
.number-stepper-btn.down::before {
  border-top: 6px solid var(--text-muted);
}
.number-stepper-btn:hover::before,
.number-stepper-btn:focus-visible::before {
  opacity: 1;
}
.number-stepper-btn.up:hover::before,
.number-stepper-btn.up:focus-visible::before {
  border-bottom-color: var(--accent-mid);
}
.number-stepper-btn.down:hover::before,
.number-stepper-btn.down:focus-visible::before {
  border-top-color: var(--accent-mid);
}
.custom-select {
  position: relative;
  width: 100%;
}
.custom-select-trigger {
  position: relative;
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  overflow: hidden;
  border: 1px solid rgba(159, 134, 214, 0.3);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.86), rgba(15, 23, 42, 0.66)),
    radial-gradient(circle at 12% 0%, rgba(159, 134, 214, 0.16), transparent 34%);
  outline: none;
  font: 600 0.94rem var(--font-body);
  text-align: left;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  cursor: pointer;
}
.custom-select-trigger::before {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: calc(var(--radius-sm) - 1px);
  pointer-events: none;
  background: linear-gradient(135deg, rgba(159, 134, 214, 0.14), transparent 38%, rgba(78, 191, 207, 0.08));
  opacity: 0;
  transition: opacity 160ms ease;
}
.custom-select-value,
.custom-select-arrow {
  position: relative;
  z-index: 1;
}
.custom-select-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.custom-select-arrow {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-right: 2px solid var(--accent-mid);
  border-bottom: 2px solid var(--accent-mid);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 160ms ease;
}
.custom-select.open .custom-select-trigger,
.custom-select-trigger:focus-visible {
  border-color: var(--stroke-strong);
  box-shadow: 0 0 0 3px rgba(159, 134, 214, 0.14), 0 0 28px rgba(78, 191, 207, 0.08);
}
.custom-select.open .custom-select-trigger::before,
.custom-select-trigger:hover::before {
  opacity: 1;
}
.custom-select.open .custom-select-arrow {
  transform: rotate(225deg) translate(-2px, -1px);
}
.custom-select-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 8px);
  z-index: 120;
  max-height: 250px;
  overflow: auto;
  padding: 7px;
  border: 1px solid rgba(159, 134, 214, 0.38);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(23, 32, 52, 0.98), rgba(12, 18, 32, 0.98)),
    radial-gradient(circle at 12% 0%, rgba(159, 134, 214, 0.18), transparent 38%);
  box-shadow: 0 20px 56px rgba(0, 0, 0, 0.42), 0 0 42px rgba(78, 191, 207, 0.1);
  backdrop-filter: blur(18px);
  transform-origin: top;
  transform: translateY(-4px) scale(0.98);
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
}
.custom-select.open .custom-select-menu {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}
.custom-select-option {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  border: 0;
  border-radius: 11px;
  padding: 9px 11px;
  color: var(--text-muted);
  background: transparent;
  font: 600 0.92rem var(--font-body);
  text-align: left;
  cursor: pointer;
}
.custom-select-option:hover,
.custom-select-option:focus-visible {
  color: var(--text);
  background: rgba(78, 191, 207, 0.1);
  transform: none;
}
.custom-select-option.selected {
  color: var(--text);
  background: linear-gradient(135deg, rgba(117, 73, 212, 0.42), rgba(78, 191, 207, 0.2));
  box-shadow: inset 0 0 0 1px rgba(159, 134, 214, 0.22);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--stroke-strong);
  box-shadow: 0 0 0 3px rgba(159, 134, 214, 0.14), 0 0 28px rgba(78, 191, 207, 0.08);
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: auto;
}
.welcome {
  margin: auto 0;
  max-width: 460px;
  width: 100%;
  align-self: center;
  text-align: center;
  color: var(--text-muted);
  display: grid;
  gap: 14px;
  padding: 16px 0 24px;
}
.welcome .w-logo { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto; box-shadow: 0 0 40px rgba(159, 134, 214, 0.3); }
.welcome h2 { font-family: var(--font-display); color: var(--text); font-size: 1.3rem; margin: 0; }
.suggestions { display: grid; gap: 8px; }
.suggestion {
  border: 1px solid var(--stroke);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--text);
  background: rgba(15, 23, 42, 0.42);
  text-align: left;
  font: 500 0.9rem var(--font-body);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}
.suggestion:hover { border-color: rgba(78, 191, 207, 0.34); background: rgba(30, 41, 59, 0.66); transform: translateY(-1px); }

.msg { display: flex; gap: 10px; max-width: 100%; flex-shrink: 0; align-items: flex-start; }
.msg.user { flex-direction: row-reverse; }
.avatar {
  flex: 0 0 34px;
  width: 34px; height: 34px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: white;
}
.msg.user .avatar { background: linear-gradient(135deg, #4ebfcf, #2f8aa0); }
.msg.assistant .avatar { background: var(--cta-gradient); overflow: hidden; }
.msg.assistant .avatar img { width: 100%; height: 100%; object-fit: cover; }
.bubble {
  min-width: 0;
  max-width: min(78%, 720px);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  background: rgba(15, 23, 42, 0.5);
  overflow-wrap: anywhere;
  word-break: break-word;
}
.msg.user .bubble { background: linear-gradient(135deg, rgba(117, 73, 212, 0.22), rgba(78, 191, 207, 0.12)); border-color: var(--stroke-strong); }
.msg.user .bubble.has-images {
  padding-left: 13px;
  padding-right: 13px;
}
.bubble .md { line-height: 1.65; }
.bubble .md > *:first-child { margin-top: 0; }
.bubble .md > *:last-child { margin-bottom: 0; }
.bubble .md p { margin: 0 0 10px; }
.bubble .md h1,
.bubble .md h2,
.bubble .md h3,
.bubble .md h4,
.bubble .md h5,
.bubble .md h6 {
  margin: 16px 0 8px;
  color: var(--text);
  font-family: var(--font-display);
  line-height: 1.25;
}
.bubble .md h1 { font-size: 1.35rem; }
.bubble .md h2 { font-size: 1.22rem; }
.bubble .md h3 { font-size: 1.08rem; }
.bubble .md h4,
.bubble .md h5,
.bubble .md h6 { font-size: 0.98rem; }
.bubble .md a { color: #7dd3fc; text-decoration: none; border-bottom: 1px solid rgba(125, 211, 252, 0.35); }
.bubble .md a:hover { color: var(--text); border-bottom-color: rgba(224, 242, 254, 0.6); }
.bubble .md ul,
.bubble .md ol { margin: 8px 0 12px; padding-left: 1.35rem; }
.bubble .md li { margin: 4px 0; }
.bubble .md li > p { margin: 4px 0; }
.bubble .md blockquote {
  margin: 10px 0;
  padding: 8px 12px;
  border-left: 3px solid rgba(78, 191, 207, 0.58);
  border-radius: 8px;
  color: var(--text-muted);
  background: rgba(78, 191, 207, 0.08);
}
.bubble .md hr { border: 0; border-top: 1px solid var(--stroke); margin: 14px 0; }
.bubble .md table {
  display: block;
  width: 100%;
  margin: 10px 0 12px;
  border-collapse: collapse;
  overflow-x: auto;
}
.bubble .md th,
.bubble .md td {
  padding: 8px 10px;
  border: 1px solid var(--stroke);
  text-align: left;
  vertical-align: top;
}
.bubble .md th { color: var(--text); background: rgba(30, 41, 59, 0.7); }
.bubble .md tr:nth-child(even) td { background: rgba(15, 23, 42, 0.22); }
.bubble .md img {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid var(--stroke);
}
.bubble .md .katex { color: var(--text); font-size: 1.05em; }
.bubble .md .katex-display {
  margin: 12px 0;
  padding: 8px 0;
  overflow-x: auto;
  overflow-y: hidden;
}
.bubble .md .katex-display > .katex {
  display: inline-block;
  min-width: max-content;
}
.bubble .md input[type="checkbox"] {
  width: auto;
  margin: 0 6px 0 0;
  accent-color: var(--accent-to);
}
.bubble .md pre {
  position: relative;
  margin: 8px 0;
  padding: 34px 12px 12px;
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.66);
  border: 1px solid var(--stroke);
  overflow-x: auto;
  font-size: 0.85rem;
}
.bubble .md pre::before {
  content: attr(data-lang);
  position: absolute;
  top: 8px;
  left: 12px;
  color: var(--text-dim);
  font: 700 0.72rem var(--font-body);
  text-transform: uppercase;
}
.bubble .md pre code {
  display: block;
  min-width: max-content;
  white-space: pre;
}
.copy-code-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  min-height: 24px;
  padding: 3px 9px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.82);
  font: 700 0.72rem var(--font-body);
}
.copy-code-btn:hover { color: var(--text); border-color: rgba(78, 191, 207, 0.42); }
.bubble .md code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.88em; }
.bubble .md :not(pre) > code { background: rgba(2, 6, 23, 0.5); padding: 1px 5px; border-radius: 6px; }
.msg-images { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.msg.user .msg-images { justify-content: flex-end; }
.bubble.has-images .md { width: 100%; }
.msg-image-btn {
  display: block;
  width: 180px;
  height: 180px;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.46);
  overflow: hidden;
  cursor: zoom-in;
}
.msg-image-btn:hover { border-color: rgba(78, 191, 207, 0.5); transform: none; }
.msg-image-btn:focus-visible { outline: 2px solid rgba(78, 191, 207, 0.7); outline-offset: 2px; }
.msg-image-btn img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

details.think {
  margin-bottom: 10px;
  border: 1px dashed rgba(159, 134, 214, 0.4);
  border-radius: 12px;
  background: rgba(159, 134, 214, 0.06);
}
details.think > summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 12px;
  color: var(--accent-mid);
  font-size: 0.82rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
details.think > summary::-webkit-details-marker { display: none; }
details.think > summary::before { content: "▸"; transition: transform 160ms ease; }
details.think[open] > summary::before { transform: rotate(90deg); }
.think .think-body {
  padding: 0 12px 10px 12px;
  color: var(--text-muted);
  font-size: 0.86rem;
  white-space: pre-wrap;
  line-height: 1.55;
  max-height: min(28vh, 220px);
  overflow-y: auto;
}
.cursor-blink::after {
  content: "▋";
  margin-left: 1px;
  color: var(--accent-to);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.composer {
  padding: 9px 12px max(9px, env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--stroke);
  display: grid;
  gap: 8px;
  flex: 0 0 auto;
  background: rgba(15, 23, 42, 0.35);
}
.attach-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 72px;
  overflow-y: auto;
}
.attach-row[hidden] { display: none; }
.attach-chip { position: relative; width: 56px; height: 56px; border-radius: 12px; overflow: hidden; border: 1px solid var(--stroke); }
.attach-chip img { width: 100%; height: 100%; object-fit: cover; }
.attach-chip button {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px; min-height: 18px;
  border-radius: 999px; padding: 0;
  border: 0; color: white; background: rgba(15, 23, 42, 0.82);
  font-size: 12px; line-height: 1; cursor: pointer;
}
.composer-input {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 50px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-md);
  padding: 4px 6px 4px 10px;
  background: rgba(15, 23, 42, 0.58);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.composer-input:focus-within { border-color: var(--stroke-strong); box-shadow: 0 0 0 3px rgba(159, 134, 214, 0.12); }
.composer-input textarea {
  flex: 1;
  min-width: 0;
  height: 34px;
  border: 0;
  background: transparent;
  box-sizing: border-box;
  padding: 5px 0;
  box-shadow: none;
  resize: none;
  overflow-y: hidden;
  min-height: 34px;
  max-height: 126px;
  line-height: 24px;
}
.composer-input textarea:focus { box-shadow: none; }
.composer-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.composer-actions .primary-btn,
.composer-actions .secondary-btn {
  min-height: 36px;
  padding: 7px 14px;
  font-size: 0.86rem;
}
.composer-actions .icon-btn {
  width: 36px;
  min-width: 36px;
  height: 36px;
  min-height: 36px;
}

button, .icon-btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  padding: 9px 15px;
  font: 700 0.9rem var(--font-body);
  cursor: pointer;
  text-decoration: none;
  position: relative;
  overflow: hidden;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}
.primary-btn { border: 0; color: white; background: var(--cta-gradient); box-shadow: 0 12px 32px var(--btn-primary-shadow); }
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 16px 42px rgba(117, 73, 212, 0.48), 0 0 28px rgba(78, 191, 207, 0.18); }
.secondary-btn, .ghost-btn { border: 1px solid var(--stroke); color: var(--text); background: rgba(15, 23, 42, 0.42); }
.secondary-btn:hover, .ghost-btn:hover { border-color: rgba(78, 191, 207, 0.38); background: rgba(30, 41, 59, 0.68); }
.ghost-btn { min-height: 34px; padding: 6px 12px; color: var(--text-muted); }
.ghost-btn[aria-pressed="true"] { color: var(--text); border-color: rgba(78, 191, 207, 0.44); background: rgba(78, 191, 207, 0.12); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn {
  width: 42px; min-width: 42px; height: 42px; min-height: 42px; padding: 0;
  border: 1px solid var(--stroke); color: var(--text-muted); background: rgba(15, 23, 42, 0.42);
}
.icon-btn:hover { color: var(--text); border-color: rgba(78, 191, 207, 0.38); }
.icon-img {
  width: 18px; height: 18px;
  border: 2px solid currentColor; border-radius: 5px;
  position: relative;
}
.icon-img::after { content: ""; position: absolute; right: 2px; bottom: 2px; left: 2px; height: 5px; background: currentColor; clip-path: polygon(0 100%, 32% 40%, 55% 70%, 78% 22%, 100% 100%); }

.lightbox-open { overflow: hidden; }
.image-lightbox[hidden] { display: none; }
.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  padding: 0;
  overflow: hidden;
}
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(10px);
}
.lightbox-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}
.lightbox-stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: visible;
  touch-action: none;
}
.lightbox-download {
  position: fixed;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom, 0px) + 18px);
  z-index: 2;
  transform: translateX(-50%);
  min-height: 38px;
  border-radius: 999px;
  padding: 8px 14px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  color: var(--text);
  background: rgba(15, 23, 42, 0.86);
  font: 700 0.88rem var(--font-body);
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.32);
}
.lightbox-download:hover { border-color: rgba(78, 191, 207, 0.45); background: rgba(30, 41, 59, 0.9); }
.lightbox-img {
  align-self: center;
  justify-self: center;
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 32px);
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  cursor: grab;
  transform-origin: center center;
  user-select: none;
  will-change: transform;
}
.image-lightbox.is-dragging .lightbox-img { cursor: grabbing; }
@media (max-width: 760px) {
  .lightbox-stage { width: 100%; height: 100%; }
  .lightbox-img {
    max-width: calc(100vw - 18px);
    max-height: calc(100dvh - 18px);
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  z-index: 50;
  max-width: min(560px, calc(100vw - 32px));
  padding: 11px 15px;
  border: 1px solid var(--stroke-strong);
  border-radius: 999px;
  color: var(--text);
  background: rgba(15, 23, 42, 0.92);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.error-text { color: var(--danger); }

@media (max-width: 760px) {
  .site-header { align-items: flex-start; flex-direction: column; gap: 12px; margin-bottom: 18px; }
  .app-head { align-items: flex-start; flex-direction: column; gap: 12px; }
  .status-strip { width: 100%; justify-content: flex-start; }
  .control-grid { grid-template-columns: 1fr 1fr; }
  .chat-shell { height: min(calc(100dvh - 320px), 660px); min-height: min(420px, calc(100dvh - 280px)); }
  .bubble { max-width: 86%; }
  .composer-input { flex-wrap: nowrap; }
  .composer-actions { margin-left: auto; }
}
@media (max-width: 480px) {
  .control-grid { grid-template-columns: 1fr; }
  .bubble { max-width: 90%; }
}
