:root {
  --bg: #0e0e10;
  --bg-elev: #16161a;
  --fg: #e8e6e3;
  --muted: #6b6b73;
  --rule: #1f1f23;
  --accent: #d8a673;
  --accent-dim: rgba(216, 166, 115, 0.18);
  --code-bg: #161618;
  --selection: #2a2a2e;
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Menlo", "Consolas", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--selection); }

body { display: flex; flex-direction: column; min-height: 100vh; }

/* ---------- header ---------- */
header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: linear-gradient(to bottom, var(--bg) 70%, rgba(14, 14, 16, 0));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.brand {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--fg);
}
.brand .dot { color: var(--muted); margin: 0 6px; }
.brand .model { color: var(--muted); font-size: 12px; }

.actions { display: flex; gap: 8px; }

.header-btn,
#new-chat,
#toggle-system {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
#new-chat:hover,
#toggle-system:hover { color: var(--fg); border-color: var(--muted); }
#new-chat:active,
#toggle-system:active { transform: translateY(1px); }

#toggle-system.active {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: rgba(216, 166, 115, 0.06);
}

/* ---------- settings panel ---------- */
#settings {
  max-width: 720px;
  width: calc(100% - 48px);
  margin: 0 auto 8px;
  padding: 16px 16px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
}
#settings[hidden] { display: none; }
#settings label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
#system-prompt {
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  min-height: 60px;
  outline: none;
  transition: border-color 0.15s ease;
}
#system-prompt:focus { border-color: var(--muted); }
#system-prompt::placeholder { color: var(--muted); }
#settings .row {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
}
#settings input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}
#temp-val {
  font-family: var(--font-mono);
  color: var(--fg);
  font-size: 12px;
  margin-left: 4px;
}
#settings .note {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  letter-spacing: 0.04em;
}
#settings-close {
  background: var(--fg);
  color: var(--bg);
  border: none;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 5px 14px;
  border-radius: 999px;
  cursor: pointer;
  letter-spacing: 0.04em;
}

/* ---------- transcript ---------- */
main#transcript {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 24px 200px;
}

.empty {
  text-align: center;
  color: var(--muted);
  margin-top: 22vh;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  user-select: none;
}
.empty .glyph {
  display: block;
  font-size: 22px;
  color: var(--accent);
  margin-bottom: 12px;
  opacity: 0.8;
}

.message { margin-bottom: 36px; }

.message .role {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.message.user .role { color: var(--accent); }
.message .role::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}

.message .content {
  font-size: 15.5px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.message .content > *:first-child { margin-top: 0; }
.message .content > *:last-child { margin-bottom: 0; }
.message .content p { margin: 0.6em 0; }
.message .content ul, .message .content ol { padding-left: 1.4em; margin: 0.6em 0; }
.message .content li { margin: 0.2em 0; }
.message .content blockquote {
  border-left: 2px solid var(--rule);
  margin: 0.8em 0;
  padding-left: 14px;
  color: var(--muted);
}
.message .content a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-dim);
}
.message .content a:hover { border-bottom-color: var(--accent); }
.message .content h1, .message .content h2, .message .content h3 {
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 1em 0 0.4em;
}
.message .content h1 { font-size: 1.3em; }
.message .content h2 { font-size: 1.15em; }
.message .content h3 { font-size: 1.05em; }
.message .content hr { border: none; border-top: 1px solid var(--rule); margin: 1.4em 0; }

.message .content code {
  font-family: var(--font-mono);
  background: var(--code-bg);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.86em;
  border: 1px solid var(--rule);
}
.message .content pre {
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.55;
  margin: 0.8em 0;
}
.message .content pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
  border: none;
}

.message .content table {
  border-collapse: collapse;
  font-size: 0.92em;
  margin: 0.8em 0;
}
.message .content th, .message .content td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--rule);
  text-align: left;
}
.message .content th { color: var(--muted); font-weight: 500; }

/* streaming cursor */
.message.streaming .content::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1em;
  vertical-align: -2px;
  background: var(--accent);
  margin-left: 4px;
  animation: blink 1.1s steps(2, end) infinite;
  border-radius: 1px;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

/* ---------- composer ---------- */
footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 24px 24px;
  background: linear-gradient(to top, var(--bg) 60%, rgba(14, 14, 16, 0));
  pointer-events: none;
}

#composer, .hint { pointer-events: auto; }

#composer {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: 16px;
  padding: 10px 10px 10px 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#composer:focus-within {
  border-color: var(--muted);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.02);
}

#input {
  flex: 1;
  background: transparent;
  color: var(--fg);
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  max-height: 240px;
  padding: 6px 0;
}
#input::placeholder { color: var(--muted); }

#send {
  background: var(--fg);
  color: var(--bg);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
}
#send:disabled { opacity: 0.25; cursor: not-allowed; }
#send:hover:not(:disabled) { transform: translateY(-1px); }
#send.streaming {
  background: var(--accent);
  color: var(--bg);
}
#send.streaming svg { display: none; }
#send.streaming::before {
  content: "";
  display: block;
  width: 10px;
  height: 10px;
  background: var(--bg);
  border-radius: 2px;
}

.hint {
  max-width: 720px;
  margin: 8px auto 0;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-align: center;
  opacity: 0.7;
}

/* ---------- responsive ---------- */
@media (max-width: 640px) {
  main#transcript { padding: 20px 16px 200px; }
  footer { padding: 14px 12px 16px; }
  header { padding: 12px 16px; }
  .hint { display: none; }
  #composer { border-radius: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
