:root {
  --bg: #0e1116;
  --surface: #161b23;
  --surface-2: #1d2430;
  --line: #2a3342;
  --ink: #e8edf4;
  --muted: #8b98ab;
  --accent: #4f8cff;
  --accent-ink: #ffffff;
  --good: #4f8cff;
  --bad: #e5484d;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: Consolas, "JetBrains Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  min-height: 100vh;
}
body { padding-bottom: 64px; }

h1, h2, h3 { margin: 0.4em 0; letter-spacing: -0.01em; }
h1.fancy { font-size: clamp(1.7rem, 3.5vw, 2.4rem); text-align: center; margin-top: 28px; }
.subtitle { text-align: center; color: var(--muted); margin: 6px 0 26px; }
.muted { color: var(--muted); }
.section-title { font-size: 1.05rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin: 30px 0 12px; }

code, pre, .mono { font-family: var(--mono); }
code {
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 0.9em;
}
pre.code {
  background: #0b0e13;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  font-size: 0.92rem;
  line-height: 1.55;
}

/* ===== icons ===== */
.icon { width: 1em; height: 1em; display: inline-block; vertical-align: -0.125em; fill: currentColor; }
.tile-icon { width: 34px; height: 34px; }
.rank-icon { width: 30px; height: 30px; }
.icon-btn .icon { width: 16px; height: 16px; }
.back-btn .icon, .btn .icon { width: 15px; height: 15px; }

/* ===== topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 22px;
  background: rgba(14, 17, 22, 0.9);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
}
.logo { font-size: 1.2rem; font-weight: 800; letter-spacing: -0.02em; }
.logo span { color: var(--accent); }
.logo em { font-style: normal; color: var(--muted); font-weight: 600; }
.hero-stats { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.stat {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.87rem;
  color: var(--muted);
}
.stat b { color: var(--ink); font-weight: 700; }
.icon-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: var(--radius);
  padding: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { color: var(--ink); border-color: var(--muted); }

/* ===== layout ===== */
main { max-width: 1020px; margin: 0 auto; padding: 10px 22px 20px; }
.hidden { display: none !important; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin: 18px 0;
}
.card h2 { margin-top: 0; font-size: 1.15rem; }

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: var(--radius);
  padding: 7px 14px;
  cursor: pointer;
  margin: 14px 0 4px;
  font-size: 0.9rem;
}
.back-btn:hover { color: var(--ink); border-color: var(--accent); }

/* ===== course tiles ===== */
.lang-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(225px, 1fr));
  gap: 14px;
}
.lang-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
  text-align: left;
  color: var(--ink);
  font-family: var(--font);
}
.lang-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.lang-card h3 { margin: 10px 0 4px; font-size: 1.05rem; }
.lang-card .desc { color: var(--muted); font-size: 0.85rem; min-height: 36px; line-height: 1.45; }
.lang-card .prog-wrap { margin-top: 12px; }
.mini-track { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.mini-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s ease; }
.lang-card .pct { font-size: 0.78rem; color: var(--muted); margin-top: 6px; display: block; }
.complete-mark {
  position: absolute;
  top: 12px;
  right: 12px;
  color: var(--accent);
  display: inline-flex;
}
.complete-mark .icon { width: 18px; height: 18px; }

/* ===== ranks ===== */
.rank-hero { text-align: center; margin: 12px 0 6px; }
.rank-hero .tile-icon { width: 42px; height: 42px; color: var(--accent); }
.rank-hero h1 { margin: 6px 0 2px; font-size: 1.6rem; }
.rank-hero p { color: var(--muted); margin: 0; }
.rank-list { display: grid; gap: 12px; margin-top: 16px; }

.rank-card {
  display: flex;
  gap: 16px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  cursor: pointer;
  transition: border-color 0.15s ease;
  color: var(--ink);
  text-align: left;
  width: 100%;
  font-family: var(--font);
}
.rank-card:hover { border-color: var(--accent); }
.rank-card.locked { opacity: 0.55; }
.rank-card .r-icon { color: var(--accent); display: inline-flex; }
.rank-card .r-info { flex: 1; }
.rank-card .r-info h3 { margin: 0; font-size: 1rem; }
.rank-card .r-info p { margin: 3px 0 0; color: var(--muted); font-size: 0.87rem; }
.rank-card .r-meta { text-align: right; font-size: 0.82rem; color: var(--muted); white-space: nowrap; }
.rank-card .r-meta b { display: block; font-size: 1.05rem; color: var(--ink); }
.rank-card .prereq-tag { font-size: 0.75rem; color: var(--muted); border: 1px solid var(--line); padding: 2px 8px; border-radius: 999px; display: inline-block; margin-bottom: 4px; }

