/* ==========================================================================
   Lane Hopper - UI styling
   The WebGL canvas fills the viewport; every menu and HUD element is an
   HTML overlay stacked above it.
   ========================================================================== */

:root {
  --ink: #12161f;
  --ink-soft: #3d4657;
  --paper: #fdfdf8;
  --paper-dim: rgba(253, 253, 248, 0.86);
  --accent: #f2803c;
  --accent-dark: #cf6224;
  --accent-ink: #2a1607;
  --good: #2f8f4a;
  /* Matches COLORS.shield in the palette, so the HUD reads as the same object
     the player sees in the world. */
  --shield: #4bb6e8;
  --shield-dark: #1d78ab;
  --focus: #1668ff;
  --scrim: rgba(12, 22, 34, 0.62);
  --panel-radius: 20px;
  --shadow-panel: 0 18px 40px rgba(8, 16, 28, 0.32);
  --shadow-button: 0 4px 0 rgba(8, 16, 28, 0.22);
  --font-ui: 'Trebuchet MS', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden; /* the canvas must never introduce page scrolling */
  background: #9fd8ef;
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

body {
  overscroll-behavior: none;
  touch-action: manipulation;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#scene {
  position: absolute;
  inset: 0;
}

#scene canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Elements hidden through the `hidden` attribute must stay hidden even though
   the overlay classes set `display: flex`. */
[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------------------
   Overlays
   -------------------------------------------------------------------------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
}

.overlay--solid {
  background: radial-gradient(circle at 50% 22%, rgba(255, 255, 255, 0.45), rgba(24, 46, 66, 0.72));
  backdrop-filter: blur(2px);
}

.overlay--scrim {
  background: var(--scrim);
  backdrop-filter: blur(3px);
}

.panel {
  width: min(560px, 100%);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 28px 32px 24px;
  border-radius: var(--panel-radius);
  background: var(--paper);
  box-shadow: var(--shadow-panel);
  text-align: center;
}

.panel--narrow {
  width: min(420px, 100%);
}

.panel__eyebrow {
  margin: 0 0 2px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-dark);
}

.panel__title {
  margin: 0 0 10px;
  font-size: 1.75rem;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.panel__title--hero {
  font-size: clamp(2.3rem, 6vw, 3.1rem);
  letter-spacing: -0.03em;
}

.panel__title-accent {
  color: var(--accent-dark);
}

.panel__body {
  margin: 0 0 16px;
  font-size: 0.98rem;
  line-height: 1.5;
  color: var(--ink-soft);
}

.panel__body--muted {
  font-size: 0.9rem;
}

.panel__actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

.panel__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 2px solid rgba(18, 22, 31, 0.1);
}

.panel__meta {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.panel__meta strong {
  color: var(--ink);
  font-size: 1.05rem;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 11px 20px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-button);
  transition: transform 0.08s ease, background-color 0.15s ease, box-shadow 0.08s ease;
}

.button:hover {
  background: #f1f2ea;
}

.button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(8, 16, 28, 0.22);
}

.button--primary {
  background: var(--accent);
  border-color: var(--accent-ink);
  color: var(--accent-ink);
  font-size: 1.08rem;
}

.button--primary:hover {
  background: #ff9450;
}

.button--ghost {
  background: transparent;
  border-color: rgba(18, 22, 31, 0.35);
  box-shadow: none;
  font-weight: 600;
}

.button--ghost:hover {
  background: rgba(18, 22, 31, 0.06);
}

.button--compact {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.85rem;
}

.button__hint {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.72;
}

.button__icon {
  font-size: 0.95em;
  line-height: 1;
}

