:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #111;
  background: #111;
}

* {
  box-sizing: border-box;
}

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

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
}

body {
  overflow: hidden;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #111;
}

#game-container,
#game-container canvas {
  display: block;
}

#game-container {
  width: 100%;
  height: 100%;
}

.hud {
  position: absolute;
  z-index: 7;
  top: 14px;
  left: 14px;
  display: grid;
  grid-template-columns: 78px minmax(190px, 1fr);
  width: min(350px, calc(100vw - 190px));
  min-height: 104px;
  overflow: hidden;
  border: 3px solid #173f8e;
  border-radius: 16px;
  background: linear-gradient(180deg, #2765c8 0%, #153c88 100%);
  box-shadow:
    inset 0 0 0 2px rgb(255 255 255 / 16%),
    0 6px 18px rgb(8 25 57 / 32%);
  color: #fff;
  pointer-events: none;
}

.hud__portrait {
  width: 78px;
  height: 100%;
  min-height: 104px;
  object-fit: cover;
  image-rendering: pixelated;
  background: #cfe4ff;
  border-right: 2px solid rgb(255 255 255 / 18%);
}

.hud__body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 9px 12px 8px;
}

.hud__brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hud__brand strong {
  font-size: 17px;
  line-height: 1;
  text-shadow: 0 2px 0 rgb(0 0 0 / 20%);
}

.hud__brand span {
  padding: 2px 6px;
  border-radius: 999px;
  background: rgb(255 255 255 / 16%);
  font-size: 10px;
  font-weight: 800;
}

.hud__player-name {
  margin-top: 3px;
  color: #dceaff;
  font-size: 12px;
  font-weight: 700;
}

.hud__mission {
  min-width: 0;
  margin-top: 7px;
}

.hud__mission span {
  display: block;
  color: #a9c9ff;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hud__mission strong {
  display: block;
  margin-top: 1px;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud__progress {
  height: 7px;
  margin-top: 7px;
  overflow: hidden;
  border: 1px solid rgb(3 22 58 / 60%);
  border-radius: 999px;
  background: rgb(5 26 69 / 60%);
}

.hud__progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffd65c, #78e583);
  transition: width 180ms ease;
}

.hud__footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 5px;
  color: #c9dcff;
  font-size: 9px;
  font-weight: 700;
}

.hud__footer kbd {
  padding: 1px 4px;
  border: 1px solid rgb(255 255 255 / 40%);
  border-radius: 4px;
  background: rgb(255 255 255 / 10%);
  font: inherit;
}

.interaction-prompt,
.notebook-prompt {
  position: absolute;
  z-index: 8;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 8px;
  color: #fff;
  background: rgb(20 20 20 / 88%);
  backdrop-filter: blur(4px);
  box-shadow: 0 3px 10px rgb(0 0 0 / 25%);
  pointer-events: none;
  font-size: 14px;
}

.interaction-prompt {
  bottom: 30px;
}

.notebook-prompt {
  top: 24px;
  background: rgb(41 65 118 / 94%);
}

.interaction-prompt kbd,
.notebook-prompt kbd {
  display: inline-block;
  min-width: 24px;
  margin: 0 3px;
  padding: 2px 6px;
  border: 1px solid rgb(255 255 255 / 55%);
  border-radius: 4px;
  background: rgb(255 255 255 / 12%);
  font-family: inherit;
  text-align: center;
}

.notebook,
.dialogue {
  position: absolute;
  color: #10234a;
}

.notebook {
  z-index: 19;
}

.dialogue {
  z-index: 12;
}

.notebook-backdrop {
  position: absolute;
  z-index: 18;
  inset: 0;
  background: rgb(4 15 34 / 46%);
  backdrop-filter: blur(2px);
}

.notebook-backdrop[hidden] {
  display: none;
}

.dialogue-backdrop {
  position: absolute;
  z-index: 11;
  inset: 0;
  background: rgb(4 15 34 / 28%);
  backdrop-filter: blur(1px);
  pointer-events: none;
}

.dialogue-backdrop[hidden] {
  display: none;
}

.notebook {
  inset: 4% 5%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 4px solid #173f8e;
  border-radius: 16px;
  background: #f7faff;
  box-shadow:
    inset 0 0 0 2px #dce8ff,
    0 18px 48px rgb(0 0 0 / 45%);
}

