* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Arial, sans-serif;
  background: #f4f7fb;
  color: #1f2937;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 92px;
  padding: 18px 28px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 20px;
  background: #002b45;
  color: white;
}

.topbar img {
  width: 148px;
  max-width: 30vw;
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 24px;
  line-height: 1.2;
}

.topbar p {
  margin: 0;
  color: rgba(255, 255, 255, 0.78);
}

.status-panel {
  min-width: 168px;
  display: grid;
  gap: 5px;
  font-weight: 700;
  text-align: right;
}

.timer-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.timer-pause-hidden {
  min-height: 28px;
  min-width: 28px;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.35);
  font-size: 13px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.status-panel:hover .timer-pause-hidden,
.timer-pause-hidden:focus-visible,
.timer-pause-hidden[aria-pressed="true"] {
  opacity: 1;
  color: white;
}

.timer-pause-hidden:hover {
  background: rgba(255, 255, 255, 0.22);
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
}

.exercise-nav {
  grid-column: 1;
  grid-row: 1;
  min-height: 0;
  padding: 20px 16px;
  overflow-y: auto;
  border-right: 1px solid #d7dfeb;
  background: #ffffff;
}

.lesson {
  grid-column: 2;
  grid-row: 1;
}

.nav-heading h2 {
  margin: 0 0 6px;
  font-size: 22px;
}

.nav-heading p {
  margin: 0 0 16px;
  color: #5f6f85;
  font-size: 14px;
  line-height: 1.45;
}

.exercise-list {
  display: grid;
  gap: 14px;
}

.topic-group {
  padding-bottom: 12px;
  border-bottom: 1px solid #e5ebf3;
}

.topic-toggle {
  width: 100%;
  min-height: 52px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #d7dfeb;
  border-radius: 8px;
  background: #ffffff;
  color: #1f2937;
  text-align: left;
}

.topic-toggle:hover {
  background: #f8fafc;
  border-color: #0077b6;
  color: #1f2937;
}

.topic-toggle span:first-child {
  display: grid;
  gap: 3px;
}

.topic-toggle strong {
  font-size: 14px;
  line-height: 1.2;
}

.topic-toggle small {
  color: #66758a;
  font-weight: 800;
}

.topic-group.open .topic-toggle {
  background: #eaf6ff;
  border-color: #0077b6;
}

.topic-exercises {
  margin-top: 8px;
  display: grid;
  gap: 8px;
}

.exercise-item {
  width: 100%;
  min-height: 54px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "number title meta";
  column-gap: 10px;
  align-items: center;
  border: 1px solid #d7dfeb;
  border-radius: 8px;
  background: #f8fafc;
  color: #1f2937;
  text-align: left;
  cursor: pointer;
}

.exercise-item:hover {
  border-color: #0077b6;
}

.exercise-item.active {
  border-color: #0077b6;
  background: #eaf6ff;
}

.exercise-item.done {
  border-color: #2ca66f;
}

.exercise-item.failed {
  border-color: #b42318;
}

.exercise-item span {
  grid-area: number;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #e2e8f0;
  color: #42526b;
  font-weight: 800;
  font-size: 13px;
}

.exercise-item.done span {
  background: #d9fbe8;
  color: #157347;
}

.exercise-item.failed span {
  background: #fee2e2;
  color: #b42318;
}

.exercise-item strong {
  grid-area: title;
  min-width: 0;
  font-size: 14px;
  line-height: 1.25;
}

.exercise-item small {
  grid-area: meta;
  font-weight: 800;
  font-size: 16px;
}

.exercise-item.done small {
  color: #157347;
}

.exercise-item.failed small {
  color: #b42318;
}

.lesson {
  min-height: 0;
  padding: 18px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 18px;
}

.briefing {
  padding: 20px;
  border: 1px solid #d7dfeb;
  border-radius: 8px;
  background: #ffffff;
}

.briefing-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.briefing-actions {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.briefing-toggle {
  width: 32px;
  height: 32px;
  min-height: 0;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e8eef7;
  color: #42526b;
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
}

.briefing-toggle:hover {
  background: #d1dae7;
}

.briefing.minimized #briefingContent {
  display: none;
}

.eyebrow {
  margin: 0 0 6px;
  color: #0077b6;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.briefing h2 {
  margin: 0;
  font-size: 24px;
}

.briefing p,
.briefing li {
  line-height: 1.55;
}

.briefing ul {
  margin-bottom: 0;
  padding-left: 20px;
}

.briefing code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  background: #101827;
  border: 1px solid #1f2937;
  padding: 2.5px 6.5px;
  border-radius: 5px;
  color: #e7edf7;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

@keyframes roll {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.2); }
  100% { transform: rotate(360deg) scale(1); }
}

