/* Quiz Climb (climb.html). Builds on style.css. */

/* Screens and messages are switched with the hidden attribute; it must win over display rules below. */
.climb [hidden] {
  display: none !important;
}

.climb {
  --good: #1f8a4c;
  --bad: #b3261e;
  --fig-1: #2a78d6;
  --fig-2: #eb6834;
  /* Text serif fonts draw π with its curled leg (not like п) and keep √ on the line. */
  --math-font: 'Noto Serif', 'DejaVu Serif', Cambria, Georgia, 'Times New Roman', serif;
}

@media (prefers-color-scheme: dark) {
  .climb {
    --good: #6ee7a0;
    --bad: #ffb4ab;
    --fig-1: #3987e5;
    --fig-2: #d95926;
  }
}

.math,
.choice,
.feedback {
  font-family: var(--math-font);
}

.climb .bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.climb .bar h1 {
  font-size: 20px;
}

.status-line {
  margin: 0;
  padding: 0 24px;
  color: var(--error-text);
}

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

main.climb-main {
  display: block;
  padding: 16px 24px 24px;
}

.start,
.done {
  max-width: 900px;
  margin: 0 auto;
}

.climbers {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}

.climber {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  background: var(--stage);
  color: #1d1530;
}

.climber canvas {
  width: 72px;
  height: 72px;
}

/* "Create your own": an empty frame after the climbers, a link to the Character Studio. */
.climber.create {
  justify-content: center;
  border: 2px dashed var(--muted);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  text-align: center;
  text-decoration: none;
}

.climber.create:hover,
.climber.create:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.create-frame {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  font-size: 40px;
  line-height: 1;
}

.climber[aria-pressed='true'] {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  background: var(--stage);
  color: #1d1530;
}

.shared {
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

.shared p {
  margin: 0 0 8px;
}

.shared .info:empty {
  display: none;
}

.worlds-box {
  margin-top: 16px;
}

.worlds {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px 16px;
}

.world {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 6px;
  align-items: baseline;
}

.world .info {
  grid-column: 2;
  font-size: 13px;
}

.worlds-box > .info {
  margin: 8px 0 0;
  font-size: 14px;
}

.levels-box {
  margin: 0 0 12px;
}

.columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 0;
}

legend {
  font-weight: 600;
  padding: 0 4px;
}

.checks {
  display: grid;
  gap: 4px;
}

#topics {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px 18px;
}

.topic-group {
  display: grid;
  gap: 3px;
  align-content: start;
}

.group-title {
  margin: 0 0 2px;
  font-weight: 600;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.check {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.file {
  display: block;
  margin-top: 8px;
  font-size: 14px;
}

.problem {
  color: var(--error-text);
}

/* Start stays on screen while the choices scroll under it: on a phone they are
   two screens tall. The row reaches the panel's edges and covers what passes
   beneath it. */
.start-row {
  position: sticky;
  bottom: 0;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin: 14px -16px -14px;
  padding: 10px 16px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  border-radius: 0 0 12px 12px;
}

.start-row .info {
  margin: 0;
}

/* Tabbing down the lists scrolls each box into view above the Start row, not under it. */
:root:has(#start:not([hidden])) {
  scroll-padding-bottom: 96px;
}

.start .intro {
  margin: 0 0 10px;
}

/* ---- game ------------------------------------------------------------------- */

.game {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: calc(100vh - 110px);
  /* Phones: the visible height, without the address bar, so the touch buttons stay on screen. */
  height: calc(100dvh - 110px);
  min-height: 360px;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 18px;
  font-variant-numeric: tabular-nums;
}

.hud b {
  font-weight: 700;
}

/* In a class game: the game, how many climb it, and the connection. */
.hud-class {
  padding: 2px 10px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-weight: 600;
}

/* While a cake's speed lasts: how long, in the dessert pink. */
.hud-speed {
  padding: 2px 10px;
  border-radius: 999px;
  background: #ff9fd2;
  color: #1d1530;
  font-weight: 600;
}

.hud-class.warn {
  border-color: var(--muted);
  color: var(--muted);
}

/* Leave sits by the chip, away from Answer questions on the right. */
.hud-leave {
  min-height: 28px;
  padding: 2px 10px;
}

.hud .energy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.hud meter {
  width: 110px;
}

#hud-answer {
  margin-left: auto;
}

#hud-answer.urgent {
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    transform: scale(1.06);
  }
}

@media (prefers-reduced-motion: reduce) {
  #hud-answer.urgent {
    animation: none;
    outline: 3px solid var(--accent);
  }
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
}

#view {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  background: var(--stage);
  touch-action: none;
}

.toast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 14px;
  border-radius: 16px;
  background: rgba(29, 21, 48, 0.82);
  color: #ffffff;
  font-weight: 600;
  pointer-events: none;
  /* As wide as its text, up to the stage; longer hints wrap instead of being cut. */
  width: max-content;
  max-width: calc(100% - 24px);
  text-align: center;
}