.notebook[hidden],
.notebook-backdrop[hidden],
.dialogue[hidden],
.dialogue-backdrop[hidden],
.interaction-prompt[hidden],
.notebook-prompt[hidden] {
  display: none;
}

.notebook__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 74px;
  padding: 12px 18px;
  background: linear-gradient(180deg, #3473dc 0%, #2452a4 100%);
  color: #fff;
  border-bottom: 3px solid #173f8e;
}

.notebook__brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.notebook__brand-icon {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 2px solid rgb(255 255 255 / 30%);
  border-radius: 10px;
  background: rgb(255 255 255 / 14%);
  font-size: 28px;
}

.notebook__header h1 {
  margin: 1px 0 0;
  font-size: 25px;
  line-height: 1;
}

.notebook__eyebrow {
  color: #cfe0ff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#notebook-close {
  width: 40px;
  height: 40px;
  border: 2px solid rgb(255 255 255 / 24%);
  border-radius: 9px;
  background: rgb(255 255 255 / 12%);
  color: #fff;
  font-size: 24px;
  line-height: 1;
}

#notebook-close:hover {
  background: rgb(255 255 255 / 22%);
}

.notebook__content {
  display: grid;
  grid-template-columns: minmax(270px, 0.82fr) minmax(0, 1.65fr);
  gap: 0;
  flex: 1;
  min-height: 0;
  background: #ffffff;
}

.notebook__mission,
.notebook__editor {
  padding: 20px;
  overflow: auto;
}

.notebook__mission {
  border-right: 2px solid #d4e1f8;
  background:
    linear-gradient(180deg, #eef5ff 0%, #f8fbff 62%, #edf4ff 100%);
}

.notebook__mission h2 {
  margin: 5px 0 10px;
  color: #173f8e;
  font-size: 23px;
  line-height: 1.15;
}

.notebook__section-label {
  color: #4e73b5;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

#mission-description {
  color: #33496f;
  font-size: 14px;
  line-height: 1.55;
}

#mission-concepts {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 9px 0 0;
  padding: 0;
  list-style: none;
}

#mission-concepts li {
  padding: 5px 9px;
  border: 1px solid #bdd2f3;
  border-radius: 999px;
  background: #fff;
  color: #2452a4;
  font-size: 11px;
  font-weight: 800;
}

.notebook__concepts {
  margin-top: 22px;
}

.notebook__concepts > strong {
  color: #253c67;
  font-size: 12px;
}

.notebook__tip {
  display: grid;
  gap: 3px;
  margin-top: 22px;
  padding: 12px;
  border: 1px solid #bcd2f7;
  border-radius: 10px;
  background: #e5f0ff;
  color: #39547f;
  font-size: 12px;
}

.notebook__tip strong {
  color: #2452a4;
}

.notebook__editor {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #ffffff;
}

.notebook__editor-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.notebook__editor-heading > div {
  display: grid;
  gap: 2px;
}

.notebook__editor-heading strong {
  color: #173f8e;
  font-size: 18px;
}

.notebook__language {
  padding: 4px 9px;
  border-radius: 999px;
  background: #e7efff;
  color: #2452a4;
  font-size: 10px;
  font-weight: 900;
}

#code-editor {
  width: 100%;
  flex: 1;
  min-height: 210px;
  padding: 15px;
  border: 2px solid #9eb9e7;
  border-radius: 10px;
  outline: none;
  background: #fbfdff;
  color: #172542;
  box-shadow: inset 0 2px 8px rgb(18 52 105 / 6%);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.55;
  resize: none;
}

#code-editor:focus {
  border-color: #3473dc;
  box-shadow:
    0 0 0 3px rgb(52 115 220 / 14%),
    inset 0 2px 8px rgb(18 52 105 / 6%);
}

.notebook__api-help {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px;
  border: 1px solid #d1def3;
  border-radius: 10px;
  background: #f5f8ff;
  font-size: 12px;
}

.notebook__api-help > strong {
  grid-column: 1 / -1;
  color: #4c6287;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.notebook__api-help > div {
  display: grid;
  gap: 2px;
  padding: 8px 9px;
  border: 1px solid #d7e3f7;
  border-radius: 8px;
  background: #fff;
}

