:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --raw: #3b82f6;
  --raw-bg: #eff6ff;
  --meta: #10b981;
  --meta-bg: #ecfdf5;
  --winner: #f59e0b;
  --winner-bg: #fffbeb;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.08), 0 4px 10px rgba(15, 23, 42, 0.04);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 15px;
}

/* Header */
.header {
  background: linear-gradient(135deg, #1e40af, #6d28d9);
  color: #fff;
  padding: 32px 0;
  text-align: center;
}
.header h1 { font-size: 30px; font-weight: 700; margin-bottom: 8px; }
.header p { font-size: 16px; opacity: 0.9; }

/* Container */
.container { max-width: 1280px; margin: 0 auto; padding: 0 24px; }

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.tab {
  background: transparent;
  border: 0;
  padding: 16px 24px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active { color: #1e40af; border-bottom-color: #1e40af; }

/* Main area */
.main { padding: 32px 0; }

/* Scenario selector */
.scenario-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.scenario-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}
.scenario-card:hover {
  border-color: #1e40af;
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.scenario-card.selected {
  border-color: #1e40af;
  background: #eff6ff;
  box-shadow: var(--shadow);
}
.scenario-card .icon { font-size: 24px; }
.scenario-card .title { font-weight: 600; font-size: 14px; margin: 8px 0 4px; }
.scenario-card .module {
  font-size: 11px;
  color: #6d28d9;
  font-weight: 600;
  background: #f3e8ff;
  padding: 2px 8px;
  border-radius: 10px;
  display: inline-block;
}

/* Description box */
.description-box {
  background: var(--card);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.description-box h3 {
  font-size: 18px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.description-box p { color: var(--text-muted); margin-bottom: 12px; }
.description-box .why {
  font-size: 13px;
  background: #fef3c7;
  border-left: 3px solid #f59e0b;
  padding: 8px 12px;
  border-radius: 4px;
  color: #78350f;
}

/* Question input */
.question-area {
  background: var(--card);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.question-area label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.question-area textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  background: #fafbfc;
}
.question-area textarea:focus {
  outline: none;
  border-color: #1e40af;
  background: #fff;
}

/* File upload area */
.file-area {
  margin-top: 12px;
  padding: 12px;
  background: #f1f5f9;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.file-area strong { color: var(--text); }

/* Run button */
.run-button {
  display: block;
  width: 100%;
  padding: 16px;
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, #1e40af, #6d28d9);
  color: #fff;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  margin: 16px 0 24px;
  transition: all 0.2s;
}
.run-button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}
.run-button:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

/* Results grid */
.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
@media (max-width: 900px) {
  .results-grid { grid-template-columns: 1fr; }
}

.result-card {
  background: var(--card);
  border-radius: 12px;
  padding: 20px 24px;
  box-shadow: var(--shadow);
  border-top: 4px solid var(--border);
  min-height: 280px;
  display: flex;
  flex-direction: column;
}
.result-card.raw { border-top-color: var(--raw); }
.result-card.meta { border-top-color: var(--meta); }

.result-card.winner {
  box-shadow: 0 0 0 3px var(--winner), var(--shadow-lg);
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.result-header h4 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
}
.result-card.raw .result-header h4 { color: var(--raw); }
.result-card.meta .result-header h4 { color: var(--meta); }

.status {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 10px;
  font-weight: 600;
}
.status.idle { background: #e2e8f0; color: var(--text-muted); }
.status.running { background: #fef3c7; color: #92400e; }
.status.done { background: #dcfce7; color: #166534; }
.status.error { background: #fee2e2; color: #991b1b; }

.answer {
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 14px;
  min-height: 80px;
  flex: 1;
  margin-bottom: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", monospace;
  font-size: 13px;
  line-height: 1.5;
}
.answer.empty { color: var(--text-light); font-style: italic; font-family: inherit; }

.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 600;
  background: #f1f5f9;
  color: var(--text-muted);
}
.result-card.meta .badge { background: var(--meta-bg); color: #065f46; }
.result-card.raw .badge { background: var(--raw-bg); color: #1e40af; }

.stats { display: flex; gap: 16px; font-size: 12px; color: var(--text-muted); }
.stats span strong { color: var(--text); font-weight: 700; }

/* Winner banner */
.winner-banner {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border: 2px solid var(--winner);
  border-radius: 12px;
  padding: 16px 24px;
  text-align: center;
  font-weight: 600;
  font-size: 15px;
  color: #78350f;
  display: none;
}
.winner-banner.show { display: block; }

/* Learning tab */
.learning-tab { display: none; }
.learning-tab.active { display: block; }

.step-card {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--meta);
}
.step-card.disabled { opacity: 0.5; pointer-events: none; }
.step-card.done { border-left-color: var(--meta); background: #f0fdf4; }
.step-number {
  display: inline-block;
  width: 28px;
  height: 28px;
  background: var(--meta);
  color: #fff;
  border-radius: 50%;
  text-align: center;
  line-height: 28px;
  font-weight: 700;
  margin-right: 10px;
}
.step-card h3 { margin-bottom: 8px; }
.step-card .step-content { margin-top: 12px; }

.btn {
  background: var(--meta);
  color: #fff;
  border: 0;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}
.btn:hover { opacity: 0.9; }
.btn:disabled { background: #cbd5e1; cursor: not-allowed; }
.btn.secondary { background: #f1f5f9; color: var(--text); }

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid #fef3c7;
  border-top-color: #92400e;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Footer */
.footer {
  margin-top: 48px;
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.footer a { color: #1e40af; text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* Login overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1e40af, #6d28d9);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-box {
  background: #fff;
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.login-box input:focus {
  outline: none;
  border-color: #1e40af;
}
.login-box .run-button {
  margin: 0;
}

/* Hidden helper */
.hidden { display: none !important; }
