:root {
  color-scheme: dark;
  --bg: #090b12;
  --bg-2: #0f1422;
  --panel: rgba(255, 255, 255, 0.055);
  --panel-2: rgba(255, 255, 255, 0.09);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f5f7fb;
  --muted: #a7afc1;
  --soft: #d9deec;
  --primary: #7c5cff;
  --primary-2: #23d7a4;
  --danger: #ff5c7a;
  --warning: #f2c94c;
  --ok: #38d996;
  --code-bg: #070a11;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  --radius: 22px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.light {
  color-scheme: light;
  --bg: #f5f7fb;
  --bg-2: #ffffff;
  --panel: rgba(17, 24, 39, 0.045);
  --panel-2: rgba(17, 24, 39, 0.075);
  --line: rgba(17, 24, 39, 0.12);
  --text: #111827;
  --muted: #5b6475;
  --soft: #2f3543;
  --code-bg: #111827;
  --shadow: 0 24px 70px rgba(17, 24, 39, 0.13);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  background:
    radial-gradient(circle at top left, rgba(124, 92, 255, 0.26), transparent 28rem),
    radial-gradient(circle at 88% 12%, rgba(35, 215, 164, 0.18), transparent 23rem),
    linear-gradient(135deg, var(--bg), var(--bg-2));
  color: var(--text);
}

button, input, textarea, select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: rgba(6, 8, 14, 0.74);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

body.light .sidebar { background: rgba(255, 255, 255, 0.78); }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 18px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 900;
  letter-spacing: -0.06em;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 15px 35px rgba(124, 92, 255, 0.27);
}

.brand span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.86rem;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 0;
  text-align: left;
  color: var(--muted);
  border-radius: 14px;
  background: transparent;
  padding: 13px 14px;
  transition: 0.18s ease;
}

.nav-item:hover,
.nav-item.active {
  color: var(--text);
  background: var(--panel-2);
  transform: translateX(2px);
}

.sidebar-card {
  margin-top: auto;
  padding: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(150deg, var(--panel-2), var(--panel));
  border-radius: var(--radius);
}

.sidebar-card p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.main-content {
  min-width: 0;
  padding: 26px clamp(18px, 4vw, 54px) 60px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 28px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 4rem);
  letter-spacing: -0.06em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary-2);
  text-transform: uppercase;
  letter-spacing: 0.13em;
  font-size: 0.75rem;
  font-weight: 800;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.hero {
  position: relative;
  overflow: hidden;
  padding: clamp(24px, 5vw, 48px);
  border-radius: calc(var(--radius) + 8px);
  border: 1px solid var(--line);
  background:
    linear-gradient(140deg, rgba(124, 92, 255, 0.25), rgba(35, 215, 164, 0.08)),
    var(--panel);
  box-shadow: var(--shadow);
}

.hero::after {
  content: "";
  position: absolute;
  right: -6rem;
  bottom: -8rem;
  width: 24rem;
  height: 24rem;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(124, 92, 255, 0.24), transparent 65%);
  pointer-events: none;
}

.hero h2 {
  max-width: 950px;
  margin: 0 0 14px;
  font-size: clamp(2.1rem, 5vw, 5.2rem);
  line-height: 0.96;
  letter-spacing: -0.07em;
}

