/* ══════════════════════════════════════════════
   Linear Equations Learning Platform
   Dark MathSpaces theme + Duolingo gamification
   ══════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --bg:    #0f0f1a;
  --bg2:   #1a1a2e;
  --card:  #242440;
  --btn:   #2e2e50;
  --acc:   #cc0000;
  --txt:   #f0f0f0;
  --dim:   #9090b0;
  --bdr:   #35355a;
  --green: #1a7a1a;
  --green2:#22aa22;
  --gold:  #c47400;
}

html, body {
  width: 100%; min-height: 100vh;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button, input, select { font-family: inherit; }
button { cursor: pointer; }

/* ══════════════════════════════════════════════
   LICENSE GATE
   ══════════════════════════════════════════════ */
#licenseGate {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}

.gate-box {
  background: var(--bg2);
  border: 1px solid var(--bdr);
  padding: 40px 32px;
  width: 100%; max-width: 400px;
  text-align: center;
}

.gate-box .gate-logo { font-size: 56px; margin-bottom: 14px; display: block; }
.gate-box h1 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.gate-box .gate-sub { font-size: 13px; color: var(--dim); margin-bottom: 28px; line-height: 1.6; }

.gate-box input[type="text"] {
  width: 100%;
  padding: 13px 14px;
  background: var(--btn);
  border: 1px solid var(--bdr);
  color: var(--txt);
  font-size: 15px;
  font-family: monospace;
  letter-spacing: 3px;
  text-align: center;
  text-transform: uppercase;
  margin-bottom: 12px;
  outline: none;
  transition: border-color .2s;
}
.gate-box input[type="text"]:focus { border-color: var(--acc); }
.gate-box input[type="text"]::placeholder { letter-spacing: 1px; text-transform: none; color: var(--dim); }

.gate-box .gate-err {
  font-size: 13px; color: var(--acc);
  min-height: 18px; margin-bottom: 10px;
}

.gate-box .gate-note {
  font-size: 12px; color: var(--dim);
  margin-top: 20px; line-height: 1.6;
}

/* ══════════════════════════════════════════════
   MAIN APP
   ══════════════════════════════════════════════ */
#mainApp { display: none; min-height: 100vh; flex-direction: column; }
#mainApp.visible { display: flex; }

/* ── Header ── */
#appHeader {
  background: var(--bg2);
  border-bottom: 1px solid var(--bdr);
  padding: 0 16px;
  height: 56px;
  display: flex; align-items: center; gap: 12px;
  flex-shrink: 0;
  position: sticky; top: 0; z-index: 100;
}

.hdr-logo { font-size: 26px; flex-shrink: 0; }
.hdr-title { flex-shrink: 0; }
.hdr-title strong { font-size: 17px; font-weight: 700; display: block; line-height: 1.1; }
.hdr-title span { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; }

.hdr-xp {
  flex: 1; display: flex; align-items: center; gap: 8px;
  min-width: 0; padding: 0 8px;
}

.level-badge {
  background: var(--acc);
  color: white;
  font-size: 11px; font-weight: 700;
  padding: 3px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.xp-bar-wrap {
  flex: 1; min-width: 40px; max-width: 140px;
  background: var(--btn);
  height: 8px;
  overflow: hidden;
}
.xp-bar-fill {
  height: 100%;
  background: var(--acc);
  transition: width .4s ease;
}

.xp-label { font-size: 11px; color: var(--dim); white-space: nowrap; flex-shrink: 0; }

.hdr-stats {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}

.hdr-hearts { font-size: 14px; }
.hdr-streak { font-size: 13px; font-weight: 700; color: var(--gold); }

/* ── Buttons ── */
.btn {
  padding: 10px 20px;
  border: none;
  font-size: 13px; font-weight: 700;
  cursor: pointer;
  transition: opacity .15s;
}
.btn:hover { opacity: .85; }
.btn:active { opacity: .7; }
.btn-primary { background: var(--acc); color: white; }
.btn-ghost { background: var(--btn); color: var(--txt); border: 1px solid var(--bdr); }
.btn-green { background: var(--green); color: white; }
.btn-sm { padding: 7px 14px; font-size: 12px; }
.btn-full { width: 100%; }

/* ── Screens ── */
.screen { display: none; flex: 1; }
.screen.active { display: block; }

/* ══════════════════════════════════════════════
   HOME SCREEN — Chapter Map
   ══════════════════════════════════════════════ */
#homeScreen {
  padding: 24px 16px 48px;
  max-width: 600px; margin: 0 auto;
}

.home-welcome {
  text-align: center;
  margin-bottom: 28px;
}
.home-welcome h2 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.home-welcome p { font-size: 14px; color: var(--dim); }

