* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f6f7fb;
  color: #1f2937;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 28px;
  background: #111827;
  color: white;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
}

.topbar p {
  margin: 4px 0 0;
  color: #cbd5e1;
}

.badge {
  border: 1px solid #374151;
  background: #1f2937;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
}

main {
  padding: 20px;
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
}

.hidden {
  display: none !important;
}

.level-view {
  max-width: 1180px;
  margin: 0 auto;
}

.level-view-header {
  margin-bottom: 18px;
}

.level-view-header h2 {
  margin: 0 0 6px;
  font-size: 26px;
}

.level-view-header p {
  margin: 0;
  color: #6b7280;
}

.level-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.level-card {
  min-height: 180px;
  text-align: left;
  color: #111827;
  border: 1px solid #e5e7eb;
  background: white;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.level-card:hover {
  border-color: #818cf8;
  background: #f8fafc;
}

.level-card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: #6b7280;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.level-card h3 {
  margin: 12px 0 8px;
  font-size: 19px;
}

.level-card p {
  margin: 0;
  color: #4b5563;
  font-size: 14px;
  line-height: 1.45;
}

.level-card-progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
  margin-top: 16px;
}

.level-card-progress div {
  height: 100%;
  border-radius: inherit;
  background: #10b981;
}

.sidebar,
.task-card,
.editor-panel,
.output-panel {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.sidebar {
  padding: 16px;
  height: calc(100vh - 120px);
  overflow: auto;
}

.sidebar h2 {
  margin: 0;
  font-size: 18px;
}

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

.level-meta {
  color: #6b7280;
  font-size: 13px;
  margin-top: 2px;
}

.back-button {
  width: 100%;
  margin-bottom: 14px;
}

.progress-count {
  color: #047857;
  font-size: 13px;
  font-weight: 800;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
  margin-bottom: 14px;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: #10b981;
  transition: width 180ms ease;
}

.task-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.level-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.level-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 2px 2px;
}

.level-title span {
  color: #6b7280;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.level-title strong {
  color: #111827;
  font-size: 14px;
}

.task-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #111827;
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
}

.task-item-main {
  min-width: 0;
}

.task-item:hover,
.task-item.active {
  background: #eef2ff;
  border-color: #818cf8;
}

.task-item.completed {
  border-color: #a7f3d0;
  background: #f0fdf4;
}

.task-item.completed.active,
.task-item.completed:hover {
  border-color: #34d399;
  background: #ecfdf5;
}

.task-item-status {
  display: grid;
  place-items: center;
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  color: white;
  background: transparent;
  font-weight: 900;
}

.task-item.completed .task-item-status {
  background: #10b981;
}

.task-item-title {
  color: #111827;
  font-weight: 700;
  margin-bottom: 4px;
}

.task-item-meta {
  color: #6b7280;
  font-size: 13px;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.task-card {
  padding: 18px;
}

.task-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.task-header h2 {
  margin: 0 0 6px;
}

.meta {
  color: #6b7280;
  font-size: 14px;
}

.task-status {
  white-space: nowrap;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  background: #f9fafb;
  color: #6b7280;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 800;
}

.task-status.completed {
  border-color: #a7f3d0;
  background: #ecfdf5;
  color: #047857;
}

.description {
  margin-top: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.theory {
  margin-top: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.theory:not(:empty) {
  border-left: 4px solid #10b981;
  background: #f0fdf4;
  padding: 12px 14px;
}

.section-label {
  margin-bottom: 6px;
  color: #047857;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.example-block {
  margin-top: 14px;
}

.example-block:not(:empty) {
  border: 1px solid #dbeafe;
  background: #eff6ff;
  padding: 12px 14px;
}

.example-block .section-label {
  color: #1d4ed8;
}

.example-block pre {
  margin: 0;
  overflow: auto;
  white-space: pre;
}

.example-block code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(360px, 0.75fr);
  gap: 20px;
}

.editor-panel,
.output-panel {
  overflow: hidden;
}

.panel-title {
  padding: 12px 14px;
  border-bottom: 1px solid #e5e7eb;
  font-weight: 700;
  background: #f9fafb;
}

.editor {
  min-height: 420px;
}

.cm-editor {
  min-height: 420px;
  font-size: 15px;
}

.cm-scroller {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.buttons {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid #e5e7eb;
}

button {
  border: none;
  border-radius: 10px;
  background: #4f46e5;
  color: white;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: #4338ca;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button.secondary {
  background: #e5e7eb;
  color: #111827;
}

button.secondary:hover {
  background: #d1d5db;
}

.output {
  margin: 0;
  padding: 14px;
  min-height: 480px;
  white-space: pre-wrap;
  overflow: auto;
  background: #0b1020;
  color: #d1fae5;
  font-size: 14px;
  line-height: 1.55;
}

@media (max-width: 920px) {
  main {
    padding: 12px;
  }

  .layout,
  .workbench {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: auto;
  }
}
