/* =============================================
   LLM PLAYGROUND — BYOK
   Aesthetic: Dark editorial / refined terminal
   ============================================= */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0d0f12;
  --bg-panel:   #13161b;
  --bg-input:   #0a0c0f;
  --bg-hover:   #1c2028;
  --border:     #232830;
  --border-hi:  #3a4150;
  --bg-header:  rgba(13,15,18,0.85);

  --text-brand:     #f2f3f5;
  --text-primary:   #e8ecf1;
  --text-secondary: #979EAA;
  --text-muted:     #7C879C;

  --accent:     #4fffb0;
  --accent-dim: #1a3d2e;
  --accent2:    #ff6b6b;

  --claude-color:  #d97757;
  --openai-color:  #10a37f;
  --gemini-color:  #4285f4;

  --radius:     8px;
  --radius-lg:  14px;
  --font-ui:    'Syne', sans-serif;
  --font-mono:  'JetBrains Mono', monospace;
  --transition: 160ms ease;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  overflow-x: hidden;
  transition: background-color 0.3s, color 0.3s;
}

/* Noise texture overlay */
.noise {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  opacity: 0.028;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}

body.light-mode {
  --bg:         #f5f6f7;
  --bg-panel:   #c2c6cc;
  --bg-input:   #d2d4d6;
  --bg-hover:   #8699bf;
  --border:     #becee8;
  --border-hi:  #6a8fde;
  --bg-header:  rgba(235,238,242,0.90);

  --text-brand:     #0f4b96;
  --text-primary:   #0d2442;
  --text-secondary: #2b5599;
  --text-muted:     #294987;

  --accent:     #328ddb;
  --accent-dim: #1a3d2e;
  --accent2:    #ff6b6b;
}

/* ── HEADER ─────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border);
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 28px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ① Logo link */
.logo {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--text-primary);
}

.logo h1 {
  font-size: inherit;
  font-weight: inherit;
  margin: 0;
}

.logo a {
  color: inherit;
  text-decoration: none;
  transition: color var(--transition);
}

.logo a:hover {
  color: var(--accent);
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.badge {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid #2a5a40;
}

.version {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

/* ④ Theme toggle button in header */
.theme-toggle-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.theme-toggle-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.theme-toggle-btn svg {
  width: 15px;
  height: 15px;
  display: block;
}

/* Sun = visible in dark mode; Moon = visible in light mode */
.theme-toggle-btn .icon-moon { display: none; }

body.light-mode .theme-toggle-btn .icon-sun  { display: none; }
body.light-mode .theme-toggle-btn .icon-moon { display: block; }

/* ── MAIN LAYOUT ─────────────────────────────── */
.main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  height: calc(100vh - 56px - 44px - 20px);
}

/* ── PANELS ──────────────────────────────────── */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.panel::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-hi), transparent);
}

.panel-label {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.2em;
  color: var(--text-muted);
  margin-bottom: 22px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── FIELD GROUPS ────────────────────────────── */
.field-group {
  margin-bottom: 22px;
}

.field-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.field-hint {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
  margin-left: auto;
}

.field-value {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  margin-left: auto;
}

/* ── SEGMENTED CONTROL ───────────────────────── */
.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 3px;
}

.seg-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: 0.02em;
}

.seg-btn:hover:not(.active) {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.seg-btn.active {
  background: var(--bg-panel);
  color: var(--text-primary);
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.seg-btn.active[data-provider="claude"]  { color: var(--claude-color); }
.seg-btn.active[data-provider="openai"]  { color: var(--openai-color); }
.seg-btn.active[data-provider="gemini"]  { color: var(--gemini-color); }

/* ── SELECT ──────────────────────────────────── */
.select-wrapper {
  position: relative;
}

select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 10px 32px 10px 12px;
  appearance: none;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}

select:focus { border-color: var(--border-hi); }

.select-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: 12px;
}

/* ── INPUT / TEXTAREA ────────────────────────── */
.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

input[type="password"],
input[type="text"] {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 10px 40px 10px 12px;
  outline: none;
  transition: border-color var(--transition);
}

input:focus { border-color: var(--border-hi); }

.toggle-visibility {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition);
}

.toggle-visibility:hover { color: var(--text-primary); }
.toggle-visibility svg { width: 15px; height: 15px; }

/* ② Save-key row */
.save-key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  gap: 8px;
}

.save-key-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.save-key-label input[type="checkbox"] {
  width: 13px;
  height: 13px;
  accent-color: var(--accent);
  cursor: pointer;
  padding: 0;         /* reset the generic input padding */
  border: none;
}

