/* 99 Knights and a Forest — storybook-heraldic UI.
   Palette: parchment, ink brown, banner red, royal blue, meadow green, trumpet gold. */

:root {
  --parchment: #fbf3df;
  --ink: #3b2e1e;
  --banner-red: #e2574c;
  --royal-blue: #3e6fb0;
  --meadow: #7dbb57;
  --gold: #f2b63c;
  --display: "Grandstander", "Comic Sans MS", cursive;
  --body: "Nunito", "Avenir Next", "Trebuchet MS", sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
  font-family: var(--body);
  color: var(--ink);
  background: #9fd8ef;
}

#game {
  position: fixed;
  inset: 0;
  touch-action: none;
}
#game canvas {
  display: block;
}

/* ---- Pennant counter: the signature element ---- */

#pennant {
  position: fixed;
  top: 0;
  left: 50%;
  translate: -50% 0;
  transform-origin: top center;
  background: var(--banner-red);
  color: var(--parchment);
  padding: 14px 30px 34px;
  text-align: center;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 74%, 0 100%);
  border-left: 4px solid var(--gold);
  border-right: 4px solid var(--gold);
  box-shadow: 0 4px 0 rgb(0 0 0 / 12%);
  z-index: 5;
  pointer-events: none;
}
#pennant #count {
  display: block;
  font-family: var(--display);
  font-weight: 800;
  font-size: 44px;
  line-height: 1;
  text-shadow: 0 3px 0 rgb(0 0 0 / 18%);
}
#pennant .of {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
#pennant.swing {
  animation: swing 0.7s ease-out;
}
@keyframes swing {
  20% { transform: rotate(4deg); }
  50% { transform: rotate(-3deg); }
  80% { transform: rotate(1.5deg); }
  100% { transform: rotate(0); }
}

/* ---- Magic compass ---- */

#compass {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: var(--parchment);
  border: 4px solid var(--ink);
  box-shadow: 0 4px 0 rgb(0 0 0 / 15%);
  z-index: 5;
  pointer-events: none;
}
#needle {
  position: absolute;
  inset: 0;
  transition: transform 0.25s ease-out, opacity 0.4s;
}
#needle::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 7px;
  translate: -50% 0;
  border: 9px solid transparent;
  border-bottom: 26px solid var(--gold);
  filter: drop-shadow(0 1px 0 rgb(0 0 0 / 25%));
}
#compass .compass-label {
  position: absolute;
  bottom: 8px;
  width: 100%;
  text-align: center;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink);
}

/* ---- Toast + hint ---- */

#toast {
  position: fixed;
  top: 110px;
  left: 50%;
  translate: -50% 0;
  background: var(--parchment);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 10px 22px;
  font-weight: 800;
  font-size: 18px;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 5;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show {
  opacity: 1;
}

#hint {
  position: fixed;
  bottom: 18px;
  left: 50%;
  translate: -50% 0;
  background: rgb(59 46 30 / 72%);
  color: var(--parchment);
  border-radius: 12px;
  padding: 8px 18px;
  font-size: 15px;
  text-align: center;
  z-index: 5;
  transition: opacity 0.8s;
  pointer-events: none;
  max-width: 92vw;
}
#hint.hidden {
  opacity: 0;
}

/* ---- Overlays (title, win, no-webgl) ---- */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 24px;
  background: linear-gradient(#8fd0ec, #bfe6f4 55%, var(--meadow) 55.3%);
  z-index: 10;
  text-align: center;
}
.overlay.hidden {
  display: none;
}

/* The win screen celebrates OVER the world: parade and fireworks show through. */
#win-overlay {
  background: rgb(143 208 236 / 20%);
  justify-content: flex-start;
  padding-top: 7vh;
  gap: 18px;
}

.banner {
  background: var(--royal-blue);
  color: var(--parchment);
  padding: 26px 54px 40px;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%);
  border-left: 6px solid var(--gold);
  border-right: 6px solid var(--gold);
  box-shadow: 0 6px 0 rgb(0 0 0 / 12%);
}
.banner.gold {
  background: var(--gold);
  color: var(--ink);
}
.banner h1 {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(34px, 7vw, 64px);
  line-height: 1.05;
  text-shadow: 0 4px 0 rgb(0 0 0 / 15%);
}

.story {
  font-size: clamp(16px, 2.4vw, 20px);
  font-weight: 600;
  line-height: 1.55;
  background: var(--parchment);
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 16px 26px;
  max-width: 620px;
  box-shadow: 0 4px 0 rgb(0 0 0 / 12%);
}

.sign-btn {
  font-family: var(--display);
  font-weight: 800;
  font-size: 24px;
  color: var(--parchment);
  background: var(--banner-red);
  border: 4px solid var(--ink);
  border-radius: 14px;
  padding: 14px 38px;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s;
}
.sign-btn:hover {
  transform: translateY(2px);
  box-shadow: 0 4px 0 var(--ink);
}
.sign-btn:active {
  transform: translateY(6px);
  box-shadow: 0 0 0 var(--ink);
}
.sign-btn:focus-visible {
  outline: 4px solid var(--gold);
  outline-offset: 2px;
}
.sign-btn.secondary {
  background: var(--parchment);
  color: var(--ink);
  font-size: 17px;
  padding: 10px 24px;
}

/* ---- Virtual joystick ---- */

.joystick-base {
  position: fixed;
  width: 120px;
  height: 120px;
  translate: -50% -50%;
  border-radius: 50%;
  border: 3px solid rgb(251 243 223 / 70%);
  background: rgb(59 46 30 / 25%);
  z-index: 6;
  pointer-events: none;
}
.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--parchment);
  border: 3px solid var(--ink);
  transform: translate(-50%, -50%);
}

@media (prefers-reduced-motion: reduce) {
  #pennant.swing {
    animation: none;
  }
  #needle {
    transition: none;
  }
}