.rolling {
  animation: roll 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-block;
}

.status-badge {
  height: fit-content;
  padding: 7px 10px;
  border-radius: 999px;
  background: #e8eef7;
  color: #42526b;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.status-badge.done {
  background: #d9fbe8;
  color: #157347;
}

.hint-box {
  margin-top: 14px;
  padding: 12px 14px;
  border-left: 4px solid #0077b6;
  border-radius: 0 8px 8px 0;
  background: #eaf6ff;
  color: #304257;
  line-height: 1.5;
}

.hint-box[hidden] {
  display: none;
}

.hint-toggle {
  margin-top: 12px;
  background: #475569;
}

.hint-toggle:hover {
  background: #334155;
}

.lab {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.05fr);
  gap: 18px;
}

.editor-shell,
.preview-shell {
  max-height: 780px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid #d1dae7;
  border-radius: 8px;
  overflow: hidden;
  background: white;
}

.panel-title {
  min-height: 44px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #d1dae7;
  font-weight: 800;
}

.file-pill {
  padding: 4px 8px;
  border-radius: 999px;
  background: #e8edf5;
  color: #42526b;
  font-size: 12px;
}

code,
pre,
textarea {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.code-editor {
  flex: 1;
  min-height: 420px;
  position: relative;
  overflow: hidden;
  background: #101827;
}

.editor-highlight,
#editor {
  position: absolute;
  inset: 0;
  width: 100%;
  padding: 16px;
  margin: 0;
  border: 0;
  font-size: 15px;
  line-height: 1.55;
  tab-size: 2;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-y: auto;
  overflow-x: hidden;
}

.editor-highlight {
  overflow: hidden;
  pointer-events: none;
  color: #e7edf7;
}

#editor {
  height: 100%;
  max-height: 750px;
  resize: none;
  outline: none;
  background: transparent;
  color: transparent;
  caret-color: #f8fafc;
}

#editor::selection {
  background: rgba(96, 165, 250, 0.32);
}

.syntax-keyword {
  color: #7dd3fc;
  font-weight: 700;
}

.syntax-type {
  color: #c4b5fd;
}

.syntax-string {
  color: #fbbf24;
}

.syntax-number {
  color: #86efac;
}

.syntax-comment {
  color: #94a3b8;
  font-style: italic;
}

.syntax-function {
  color: #67e8f9;
}

.syntax-operator {
  color: #f0abfc;
}

.visual-tools {
  padding: 12px;
  display: grid;
  gap: 10px;
  border-top: 1px solid #233047;
  background: #f8fafc;
  color: #162033;
}

.visual-tools[hidden] {
  display: none;
}

.visual-tools-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.visual-tools-title {
  font-weight: 800;
}

.visual-control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.visual-control {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.visual-control label {
  color: #162033;
  font-size: 12px;
  font-weight: 800;
}

.visual-control input,
.visual-control select {
  width: 100%;
  min-height: 34px;
  border: 2px solid #e5e5e5;
  border-radius: 2px;
  background: #d1dae7;
  color: #e5e5e5;
  font: inherit;
}

.visual-control input[type="color"] {
  padding: 3px;
}

.visual-control input[type="range"] {
  accent-color: #00a6a6;
}

.actions {
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  border-top: 1px solid #233047;
  background: #101827;
}

button {
  min-height: 40px;
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  background: #0077b6;
  color: white;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: #005f92;
}

.secondary-button {
  background: #334155;
}

.secondary-button:hover {
  background: #1f2937;
}


.feedback {
  min-height: 42px;
  padding: 11px 14px;
  border-top: 1px solid #d1dae7;
  background: #f8fafc;
  color: #42526b;
  font-size: 14px;
  font-weight: 800;
}

.feedback.correct {
  background: #ecfdf3;
  color: #157347;
}

.feedback.wrong {
  background: #fef2f2;
  color: #b42318;
}

.feedback.neutral {
  background: #f8fafc;
  color: #42526b;
}

#preview {
  flex: 1;
  width: 100%;
  min-height: 420px;
  border: 0;
  background: white;
}

.restart-button {
  margin-top: 14px;
}

.restart-button button {
  width: 100%;
  background: #475569;
}

.restart-button button:hover {
  background: #334155;
}

/* ─── Interactive Console / Terminal ─── */

.console-area {
  display: flex;
  flex-direction: column;
  border-top: 1px solid #1e293b;
  background: #0c1322;
  max-height: 220px;
  overflow: hidden;
}

.console-area[hidden],
.terminal-disabled .console-area,
.console-input-row[hidden] {
  display: none !important;
}

.console-header {
  padding: 6px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #151d2e;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #1e293b;
}