.btn-forget-key {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-forget-key svg { width: 11px; height: 11px; }

.btn-forget-key:hover {
  color: var(--accent2);
  border-color: var(--accent2);
}

.security-note {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ── SYSTEM PROMPT ───────────────────────────── */
.inline-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  padding: 2px 7px;
  border-radius: 4px;
  cursor: pointer;
  margin-left: auto;
  transition: all var(--transition);
}

.inline-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-hi);
}

.system-prompt-preview {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.7;
  cursor: pointer;
  transition: border-color var(--transition);
}

.system-prompt-preview:hover { border-color: var(--border-hi); }

textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 10px 12px;
  resize: vertical;
  outline: none;
  transition: border-color var(--transition);
  line-height: 1.7;
}

textarea:focus { border-color: var(--border-hi); }

/* ── SLIDER ──────────────────────────────────── */
.slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform var(--transition);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.slider::-webkit-slider-thumb:hover { transform: scale(1.2); }

.slider::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

/* ── CHAT PANEL ──────────────────────────────── */
.panel-chat {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-window {
  flex: 1;
  min-height: 300px;
  max-height: 480px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-right: 4px;
  scroll-behavior: smooth;
}

/* Scrollbar */
.chat-window::-webkit-scrollbar { width: 4px; }
.chat-window::-webkit-scrollbar-track { background: transparent; }
.chat-window::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Empty state */
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-muted);
  text-align: center;
  padding: 48px 0;
}

.empty-icon {
  font-size: 36px;
  opacity: 0.4;
  animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.2; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(1.05); }
}

.chat-empty p {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.8;
  color: var(--text-muted);
}

/* Chat messages */
.message {
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: msg-in 200ms ease both;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.message-meta .role {
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.message.user      .role { color: var(--text-secondary); }
.message.assistant .role { color: var(--accent); }
.message.error     .role { color: var(--accent2); }

.message-time { margin-left: auto; }

.message-body {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .message-body {
  background: var(--bg-hover);
  border-color: var(--border-hi);
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.message.assistant .message-body {
  border-left: 2px solid var(--accent);
}

.message.error .message-body {
  border-left: 2px solid var(--accent2);
  color: #ff9b9b;
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ① History-trimming notice in chat */
.message.notice .message-body {
  border-left: 2px solid var(--text-muted);
  background: transparent;
  border-top: none; border-right: none; border-bottom: none;
  border-radius: 0;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 6px 10px;
  font-style: italic;
}

/* Provider tag on assistant messages */
.provider-tag {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 500;
}

.provider-tag.claude  { background: rgba(217,119,87,0.15);  color: var(--claude-color); }
.provider-tag.openai  { background: rgba(16,163,127,0.15);  color: var(--openai-color); }
.provider-tag.gemini  { background: rgba(66,133,244,0.15);  color: var(--gemini-color); }

/* ── INPUT AREA ──────────────────────────────── */
.input-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.textarea-wrapper { position: relative; }

.textarea-wrapper textarea { padding-bottom: 26px; }

.char-counter {
  position: absolute;
  bottom: 10px;
  right: 12px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  pointer-events: none;
}

.char-counter span:first-child { color: var(--text-secondary); }

.input-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ── BUTTONS ─────────────────────────────────── */
.btn-clear {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 9px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-clear svg { width: 13px; height: 13px; }

.btn-clear:hover {
  color: var(--accent2);
  border-color: var(--accent2);
}

.btn-send {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: #0a1a12;
  border: none;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 9px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  min-width: 110px;
  justify-content: center;
}

.btn-send svg { width: 14px; height: 14px; }

.btn-send:hover:not(:disabled) {
  background: #6fffbf;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(79,255,176,0.25);
}

.btn-send:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: none;
}

.btn-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Spinner */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(0,0,0,0.2);
  border-top-color: #0a1a12;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Typing indicator */
.typing-indicator .message-body {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 16px 14px;
}

.dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.2s ease infinite;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* ── FOOTER ──────────────────────────────────── */
.footer {
  max-width: 1280px;
  margin: 0 auto;
  padding: 10px 28px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-primary);
  border-top: 1px solid var(--border);
  line-height: 1.6;
}

/* ── UTILITIES ───────────────────────────────── */
.hidden { display: none !important; }

/* ── RESPONSIVE ──────────────────────────────── */
@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
    padding: 16px;
  }
  .chat-window { max-height: 360px; }
}

@media (max-width: 480px) {
  .header-inner { padding: 0 16px; }
  .main { padding: 12px; gap: 12px; }
  .panel { padding: 16px; }
  .segmented { gap: 2px; }
  .seg-btn { font-size: 11px; padding: 6px 6px; }
  .logo { font-size: 11px; letter-spacing: 0.06em; }
}