.touch {
  display: none;
  position: absolute;
  inset: auto 12px 12px;
  justify-content: space-between;
  pointer-events: none;
}

.touch button {
  pointer-events: auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  font-size: 22px;
  background: rgba(255, 255, 255, 0.75);
  color: #1d1530;
  border: 2px solid #1d1530;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch button.held {
  background: #ffd54a;
}

.touch .jump {
  margin-left: auto;
}

.touch button[data-key='right'] {
  margin-left: 12px;
}

@media (pointer: coarse) {
  .touch {
    display: flex;
  }
}

/* The game shows them too once a finger is used on a screen with a fine pointer (controls.ts). */
#game.touch-mode .touch {
  display: flex;
}

/* ---- question dialog ------------------------------------------------------- */

/* The finish heading takes the focus in a class game (main.ts): it is no control, so no ring. */
#h-done:focus {
  outline: none;
}

/* "How to play": the goal, the keys, the flags and the blocks, with the game's own pictures (swatch.ts). */
.howto {
  width: min(680px, calc(100vw - 32px));
  max-height: 88vh;
  overflow-y: auto;
}

.howto h2 {
  margin: 0 0 8px;
}

.howto h3 {
  margin: 16px 0 6px;
  font-size: 16px;
}

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

.howto-goal p {
  margin: 0;
}

.tile-pic {
  flex: none;
  width: 56px;
  height: 56px;
}

.tile-pic canvas {
  display: block;
  width: 56px;
  height: 56px;
  border-radius: 8px;
}

.howto-keys {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.howto-keys th,
.howto-keys td {
  padding: 5px 8px;
  border-top: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.howto-keys thead th {
  border-top: 0;
  color: var(--muted);
}

.howto kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  font: 600 13px/1.5 ui-monospace, monospace;
  text-align: center;
}

.howto-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.howto-tiles li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

/* The question to leave a class game shares the question dialog's frame. */
.leave {
  width: min(440px, calc(100vw - 32px));
}

.leave h2 {
  margin: 0 0 8px;
}

.leave .buttons {
  justify-content: flex-end;
  margin-top: 14px;
}


.quiz {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  padding: 18px 20px;
}

.quiz::backdrop {
  background: rgba(20, 15, 35, 0.55);
}

.quiz-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.quiz-head h2 {
  margin: 0;
}

.prompt {
  font-size: 20px;
  font-weight: 600;
  margin: 14px 0;
}

.choices {
  display: grid;
  gap: 8px;
}

.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  font-size: 17px;
  min-height: 44px;
}

.choice .key {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}

/* A picked "pick all" choice is filled and its box is ticked (question.ts). The
   keyboard focus is a dashed ring, so a focused choice never looks picked. */
.choice:focus-visible {
  outline-style: dashed;
  outline-offset: 3px;
}

.choice .tick {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 22px;
  height: 22px;
  border: 2px solid var(--muted);
  border-radius: 5px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}

.choice[aria-pressed='true'] .tick {
  border-color: var(--accent-text);
  background: var(--accent-text);
  color: var(--accent);
}

.choice[aria-pressed='true'] .tick::after {
  content: '✓';
}

.choice[aria-pressed='true'] .key {
  border-color: currentColor;
  color: inherit;
}

/* The question takes the focus when it opens; it needs no ring. */
.prompt:focus {
  outline: none;
}

/* After an answer (markChoices): ✓ and ✗ as well as colour; a right choice not picked is dashed. */
.choice .mark {
  margin-left: auto;
  font-size: 20px;
  font-weight: 700;
}

.choice.right,
.choice.missed,
.choice.wrong {
  border-width: 2px;
}

.choice.right,
.choice.missed {
  border-color: var(--good);
}

.choice.missed {
  border-style: dashed;
}

.choice.wrong {
  border-color: var(--bad);
}

.choice.right .mark,
.choice.missed .mark {
  color: var(--good);
}

.choice.wrong .mark {
  color: var(--bad);
}

/* The choices are disabled once answered; the marked ones stay at full strength. */
.choice:disabled:is(.right, .missed, .wrong) {
  opacity: 1;
}

/* In a "pick all" question, ✓ and ✗ now say what was picked: drop the pressed fill, which would hide them. */
.choice[aria-pressed]:is(.right, .missed, .wrong) {
  background: var(--bg);
  color: var(--text);
  outline: none;
}