/* ===== lesson ===== */
.lesson-steps { display: flex; flex-direction: column; gap: 14px; }
.step-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
}
.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.step-tag {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 6px;
  padding: 3px 8px;
}
.step-head h3 { margin: 0; font-size: 1.02rem; }
.step-card p { color: #c6cfdd; line-height: 1.6; margin: 8px 0; font-size: 0.95rem; }
.tip { color: var(--muted); font-size: 0.88rem; }
.tip b { color: var(--ink); }

.mcq .opt, .mcq-opt {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin: 6px 0;
  cursor: pointer;
  font-size: 0.93rem;
  font-family: var(--mono);
}
.mcq .opt:hover, .mcq-opt:hover { border-color: var(--accent); }
.mcq .opt.correct, .mcq-opt.correct { border-color: var(--accent); background: rgba(79, 140, 255, 0.12); }
.mcq .opt.wrong, .mcq-opt.wrong { border-color: var(--bad); background: rgba(229, 72, 77, 0.1); }

.feedback { margin-top: 8px; font-weight: 600; min-height: 1.4em; font-size: 0.92rem; }
.feedback.good { color: var(--accent); }
.feedback.bad { color: var(--bad); }

.bug-item textarea, .g-area, .g-input {
  width: 100%;
  min-height: 74px;
  background: #0b0e13;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 0.92rem;
  resize: vertical;
}
.bug-item textarea:focus, .g-area:focus, .g-input:focus { outline: none; border-color: var(--accent); }

.kw-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 10px; margin-top: 10px; }
.kw {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.87rem;
  cursor: pointer;
  display: block;
}
.kw:hover { border-color: var(--accent); }
.kw b { color: var(--ink); font-family: var(--mono); }
.kw span { display: block; color: var(--muted); margin-top: 3px; }
.kw input { accent-color: var(--accent); margin-right: 6px; }
.kw.checked { border-color: var(--accent); }

.lesson-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  margin: 22px 0;
}
.xp-note { color: var(--muted); font-size: 0.88rem; }

/* ===== buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius);
  padding: 11px 20px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
}
.btn:hover { filter: brightness(1.12); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn.ghost:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }

/* ===== project ===== */
.proj-check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin: 8px 0;
  cursor: pointer;
}
.proj-check input { margin-top: 3px; accent-color: var(--accent); }
.proj-checks .done-all { color: var(--accent); font-weight: 700; }

/* ===== arcade ===== */
.game-btns { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
.game-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 11px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font);
}
.game-btn:hover { border-color: var(--accent); }
.game-btn .icon { width: 17px; height: 17px; color: var(--accent); }
.arcade-bests { font-size: 0.87rem; }
.badge-shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 10px; }

/* ===== overlay & games ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 10, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.overlay-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: min(640px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-box { width: min(440px, 92vw); }
.close-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.close-btn:hover { color: var(--ink); border-color: var(--muted); }

.g-title { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0 0 4px; }
.g-title .icon { width: 20px; height: 20px; color: var(--accent); }
.g-sub { text-align: center; color: var(--muted); margin: 0 0 16px; font-size: 0.9rem; }
.g-stats { display: flex; justify-content: center; gap: 20px; margin-bottom: 14px; color: var(--muted); font-size: 0.9rem; flex-wrap: wrap; }
.g-stats b { color: var(--ink); }
.g-feedback { text-align: center; min-height: 1.5em; font-weight: 700; margin: 10px 0; font-size: 0.92rem; }
.g-feedback.ok { color: var(--accent); }
.g-feedback.err { color: var(--bad); }
.g-target {
  background: #0b0e13;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  font-family: var(--mono);
  white-space: pre-wrap;
  line-height: 1.6;
  margin-bottom: 10px;
  font-size: 0.95rem;
}
.g-btns { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }

.g-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.g-card {
  aspect-ratio: 1;
  font-size: clamp(0.8rem, 2.4vw, 1.05rem);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 4px;
  font-family: var(--mono);
}
.g-card:hover { border-color: var(--accent); }
.g-card.flipped, .g-card.matched { background: rgba(79, 140, 255, 0.14); }
.g-card.matched { border-color: var(--accent); opacity: 0.7; cursor: default; }
.g-hint { text-align: center; color: var(--muted); font-size: 0.85rem; margin-top: 10px; }

.g-end { text-align: center; padding: 16px 6px; }
.g-end .g-end-icon { width: 44px; height: 44px; color: var(--accent); }
.g-end h2 { margin: 10px 0 4px; }
.g-end p { color: var(--muted); margin: 4px 0; }

/* ===== toast ===== */
.toast-pop {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  animation: toastIn 0.25s ease;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--ink);
  padding: 11px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-weight: 600;
  font-size: 0.92rem;
  text-align: center;
  max-width: 90vw;
}

/* ===== modal content ===== */
.modal-box h2 { margin-top: 0; }
.modal-box .modal-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.modal-box .modal-actions .btn { flex: 1; justify-content: center; }

footer { text-align: center; color: var(--muted); font-size: 0.83rem; padding: 24px; }

@keyframes toastIn {
  from { transform: translateX(-50%) translateY(-8px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; }
  .hero-stats { margin-left: 0; }
  .g-grid { grid-template-columns: repeat(3, 1fr); }
}
