:root {
  --bg: #0b0e14;
  --bg-grad: radial-gradient(1200px 600px at 70% -10%, #16202e, var(--bg));
  --panel: #141a24;
  --panel-2: #1b2430;
  --line: #273141;
  --text: #e7edf5;
  --muted: #9fb0c3;
  --accent: #5ea0ff;
  --accent-ink: #04122b;
  --good: #46d39a;
  --warn: #ffcf6b;
  --bad: #ff7b7b;
  --radius: 14px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-grad);
  color: var(--text);
  min-height: 100vh;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 10px 16px;
  border-radius: 0 0 10px 0;
  z-index: 100;
  font-weight: 700;
}
.skip-link:focus {
  left: 0;
}

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

.wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 28px 18px 64px;
}

header h1 {
  font-size: 1.65rem;
  margin: 0 0 8px;
  letter-spacing: 0.2px;
}
header h1 .accent {
  color: var(--accent);
  font-weight: 600;
}
header .subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.96rem;
  max-width: 68ch;
}
header code {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 0.9em;
}

.status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--muted);
}
.chip .chip-label {
  color: var(--muted);
}
.chip b {
  color: var(--text);
  font-weight: 650;
}
.chip[data-tier="webgpu"] b {
  color: var(--good);
}
.chip[data-tier="unavailable"] b {
  color: var(--warn);
}
.chip[data-tier="wasm"] b,
.chip[data-tier="cpu"] b {
  color: var(--accent);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.dot.ready {
  background: var(--good);
  box-shadow: 0 0 0 3px rgba(70, 211, 154, 0.18);
}
.dot.warn {
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(255, 207, 107, 0.18);
}
.dot.pulse {
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
@media (prefers-reduced-motion: reduce) {
  .dot.pulse { animation: none; }
  html { scroll-behavior: auto; }
}

.loading-note {
  margin: 4px 0 0;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.85rem;
}
.loading-note.done {
  display: none;
}

.log {
  margin: 18px 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 140px;
}

.msg {
  display: flex;
}
.msg.user {
  justify-content: flex-end;
}
.msg.bot {
  justify-content: flex-start;
}
.msg .bubble {
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  max-width: 85%;
}
.msg.user .bubble {
  background: var(--panel-2);
}
.msg.bot .bubble {
  background: var(--panel);
  width: 100%;
}
.msg .answer {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg .answer .thinking {
  color: var(--muted);
  font-style: italic;
  animation: pulse 1.2s ease-in-out infinite;
}
.msg .answer .cursor {
  display: inline-block;
  width: 0.5ch;
  background: var(--accent);
  animation: blink 0.9s steps(1) infinite;
  margin-left: 1px;
}
@keyframes blink {
  50% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .msg .answer .cursor { animation: none; opacity: 0.6; }
}

.msg .cite {
  margin-top: 9px;
  font-size: 0.78rem;
  color: var(--accent);
  border-top: 1px dashed var(--line);
  padding-top: 7px;
}
.msg .cite b {
  color: var(--muted);
  font-weight: 600;
}
.msg .cite .src {
  display: inline-block;
  background: rgba(94, 160, 255, 0.1);
  border: 1px solid rgba(94, 160, 255, 0.3);
  border-radius: 6px;
  padding: 1px 7px;
  margin: 2px 4px 2px 0;
}
.msg .meta {
  margin-top: 6px;
  font-size: 0.73rem;
  color: var(--muted);
}
.msg .meta .badge {
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 5px;
  margin-right: 6px;
  background: var(--panel-2);
  color: var(--muted);
}
.msg .meta .badge.webgpu {
  background: rgba(70, 211, 154, 0.15);
  color: var(--good);
}
.msg .meta .badge.grounded {
  background: rgba(94, 160, 255, 0.15);
  color: var(--accent);
}
.msg .meta .badge.refusal {
  background: rgba(255, 207, 107, 0.15);
  color: var(--warn);
}

.composer {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}
#q {
  flex: 1;
  padding: 13px 14px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  font: inherit;
}
#q:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button {
  padding: 13px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  cursor: pointer;
  font: inherit;
}
button:hover {
  filter: brightness(1.06);
}
button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
button:disabled {
  opacity: 0.55;
  cursor: default;
}
#stop {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.examples-label {
  color: var(--muted);
  font-size: 0.82rem;
  margin-right: 2px;
}
.examples button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 500;
  font-size: 0.8rem;
  padding: 7px 11px;
}

.about {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.86rem;
}
.about h2 {
  color: var(--text);
  font-size: 1rem;
  margin: 0 0 10px;
}
.about ul {
  margin: 0;
  padding-left: 1.2em;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.about a {
  color: var(--accent);
}
.about code {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 0.9em;
}
