:root {
  color-scheme: light dark;
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2e38;
  --text: #e8e9ec;
  --muted: #9aa0ac;
  --accent: #f2b705;
  --accent-text: #1a1a1a;
  --bubble-user: #2563eb;
  --bubble-assistant: #22252d;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f7f8;
    --panel: #ffffff;
    --border: #e2e2e5;
    --text: #1a1a1a;
    --muted: #666a75;
    --bubble-assistant: #eef0f3;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  padding: 24px 16px 48px;
}

.wrap {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

header h1 {
  font-size: 1.4rem;
  margin: 0 0 4px;
}

header .sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

header .sub a { color: var(--accent); }

.token-box, .chat-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.token-box label {
  font-size: 0.85rem;
  color: var(--muted);
  display: block;
  margin-bottom: 6px;
}

.token-row {
  display: flex;
  gap: 8px;
}

#tokenInput {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 0.9rem;
  background: var(--accent);
  color: var(--accent-text);
}

button:disabled { opacity: 0.5; cursor: not-allowed; }

.hint {
  margin: 10px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.hint code {
  background: var(--bubble-assistant);
  padding: 1px 5px;
  border-radius: 4px;
}

.messages {
  min-height: 280px;
  max-height: 50vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 8px;
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--bubble-assistant);
  border-bottom-left-radius: 4px;
}

.msg.system-note {
  align-self: center;
  color: var(--muted);
  font-size: 0.8rem;
  background: none;
}

.composer {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

#promptInput {
  flex: 1;
  resize: vertical;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--muted);
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 160px;
}

.controls input[type="text"] {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
}

.temp-label { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 8px; min-width: 220px; }
.temp-label input[type="range"] { flex: 1; }

#clearBtn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 500;
}

.status {
  min-height: 18px;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 10px 0 0;
}

.status.error { color: #ef4444; }

footer p {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
}