/* Visible focus ring for keyboard users on every interactive control. */
.button:focus-visible,
.button:focus {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.button:focus:not(:focus-visible) {
  outline: none;
}

/* --------------------------------------------------------------------------
   Control legend
   -------------------------------------------------------------------------- */

.controls {
  display: grid;
  gap: 8px;
  margin: 20px 0 0;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(18, 22, 31, 0.05);
  text-align: left;
}

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

.controls__action {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.controls__keys {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.controls__or {
  font-size: 0.72rem;
  color: var(--ink-soft);
  padding: 0 2px;
}

kbd {
  display: inline-block;
  min-width: 26px;
  padding: 3px 6px;
  border: 2px solid rgba(18, 22, 31, 0.55);
  border-bottom-width: 3px;
  border-radius: 6px;
  background: var(--paper);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  color: var(--ink);
}

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

.hud {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  pointer-events: none; /* keeps the route ahead clickable/visible */
}

.hud__scores,
.hud__actions {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.hud__actions {
  flex-direction: column;
  align-items: flex-end;
}

.hud__score {
  min-width: 78px;
  padding: 8px 14px 9px;
  border-radius: 14px;
  background: var(--paper-dim);
  box-shadow: 0 6px 16px rgba(8, 16, 28, 0.2);
  text-align: center;
}

.hud__score--secondary {
  background: rgba(253, 253, 248, 0.7);
}

.hud__label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.hud__value {
  display: block;
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.hud__score--secondary .hud__value {
  font-size: 1.25rem;
}

/* Shield indicator: charge pips, a status line in words and a countdown bar. */

.hud__score--shield {
  min-width: 112px;
  background: rgba(253, 253, 248, 0.7);
}

.hud__score--shield .hud__label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.hud__score--shield .hud__label kbd {
  min-width: 0;
  padding: 0 4px;
  font-size: 0.62rem;
  border-width: 1px;
  border-bottom-width: 2px;
  letter-spacing: normal;
}

.hud__pips {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin: 5px 0 3px;
}

.hud__pip {
  width: 14px;
  height: 14px;
  /* An octagon, echoing the shape of the token in the world. */
  clip-path: polygon(
    30% 0%,
    70% 0%,
    100% 30%,
    100% 70%,
    70% 100%,
    30% 100%,
    0% 70%,
    0% 30%
  );
  background: rgba(18, 22, 31, 0.16);
  box-shadow: inset 0 0 0 2px rgba(18, 22, 31, 0.28);
}

/* A held charge is filled in as well as recoloured, so the difference does not
   depend on being able to tell the two colours apart. */
.hud__pip--filled {
  background: var(--shield);
  box-shadow: inset 0 0 0 2px var(--shield-dark);
}

.hud__shield-status {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

[data-shield-state='active'] .hud__shield-status {
  color: var(--shield-dark);
}

.hud__meter {
  display: block;
  height: 4px;
  margin-top: 5px;
  border-radius: 999px;
  background: rgba(18, 22, 31, 0.16);
  overflow: hidden;
}

.hud__meter-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--shield-dark);
  /* Scaled from the left edge, so the width comes from one cheap transform. */
  transform-origin: left center;
  transform: scaleX(0);
}

.button--icon {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 0.82rem;
  border-radius: 10px;
  background: var(--paper-dim);
  box-shadow: 0 3px 0 rgba(8, 16, 28, 0.18);
}

.button--icon .button__label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.button--icon kbd {
  min-width: 0;
  padding: 1px 4px;
  font-size: 0.66rem;
  border-width: 1px;
  border-bottom-width: 2px;
}

/* --------------------------------------------------------------------------
   Results / badges
   -------------------------------------------------------------------------- */

.results {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 16px 0 0;
}

.results__row {
  min-width: 108px;
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(18, 22, 31, 0.06);
}

.results__label {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.results__value {
  margin: 2px 0 0;
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 auto;
  padding: 6px 14px;
  border: 2px solid var(--good);
  border-radius: 999px;
  background: rgba(47, 143, 74, 0.12);
  color: #1d6b34;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

/* --------------------------------------------------------------------------
   Debug panel (development only)
   -------------------------------------------------------------------------- */

.debug {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 30;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(12, 22, 34, 0.82);
  color: #dfe9f5;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.55;
  white-space: pre;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Narrow / short viewports
   -------------------------------------------------------------------------- */

@media (max-width: 640px), (max-height: 560px) {
  .panel {
    padding: 20px 20px 18px;
  }

  .panel__title--hero {
    font-size: clamp(1.9rem, 9vw, 2.4rem);
  }

  .controls {
    margin-top: 14px;
    padding: 10px 12px;
  }

  .hud__value {
    font-size: 1.35rem;
  }
}

/* --------------------------------------------------------------------------
   Reduced motion
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .button {
    transition: none;
  }

  .button:active {
    transform: none;
  }

  .overlay--solid,
  .overlay--scrim {
    backdrop-filter: none;
  }
}
