@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
  --bg: #12181a;
  --card: #1a2124;
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.16);
  --text: #f2f4f3;
  --text-dim: #8b9490;
  --accent: #e8c15a;
  --accent-text: #1a1305;
  --danger: #ef8080;
  --success: #8ed6a8;
  --info: #8ec6e8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.lab-mono { font-family: 'JetBrains Mono', monospace; }

a.lab-link {
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
}
a.lab-link:hover { text-decoration: underline; }

/* Page layout: mobile-first, comfortable max-width once there's room */
.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}
@media (min-width: 480px) {
  .page { padding: 40px 24px 56px; }
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.heading { font-size: 22px; font-weight: 600; margin: 0; }
.sub { font-size: 14px; color: var(--text-dim); margin: 4px 0 28px; line-height: 1.4; }

/* Shared card shell used by auth, and every simulation */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px 20px;
}
@media (min-width: 480px) {
  .card { padding: 32px 28px; }
}

/* Landing page grid of simulation links */
.lab-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
a.lab-card, div.lab-card {
  display: block;
  text-decoration: none;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
}
a.lab-card:hover { border-color: var(--border-strong); }
.lab-card h2 { font-size: 16px; font-weight: 600; margin: 0 0 4px; }
.lab-card p { font-size: 13px; color: var(--text-dim); margin: 0; line-height: 1.4; }
.lab-card.locked { opacity: 0.55; }
.lab-card .lock-tag { display: inline-block; font-size: 11px; font-weight: 600; color: var(--accent); margin-top: 8px; }

/* Shared form controls: auth page and simulation input both use these */
label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  margin: 0 0 6px;
}
.field + .field { margin-top: 16px; }

input[type="email"], input[type="password"], input[type="text"] {
  width: 100%;
  height: 48px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  padding: 0 14px;
  outline: none;
}
input::placeholder { color: var(--text-dim); }
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232,193,90,0.18);
}

.btn-primary {
  height: 48px;
  font-family: inherit;
  font-weight: 600;
  font-size: 15px;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  min-height: 16px;
  line-height: 1.4;
}

/* Auth tabs (login page) */
.tabs {
  display: flex;
  background: rgba(255,255,255,0.05);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 24px;
}
.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 9px 0;
  border-radius: 7px;
  cursor: pointer;
}
.tab-btn.active { background: var(--card); color: var(--text); }

/* ---- Simulation UI ---- */

/* The solving surface itself keeps the chalkboard look; everything else
   (buttons, inputs, feedback) stays on the modern system above. */
.sim-card {
  background: radial-gradient(ellipse at 30% 0%, #1f362c, #16261f 75%);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 16px;
  padding: 24px 20px;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.25);
}
@media (min-width: 480px) {
  .sim-card { padding: 32px 28px; }
}

.sim-header { margin-bottom: 16px; }
.sim-title { display: block; font-size: 18px; font-weight: 600; }
.sim-sub {
  display: block;
  margin-top: 6px;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.01em;
  line-height: 1.4;
}

.sim-solution { max-height: 260px; overflow-y: auto; margin-bottom: 10px; padding: 4px 2px; }

.sim-milestone {
  display: none;
  position: relative;
  overflow: hidden;
  background: rgba(232,193,90,0.12);
  border: 1px solid rgba(232,193,90,0.35);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
  font-family: 'Inter', sans-serif;
}
.sim-milestone.show { display: block; animation: milestone-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
.sim-milestone strong { display: block; font-size: 14px; color: var(--accent); margin-bottom: 2px; }
.sim-milestone span { display: block; font-size: 13px; color: var(--text-dim); }
@keyframes milestone-pop {
  0% { opacity: 0; transform: scale(0.9) translateY(-6px); }
  60% { opacity: 1; transform: scale(1.02) translateY(0); }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) { .sim-milestone.show { animation: none; } }

.confetti-piece {
  position: absolute;
  top: 6px;
  width: 6px;
  height: 6px;
  border-radius: 2px;
  pointer-events: none;
  animation: confetti-burst 0.7s ease-out forwards;
}
@keyframes confetti-burst {
  from { opacity: 1; transform: translate(0, 0) rotate(0deg); }
  to { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(220deg); }
}
.sim-row { display: grid; grid-template-columns: 1fr 24px 1fr; align-items: baseline; }
.sim-row .sim-left { text-align: right; padding-right: 6px; }
.sim-row .sim-mid { text-align: center; color: var(--text-dim); }
.sim-row .sim-right { text-align: left; padding-left: 6px; }

.sim-row.eq { font-size: 17px; color: var(--text-dim); padding: 6px 0; }
.sim-row.eq.latest { font-size: clamp(22px, 5.5vw, 30px); color: var(--text); font-weight: 700; padding: 8px 0 10px; }
.sim-row.eq.latest.solved { color: var(--success); }
.sim-row.eq.after-op { border-top: 1px solid var(--border); margin-top: 2px; padding-top: 8px; }

.sim-row.op {
  font-size: 14px; color: var(--danger); font-weight: 600; padding: 0 0 2px;
  animation: dropin 0.2s ease;
}
@keyframes dropin { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .sim-row.op { animation: none; } }

.sim-form { display: flex; gap: 8px; margin-bottom: 8px; }
.sim-form input { flex: 1; height: 44px; }
.sim-btn {
  height: 44px; padding: 0 18px; font-family: inherit; font-weight: 600; font-size: 14px;
  background: transparent; color: var(--accent); border: 1px solid var(--border-strong);
  border-radius: 10px; cursor: pointer;
}
.sim-btn:hover { border-color: var(--accent); }
.sim-btn:disabled { opacity: 0.5; cursor: default; }

.sim-feedback { font-size: 14px; min-height: 20px; margin-bottom: 14px; line-height: 1.4; }
.sim-feedback.idle { color: var(--text-dim); }
.sim-feedback.error { color: var(--danger); }
.sim-feedback.info { color: var(--info); }
.sim-feedback.good, .sim-feedback.success { color: var(--success); }
.sim-feedback.hint { color: var(--accent); }

.sim-controls {
  display: flex; justify-content: space-between; align-items: center; font-size: 12px;
  color: var(--text-dim); border-top: 1px solid var(--border); padding-top: 12px;
}
.sim-stats { display: flex; gap: 16px; }
.sim-stats b { color: var(--text); font-weight: 600; }
.sim-links { display: flex; gap: 14px; }
.sim-link { background: none; border: none; color: var(--accent); font-size: 12px; cursor: pointer; text-decoration: underline; padding: 0; }
.sim-link:disabled { color: var(--text-dim); cursor: default; text-decoration: none; opacity: 0.6; }

.sim-next {
  margin-top: 12px; width: 100%; height: 44px; font-family: inherit; font-weight: 600; font-size: 14px;
  background: var(--accent); color: var(--accent-text); border: none; border-radius: 10px; cursor: pointer;
}
.sim-next:hover { filter: brightness(1.05); }
