/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0e0e10;
  --surface: #17171a;
  --surface2: #1f1f24;
  --border: #2e2e36;
  --rule-color: #ff5c5c;
  --rule-dim: #3a1a1a;
  --llm-color: #4fc3f7;
  --llm-dim: #0d2a38;
  --text: #e8e8f0;
  --text-muted: #7a7a90;
  --accent: #f5e642;
  --font-display: 'Syne', sans-serif;
  --font-mono: 'Space Mono', monospace;
  --radius: 12px;
}

html { scroll-behavior: smooth; font-size: 18px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== HEADER ===== */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 28px 40px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 20px;
}

header h1 {
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1;
}

.dot { color: var(--accent); }

.subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 5px;
  font-weight: 400;
}

.confused-counter {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--rule-dim);
  border: 1px solid var(--rule-color);
  border-radius: 100px;
  padding: 8px 18px;
  white-space: nowrap;
  flex-shrink: 0;
}

.counter-label { font-size: 0.75rem; color: var(--rule-color); font-family: var(--font-mono); }
.counter-num {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--rule-color);
  font-family: var(--font-mono);
  min-width: 2ch;
  text-align: center;
  transition: transform 0.2s;
}
.counter-num.bump { transform: scale(1.5); }

/* ===== MAIN ===== */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px 20px 0;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ===== PANELS ===== */
.panels {
  display: grid;
  grid-template-columns: 1fr 48px 1fr;
  gap: 0;
  flex: 1;
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: border-color 0.3s;
}

.panel-rule { border-top: 3px solid var(--rule-color); }
.panel-llm  { border-top: 3px solid var(--llm-color); }

.panel-rule.shake {
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ===== PANEL HEADER ===== */
.panel-header {
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--border);
}

.bot-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 3px 10px;
  border-radius: 100px;
  margin-bottom: 10px;
}

.rule-tag { background: var(--rule-dim); color: var(--rule-color); border: 1px solid var(--rule-color); }
.llm-tag  { background: var(--llm-dim);  color: var(--llm-color);  border: 1px solid var(--llm-color); }

.panel-header h2 {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.bot-icon { font-size: 1.2rem; }

.panel-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 12px;
}

.panel-desc strong { color: var(--text); }

.peek-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.peek-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ===== PEEK BOX ===== */
.peek-box {
  display: none;
  background: #111114;
  border-bottom: 1px solid var(--border);
  padding: 16px 22px;
  animation: slideDown 0.25s ease;
}

.peek-box.open { display: block; }

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.peek-title {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  margin-bottom: 10px;
  letter-spacing: 1px;
}

.peek-box pre {
  background: #0a0a0c;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
}

.peek-box code {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: #b0f0b0;
  line-height: 1.7;
}

.llm-explain { display: flex; flex-direction: column; gap: 8px; }

.llm-step {
  font-size: 0.82rem;
  color: var(--text);
  background: var(--llm-dim);
  border-left: 3px solid var(--llm-color);
  padding: 8px 12px;
  border-radius: 0 6px 6px 0;
}

.peek-note {
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-style: italic;
}

/* ===== CHAT WINDOW ===== */
.chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 300px;
  max-height: 420px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.chat-window::-webkit-scrollbar { width: 4px; }
.chat-window::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* ===== MESSAGES ===== */
.message { display: flex; flex-direction: column; max-width: 88%; animation: msgIn 0.25s ease; }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.user-msg { align-self: flex-end; align-items: flex-end; }
.bot-msg  { align-self: flex-start; align-items: flex-start; }

.msg-label {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-bottom: 4px;
  letter-spacing: 1px;
}

.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.6;
}

.user-msg .bubble {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-right-radius: 4px;
}

.panel-rule .bot-msg .bubble {
  background: var(--rule-dim);
  border: 1px solid var(--rule-color);
  color: #ffb3b3;
  border-bottom-left-radius: 4px;
}

.panel-llm .bot-msg .bubble {
  background: var(--llm-dim);
  border: 1px solid var(--llm-color);
  color: #b3e8ff;
  border-bottom-left-radius: 4px;
}

/* error state */
.bubble.error {
  background: #2a1010 !important;
  border-color: var(--rule-color) !important;
  color: var(--rule-color) !important;
}

/* reason tag */
.reason-tag {
  font-size: 0.63rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-top: 4px;
  padding: 2px 8px;
  background: var(--surface2);
  border-radius: 100px;
  border: 1px solid var(--border);
  align-self: flex-start;
}

/* typing indicator */
.typing .bubble {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 14px 18px;
}

.dot-bounce {
  width: 7px; height: 7px;
  background: var(--llm-color);
  border-radius: 50%;
  animation: bounce 1s infinite;
}
.dot-bounce:nth-child(2) { animation-delay: 0.15s; }
.dot-bounce:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ===== VS DIVIDER ===== */
.vs-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 2px;
  position: relative;
}

.vs-divider span {
  background: var(--bg);
  padding: 8px 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  writing-mode: vertical-rl;
}

/* ===== STARTERS ===== */
.starters-section {
  margin-top: 20px;
  padding: 0 4px;
}

.starters-label {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  letter-spacing: 1px;
  margin-bottom: 10px;
}

.starters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.starter-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 0.82rem;
  padding: 7px 14px;
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.2s;
}
.starter-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

/* ===== INPUT AREA ===== */
.input-area {
  display: flex;
  gap: 10px;
  padding: 16px 0 24px;
  margin-top: 16px;
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  background: var(--bg);
}

#userInput {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 0.95rem;
  padding: 12px 18px;
  outline: none;
  transition: border-color 0.2s;
}

#userInput:focus { border-color: var(--accent); }
#userInput::placeholder { color: var(--text-muted); }

#sendBtn {
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: #0e0e10;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 12px 22px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

#sendBtn:hover { transform: translateY(-1px); box-shadow: 0 4px 20px rgba(245,230,66,0.3); }
#sendBtn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ===== RESPONSIVE ===== */
@media (max-width: 700px) {
  header { flex-direction: column; align-items: flex-start; padding: 16px 16px 14px; }
  .panels { grid-template-columns: 1fr; grid-template-rows: auto auto auto; }
  .vs-divider { writing-mode: horizontal-tb; padding: 8px 0; }
  .vs-divider span { writing-mode: horizontal-tb; }
  main { padding: 12px 12px 0; }
  .chat-window { max-height: 260px; }
}