/* Path container */
.chapter-path {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Connector line between cards */
.chapter-path::before {
  content: '';
  position: absolute;
  left: 36px;
  top: 60px;
  bottom: 60px;
  width: 2px;
  background: var(--bdr);
  z-index: 0;
}

.chapter-card {
  background: var(--card);
  border: 1px solid var(--bdr);
  padding: 16px;
  display: flex; align-items: center; gap: 14px;
  cursor: pointer;
  position: relative; z-index: 1;
  transition: border-color .2s, background .2s;
  margin-bottom: 12px;
  margin-left: 24px;
  text-decoration: none;
  color: inherit;
}
.chapter-card:hover:not(.locked) { border-color: var(--acc); background: #2a2a44; }
.chapter-card.locked { opacity: .55; cursor: not-allowed; }
.chapter-card.completed { border-color: var(--green); }

.chapter-icon {
  width: 52px; height: 52px;
  background: var(--btn);
  border: 2px solid var(--bdr);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
  position: relative;
}
.chapter-card.completed .chapter-icon { border-color: var(--green); background: #0a2a0a; }
.chapter-card.locked .chapter-icon { background: #1a1a30; }

.chapter-info { flex: 1; min-width: 0; }
.chapter-info h3 { font-size: 15px; font-weight: 700; margin-bottom: 3px; }
.chapter-info p { font-size: 12px; color: var(--dim); margin-bottom: 8px; line-height: 1.4; }

.chapter-progress {
  height: 5px;
  background: var(--btn);
  overflow: hidden;
  margin-bottom: 5px;
}
.chapter-progress-fill {
  height: 100%;
  background: var(--acc);
  transition: width .4s ease;
}
.chapter-card.completed .chapter-progress-fill { background: var(--green); }

.chapter-meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--dim);
}
.chapter-xp { color: var(--gold); font-weight: 700; }

.chapter-num {
  position: absolute;
  left: -24px; top: 50%;
  transform: translateY(-50%);
  width: 24px; height: 24px;
  background: var(--bdr);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  color: var(--dim);
}
.chapter-card.completed .chapter-num { background: var(--green); color: white; }
.chapter-card.active-chapter .chapter-num { background: var(--acc); color: white; }

/* ══════════════════════════════════════════════
   EXERCISE SCREEN
   ══════════════════════════════════════════════ */
#exerciseScreen {
  display: none;
  flex-direction: column;
  min-height: calc(100vh - 56px);
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
  padding: 0 16px 48px;
}
#exerciseScreen.active { display: flex; }

.ex-header {
  padding: 16px 0 12px;
  display: flex; align-items: center; gap: 12px;
}

.ex-back {
  background: none; border: none;
  color: var(--dim); font-size: 22px; padding: 4px;
  cursor: pointer; flex-shrink: 0;
}
.ex-back:hover { color: var(--txt); }

.ex-progress-wrap {
  flex: 1;
  background: var(--btn);
  height: 8px;
  overflow: hidden;
}
.ex-progress-fill {
  height: 100%;
  background: var(--acc);
  transition: width .4s ease;
}

.ex-xp-session {
  font-size: 12px; color: var(--gold); font-weight: 700;
  white-space: nowrap; flex-shrink: 0;
}

/* Exercise card */
.ex-card {
  background: var(--card);
  border: 1px solid var(--bdr);
  padding: 24px;
  margin-bottom: 16px;
}

.ex-type-badge {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px;
  color: var(--dim); margin-bottom: 10px;
  display: block;
}

.ex-question {
  font-size: 18px; font-weight: 700;
  line-height: 1.5; margin-bottom: 20px;
  color: var(--txt);
}
.ex-question code {
  background: var(--btn);
  padding: 1px 6px;
  font-family: monospace;
  color: #a0d0ff;
}

/* Canvas container for coordinate tasks */
.ex-canvas-wrap {
  width: 100%; height: 280px;
  border: 1px solid var(--bdr);
  background: #1a1a2e;
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}
.ex-canvas-wrap canvas { display: block; width: 100%; height: 100%; }
.ex-canvas-hint {
  position: absolute; bottom: 6px; right: 8px;
  font-size: 11px; color: var(--dim);
  pointer-events: none;
}

/* Multiple choice */
.mc-options {
  display: flex; flex-direction: column; gap: 10px;
}
.mc-option {
  background: var(--btn);
  border: 2px solid var(--bdr);
  padding: 12px 16px;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  color: var(--txt);
  font-family: inherit;
}
.mc-option:hover:not(:disabled) { border-color: var(--acc); background: #3a3a60; }
.mc-option.selected { border-color: var(--acc); background: #3a1a1a; }
.mc-option.correct { border-color: var(--green2); background: #0a2a0a; color: #6fda6f; }
.mc-option.wrong { border-color: var(--acc); background: #2a0a0a; color: #ff8888; }
.mc-option:disabled { cursor: default; }

/* Fill in blank */
.fib-wrap {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  font-size: 16px; line-height: 2;
}
.fib-input {
  background: var(--btn);
  border: 2px solid var(--bdr);
  color: var(--txt);
  font-size: 15px;
  padding: 6px 10px;
  width: 100px; text-align: center;
  outline: none;
  font-family: monospace;
  transition: border-color .15s;
}
.fib-input:focus { border-color: var(--acc); }
.fib-input.correct { border-color: var(--green2); background: #0a2a0a; color: #6fda6f; }
.fib-input.wrong { border-color: var(--acc); background: #2a0a0a; color: #ff8888; }

/* Number input */
.num-input-wrap { display: flex; gap: 10px; align-items: center; }
.num-input {
  background: var(--btn);
  border: 2px solid var(--bdr);
  color: var(--txt);
  font-size: 20px;
  padding: 10px 14px;
  width: 140px; text-align: center;
  outline: none;
  font-family: monospace;
  transition: border-color .15s;
}
.num-input:focus { border-color: var(--acc); }
.num-input.correct { border-color: var(--green2); background: #0a2a0a; color: #6fda6f; }
.num-input.wrong { border-color: var(--acc); background: #2a0a0a; color: #ff8888; }

/* True/False */
.tf-wrap { display: flex; gap: 12px; }
.tf-btn {
  flex: 1;
  background: var(--btn);
  border: 2px solid var(--bdr);
  color: var(--txt);
  font-size: 16px; font-weight: 700;
  padding: 14px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.tf-btn:hover:not(:disabled) { border-color: var(--acc); background: #3a3a60; }
.tf-btn.selected { border-color: var(--acc); background: #3a1a1a; }
.tf-btn.correct { border-color: var(--green2); background: #0a2a0a; color: #6fda6f; }
.tf-btn.wrong { border-color: var(--acc); background: #2a0a0a; color: #ff8888; }
.tf-btn:disabled { cursor: default; }

/* Step ordering */
.step-order-wrap { display: flex; flex-direction: column; gap: 8px; }
.step-item {
  background: var(--btn);
  border: 2px solid var(--bdr);
  padding: 11px 14px;
  display: flex; align-items: center; gap: 10px;
  cursor: grab;
  font-size: 14px;
  transition: border-color .15s;
}
.step-item:active { cursor: grabbing; }
.step-item.drag-over { border-color: var(--acc); }
.step-item .step-handle { color: var(--dim); font-size: 16px; flex-shrink: 0; }

/* ── Answer feedback strip ── */
.ex-feedback {
  padding: 14px 16px;
  font-size: 15px; font-weight: 700;
  display: none; align-items: center; gap: 10px;
  margin-bottom: 12px;
}
.ex-feedback.correct-fb { background: #0a2a0a; border: 1px solid var(--green2); color: #6fda6f; display: flex; }
.ex-feedback.wrong-fb { background: #2a0a0a; border: 1px solid #cc3333; color: #ff9090; display: flex; }
.ex-feedback .fb-icon { font-size: 20px; flex-shrink: 0; }
.ex-feedback .fb-text { flex: 1; }

/* ── Action buttons ── */
.ex-actions {
  display: flex; gap: 10px; flex-wrap: wrap;
}

/* ══════════════════════════════════════════════
   CELEBRATION OVERLAY
   ══════════════════════════════════════════════ */
#celebrationOverlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.85);
  z-index: 8000;
  display: none;
  flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  padding: 24px;
}
#celebrationOverlay.active { display: flex; }

.celeb-icon { font-size: 80px; margin-bottom: 16px; animation: celebBounce .6s ease infinite alternate; }
.celeb-title { font-size: 28px; font-weight: 700; margin-bottom: 8px; }
.celeb-sub { font-size: 16px; color: var(--dim); margin-bottom: 24px; }
.celeb-xp {
  font-size: 36px; font-weight: 700; color: var(--gold);
  margin-bottom: 28px;
}
.celeb-stars { font-size: 40px; letter-spacing: 8px; margin-bottom: 20px; }

/* Confetti particles */
.confetti-wrap {
  position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 7999;
}
.confetti-p {
  position: absolute;
  width: 10px; height: 10px;
  opacity: 0;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  0%   { opacity: 1; transform: translateY(-20px) rotate(0deg); }
  100% { opacity: 0; transform: translateY(100vh) rotate(720deg); }
}

@keyframes celebBounce {
  from { transform: scale(1); }
  to   { transform: translateY(-12px) scale(1.1); }
}

/* ══════════════════════════════════════════════
   HEARTS OUT MODAL
   ══════════════════════════════════════════════ */
#heartsModal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.8); z-index: 7000;
  display: none; align-items: flex-end; justify-content: center; padding: 16px;
}
#heartsModal.active { display: flex; }
.hearts-box {
  background: var(--card); border: 1px solid var(--bdr);
  padding: 28px 24px;
  width: 100%; max-width: 400px;
  text-align: center;
  animation: slideUp .3s ease;
}
.hearts-box h2 { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.hearts-box p { font-size: 14px; color: var(--dim); margin-bottom: 20px; }
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* ══════════════════════════════════════════════
   TEACHER PANEL
   ══════════════════════════════════════════════ */
#teacherPanel {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.8); z-index: 6000;
  display: none; align-items: flex-start; justify-content: center;
  padding: 16px; overflow-y: auto;
}
#teacherPanel.active { display: flex; }
.teacher-box {
  background: var(--bg2); border: 1px solid var(--bdr);
  padding: 24px;
  width: 100%; max-width: 560px;
  margin-top: 20px; margin-bottom: 40px;
}
.teacher-box h2 { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.teacher-box .sub { font-size: 13px; color: var(--dim); margin-bottom: 20px; }

.teacher-chapter-row {
  background: var(--btn);
  border: 1px solid var(--bdr);
  padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 8px;
  font-size: 14px;
}
.teacher-chapter-row .tc-name { flex: 1; font-weight: 700; }
.teacher-chapter-row .tc-badge {
  font-size: 11px; font-weight: 700; padding: 2px 8px;
}
.tc-badge.locked { background: #444; color: #aaa; }
.tc-badge.unlocked { background: var(--green); color: white; }

.answer-list {
  background: var(--btn);
  border: 1px solid var(--bdr);
  padding: 12px 14px;
  font-size: 13px;
  margin-bottom: 8px;
}
.answer-list h4 { font-size: 13px; font-weight: 700; color: var(--dim); margin-bottom: 8px; }
.answer-row { display: flex; gap: 8px; margin-bottom: 5px; }
.answer-row .aq { flex: 1; color: var(--dim); }
.answer-row .aa { color: #a0d0ff; font-family: monospace; }

/* ══════════════════════════════════════════════
   LICENSE INFO MODAL
   ══════════════════════════════════════════════ */
#licenseModal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.8); z-index: 6000;
  display: none; align-items: center; justify-content: center; padding: 16px;
}
#licenseModal.active { display: flex; }
.license-box {
  background: var(--bg2); border: 1px solid var(--bdr);
  padding: 28px 24px; width: 100%; max-width: 380px; text-align: center;
}
.license-box h2 { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.license-box .lk {
  font-family: monospace; font-size: 16px;
  color: #a0d0ff; letter-spacing: 2px;
  background: var(--btn); padding: 8px 14px;
  margin: 12px 0; display: block;
}
.license-box .lr { font-size: 13px; color: var(--dim); margin-bottom: 20px; }
.license-box .lbadge {
  display: inline-block; padding: 3px 10px;
  font-size: 12px; font-weight: 700; margin-bottom: 8px;
}
.lbadge.student { background: #004488; color: #a0d0ff; }
.lbadge.teacher { background: var(--green); color: white; }

/* ══════════════════════════════════════════════
   CORRECT / WRONG FLASH ANIMATIONS
   ══════════════════════════════════════════════ */
@keyframes correctFlash {
  0%, 100% { background: var(--card); }
  50%       { background: #0a2a0a; }
}
@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
.anim-correct { animation: correctFlash .5s ease; }
.anim-wrong   { animation: wrongShake .4s ease; }

/* ══════════════════════════════════════════════
   TOAST
   ══════════════════════════════════════════════ */
#toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--green);
  color: white;
  padding: 11px 22px;
  font-size: 14px; font-weight: 700;
  z-index: 9000;
  opacity: 0; pointer-events: none;
  transition: opacity .3s;
  white-space: nowrap;
}
#toast.show { opacity: 1; }

/* ══════════════════════════════════════════════
   UTILITY
   ══════════════════════════════════════════════ */
.hidden { display: none !important; }
.text-dim { color: var(--dim); }
.text-green { color: var(--green2); }
.text-red { color: var(--acc); }
.text-gold { color: var(--gold); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }

/* ══════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════ */
@media (max-width: 500px) {
  .hdr-xp { display: none; }
  .ex-question { font-size: 16px; }
  .gate-box { padding: 28px 18px; }
  .chapter-path::before { left: 28px; }
  .chapter-num { left: -20px; width: 20px; height: 20px; font-size: 10px; }
  .chapter-card { margin-left: 18px; }
}

@media (max-width: 360px) {
  #appHeader { padding: 0 10px; gap: 8px; }
  .hdr-stats { gap: 6px; }
  .btn { padding: 9px 14px; }
}