/* ...but the ticked box still shows which choices were picked. */
.choice[aria-pressed='true']:is(.right, .missed, .wrong) .tick {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.typed {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Keys the phone's number pad lacks (/ − space), above the answer box so the
   keyboard never covers them. Only in touch mode (main.ts). */
.answer-keys {
  display: none;
  flex-basis: 100%;
  gap: 8px;
}

.quiz.touch-mode .answer-keys {
  display: flex;
}

.answer-keys button {
  min-width: 52px;
  min-height: 40px;
  font-family: var(--math-font);
  font-size: 18px;
}

/* min-width 0: the box shrinks on a phone, so Check stays beside it, not on a line of its own. */
.typed input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 18px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.figure {
  margin: 0 0 12px;
  padding: 6px;
  border-radius: 10px;
  background: var(--bg);
}

.figure-svg {
  display: block;
  width: 100%;
  max-width: 340px;
  height: auto;
  margin: 0 auto;
}

.figure-svg .fig-text {
  fill: var(--text);
  font-family: var(--math-font);
  font-size: 15px;
}

.figure-svg .fig-small {
  font-size: 12px;
  fill: var(--muted);
}

/* A caption that a curve may cross: outlined in the background colour. */
.figure-svg .fig-halo {
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 5px;
  stroke-linejoin: round;
}

.figure-svg .fig-big {
  font-size: 24px;
  font-weight: 700;
}

.figure-svg .fig-axis {
  stroke: var(--muted);
  stroke-width: 1.2;
}

.figure-svg .fig-arrow {
  fill: var(--muted);
}

.figure-svg .fig-line,
.figure-svg .fig-ray,
.figure-svg .fig-shape {
  fill: none;
  stroke: var(--text);
  stroke-width: 2;
  stroke-linejoin: round;
}

.figure-svg .fig-faint {
  fill: none;
  stroke: var(--border);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
}

.figure-svg .fig-angle {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
}

.figure-svg .fig-arrow-angle {
  fill: var(--accent);
}

.figure-svg .fig-dot {
  fill: var(--accent);
  stroke: var(--panel);
  stroke-width: 2;
}

.figure-svg .fig-cos {
  fill: none;
  stroke: var(--fig-1);
  stroke-width: 4;
  stroke-linecap: round;
}

.figure-svg .fig-sin {
  fill: none;
  stroke: var(--fig-2);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 8 5;
}

.figure-svg .fig-filled {
  fill: var(--fig-1);
  stroke: var(--text);
  stroke-width: 1.5;
}

.figure-svg .fig-empty {
  fill: none;
  stroke: var(--text);
  stroke-width: 1.5;
}

.figure-svg .fig-cos-text {
  fill: var(--fig-1);
  font-weight: 600;
}

.figure-svg .fig-sin-text {
  fill: var(--fig-2);
  font-weight: 600;
}

#quiz-check {
  margin-top: 10px;
}

.feedback {
  min-height: 1.45em;
  font-weight: 600;
}

.feedback.good {
  color: var(--good);
}

.feedback.bad {
  color: var(--bad);
}

#quiz-wait {
  width: 100%;
}

.quiz-foot {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

/* ---- results ------------------------------------------------------------------- */

.results {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 18px;
  font-variant-numeric: tabular-nums;
}

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

.results dd {
  margin: 0;
  font-weight: 600;
}

/* ---- questions to review (finish screen) ---------------------------------------- */

.review {
  margin-top: 24px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.review h3 {
  margin: 0;
  font-size: 15px;
}

.review-list {
  display: grid;
  gap: 14px;
  margin: 12px 0 0;
  padding-left: 1.6em;
}

.review-list .prompt {
  font-size: 17px;
  margin: 0 0 6px;
}

.review-list .figure {
  width: fit-content;
  margin-bottom: 6px;
}

.review-list .figure svg {
  width: 220px;
  margin: 0;
}

.review-answer {
  margin: 2px 0 0;
}

.review-answer .good {
  color: var(--good);
  font-weight: 600;
}

.review-answer .bad {
  color: var(--bad);
}

@media (max-width: 720px) {
  main.climb-main {
    padding: 8px 16px 16px;
  }
  .climb .bar {
    padding: 10px 16px;
  }
  .game {
    height: calc(100vh - 150px);
  }
  #hud-answer {
    margin-left: 0;
  }
}

/* Join a class game, at the top of the start screen. */
.class-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

.class-box h2 {
  margin-top: 0;
}

.class-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px 12px;
}

.class-box .field {
  display: grid;
  gap: 4px;
  font-weight: 600;
}

.class-box input,
.class-box select {
  font: inherit;
  font-weight: 400;
  max-width: 100%;
}

#class-code {
  width: 8ch;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* Class mode: the teacher's room decides the world, the questions and the
   difficulty, so the start screen shows only the join box and the climbers. */
.start.class-mode .solo-only {
  display: none;
}

/* In a class game, once joined: the waiting line stands out. */
#class-status.joined {
  padding: 8px 12px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  font-size: 17px;
  font-weight: 600;
  color: inherit;
}

/* Joined: the climber is fixed until Leave. */
.climbers.locked .climber:not([aria-pressed='true']) {
  opacity: 0.45;
  cursor: not-allowed;
}

/* The join guide sits under the join box, a little apart. */
.guide-join {
  margin: 8px 0 0;
}

.teacher-link {
  margin: 6px 0 0;
}

/* Class mode (a join link) is for pupils: the teacher's link would only distract. */
.start.class-mode .teacher-link {
  display: none;
}