.notebook__api-help code {
  color: #2452a4;
  font-weight: 900;
}

.notebook__api-help span {
  color: #667793;
  font-size: 11px;
}

.notebook__hint {
  margin-top: -5px;
  color: #666;
}

.notebook__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.notebook__actions button {
  min-width: 96px;
  padding: 9px 15px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-weight: 900;
  box-shadow: inset 0 -2px 0 rgb(0 0 0 / 18%);
}

#run-code {
  background: linear-gradient(180deg, #3b7ce6, #2452a4);
}

#submit-code {
  background: linear-gradient(180deg, #55bd71, #31924d);
}

.notebook__actions button:hover:not(:disabled) {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.notebook__actions button:disabled {
  opacity: 0.5;
}

.program-terminal {
  min-height: 126px;
  padding: 0 12px 12px;
  border: 2px solid #172744;
  border-radius: 10px;
  background: #172033;
  color: #dce2eb;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow: auto;
}

.program-terminal__header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0 -12px 10px;
  padding: 7px 11px;
  border-bottom: 1px solid #2f405f;
  background: #202d45;
  color: #97b2dc;
  font-size: 10px;
  font-weight: 800;
}

.program-terminal__header span:first-child {
  color: #e7efff;
}

#program-output {
  min-height: 58px;
  margin: 0;
  padding: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: inherit;
  font: inherit;
}

.program-terminal__input {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.program-terminal__input[hidden] {
  display: none;
}

.program-terminal__input span {
  color: #8fd18a;
  font-weight: 700;
}

#terminal-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  padding: 3px 0;
  background: transparent;
  color: #fff;
  caret-color: #fff;
  font: inherit;
}

.notebook__footer {
  padding: 9px 20px;
  border-top: 1px solid #d8ddea;
  background: #eaf1fc;
  color: #62728e;
  font-size: 12px;
  text-align: right;
}

.dialogue {
  left: 50%;
  bottom: 30px;
  width: min(900px, calc(100% - 44px));
  min-height: 178px;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  align-items: end;
  filter: drop-shadow(0 12px 24px rgb(0 0 0 / 35%));
}

.dialogue__portrait-wrap {
  position: relative;
  z-index: 2;
  align-self: stretch;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
}

.dialogue__portrait-wrap::after {
  content: "";
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 8px;
  height: 20px;
  border-radius: 50%;
  background: rgb(8 24 54 / 25%);
  filter: blur(6px);
  z-index: -1;
}

.dialogue__portrait {
  width: 150px;
  height: 150px;
  object-fit: contain;
  image-rendering: pixelated;
  transform: translateY(5px);
}

.dialogue__panel {
  position: relative;
  overflow: hidden;
  align-self: end;
  margin-left: -10px;
  border: 4px solid #2452a4;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: inset 0 0 0 2px #dbe7ff;
}

.dialogue__panel::before {
  content: "";
  position: absolute;
  left: -16px;
  bottom: 32px;
  width: 28px;
  height: 28px;
  background: #fff;
  border-left: 4px solid #2452a4;
  border-bottom: 4px solid #2452a4;
  transform: rotate(45deg);
}

.dialogue__header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 42px;
  padding: 8px 16px;
  background: linear-gradient(180deg, #3473dc 0%, #2452a4 100%);
  color: #fff;
}

#dialogue-speaker {
  display: block;
  font-size: 18px;
  font-weight: 800;
  text-shadow: 0 1px 0 rgb(0 0 0 / 25%);
}

.dialogue__progress {
  font-size: 12px;
  font-weight: 700;
  opacity: 0.85;
}

.dialogue__content {
  position: relative;
  z-index: 1;
  min-height: 86px;
  padding: 16px 20px 12px;
}

#dialogue-text {
  margin: 0;
  color: #16264a;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.5;
}

.dialogue__actions {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  padding: 8px 12px 10px;
  border-top: 1px solid #dbe5f8;
  background: #f4f8ff;
}

.dialogue__actions span {
  color: #6b7895;
  font-size: 12px;
  font-weight: 600;
}

#dialogue-next {
  min-width: 96px;
  padding: 8px 14px;
  border: 0;
  border-radius: 8px;
  background: #2452a4;
  color: #fff;
  font-weight: 800;
  box-shadow: inset 0 -2px 0 rgb(0 0 0 / 20%);
}

