:root {
  --bg: #0a0e17;
  --bg-glow: radial-gradient(ellipse 80% 50% at 50% -10%, rgba(34, 211, 238, 0.08), transparent);
  --fg: #e7ecf3;
  --card-bg: #10151f;
  --card-bg-raised: #141b28;
  --border: #232c3d;
  --border-strong: #2f3a4f;
  --accent: #22d3ee;
  --accent-dim: #0e7490;
  --accent-fg: #04141a;
  --muted: #8b96a8;
  --error: #ff6b6b;
  --success: #34d399;
  --success-fg: #04140d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg) var(--bg-glow);
  color: var(--fg);
  min-height: 100vh;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 2rem;
  background: rgba(16, 21, 31, 0.8);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.site-header .brand {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.site-header h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: rgba(52, 211, 153, 0.08);
  color: var(--success);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.live-badge .dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.layout {
  max-width: 640px;
  margin: 1.5rem auto;
  padding: 0 1rem 3rem;
  display: grid;
  gap: 1.25rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.02) inset, 0 8px 24px rgba(0, 0, 0, 0.2);
}

.card h2 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.chat-card {
  display: flex;
  flex-direction: column;
  height: 75vh;
  max-height: 800px;
}

.chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.chat-title { display: flex; flex-direction: column; gap: 0.25rem; }
.who { margin: 0; color: var(--muted); font-size: 0.8rem; }
.who strong { color: var(--fg); font-weight: 600; }

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  padding: 0.75rem;
  margin: 0.85rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Chat bubbles (app.js emits .msg with .user / .bot / .sys) */
.msg {
  padding: 0.55rem 0.8rem;
  border-radius: 10px;
  max-width: 85%;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.92rem;
  line-height: 1.45;
}

.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 500;
}

.msg.bot {
  align-self: flex-start;
  background: var(--card-bg-raised);
  border: 1px solid var(--border);
}

.msg.sys {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
  max-width: 100%;
}

/* Success banner on solve */
.banner {
  align-self: center;
  max-width: 100%;
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid var(--success);
  color: var(--success);
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.88rem;
  box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.2);
}

.chat-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
}

input[type="text"] {
  flex: 1;
  padding: 0.65rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--card-bg-raised);
  color: var(--fg);
  font-size: 0.92rem;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.15);
}

input[type="text"]::placeholder { color: var(--muted); }

button, .button {
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-block;
  transition: filter 0.15s ease, transform 0.05s ease;
}

button:hover, .button:hover { filter: brightness(1.1); }
button:active, .button:active { transform: translateY(1px); }

.button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border-strong);
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 500;
}

.button.ghost:hover { color: var(--fg); border-color: var(--muted); filter: none; }

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

.icon-button {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  line-height: 1;
  flex-shrink: 0;
  background: var(--card-bg-raised);
  color: var(--fg);
  border: 1px solid var(--border-strong);
}

.icon-button:hover { border-color: var(--accent); color: var(--accent); filter: none; }

.send-button {
  font-size: 1rem;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
}

.send-button:hover { filter: brightness(1.1); }

/* Debrief panel shown after solving */
.debrief {
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: var(--card-bg-raised);
  padding: 1rem 1.15rem;
  margin: 0 0 0.85rem;
  font-size: 0.88rem;
  line-height: 1.5;
}

.debrief h3 { margin: 0 0 0.5rem; font-size: 1rem; }
.debrief h4 { margin: 0.85rem 0 0.25rem; color: var(--accent); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.debrief p { margin: 0.4rem 0; color: var(--fg); }
.debrief ul { margin: 0.3rem 0; padding-left: 1.25rem; }
.debrief li { margin: 0.2rem 0; }

.debrief .flag {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  color: var(--success);
  font-weight: 700;
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.3);
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  display: inline-block;
}

.hidden { display: none !important; }
[hidden] { display: none !important; }
