* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  background: #8ec8f0;
  color: #fff9ec;
  /* Stop the page panning/zooming under a thumb on touch devices. */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

canvas {
  display: block;
}

.hidden {
  display: none !important;
}

/* --- Mobile joystick --- hidden on desktop; shown when JS adds body.touch. */
#joystick {
  position: fixed;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 2px solid rgba(255, 255, 255, 0.45);
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 8;
}

#joyknob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  transform: translate(-50%, -50%);
}

/* --- HUD --- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  padding: 16px clamp(14px, 3vw, 32px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-shadow: 0 2px 8px rgba(12, 24, 48, 0.55);
}

#top {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#clock {
  font-size: clamp(1.5rem, 4.6vw, 2.4rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  padding: 2px 14px;
  border-radius: 14px;
  background: rgba(18, 38, 72, 0.42);
}

#clock.late {
  background: rgba(214, 48, 48, 0.55);
  animation: pulse 700ms ease-in-out infinite;
}

#period {
  font-size: clamp(0.85rem, 2.4vw, 1.05rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(18, 38, 72, 0.42);
}

#warnings {
  font-size: clamp(0.8rem, 2.2vw, 1rem);
  font-weight: 800;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 176, 32, 0.32);
  box-shadow: inset 0 0 0 1px rgba(255, 214, 130, 0.6);
}

#stars {
  margin-left: auto;
  font-size: clamp(1rem, 3vw, 1.4rem);
  font-weight: 800;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(18, 38, 72, 0.42);
}

#stars.pop {
  animation: pop 420ms ease-out;
}

/* The objective line is the thing a young player actually steers by: what to
   do, an arrow pointing at it, and how far away it is. */
#objective {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  align-self: flex-start;
  padding: 9px 18px 9px 14px;
  border-radius: 999px;
  background: rgba(18, 38, 72, 0.42);
  font-size: clamp(0.9rem, 2.6vw, 1.15rem);
  font-weight: 700;
}

#compass {
  display: inline-block;
  font-size: 1.3em;
  color: #ffd166;
  /* The glyph points right at rest; JS rotates from "up", so start it there. */
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

#distance {
  font-variant-numeric: tabular-nums;
  opacity: 0.75;
  font-weight: 600;
}

#task {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-self: flex-start;
  font-size: clamp(0.85rem, 2.4vw, 1.05rem);
  font-weight: 700;
}

#task .item {
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(18, 38, 72, 0.42);
}

#task .item.done {
  background: rgba(63, 191, 95, 0.5);
  text-decoration: line-through;
  opacity: 0.85;
}

#message {
  margin-top: auto;
  align-self: center;
  max-width: 44ch;
  text-align: center;
  font-size: clamp(0.95rem, 2.6vw, 1.2rem);
  font-weight: 700;
  padding: 8px 18px;
  border-radius: 14px;
  background: rgba(18, 38, 72, 0.4);
  opacity: 0;
  transition: opacity 180ms ease;
}

#message.show {
  opacity: 1;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

/* --- Lesson / between-periods card --- */
#panel {
  position: fixed;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 22, 44, 0.55);
  backdrop-filter: blur(3px);
}

#card {
  width: min(560px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  text-align: center;
  padding: clamp(20px, 4vw, 34px);
  border-radius: 22px;
  background: linear-gradient(160deg, #fffaf0, #ffe9c7);
  color: #1d2b44;
  box-shadow: 0 26px 60px rgba(8, 18, 38, 0.45);
}

#card-kicker {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #d4791f;
}

#card h2 {
  margin: 4px 0 10px;
  font-size: clamp(1.8rem, 6vw, 2.6rem);
}

#card-text {
  margin: 0 0 16px;
  font-size: clamp(1rem, 3vw, 1.2rem);
  line-height: 1.5;
  color: #33405c;
}

#card-result {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(63, 191, 95, 0.18);
  font-weight: 800;
  font-size: clamp(1rem, 3vw, 1.15rem);
}

#card-result.missed {
  background: rgba(214, 48, 48, 0.14);
}

#options {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

#options button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 16px 18px;
  border: 3px solid #f0c98a;
  border-radius: 16px;
  background: #fff;
  color: #1d2b44;
  font: inherit;
  font-size: clamp(1.1rem, 3.4vw, 1.4rem);
  font-weight: 800;
  cursor: pointer;
  transition: transform 110ms ease, border-color 110ms ease;
}

#options button:hover {
  transform: translateY(-2px);
  border-color: #f0a03a;
}

#options button .key {
  font-size: 0.75em;
  font-weight: 800;
  color: #9aa3b0;
}

#options button .swatch {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.15);
}

#options button.right {
  border-color: #3fbf5f;
  background: #e6faea;
}

#options button.wrong {
  border-color: #d63030;
  background: #ffe9e9;
  animation: shake 260ms ease;
}

#continue {
  padding: 14px 34px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(140deg, #ffb703, #fb8500);
  color: #2b1a02;
  font: inherit;
  font-size: clamp(1.05rem, 3.2vw, 1.3rem);
  font-weight: 900;
  letter-spacing: 0.03em;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(251, 133, 0, 0.35);
}

#continue:hover {
  transform: translateY(-1px);
}

#card-hint {
  margin: 12px 0 0;
  font-size: 0.9rem;
  font-weight: 700;
  color: #7c8699;
}

/* --- Overlay --- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 30%, #4a9fe0, #123a63 72%);
  cursor: pointer;
}

#overlay h1 {
  font-size: clamp(2.6rem, 11vw, 5.5rem);
  margin: 0 0 6px;
  letter-spacing: 0.01em;
}

#overlay h1 span {
  color: #ffd166;
}

#overlay-text {
  font-size: clamp(1.1rem, 3.6vw, 1.5rem);
  margin: 0 0 18px;
  color: #ffd166;
  font-weight: 800;
}

#overlay-score {
  margin: 0 auto 18px;
  padding: 14px 22px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.12);
  font-size: clamp(1rem, 3vw, 1.25rem);
  font-weight: 700;
  line-height: 1.6;
  max-width: 40ch;
}

.hint {
  margin: 6px auto;
  color: #d7e7f7;
  font-size: clamp(0.85rem, 2.4vw, 1rem);
  max-width: 54ch;
  line-height: 1.5;
}

.hint b {
  color: #fff9ec;
}

/* --- Crosshair --- */
#crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255, 255, 255, 0.55);
  font-size: 20px;
  pointer-events: none;
}
