@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/source-sans.woff2") format("woff2");
}

@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/source-sans-semibold.woff2") format("woff2");
}

@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/jetbrains-mono.woff2") format("woff2");
}

:root {
  color-scheme: dark;
  --bg: #000000;
  --panel: #111111;
  --text: #ffffff;
  --muted: #aaaaaa;
  --line: #333333;
  --good: #22c55e;
  --good-bg: #052e14;
  --bad: #ef4444;
  --bad-bg: #2a0b0b;
  --font-body: "Source Sans 3", sans-serif;
  --font-code: "JetBrains Mono", monospace;
  --header-h: 3.1rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.98rem;
  line-height: 1.45;
  background: var(--bg);
}

a {
  color: var(--text);
}

a:hover {
  color: var(--muted);
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: var(--header-h);
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 1.05rem;
  white-space: nowrap;
}

.header-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.header-actions .btn {
  padding: 0.3rem 0.65rem;
  font-size: 0.82rem;
}

.has-tooltip {
  position: relative;
}

.has-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  z-index: 20;
  width: min(260px, 70vw);
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.35;
  text-align: left;
  white-space: normal;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-0.15rem);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.has-tooltip:hover::after,
.has-tooltip:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.pill {
  padding: 0.22rem 0.55rem;
  border: 1px solid var(--line);
  background: var(--panel);
  white-space: nowrap;
}

.main {
  width: min(1180px, calc(100% - 1.5rem));
  margin: 0 auto 1.5rem;
}

.main-challenge {
  width: min(1680px, calc(100% - 0.75rem));
  margin: 0 auto;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0.42rem 0.8rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  background: transparent;
  color: var(--text);
}

.btn-primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.btn-primary:hover {
  background: var(--muted);
  border-color: var(--muted);
  color: var(--bg);
}

.btn-secondary:hover {
  border-color: var(--muted);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.home-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  padding: 0.85rem 0 0.65rem;
}

.home-controls .search-field {
  flex: 1 1 220px;
  min-width: 0;
}

.progress-bar {
  width: min(180px, 100%);
  height: 4px;
  background: var(--line);
  overflow: hidden;
  flex: 0 0 auto;
}

.progress-bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--good);
}

.progress-transfer-status {
  margin: 0 0 0.55rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.progress-transfer-status.is-error {
  color: var(--bad);
}

.progress-transfer-status.is-ok {
  color: var(--good);
}

.search-field input {
  width: 100%;
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0.45rem 0.7rem;
  font: inherit;
  color: var(--text);
  background: var(--panel);
}

.search-field input::placeholder {
  color: var(--muted);
}

.search-field input:focus {
  outline: none;
  border-color: var(--text);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.filter-status {
  margin: 0 0 0.65rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.empty-filter {
  margin: 0.35rem 0 0;
  padding: 0.85rem;
  border: 1px dashed var(--line);
  color: var(--muted);
}

.topic-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.topic-chip {
  appearance: none;
  padding: 0.28rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.topic-chip:hover {
  border-color: var(--muted);
  color: var(--text);
}

.topic-chip.good {
  border-color: var(--good);
  color: var(--good);
  background: var(--good-bg);
}

.topic-chip.bad {
  border-color: var(--bad);
  color: var(--bad);
  background: var(--bad-bg);
}

.topic-chip.partial {
  border-color: var(--good);
  color: var(--text);
}

.topic-chip.is-active {
  border-color: var(--text);
  color: var(--bg);
  background: var(--text);
}

.topic-chip.is-active.good,
.topic-chip.is-active.bad,
.topic-chip.is-active.partial {
  border-color: var(--text);
  color: var(--bg);
  background: var(--text);
}

.level-block {
  margin-bottom: 1.1rem;
}

.level-block h2 {
  margin: 0 0 0.5rem;
  font-size: 0.98rem;
  font-weight: 600;
}

.challenge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 0.55rem;
}

.challenge-link.is-quiz {
  border-style: dashed;
}

.challenge-link.is-game {
  border-color: #4b5563;
}

.game-preview {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
  background: #0a0a0a;
}

.game-preview[hidden] {
  display: none !important;
}

.game-preview-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.4rem 0.7rem;
  border-bottom: 1px solid var(--line);
}

.game-preview-label {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.game-preview-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  max-height: 200px;
  padding: 0.45rem;
  overflow: hidden;
}

.game-preview-stage canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
}

.page-game .monaco-host {
  min-height: 0;
}

.challenge-link {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  background: var(--panel);
  color: inherit;
  text-decoration: none;
  min-height: 0;
}

.challenge-link:hover {
  border-color: var(--text);
}

.challenge-link.good {
  border-color: var(--good);
  background: var(--good-bg);
}

.challenge-link.bad {
  border-color: var(--bad);
  background: var(--bad-bg);
}

.challenge-top {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.challenge-link.good .challenge-top,
.challenge-link.good h3 {
  color: var(--good);
}

.challenge-link.bad .challenge-top,
.challenge-link.bad h3 {
  color: var(--bad);
}

.challenge-link h3 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 600;
  line-height: 1.25;
}

.challenge-link p {
  margin: 0;
  flex: 1;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.status-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--line);
  align-self: center;
}

.status-dot.good {
  background: var(--good);
}

.status-dot.bad {
  background: var(--bad);
}

/* —— Challenge workspace: fill the viewport, scroll only inside panels —— */
.page-challenge {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.page-challenge .site-header {
  flex: 0 0 auto;
}

.page-challenge .main-challenge {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
  padding: 0 0 0.45rem;
}

.challenge-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(0, 1.55fr);
  gap: 0.55rem;
  padding-top: 0.45rem;
  align-items: stretch;
}

