:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --ink: #172033;
  --muted: #63708a;
  --line: #d9e0ef;
  --panel: #ffffff;
  --panel-strong: #eef4ff;
  --blue: #2d65f2;
  --blue-dark: #173b91;
  --green: #00a884;
  --amber: #f5a524;
  --red: #d64545;
  --purple: #7549d8;
  --shadow: 0 18px 45px rgba(30, 48, 95, 0.14);
  --radius: 8px;
  --radius-lg: 18px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 15% 10%, rgba(45, 101, 242, 0.16), transparent 28rem),
    radial-gradient(circle at 88% 16%, rgba(0, 168, 132, 0.14), transparent 26rem),
    linear-gradient(180deg, #fbfcff 0%, var(--bg) 52%, #edf3ff 100%);
  color: var(--ink);
  font-family: var(--font);
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
}

button:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(45, 101, 242, 0.35);
  outline-offset: 3px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1rem, 3vw, 2.4rem);
  border-bottom: 1px solid rgba(217, 224, 239, 0.8);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 2.65rem;
  height: 2.65rem;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: #fff;
  font-weight: 900;
  box-shadow: var(--shadow);
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  font-size: 0.76rem;
}

.top-actions,
.hero-actions,
.mission-controls,
.teacher-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 2.65rem;
  border-radius: var(--radius);
  padding: 0.7rem 1rem;
  cursor: pointer;
  font-weight: 800;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  color: #fff;
  box-shadow: 0 12px 28px rgba(45, 101, 242, 0.28);
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--blue-dark);
}

.ghost-button {
  border: 1px solid transparent;
  background: rgba(45, 101, 242, 0.08);
  color: var(--blue-dark);
}

.danger-button {
  background: rgba(214, 69, 69, 0.1);
  color: var(--red);
}

.compact {
  min-height: 2rem;
  padding: 0.4rem 0.65rem;
  font-size: 0.82rem;
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.danger-button:hover,
.code-block:hover,
.mission-tab:hover {
  transform: translateY(-1px);
}

.app-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: clamp(1rem, 2vw, 2rem);
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 0.85fr);
  gap: clamp(1rem, 3vw, 2rem);
  align-items: stretch;
  min-height: 420px;
}

.hero-copy,
.quest-map,
.mission-card,
.workspace,
.preview-panel,
.score-card,
.teacher-panel {
  border: 1px solid rgba(217, 224, 239, 0.92);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.hero-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(1.4rem, 4vw, 3.2rem);
}

.section-label {
  margin: 0 0 0.65rem;
  color: var(--blue-dark);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 900px;
  margin-bottom: 1rem;
  font-size: clamp(2.2rem, 5vw, 5.4rem);
  line-height: 0.98;
}

h2 {
  margin-bottom: 0.65rem;
  font-size: clamp(1.25rem, 2.5vw, 2rem);
  line-height: 1.08;
}

h3 {
  margin-bottom: 0.55rem;
  font-size: 1rem;
}

p {
  color: var(--muted);
  line-height: 1.65;
}

.quest-map {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  min-height: 360px;
  background:
    linear-gradient(135deg, rgba(22, 33, 63, 0.94), rgba(31, 47, 98, 0.9)),
    #172033;
}

.quest-map canvas {
  width: 100%;
  height: 100%;
  min-height: 340px;
}

.map-hud {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  gap: 0.7rem;
  align-items: center;
  padding: 0.65rem 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  backdrop-filter: blur(12px);
}

.mission-strip {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  margin: 1.25rem 0;
}

