/* Page frame: HUD bar on top, a view below. Lesson view = two panes. */

/* ---------- HUD ---------- */

.hud {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  height: var(--hud-height);
  padding: 0 1rem;
  background: var(--hud-bg);
  border-bottom: var(--border);
  font-family: var(--font-pixel);
  font-size: 1.05rem;
  white-space: nowrap;
}

.hud__home {
  color: var(--yellow);
  font-weight: 700;
  font-size: 1.3rem;
  text-decoration: none;
}

.hud__item { display: flex; align-items: baseline; gap: 0.4em; min-width: 0; }
.hud__callsign { color: inherit; text-decoration: none; }
.hud__callsign:hover .hud__value { text-decoration: underline; }
.hud__label { color: var(--teal); font-size: 0.85em; text-transform: uppercase; }
.hud__value { overflow: hidden; text-overflow: ellipsis; }

.hud__xp { position: relative; flex: 1 1 auto; display: flex; align-items: center; gap: 0.6em; min-width: 8rem; }

.xpbar {
  flex: 1 1 auto;
  height: 16px;
  background: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--night-2);
  max-width: 22rem;
}
.xpbar__fill {
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(90deg, var(--yellow) 0 8px, #ffbf00 8px 12px);
  transition: width 400ms steps(10);
}

.hud__end { margin-left: auto; display: flex; gap: 0.5rem; }

/* ---------- View ---------- */

.view {
  min-height: calc(100vh - var(--hud-height));
}

.screen {
  max-width: 64rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* ---------- Lesson: two-pane layout ---------- */

.lesson {
  display: grid;
  grid-template-columns: minmax(20rem, 2fr) 3fr;
  gap: 1rem;
  height: calc(100vh - var(--hud-height));
  padding: 1rem;
}

.lesson__left {
  overflow-y: auto;
  min-height: 0;
  min-width: 0;      /* wide code blocks scroll instead of widening the page */
}

.lesson__right {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
  min-width: 0;      /* long code lines scroll inside the editor instead of widening the page */
}

.editor-wrap {
  flex: 3 1 0;
  min-height: 12rem;
  background: var(--editor-bg);
  border: var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.toolbar__status {
  margin-left: auto;
  font-family: var(--font-pixel);
  font-size: 0.95rem;
  color: var(--teal);
}

.console {
  flex: 2 1 0;
  min-height: 8rem;
  overflow-y: auto;
  background: var(--console-bg);
  color: #d7ffd9;
  border: var(--border);
  box-shadow: var(--shadow);
  padding: 0.75rem 1rem;
  font-family: var(--font-code);
  font-size: var(--code-size);
  white-space: pre-wrap;
  word-break: break-word;
}
/* Robot simulator mat (robotics tasks with a "sim" block) */
/* Under the editor: the robot mat (robotics tasks) and the output, side by side so the
   output stays readable next to the mat. They stack on narrow screens (see the media query). */
.lesson__bottom {
  flex: 2 1 0;
  min-height: 0;
  display: flex;
  gap: 0.75rem;
}
.lesson__bottom > .console { flex: 1 1 0; min-width: 0; }
/* On robot tasks the mat needs room too: editor and mat + output split the height evenly. */
.lesson__right:has(.sim-mat:not([hidden])) > .lesson__bottom { flex: 3 1 0; }
.lesson__bottom > .sim-mat {
  flex: 1.25 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.lesson__bottom > .sim-mat > .sim-mat__canvas {
  flex: 1 1 0;
  min-height: 5rem;
  width: 100%;
  height: auto;
  max-height: none;
  aspect-ratio: auto;
  object-fit: contain;          /* the drawing keeps its shape inside whatever box it gets */
}
.sim-mat {
  flex: 0 0 auto;
  background: var(--paper);
  color: var(--paper-ink);
  border: var(--border);
  box-shadow: var(--shadow);
  padding: 0.4rem 0.6rem 0.5rem;
}
.sim-mat[hidden] { display: none; }
.sim-mat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}
.sim-mat__title {
  font-family: var(--font-pixel);
  text-transform: uppercase;
  font-size: 0.9rem;
}
.sim-mat__canvas {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 15rem;
  aspect-ratio: var(--mat-ratio, 5 / 3);
  margin: 0 auto;
  image-rendering: pixelated;
}
.sim-mat__readout {
  font-family: var(--font-code);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 0.25rem;
}

.console__title {
  font-family: var(--font-pixel);
  color: var(--teal);
  font-size: 0.9rem;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}
.console__err { color: #ff9a9d; }
.console__empty, .console__note { color: #8b84a8; font-style: italic; }

/* Verdict box at the end of a run's output. Uses the readable body font. */
.verdict {
  margin-top: 0.75rem;
  padding: 0.6rem 0.85rem;
  border: 3px solid;
  font-family: var(--font-body);
  font-size: 1.1rem;
  line-height: 1.45;
  white-space: normal;
  color: var(--text-light);
}
.verdict--pass  { border-color: var(--green); background: #5bd16b1f; }
.verdict--fail  { border-color: var(--yellow); background: #ffd23f17; }
.verdict--error { border-color: var(--red); background: #ff5a5f1c; }
.verdict__title { font-family: var(--font-pixel); font-weight: 700; font-size: 1.15rem; margin-bottom: 0.2rem; }
.verdict--pass .verdict__title  { color: var(--green); }
.verdict--fail .verdict__title  { color: var(--yellow); }
.verdict--error .verdict__title { color: #ff8a8d; }
.verdict code {
  font-family: var(--font-code);
  background: #ffffff1a;
  padding: 0.05em 0.3em;
  white-space: pre-wrap;
}
.verdict__toggle {
  margin-top: 0.5rem;
  background: none;
  border: none;
  padding: 0;
  color: var(--sky);
  text-decoration: underline;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}
.verdict__raw {
  margin: 0.5rem 0 0;
  padding: 0.5rem;
  background: #00000055;
  font-size: 0.9rem;
  white-space: pre-wrap;
  color: #ffd0d1;
}

/* Editor fills its frame. */
.editor-wrap .cm-editor { height: 100%; }

/* Worked examples in the lesson panel (staticCode). */
.code-block {
  background: var(--editor-bg);
  color: #f6f1ff;
  border: 3px solid var(--ink);
  padding: 0.6rem 0.85rem;
  font-family: var(--font-code);
  font-size: var(--code-size);
  line-height: 1.5;
  overflow-x: auto;
  margin: 0 0 0.75rem;
}

/* ---------- Narrow screens: stack panes, let the page scroll ---------- */

@media (max-width: 900px) {
  .lesson {
    grid-template-columns: 1fr;
    height: auto;
  }
  .lesson__left { overflow: visible; }
  .editor-wrap { min-height: 16rem; }
  .console { min-height: 10rem; }
  .lesson__bottom { flex-direction: column; }
  .lesson__bottom > .sim-mat { flex: 0 0 auto; }
  .lesson__bottom > .sim-mat > .sim-mat__canvas {
    flex: none;
    width: auto;
    max-width: 100%;
    max-height: 15rem;
    aspect-ratio: var(--mat-ratio, 5 / 3);
  }
}

@media (max-width: 640px) {
  .hud { gap: 0.75rem; font-size: 0.95rem; overflow-x: auto; }
  .hud__item--case { display: none; }
  .hud__item .hud__label { display: none; }
  .hud__xp { min-width: 6rem; }
}

/* One-time warning when the browser won't save. */
.save-banner {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(36rem, calc(100vw - 2rem));
  background: #ffe3e3;
  color: var(--paper-ink);
  border: var(--border);
  box-shadow: var(--shadow);
  padding: 0.6rem 0.9rem;
  font-size: 1.05rem;
}

.hud__sound {
  background: none;
  border: 2px solid transparent;
  font-size: 1.3rem;
  line-height: 1;
  padding: 0.2rem 0.35rem;
  cursor: pointer;
  filter: grayscale(0.2);
}
.hud__sound:hover { border-color: var(--night-2); }
.hud__sound[aria-pressed="true"] { filter: none; }

/* Very narrow screens: drop the rank (HQ shows it) so the name stays readable. */
@media (max-width: 480px) {
  .hud { gap: 0.5rem; padding: 0 0.6rem; }
  .hud__home { font-size: 1.1rem; }
  .hud__item:not(.hud__callsign) { display: none; }
  .hud__callsign { flex: 0 1 auto; min-width: 3.5rem; }
  .hud__xp { min-width: 4.5rem; }
}

/* Current city: a little luggage-tag badge */
.hud__place {
  display: flex;
  align-items: baseline;
  gap: 0.35em;
  background: var(--yellow);
  color: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
  padding: 0.05rem 0.5rem;
  white-space: nowrap;
}
.hud__place .hud__label { color: var(--ink); opacity: 0.7; }
.hud__pin { font-size: 0.9em; }
@media (max-width: 640px) { .hud__place .hud__label { display: none; } }
@media (max-width: 480px) { .hud__place { display: none; } }