#dialogue-next:hover {
  background: #2f65c5;
}

@media (max-width: 760px) {
  .dialogue {
    bottom: 18px;
    width: calc(100% - 24px);
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .dialogue__portrait {
    width: 96px;
    height: 96px;
  }

  .dialogue__panel {
    margin-left: -6px;
  }

  #dialogue-text {
    font-size: 15px;
  }

  .dialogue__actions span {
    display: none;
  }

  .notebook {
    inset: 3%;
  }

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

  .notebook__mission {
    border-right: 0;
    border-bottom: 1px solid #d8ddea;
  }
}


.quick-actions {
  position: absolute;
  z-index: 8;
  top: 14px;
  right: 14px;
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.quick-action {
  display: grid;
  grid-template-columns: 30px auto;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 7px;
  min-width: 112px;
  min-height: 58px;
  padding: 7px 10px;
  border: 3px solid #173f8e;
  border-radius: 12px;
  background: linear-gradient(180deg, #2f75df, #1b4da7);
  color: #fff;
  box-shadow:
    inset 0 0 0 2px rgb(255 255 255 / 12%),
    0 5px 14px rgb(7 23 54 / 28%);
  font-size: 12px;
  font-weight: 800;
}

.quick-action__icon {
  grid-row: 1 / 3;
  display: grid;
  width: 30px;
  height: 34px;
  place-items: center;
  border-radius: 7px;
  background: rgb(255 255 255 / 16%);
  font-size: 22px;
}

.quick-action kbd {
  justify-self: start;
  padding: 1px 5px;
  border: 1px solid rgb(255 255 255 / 40%);
  border-radius: 4px;
  background: rgb(255 255 255 / 12%);
  font: inherit;
  font-size: 9px;
}

.quick-action:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.quick-action:disabled {
  cursor: not-allowed;
  opacity: 0.46;
  filter: grayscale(0.35);
}

.quick-action--danger {
  min-width: 92px;
  grid-template-columns: 28px auto;
  grid-template-rows: 1fr;
  border-color: #8e2b2b;
  background: linear-gradient(180deg, #ef5a55, #c83535);
}

.quick-action--danger .quick-action__icon {
  grid-row: 1;
  width: 28px;
  height: 30px;
}

@media (max-width: 620px) {
  .hud {
    grid-template-columns: 58px minmax(160px, 1fr);
    width: calc(100vw - 28px);
  }

  .hud__portrait {
    width: 58px;
  }

  .hud__footer span:last-child {
    display: none;
  }

  .quick-actions {
    top: 128px;
  }

  .quick-action {
    min-width: auto;
  }

  .quick-action > span:not(.quick-action__icon),
  .quick-action kbd {
    display: none;
  }

  .quick-action {
    grid-template-columns: 34px;
  }

  .quick-action__icon {
    grid-row: 1;
  }
}

.interaction-prompt {
  border: 2px solid rgb(255 255 255 / 22%);
  font-weight: 700;
  animation: interaction-prompt-in 140ms ease-out;
}

.interaction-prompt::before {
  content: "●";
  display: inline-block;
  margin-right: 8px;
  color: #7fb0ff;
  text-shadow: 0 0 8px rgb(127 176 255 / 65%);
}

@keyframes interaction-prompt-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.notebook__lesson-card {
  display: grid;
  gap: 5px;
  margin-top: 14px;
  padding: 11px 12px;
  border: 1px solid #c9daf6;
  border-radius: 10px;
  background: #ffffff;
  color: #405575;
}

.notebook__lesson-card strong {
  color: #2452a4;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.notebook__lesson-card p {
  margin: 0;
  font-size: 12px;
  line-height: 1.48;
}

.notebook__lesson-card--why {
  border-color: #f0d79c;
  background: #fff9e9;
}

.notebook__lesson-card--why strong {
  color: #9a6518;
}

@media (max-height: 720px) {
  .notebook__mission {
    overflow-y: auto;
  }

  .notebook__lesson-card {
    margin-top: 9px;
    padding: 8px 9px;
  }

  .notebook__lesson-card p {
    font-size: 11px;
  }
}