.mission-tabs {
  display: flex;
  gap: 0.55rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.mission-tab {
  display: grid;
  min-width: 8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.mission-tab small {
  color: var(--muted);
}

.mission-tab.active {
  border-color: rgba(45, 101, 242, 0.5);
  background: var(--panel-strong);
}

.mission-tab.locked {
  opacity: 0.56;
}

.studio-grid {
  display: grid;
  grid-template-columns: 320px minmax(360px, 1fr) minmax(360px, 0.95fr);
  gap: 1rem;
  align-items: start;
}

.mission-card,
.workspace,
.preview-panel,
.score-card,
.teacher-panel {
  padding: 1rem;
}

.mission-card {
  position: sticky;
  top: 5.6rem;
}

.mission-card__header {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.mission-card__header span,
.mission-card__header strong {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  background: rgba(45, 101, 242, 0.1);
  color: var(--blue-dark);
  font-size: 0.8rem;
}

.mission-goals ul {
  display: grid;
  gap: 0.6rem;
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
}

.mission-goals li {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
}

.mission-goals li::before {
  content: "";
  flex: 0 0 auto;
  width: 0.7rem;
  height: 0.7rem;
  margin-top: 0.42rem;
  border-radius: 999px;
  background: var(--amber);
}

.hint-box {
  margin-top: 1rem;
  border-left: 4px solid var(--green);
  border-radius: var(--radius);
  padding: 0.8rem;
  background: rgba(0, 168, 132, 0.08);
  color: #24514a;
  line-height: 1.55;
}

.workspace {
  min-width: 0;
}

.block-dock {
  display: grid;
  gap: 0.75rem;
}

.block-palette {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.code-block {
  display: grid;
  gap: 0.3rem;
  min-height: 5.3rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.75rem;
  background: linear-gradient(180deg, #ffffff, #f7f9ff);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.code-block.html {
  border-left: 5px solid #ee6c4d;
}

.code-block.css {
  border-left: 5px solid var(--blue);
}

.code-block.js {
  border-left: 5px solid var(--amber);
}

.code-block__type {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.code-block small {
  color: var(--muted);
  line-height: 1.35;
}

.editor-tabs {
  display: flex;
  gap: 0.45rem;
  margin: 1rem 0 0.55rem;
}

.editor-tab,
.device-button {
  min-height: 2.35rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 0.85rem;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.editor-tab.active,
.device-button.active {
  border-color: transparent;
  background: var(--blue);
  color: #fff;
}

.editor-stack {
  min-height: 430px;
}

.editor-panel {
  display: none;
}

.editor-panel.active {
  display: grid;
  gap: 0.45rem;
}

.editor-panel span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

textarea {
  min-height: 430px;
  width: 100%;
  resize: vertical;
  border: 1px solid #cfd7e8;
  border-radius: 14px;
  padding: 1rem;
  background: #111827;
  color: #f7fbff;
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.55;
  tab-size: 2;
}

.preview-panel {
  display: grid;
  gap: 0.9rem;
  min-width: 0;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
}

.device-toggle {
  display: flex;
  gap: 0.4rem;
}

.browser-frame {
  overflow: hidden;
  border: 1px solid #cfd7e8;
  border-radius: 16px;
  background: #fff;
}

.browser-frame.mobile {
  width: min(100%, 360px);
  margin-inline: auto;
}

.browser-bar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.2rem;
  padding: 0 0.75rem;
  border-bottom: 1px solid var(--line);
  background: #f4f7fc;
}

.browser-bar span {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 999px;
  background: #ff6b6b;
}

.browser-bar span:nth-child(2) {
  background: #ffd166;
}

.browser-bar span:nth-child(3) {
  background: #06d6a0;
}

.browser-bar strong {
  margin-left: 0.45rem;
  color: var(--muted);
  font-size: 0.78rem;
}

iframe {
  display: block;
  width: 100%;
  height: 360px;
  border: 0;
  background: #fff;
}

.browser-frame.mobile iframe {
  height: 560px;
}

.console-panel {
  overflow: hidden;
  border: 1px solid #24304d;
  border-radius: 14px;
  background: #111827;
  color: #d6e4ff;
}

.console-panel__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.console-panel ol {
  min-height: 7rem;
  max-height: 12rem;
  overflow: auto;
  margin: 0;
  padding: 0.75rem 0.75rem 0.75rem 2rem;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.82rem;
}

.console-panel li {
  margin-bottom: 0.35rem;
}

.console-panel li.error {
  color: #ffb4b4;
}

.console-panel li.warn {
  color: #ffe082;
}

.result-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 1rem;
  margin-top: 1rem;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 2.15rem;
  border-radius: 999px;
  padding: 0.4rem 0.7rem;
  background: rgba(0, 168, 132, 0.1);
  color: #046b58;
  font-weight: 900;
}

.teacher-panel ol {
  display: grid;
  gap: 0.55rem;
  margin: 0 0 1rem;
  padding-left: 1.4rem;
  color: var(--muted);
  line-height: 1.55;
}

.shake {
  animation: shake 0.32s ease;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  35% {
    transform: translateX(-8px);
  }
  70% {
    transform: translateX(8px);
  }
}

@media (max-width: 1180px) {
  .hero-panel,
  .studio-grid,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .mission-card {
    position: static;
  }
}

@media (max-width: 720px) {
  .topbar,
  .mission-strip,
  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .hero-actions,
  .mission-controls,
  .teacher-actions {
    width: 100%;
  }

  .top-actions > *,
  .hero-actions > *,
  .mission-controls > *,
  .teacher-actions > * {
    flex: 1;
  }

  .block-palette {
    grid-template-columns: 1fr;
  }

  textarea {
    min-height: 320px;
  }

  iframe {
    height: 300px;
  }
}

@media print {
  .topbar,
  .workspace,
  .preview-panel,
  .hero-panel,
  .mission-strip {
    display: none;
  }

  body {
    background: #fff;
  }

  .mission-card,
  .teacher-panel,
  .score-card {
    box-shadow: none;
  }
}
