:root {
  --bg: #0f1117;
  --bg-soft: #151823;
  --surface: #1b1f2d;
  --surface-2: #242a3b;
  --surface-3: #2d3348;
  --line: rgba(255, 255, 255, 0.06);
  --line-strong: rgba(255, 255, 255, 0.12);
  --text: #e8eaf2;
  --text-dim: #9ba0b4;
  --text-mute: #6b7085;
  --accent: #7c5cff;
  --accent-bright: #a990ff;
  --accent-soft: rgba(124, 92, 255, 0.15);
  --mint: #4ade80;
  --amber: #fbbf24;
  --rose: #fb7185;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.15), 0 8px 24px rgba(0, 0, 0, 0.18);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.35);
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', 'Menlo', 'Consolas', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
}

.bg-accent {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(124, 92, 255, 0.18), transparent 60%),
    radial-gradient(700px 420px at 90% 110%, rgba(74, 222, 128, 0.10), transparent 60%);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); border: 0;
}

/* Header */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px) saturate(160%);
  -webkit-backdrop-filter: blur(12px) saturate(160%);
  background: rgba(15, 17, 23, 0.72);
  border-bottom: 1px solid var(--line);
}

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

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

.brand-logo {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent) 0%, #5b8cff 100%);
  color: white;
  border-radius: 11px;
  box-shadow: 0 6px 18px rgba(124, 92, 255, 0.35);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.1; }

.brand-kicker {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-mute);
  font-weight: 500;
}

.brand-text h1 {
  margin: 2px 0 0;
  font-size: 1.12rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.flag-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 11px;
  font-weight: 600;
  font-size: 0.88rem;
  font-family: var(--sans);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 6px 18px rgba(124, 92, 255, 0.32);
}

.flag-btn:hover {
  background: var(--accent-bright);
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(124, 92, 255, 0.42);
}

.flag-btn:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 3px;
}

/* Layout */

.shell {
  position: relative;
  z-index: 1;
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 28px 48px;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  align-items: start;
}

/* Control panel */

.control-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: var(--shadow-soft);
  position: sticky;
  top: 92px;
}

.panel-kicker {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-bright);
  font-weight: 600;
}

.panel-header h2 {
  margin: 4px 0 6px;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.panel-lead {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.5;
}

.diff-display {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 16px 18px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.diff-number {
  font-size: 2.4rem;
  font-weight: 700;
  font-family: var(--mono);
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, var(--accent-bright), #5b8cff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1;
}

.diff-tier {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  text-transform: capitalize;
}

/* Select */

.select-label {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-mute);
  font-weight: 600;
  margin-bottom: -6px;
}

.select-wrap {
  position: relative;
}

.diff-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  width: 100%;
  padding: 12px 40px 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.diff-select:hover {
  border-color: var(--accent);
}

.diff-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.select-chevron {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

.diff-select option {
  background: var(--surface);
  color: var(--text);
}

/* Tier legend */

.tier-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: var(--bg-soft);
  border-radius: 12px;
  border: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--text-dim);
}

.tier-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 3px 0;
  transition: color 0.15s ease;
}

.tier-row.active {
  color: var(--text);
  font-weight: 600;
}

.tier-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
}

.t-easy { background: var(--mint); }
.t-light { background: #60a5fa; }
.t-mid { background: var(--accent-bright); }
.t-hard { background: var(--amber); }
.t-expert { background: var(--rose); }

/* Chat card */

.chat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 560px;
}

.chat-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  padding: 14px 22px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
  font-size: 0.8rem;
}

.meta-item { display: flex; flex-direction: column; gap: 2px; }
.meta-label { color: var(--text-mute); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; }
.meta-item strong {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 0.86rem;
}

/* Messages */

.messages {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  max-height: 55vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}

.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; }
.messages::-webkit-scrollbar-track { background: transparent; }

.bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.5;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: fadeUp 0.24s ease-out;
}

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

.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 6px 14px rgba(124, 92, 255, 0.25);
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

.bubble.system {
  align-self: center;
  background: transparent;
  color: var(--text-mute);
  font-size: 0.82rem;
  font-style: italic;
  text-align: center;
  max-width: 90%;
  padding: 4px 8px;
}

.bubble.error {
  align-self: center;
  background: rgba(251, 113, 133, 0.1);
  color: var(--rose);
  border: 1px solid rgba(251, 113, 133, 0.3);
  font-size: 0.85rem;
  max-width: 90%;
}

.typing {
  display: inline-flex; gap: 5px; align-items: center;
  padding: 2px 0;
}
.typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent-bright);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-4px); }
}

/* Chat form */

.chat-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 22px 20px;
  background: var(--bg-soft);
  border-top: 1px solid var(--line);
}

#chat-input {
  width: 100%;
  resize: vertical;
  min-height: 60px;
  max-height: 200px;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.95rem;
  line-height: 1.5;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

#chat-input::placeholder { color: var(--text-mute); }

#chat-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chat-form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.input-counter {
  font-size: 0.76rem;
  color: var(--text-mute);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.input-counter.warn { color: var(--amber); }

.send-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 11px;
  font-weight: 600;
  font-size: 0.88rem;
  font-family: var(--sans);
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 6px 18px rgba(124, 92, 255, 0.32);
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-bright);
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(124, 92, 255, 0.42);
}

.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Dialog */

.flag-dialog {
  border: none;
  padding: 0;
  background: transparent;
  max-width: 460px;
  width: 92%;
}

.flag-dialog::backdrop {
  background: rgba(10, 12, 18, 0.7);
  backdrop-filter: blur(6px);
}

.flag-dialog-form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 26px 28px 22px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.flag-dialog-form h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.dialog-hint {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.86rem;
}

.dialog-hint code {
  font-family: var(--mono);
  font-size: 0.82rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  padding: 2px 7px;
  border-radius: 6px;
  color: var(--accent-bright);
}

#flag-input {
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  font-family: var(--mono);
  font-size: 0.92rem;
  background: var(--bg-soft);
  color: var(--text);
}

#flag-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.flag-feedback {
  min-height: 20px;
  margin: 0;
  font-size: 0.86rem;
  font-weight: 500;
}

.flag-feedback.success { color: var(--mint); }
.flag-feedback.error { color: var(--rose); }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.btn-primary, .btn-ghost {
  border: none;
  padding: 10px 18px;
  border-radius: 11px;
  font-weight: 600;
  font-family: var(--sans);
  font-size: 0.86rem;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-bright); }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--line-strong);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

/* Footer */

.site-footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 24px 20px 32px;
  color: var(--text-mute);
  font-size: 0.78rem;
}

.site-footer a { color: var(--accent-bright); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* Responsive */

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    padding: 20px 18px 40px;
  }
  .control-panel {
    position: static;
    top: auto;
  }
}

@media (max-width: 520px) {
  .header-inner { padding: 14px 18px; }
  .brand-text h1 { font-size: 1rem; }
  .bubble { max-width: 92%; }
  .chat-meta { gap: 6px 18px; padding: 12px 18px; }
  .messages { padding: 18px; }
  .chat-form { padding: 14px 18px 18px; }
}
