:root {
  --bg: #0f1117;
  --surface: #171a23;
  --surface-2: #1e222d;
  --border: #2a2f3d;
  --text: #e6e8ee;
  --text-dim: #9aa0b0;
  --accent: #6c5ce7;
  --accent-hover: #7d6ff0;
  --success: #2ecc71;
  --warning: #f39c12;
  --danger: #e74c3c;
  --radius: 12px;
  --radius-sm: 8px;
}

* {
  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);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Nav ---------- */

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 1.1rem;
  cursor: pointer;
  user-select: none;
}

.logo {
  color: var(--accent);
  font-size: 1.4rem;
}

.nav nav {
  display: flex;
  gap: 8px;
}

.nav-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid transparent;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s;
  font-family: inherit;
}

.nav-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-btn.active {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

/* ---------- Layout ---------- */

main {
  flex: 1;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 48px 24px;
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  margin-bottom: 24px;
}

.card > h2:first-child,
.card > h1:first-child {
  margin-top: 0;
}

/* ---------- Typography ---------- */

h1 {
  font-size: 1.75rem;
  margin-bottom: 12px;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

h2 {
  font-size: 1.25rem;
  margin: 24px 0 12px;
  color: var(--text);
  letter-spacing: -0.01em;
}

h3 {
  margin: 20px 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.8rem;
}

p {
  color: var(--text-dim);
  margin-bottom: 16px;
}

p:last-child {
  margin-bottom: 0;
}

strong {
  color: var(--text);
  font-weight: 600;
}

em {
  color: var(--text);
}

/* ---------- Inputs ---------- */

input[type="text"],
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 14px 16px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.15s;
  margin-bottom: 16px;
}

input[type="text"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}

textarea {
  min-height: 160px;
  resize: vertical;
  line-height: 1.6;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  margin: 16px 0;
  cursor: pointer;
}

/* ---------- Buttons ---------- */

button.primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.05s;
  font-family: inherit;
}

button.primary:hover {
  background: var(--accent-hover);
}

button.primary:active {
  transform: translateY(1px);
}

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

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

button.secondary:hover {
  background: var(--surface-2);
  border-color: var(--text-dim);
}

/* ---------- Code & Scenario blocks ---------- */

pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px;
  overflow-x: auto;
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  color: #d4d4d4;
  margin: 16px 0;
  white-space: pre;
}

code {
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  color: var(--text);
}

pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
}

/* Scenario block — used when the AI generates a non-code challenge */
.scenario {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 20px 24px;
  margin: 16px 0;
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--text);
}

/* ---------- Analysis output ---------- */

.analysis {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  line-height: 1.7;
  margin-bottom: 24px;
}

.analysis h2 {
  font-size: 1.1rem;
  color: var(--accent);
  margin-top: 28px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0;
  text-transform: none;
}

.analysis h2:first-child {
  margin-top: 0;
}

.analysis p {
  color: var(--text);
  margin-bottom: 12px;
}

.analysis ul {
  margin: 12px 0 16px 24px;
  color: var(--text);
}

.analysis li {
  margin-bottom: 6px;
}

.analysis strong {
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Dashboard ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 6px;
}

.attempt {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  transition: border-color 0.15s;
}

.attempt:hover {
  border-color: var(--text-dim);
}

.attempt-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 12px;
  flex-wrap: wrap;
}

.attempt-concept {
  font-weight: 600;
  color: var(--text);
  font-size: 1.05rem;
}

.attempt-date {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.attempt-preview {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.attempt-details {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.attempt-details summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 500;
  list-style: none;
  user-select: none;
}

.attempt-details summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform 0.15s;
}

.attempt-details[open] summary::before {
  transform: rotate(90deg);
}

.attempt-details summary::-webkit-details-marker {
  display: none;
}

.attempt-details[open] summary {
  margin-bottom: 12px;
}

/* ---------- Loading ---------- */

.loading {
  text-align: center;
  padding: 60px 0;
}

.loading h1 {
  margin-bottom: 8px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 24px;
}

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

/* ---------- Error ---------- */

.error-box {
  background: rgba(231, 76, 60, 0.1);
  border: 1px solid rgba(231, 76, 60, 0.3);
  border-radius: var(--radius-sm);
  padding: 20px;
  color: var(--text);
  margin-bottom: 20px;
  word-break: break-word;
}

.error-box strong {
  color: var(--danger);
}

/* ---------- Footer ---------- */

footer {
  text-align: center;
  padding: 24px;
  color: var(--text-dim);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

/* ---------- Flow steps ---------- */

.steps {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
  font-size: 0.8rem;
  color: var(--text-dim);
  flex-wrap: wrap;
}

.step {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  transition: all 0.15s;
  white-space: nowrap;
}

.step.active {
  background: var(--accent);
  color: white;
}

.step.done {
  color: var(--success);
  background: rgba(46, 204, 113, 0.1);
}

/* ---------- Responsive ---------- */

@media (max-width: 600px) {
  .nav {
    padding: 12px 16px;
  }
  .nav nav {
    gap: 4px;
  }
  .nav-btn {
    padding: 6px 10px;
    font-size: 0.85rem;
  }
  main {
    padding: 24px 16px;
  }
  .card {
    padding: 24px 20px;
  }
  .analysis {
    padding: 24px 20px;
  }
  h1 {
    font-size: 1.4rem;
  }
  h2 {
    font-size: 1.1rem;
  }
  .steps {
    font-size: 0.7rem;
    gap: 4px;
  }
  .step {
    padding: 3px 8px;
  }
}