.hero p {
  max-width: 760px;
  color: var(--soft);
  font-size: 1.08rem;
  line-height: 1.65;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn,
.mini-btn {
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 11px 15px;
  color: var(--text);
  background: var(--panel-2);
  transition: 0.18s ease;
}

.primary-btn {
  color: white;
  background: linear-gradient(135deg, var(--primary), #5d42ff);
  box-shadow: 0 14px 35px rgba(124, 92, 255, 0.26);
}

.secondary-btn {
  color: #06100d;
  background: linear-gradient(135deg, var(--primary-2), #b0ffdf);
}

.ghost-btn {
  border-color: var(--line);
  background: transparent;
}

.danger-btn {
  color: white;
  background: linear-gradient(135deg, var(--danger), #d93557);
}

.mini-btn {
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 0.86rem;
}

.primary-btn:hover,
.secondary-btn:hover,
.ghost-btn:hover,
.danger-btn:hover,
.mini-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

.card {
  padding: 20px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.08);
}

.card h2, .card h3, .card h4 {
  margin-top: 0;
  letter-spacing: -0.035em;
}

.card p, .card li {
  color: var(--soft);
  line-height: 1.55;
}

.stat-card strong {
  display: block;
  font-size: 2.25rem;
  letter-spacing: -0.06em;
}

.stat-card span { color: var(--muted); }

.module-card {
  display: flex;
  min-height: 230px;
  flex-direction: column;
  justify-content: space-between;
}

.module-card h3 { margin-bottom: 8px; }

.module-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 9px;
  border-radius: 999px;
  color: var(--soft);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.78rem;
  font-weight: 700;
}

.badge.ok { color: #0a2018; background: var(--primary-2); border-color: transparent; }
.badge.warn { color: #1f1804; background: var(--warning); border-color: transparent; }
.badge.danger { color: white; background: var(--danger); border-color: transparent; }
.badge.primary { color: white; background: var(--primary); border-color: transparent; }

.progress {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid var(--line);
}

.progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
}

.lesson-stack {
  display: grid;
  gap: 14px;
}

.lesson-card {
  padding: 18px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 18px;
}

.lesson-card h3 { margin-bottom: 8px; }

.lesson-card details {
  margin-top: 12px;
}

.lesson-card summary {
  cursor: pointer;
  color: var(--primary-2);
  font-weight: 800;
}

.compare-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.code-block {
  display: block;
  width: 100%;
  margin: 12px 0;
  padding: 16px;
  overflow-x: auto;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: var(--code-bg);
  color: #eff5ff;
  font-family: var(--mono);
  font-size: 0.94rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

body.light .code-block { color: #f8fbff; }

.inline-code {
  padding: 0.15rem 0.36rem;
  border-radius: 8px;
  font-family: var(--mono);
  background: rgba(124, 92, 255, 0.12);
  color: var(--soft);
}

.practice-layout {
  display: grid;
  grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.exercise-list {
  max-height: calc(100vh - 180px);
  overflow: auto;
  padding-right: 6px;
}

.exercise-item {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 15px;
  padding: 12px;
  text-align: left;
  margin-bottom: 8px;
}

.exercise-item.active {
  border-color: rgba(35, 215, 164, 0.65);
  background: rgba(35, 215, 164, 0.09);
}

.exercise-item small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.exercise-card {
  padding: clamp(18px, 3vw, 30px);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.062);
  border-radius: calc(var(--radius) + 6px);
  box-shadow: var(--shadow);
}

.exercise-card h2 {
  margin: 6px 0 10px;
  font-size: clamp(1.45rem, 3vw, 2.5rem);
}

.exercise-card .prompt {
  color: var(--soft);
  line-height: 1.65;
}

.answer-options {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.option-row,
.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
}

.option-row code,
.checkbox-row code { font-family: var(--mono); }

.blank-input,
.answer-input,
.trace-input,
.filter-select,
.code-textarea {
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.065);
  outline: none;
}

.blank-input {
  width: min(210px, 70vw);
  margin: 0 4px;
  padding: 6px 8px;
  font-family: var(--mono);
}

.answer-input {
  width: min(520px, 100%);
  padding: 12px 13px;
  margin-top: 10px;
}

.code-textarea {
  display: block;
  width: 100%;
  min-height: 190px;
  padding: 14px;
  margin: 14px 0;
  font-family: var(--mono);
  line-height: 1.5;
  resize: vertical;
}

.filter-row {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.filter-select {
  width: 100%;
  padding: 10px 12px;
}

.order-list {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}

.order-line {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.04);
}

.order-controls {
  display: flex;
  gap: 5px;
}

.order-code {
  font-family: var(--mono);
  white-space: pre-wrap;
  color: var(--soft);
}

.trace-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  overflow: hidden;
  border-radius: 14px;
}

.trace-table th,
.trace-table td {
  border: 1px solid var(--line);
  padding: 10px;
  text-align: center;
}

.trace-table th {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
}

.trace-input {
  width: 100%;
  min-width: 70px;
  padding: 8px;
  text-align: center;
  font-family: var(--mono);
}

.feedback {
  display: none;
  margin-top: 16px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  line-height: 1.55;
}

.feedback.show { display: block; }
.feedback.correct { background: rgba(56, 217, 150, 0.12); border-color: rgba(56, 217, 150, 0.42); }
.feedback.incorrect { background: rgba(255, 92, 122, 0.12); border-color: rgba(255, 92, 122, 0.42); }
.feedback.neutral { background: rgba(124, 92, 255, 0.12); border-color: rgba(124, 92, 255, 0.35); }

.panel-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}

.panel-table th,
.panel-table td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.panel-table th { color: var(--muted); }

.exam-shell {
  display: grid;
  gap: 18px;
}

.exam-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: 360px;
  padding: 14px 16px;
  border-radius: 16px;
  color: var(--text);
  border: 1px solid var(--line);
  background: rgba(10, 12, 20, 0.92);
  box-shadow: var(--shadow);
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
}

body.light .toast { background: rgba(255, 255, 255, 0.92); }
.toast.show { opacity: 1; transform: translateY(0); }

.empty-state {
  padding: 30px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
}

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6rem;
  padding: 0.1rem 0.4rem;
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 0.86em;
  background: rgba(255, 255, 255, 0.06);
}

@media (max-width: 1040px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav-list { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .nav-item { text-align: center; }
  .sidebar-card { display: none; }
  .grid.three, .grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .practice-layout { grid-template-columns: 1fr; }
  .exercise-list { max-height: none; }
}

@media (max-width: 700px) {
  .main-content { padding: 18px 14px 40px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .topbar-actions { width: 100%; }
  .topbar-actions button { flex: 1; }
  .nav-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two, .grid.three, .grid.four, .compare-grid { grid-template-columns: 1fr; }
  .hero h2 { font-size: 2.35rem; }
  .order-line { grid-template-columns: 1fr; }
}
