:root {
  color-scheme: dark;
  --route-aspect-width: 16;
  --route-aspect-height: 9;
  --route-turquoise: #46c9d4;
  --route-yellow: #ffe43d;
  --route-navy: #082a43;
  --route-viewport-width: 100vw;
  --route-viewport-height: 100dvh;
  --route-viewport-left: 0px;
  --route-viewport-top: 0px;
  --route-game-width: min(100vw, calc(100dvh * 16 / 9));
  --route-game-height: min(100dvh, calc(100vw * 9 / 16));
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  height: var(--route-viewport-height);
  margin: 0;
  overflow: hidden;
  background: var(--route-navy);
  overscroll-behavior: none;
}

body {
  font-family: Arial, Helvetica, sans-serif;
}

.route-mobile body {
  position: fixed;
  top: var(--route-viewport-top);
  left: var(--route-viewport-left);
  width: var(--route-viewport-width);
  height: var(--route-viewport-height);
  min-height: var(--route-viewport-height);
}

#route-page {
  display: grid;
  width: 100%;
  height: 100%;
  height: var(--route-viewport-height);
  place-items: center;
  background: radial-gradient(circle at center, #18758b 0%, var(--route-navy) 78%);
}

#unity-container {
  position: relative;
  width: var(--route-game-width);
  height: var(--route-game-height);
  aspect-ratio: var(--route-aspect-width) / var(--route-aspect-height);
  overflow: hidden;
  background: #231f20;
  box-shadow: 0 0 32px rgba(0, 0, 0, 0.38);
}

/* Desktop always preserves the complete 16:9 game frame. This prevents a
   browser fullscreen or a short Unity Play frame from cropping the question,
   speedometer, answer panel, or lower controls. */
html:not(.route-mobile) #route-page {
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 8px;
}

html:not(.route-mobile) #unity-container {
  width: var(--route-game-width);
  height: var(--route-game-height);
}

/* Pin the phone page to the live visual viewport. The phone-specific Unity
   layout understands the live aspect ratio, so it can fill the complete safe
   viewport without dark side bars or cropped buttons. */
.route-mobile #route-page {
  position: fixed;
  top: var(--route-viewport-top);
  left: var(--route-viewport-left);
  grid-template-rows: 1fr;
  gap: 0;
  width: var(--route-viewport-width);
  height: var(--route-viewport-height);
  padding: env(safe-area-inset-top, 0px)
    env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
  place-items: center;
}

.route-mobile #unity-container {
  position: relative;
  width: var(--route-game-width);
  height: var(--route-game-height);
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: auto;
  box-shadow: none;
}

.route-mobile #unity-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}

#unity-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #231f20;
  outline: none;
  touch-action: none;
  pointer-events: auto;
}

#unity-loading-bar {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  background: linear-gradient(155deg, rgba(8, 42, 67, 0.96), rgba(70, 201, 212, 0.9));
}

#route-loading-title {
  font-size: clamp(2rem, 6vw, 5.25rem);
  font-weight: 900;
  letter-spacing: -0.05em;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
}

#route-loading-subtitle {
  margin-top: 0.35rem;
  font-size: clamp(0.9rem, 1.8vw, 1.5rem);
  font-weight: 700;
}

#unity-progress-bar-empty {
  width: min(50%, 560px);
  height: 18px;
  margin-top: 1.5rem;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.32);
  border: 2px solid white;
  border-radius: 999px;
}

#unity-progress-bar-full {
  width: 0;
  height: 100%;
  background: var(--route-yellow);
  border-radius: inherit;
  transition: width 120ms linear;
}

#unity-fullscreen-button {
  position: relative;
  z-index: 35;
  display: block;
  width: auto;
  min-width: 148px;
  height: 46px;
  padding: 0 14px;
  color: var(--route-navy);
  font-size: 17px;
  font-weight: 900;
  line-height: normal;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.88);
  border: 2px solid var(--route-navy);
  border-radius: 9px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.24);
}

#unity-fullscreen-button:hover,
#unity-fullscreen-button:focus-visible {
  background: var(--route-yellow);
}

#route-mobile-fullscreen-launch {
  position: fixed;
  right: max(14px, env(safe-area-inset-right, 0px));
  bottom: max(14px, env(safe-area-inset-bottom, 0px));
  z-index: 60;
  display: none;
  min-width: 190px;
  min-height: 52px;
  padding: 10px 18px;
  color: var(--route-navy);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  touch-action: manipulation;
  background: var(--route-yellow);
  border: 3px solid white;
  border-radius: 12px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5);
}

#route-mobile-fullscreen-launch:active {
  transform: translateY(1px);
}

.route-mobile #unity-fullscreen-button {
  display: none !important;
}

#route-page:fullscreen,
#route-page:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  height: var(--route-viewport-height);
  background: var(--route-navy);
}

.route-mobile:fullscreen body,
.route-mobile:-webkit-full-screen body {
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
}

#unity-warning {
  position: absolute;
  top: 12px;
  left: 50%;
  z-index: 10;
  display: none;
  width: min(92%, 760px);
  transform: translateX(-50%);
  pointer-events: none;
}

.route-warning,
.route-error {
  margin-bottom: 8px;
  padding: 10px 14px;
  color: var(--route-navy);
  font-weight: 700;
  text-align: center;
  background: var(--route-yellow);
  border: 2px solid var(--route-navy);
  border-radius: 8px;
}

.route-error {
  color: white;
  background: #b51f2e;
}

@supports (-webkit-touch-callout: none) {
  html,
  body,
  #route-page {
    min-height: -webkit-fill-available;
  }
}