.console-status {
  font-size: 11px;
  color: #f59e0b;
  text-transform: none;
}

.console-status::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: 999px;
  background: #f59e0b;
  animation: consolePulse 1.6s ease-in-out infinite;
}

.console-status:empty {
  display: none;
}

.console-status:empty::before {
  display: none;
}

@keyframes consolePulse {

  0%,
  100% {
    opacity: 0.4;
  }

  50% {
    opacity: 1;
  }
}

.console-output {
  flex: 1;
  min-height: 0;
  padding: 8px 14px;
  overflow-y: auto;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.6;
}

.console-line {
  color: #e2e8f0;
  padding: 1px 0;
  animation: consoleFadeIn 0.2s ease;
}

.console-line.input-echo {
  color: #60a5fa;
}

.console-line.system {
  color: #94a3b8;
  font-style: italic;
}

@keyframes consoleFadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.console-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-top: 1px solid #1e293b;
  background: #0f1729;
  animation: consoleFadeIn 0.2s ease;
}

.console-chevron {
  color: #22c55e;
  font-size: 14px;
  font-weight: 800;
  flex-shrink: 0;
}

.console-input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid #334155;
  border-radius: 6px;
  background: #1e293b;
  color: #f1f5f9;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.console-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.console-input::placeholder {
  color: #4b5563;
}

.console-submit {
  min-height: 34px;
  padding: 6px 14px;
  border-radius: 6px;
  background: #22c55e;
  color: #052e16;
  font-size: 13px;
  font-weight: 800;
  flex-shrink: 0;
}

.console-submit:hover {
  background: #16a34a;
}

.footer {
  padding: 10px 16px;
  text-align: center;
  background: #002b45;
  color: white;
  font-size: 14px;
}

/* ─── Leaderboard button ─── */
.lb-open-btn {
  margin-top: 6px;
  min-height: 34px;
  padding: 6px 14px;
  background: linear-gradient(135deg, #d97706, #b45309);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
  transition: transform 0.15s, box-shadow 0.15s;
}

.lb-open-btn:hover {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(217, 119, 6, 0.45);
}

/* ─── Modal ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 16px;
  animation: modalFadeIn 0.2s ease;
}

.modal-overlay[hidden] {
  display: none;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.modal-box {
  width: min(480px, 100%);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  animation: modalSlideUp 0.25s cubic-bezier(0.34, 1.3, 0.64, 1);
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.97);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, #002b45, #0077b6);
  color: white;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.modal-close {
  width: 32px;
  height: 32px;
  min-height: 0;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 18px;
  line-height: 1;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.32);
}

.modal-body {
  padding: 24px;
}

.modal-intro {
  margin: 0 0 18px;
  color: #42526b;
  font-size: 15px;
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}

.modal-stat {
  padding: 14px 10px;
  border-radius: 10px;
  background: #f0f7ff;
  text-align: center;
  display: grid;
  gap: 4px;
}

.modal-stat-value {
  font-size: 26px;
  font-weight: 800;
  color: #0077b6;
  line-height: 1;
}

.modal-stat-label {
  font-size: 12px;
  font-weight: 700;
  color: #66758a;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group {
  margin-bottom: 14px;
  display: grid;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 800;
  color: #1f2937;
}

.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid #d1dae7;
  border-radius: 8px;
  font: inherit;
  font-size: 15px;
  color: #1f2937;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus {
  border-color: #0077b6;
  box-shadow: 0 0 0 3px rgba(0, 119, 182, 0.15);
}

.lb-feedback {
  min-height: 1.4em;
  margin: 4px 0 10px;
  font-size: 14px;
  font-weight: 700;
  color: #157347;
}

.modal-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 6px;
}

.modal-submit {
  flex: 1;
  background: linear-gradient(135deg, #0077b6, #005f92);
  font-size: 15px;
}

.modal-submit:hover {
  background: linear-gradient(135deg, #0090d9, #0077b6);
}

.modal-link-btn {
  padding: 10px 14px;
  border-radius: 8px;
  background: #f0f7ff;
  color: #0077b6;
  font-weight: 800;
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s;
}

.modal-link-btn:hover {
  background: #dbeeff;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 270px minmax(0, 1fr);
  }

  .lab {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(360px, 0.9fr) minmax(420px, 1fr);
  }

  .code-editor,
  #preview {
    min-height: 320px;
  }
}

@media (max-width: 760px) {

  .topbar,
  .workspace,
  .lesson {
    display: flex;
    flex-direction: column;
  }

  .topbar {
    align-items: flex-start;
  }

  .status-panel {
    text-align: left;
  }

  .exercise-nav {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid #d7dfeb;
  }

  .briefing-header {
    flex-direction: column;
  }

  .topbar img {
    max-width: 190px;
  }
}