/* Race to School — bright, chunky, tablet-first. */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --navy: #1f5fa4;
  --crimson: #ef5b5b;
  --gold: #ffcf3f;
  --green: #4cbb6c;
  --green-dark: #2f8f4c;
  --cream: #fff8ec;
  --ink: #23324a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(#8fd4ff 0%, #bfe7ff 45%, #ffe9b8 100%);
  color: var(--ink);
  font-family: "Baloo 2", "Fredoka", "Quicksand", "Trebuchet MS", system-ui, sans-serif;
  font-weight: 700;
  touch-action: manipulation;
  user-select: none;
}

.screen { position: fixed; inset: 0; display: none; }
.screen.show { display: flex; flex-direction: column; }

/* ------------------------------ home ------------------------------ */
.home-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: calc(var(--sat) + 34px) 18px calc(var(--sab) + 28px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: stretch;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 14px; width: 100%; max-width: 560px; }
.brand-words { min-width: 0; }
.brand-mascot { width: 132px; height: 132px; flex: 0 0 auto; filter: drop-shadow(0 5px 4px rgba(20,50,90,.22)); }
.mascot-img { width: 100%; height: 100%; display: block; object-fit: contain; }
.brand-kicker { margin: 0; font-size: 17px; color: var(--navy); }
.brand-name { margin: -2px 0 0; font-size: clamp(38px,11vw,56px); line-height: .95; color: #fff; -webkit-text-stroke: 5px var(--navy); paint-order: stroke fill; text-shadow: 0 5px 0 var(--navy); letter-spacing: 0; }
.brand-sub { margin: 6px 0 0; font-size: 14px; color: #4b6b52; }
.game-title { width: 100%; max-width: 560px; margin: 2px 0 -4px; color: var(--navy); font-size: clamp(28px,7vw,42px); line-height: 1; text-align: center; text-shadow: 0 3px 0 #fff; letter-spacing: 0; }

.card {
  background: var(--cream);
  border: 4px solid #fff;
  border-radius: 22px;
  padding: 16px;
  box-shadow: 0 8px 0 rgba(31,95,164,.18), 0 14px 26px rgba(20,50,90,.16);
}
.card-title { margin: 0 0 10px; font-size: 20px; color: var(--ink); }
.road-title { margin-top: 14px; }

.name-input {
  width: 100%;
  font: inherit;
  font-size: 24px;
  padding: 12px;
  border-radius: 16px;
  border: 4px solid #ffd98a;
  background: #fff;
  text-align: center;
}
.name-input:focus { outline: none; border-color: var(--navy); }

.rides, .levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.ride, .level {
  font: inherit;
  cursor: pointer;
  background: #fff;
  border: 4px solid #d8e6f5;
  border-radius: 18px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--ink);
}
.ride img { height: 62px; width: auto; image-rendering: auto; }
.ride span, .level-name { font-size: 14px; }
.level-note { font-size: 12px; color: #5b6b86; }
.ride[aria-checked="true"], .level[aria-checked="true"] {
  border-color: var(--gold);
  background: #fffdf3;
  box-shadow: 0 0 0 4px rgba(255,207,63,.35);
}
.level-dots { display: flex; gap: 4px; }
.level-dots i { width: 8px; height: 8px; border-radius: 50%; background: #d7e3f5; }
.level-dots i.on { background: var(--gold); }

.play-btn {
  font: inherit;
  font-size: 24px;
  cursor: pointer;
  border: 0;
  border-radius: 26px;
  min-height: 76px;
  padding: 14px;
  color: #fff;
  background: linear-gradient(#57d47c,#3aa85c);
  box-shadow: 0 8px 0 var(--green-dark), 0 16px 26px rgba(20,80,40,.28);
  border: 4px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.play-btn.small { font-size: 18px; padding: 10px 18px; }
.play-btn:disabled { opacity: .45; box-shadow: none; }
.play-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 3px 0 #001a45; }
.play-tri { width: 0; height: 0; border-left: 16px solid #fff; border-top: 10px solid transparent; border-bottom: 10px solid transparent; }

.home-toggles { display: flex; gap: 8px; justify-content: center; }
.toggle {
  font: inherit; cursor: pointer; font-size: 14px;
  border-radius: 999px; padding: 8px 16px;
  border: 3px solid #d7e3f5; background: #fff; color: #8795ad;
}
.toggle[aria-pressed="true"] { border-color: var(--navy); color: var(--navy); background: #e6efff; }

.voice-pick { display: flex; gap: 8px; align-items: center; justify-content: center; font-size: 14px; }
.voice-pick select, .voice-pick button {
  font: inherit; font-size: 14px; padding: 6px 10px; border-radius: 10px;
  border: 3px solid #d7e3f5; background: #fff; color: var(--ink);
}
.voice-pick button { cursor: pointer; }

.star-line { margin: 0; text-align: center; font-size: 14px; color: var(--crimson); min-height: 18px; white-space: pre-line; }
.footer-note { margin: 0; text-align: center; font-size: 12px; color: #8795ad; }

/* ------------------------------ game ------------------------------ */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--sat) + 6px) 10px 6px;
  background: var(--navy); color: #fff;
}
.tb-btn {
  font: inherit; font-size: 18px; cursor: pointer; line-height: 1;
  width: 38px; height: 38px; border-radius: 12px;
  border: 0; background: rgba(255,255,255,.16); color: #fff;
}
.tb-btn[aria-pressed="false"] { opacity: .45; }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.clock { font-size: 24px; letter-spacing: .04em; }
.best { font-size: 12px; opacity: .85; }

.stage-wrap { position: relative; flex: 1; min-height: 0; }
#stage { display: block; width: 100%; height: 100%; }

.tap-hint {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  background: rgba(0,40,104,.86); color: #fff; padding: 8px 16px;
  border-radius: 999px; font-size: 15px; white-space: nowrap;
}

.meter-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: #dbe7fa; font-size: 12px; color: var(--navy); }
.meter { position: relative; flex: 1; height: 14px; border-radius: 999px; background: #fff; border: 2px solid #b9cdea; overflow: visible; }
.meter-fill { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, var(--gold), var(--crimson)); }
.meter-bus { position: absolute; top: -6px; left: 0; transform: translateX(-50%); font-size: 16px; }

.controls {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px;
  padding: 8px 10px calc(var(--sab) + 10px);
  background: #eef6ff;
}
.ctl {
  font: inherit; font-size: 26px; cursor: pointer;
  border: 0; border-radius: 16px; padding: 14px 0;
  background: var(--navy); color: #fff; box-shadow: 0 5px 0 #001a45;
}
.ctl.brake { background: var(--crimson); box-shadow: 0 5px 0 #7d0620; font-size: 18px; }
.ctl:active { transform: translateY(3px); box-shadow: none; }

/* ---------------------------- overlays ---------------------------- */
.overlay {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10,22,46,.72); padding: 16px;
}
.overlay[hidden] { display: none; }
.fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.win-card, .gate-card {
  position: relative;
  background: #fff; border-radius: 22px; padding: 20px;
  width: min(460px, 100%); text-align: center;
  box-shadow: 0 12px 0 rgba(0,0,0,.18);
}
.win-burst { font-size: 54px; }
.win-card h2 { margin: 6px 0; color: var(--navy); font-size: 26px; }
.win-card p { margin: 4px 0; color: #5b6b86; }
.win-time { color: var(--crimson) !important; font-size: 18px; }
.win-btns { margin-top: 14px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.ghost-btn {
  font: inherit; cursor: pointer; font-size: 16px;
  border-radius: 14px; padding: 10px 18px;
  border: 3px solid #d7e3f5; background: #fff; color: var(--navy);
}

.gate-title { margin: 0 0 6px; color: var(--navy); font-size: 22px; }
.gate-pic { font-size: 54px; line-height: 1.1; }
.gate-q { margin: 6px 0 10px; font-size: 40px; letter-spacing: .06em; color: var(--ink); }
.gate-say { margin: 0 0 8px; font-size: 18px; color: #5b6b86; }
.gate-say .lit, .gate-q .lit { color: var(--gold); }
.gate-choices { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.gate-choice {
  font: inherit; cursor: pointer; font-size: 30px; min-width: 92px;
  padding: 14px 8px; border-radius: 18px;
  border: 0; background: var(--navy); color: #fff; box-shadow: 0 5px 0 #001a45;
}
.gate-choice:active { transform: translateY(3px); box-shadow: none; }
.gate-choice.wrong { background: #b9c4d6; box-shadow: none; opacity: .6; }
.gate-msg { margin: 10px 0 0; min-height: 20px; color: var(--crimson); }
.gate-home { margin-top: 10px; }
.gate-card.correct { background: #fffaf0; }

/* Match Maze Adventures: use the tablet's landscape width, not browser height. */
@media (orientation: landscape) and (min-width: 820px) {
  .home-scroll { display: grid; grid-template-columns: minmax(300px,1fr) minmax(390px,1.12fr); grid-template-areas: "brand title" "name choice" "play choice" "tog tog" "voice voice" "star star"; gap: 10px 24px; align-content: start; justify-content: center; max-width: 1060px; padding-top: calc(var(--sat) + 18px); padding-bottom: calc(var(--sab) + 18px); }
  .brand { grid-area: brand; max-width: none; }
  .game-title { grid-area: title; max-width: none; align-self: end; margin: 0 0 -2px; font-size: 34px; }
  #nameCard { grid-area: name; }
  #choiceCard { grid-area: choice; align-self: start; }
  .play-btn { grid-area: play; }
  .home-toggles { grid-area: tog; }
  .voice-pick { grid-area: voice; }
  .star-line { grid-area: star; }
  .footer-note { display: none; }
  .brand-name { font-size: 34px; }
  .brand-mascot { width: 96px; height: 96px; }
  .ride img { height: 50px; }
  .card { padding: 12px; }
  .play-btn { padding: 10px; }
  .gate-q { font-size: 32px; }
  .gate-choice { font-size: 24px; min-width: 76px; padding: 10px 8px; }
  .gate-pic { font-size: 38px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .brand-mascot { width: 96px; height: 96px; }
  .brand-name { font-size: 34px; }
  .play-btn { min-height: 66px; font-size: 27px; }
  .home-scroll { align-content: start; gap: 11px; padding-top: calc(var(--sat) + 18px); }
}