.requirements-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.req-top {
  flex: 0 0 auto;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--line);
}

.req-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-top: 0.7rem;
  padding-bottom: 0.7rem;
}

.req-footer {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  padding-top: 0.55rem;
  padding-bottom: 0.55rem;
}

.prompt h2 {
  margin: 0.75rem 0 0.3rem;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.prompt h2:first-child {
  margin-top: 0;
}

.prompt h3 {
  margin: 0.55rem 0 0.25rem;
  font-size: 0.95rem;
}

.prompt p {
  margin: 0.25rem 0;
}

.req-list {
  margin: 0.25rem 0 0.45rem;
  padding-left: 1.1rem;
}

.req-list li {
  margin: 0.15rem 0;
}

.inline-code {
  font-family: var(--font-code);
  font-size: 0.88em;
  padding: 0.04rem 0.25rem;
  border: 1px solid var(--line);
  background: #0a0a0a;
}

.editor-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.monaco-host {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  border-bottom: 1px solid var(--line);
}

.monaco-host[hidden] {
  display: none !important;
}

.quiz-panel {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  overflow: auto;
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--line);
  background: #161616;
}

.quiz-panel[hidden] {
  display: none !important;
}

.quiz-question {
  margin: 0 0 0.7rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  background: var(--panel);
}

.quiz-question:last-child {
  margin-bottom: 0;
}

.quiz-question legend {
  padding: 0 0.3rem;
  font-weight: 600;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.3;
}

.quiz-help {
  margin: 0.25rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.quiz-choices {
  display: grid;
  gap: 0.35rem;
}

.quiz-choice {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.42rem 0.55rem;
  border: 1px solid var(--line);
  background: #0f0f0f;
  cursor: pointer;
}

.quiz-choice:hover {
  border-color: var(--muted);
}

.quiz-choice:has(input:checked) {
  border-color: var(--text);
  background: #1a1a1a;
}

.quiz-choice input {
  margin-top: 0.15rem;
  accent-color: var(--text);
}

.quiz-choice span {
  flex: 1;
  line-height: 1.35;
  font-size: 0.92rem;
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
}

.panel-pad {
  padding: 0.7rem 0.85rem;
}

.crumb {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 0.4rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.challenge-title {
  margin: 0 0 0.35rem;
  font-size: clamp(1.15rem, 2.2vw, 1.45rem);
  font-weight: 600;
  line-height: 1.2;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0;
}

.meta-chip {
  padding: 0.15rem 0.45rem;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
}

.prompt {
  margin: 0 0 0.7rem;
}

.hint-box {
  margin-top: 0.55rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  background: #0a0a0a;
}

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

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--line);
  background: #252526;
  flex: 0 0 auto;
}

.editor-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.editor-toolbar .btn {
  padding: 0.35rem 0.7rem;
  font-size: 0.88rem;
}

.editor-label {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.results {
  flex: 0 1 auto;
  border-top: 1px solid var(--line);
  padding: 0.55rem 0.75rem 0.65rem;
  min-height: 0;
  max-height: min(18vh, 160px);
  overflow: auto;
  background: #111111;
}

.results h2 {
  margin: 0 0 0.35rem;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.results-list {
  display: grid;
  gap: 0.3rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.result-item {
  display: grid;
  gap: 0.05rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--line);
}

.result-item.pass {
  border-color: var(--good);
  background: var(--good-bg);
  color: var(--good);
}

.result-item.fail {
  border-color: var(--bad);
  background: var(--bad-bg);
  color: var(--bad);
}

.result-item strong {
  font-family: var(--font-code);
  font-size: 0.8rem;
}

.result-item span {
  color: var(--muted);
  font-size: 0.84rem;
}

.banner {
  margin-bottom: 0.4rem;
  padding: 0.45rem 0.6rem;
  font-weight: 600;
  font-size: 0.9rem;
  border: 1px solid var(--line);
}

.banner.success {
  background: var(--good-bg);
  border-color: var(--good);
  color: var(--good);
}

.banner.error {
  background: var(--bad-bg);
  border-color: var(--bad);
  color: var(--bad);
}

.meta-chip.good {
  border-color: var(--good);
  color: var(--good);
}

.meta-chip.bad {
  border-color: var(--bad);
  color: var(--bad);
}

.nav-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0;
}

.nav-row .btn {
  padding: 0.35rem 0.65rem;
  font-size: 0.84rem;
  max-width: 48%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muted {
  color: var(--muted);
}

@media (max-width: 980px) {
  .challenge-shell {
    grid-template-columns: minmax(260px, 0.95fr) minmax(0, 1.35fr);
  }
}

@media (max-width: 900px) {
  .page-challenge {
    height: auto;
    overflow: auto;
  }

  .page-challenge .main-challenge {
    padding-bottom: 0.75rem;
  }

  .challenge-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .requirements-panel {
    max-height: none;
    overflow: visible;
  }

  .req-scroll {
    overflow: visible;
  }

  .editor-panel {
    min-height: 62vh;
  }

  .monaco-host,
  .quiz-panel {
    min-height: 42vh;
  }

  .results {
    max-height: none;
  }
}

@media (max-width: 600px) {
  .site-header {
    flex-direction: column;
    align-items: flex-start;
    min-height: 0;
    padding: 0.65rem 0.85rem;
  }

  .header-meta {
    width: 100%;
    justify-content: flex-start;
  }

  .has-tooltip::after {
    right: auto;
    left: 0;
  }

  .main {
    width: calc(100% - 1rem);
  }

  .home-controls {
    padding-top: 0.65rem;
  }

  .progress-bar {
    width: 100%;
  }

  .challenge-grid {
    grid-template-columns: 1fr;
  }
}
