/* Campus Rush — layout / visual design. No frameworks. */
:root {
  --green: #1e7a46;
  --green-dark: #145c33;
  --gold: #f5b301;
  --ink: #1d2430;
  --paper: #fffdf5;
  --card: #ffffff;
  --muted: #6b7280;
  color-scheme: light;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: #d9ecd9 linear-gradient(180deg, #e8f5e9, #cfe6cf);
  color: var(--ink);
  min-height: 100vh;
}
#app { max-width: 1020px; margin: 0 auto; padding: 10px 12px 24px; }
#topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; flex-wrap: wrap; margin-bottom: 8px;
}
.brand { font-size: 1.1rem; }
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.ghost-btn {
  border: 1px solid #9db8a4; background: #fff; color: #3c5a44;
  border-radius: 999px; padding: 4px 10px; cursor: pointer; font-weight: 600; font-size: .85rem;
}
.ghost-btn:hover { background: var(--green); border-color: var(--green); color: #fff; }
#stage-wrap {
  position: relative; background: var(--paper);
  border: 3px solid var(--green-dark); border-radius: 14px;
  overflow: hidden; box-shadow: 0 8px 24px rgba(0,0,0,.15);
}
#game { display: block; width: 100%; height: auto; background: #9ccc9c; touch-action: none; }
#hud {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 8px 12px; background: #122b1a; color: #fff; font-weight: 600;
}
#hud.hidden { display: none; }
.hud-item { display: flex; align-items: center; gap: 6px; }
.bar { width: 90px; height: 10px; background: #334155; border-radius: 999px; overflow: hidden; }
#hud-energy-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #fbbf24, #22c55e); transition: width .15s; }
.level-tag { margin-left: auto; background: var(--gold); color: #3b2f00; padding: 2px 10px; border-radius: 999px; }
/* Destination is the wayfinding anchor; boost is a contextual chip on energy */
.dest-tag { margin-left: auto; background: #f5b301; color: #3b2c00; padding: 2px 10px; border-radius: 999px; font-size: .9rem; }
.boost-chip { background: #b08414; color: #fff; border-radius: 999px; padding: 1px 8px; font-size: .75rem; }
.boost-chip.hidden { display: none; }
#event-toast {
  position: absolute; top: 52px; left: 50%; transform: translateX(-50%);
  background: rgba(17,24,39,.92); color: #fff; padding: 8px 16px;
  border-radius: 999px; font-weight: 600; pointer-events: none;
  transition: opacity .3s; white-space: nowrap; max-width: 92%;
  overflow: hidden; text-overflow: ellipsis; z-index: 5;
}
#event-toast.hidden { opacity: 0; }
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  background: rgba(255,253,245,.96); padding: 20px; gap: 8px; z-index: 10;
  overflow-y: auto;
}
.screen.hidden { display: none; }
.screen h1 { margin: 0; font-size: clamp(2rem, 6vw, 3rem); }
.tagline { margin: 0 0 6px; color: var(--muted); }
.card-grid { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.card-grid label { display: block; font-size: .8rem; font-weight: 700; text-transform: uppercase; margin-bottom: 4px; }
select {
  font-size: 1rem; padding: 8px 10px; border-radius: 10px;
  border: 2px solid var(--green-dark); background: #fff; min-width: 220px;
}
.blurb { max-width: 560px; background: #fef3c7; border: 2px dashed var(--gold); border-radius: 10px; padding: 8px 12px; }
.blurb.hidden { display: none; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.menu-col { display: flex; flex-direction: column; gap: 10px; width: min(320px, 90%); }
.menu-btn { font-size: 1.2rem; padding: 14px 22px; }
#screen-start button:not(.primary) { border: 2px solid var(--green-dark); background: #fff; border-radius: 999px; padding: 10px 16px; cursor: pointer; font-weight: 700; }
.mode-grid { display: grid; gap: 8px; width: min(560px, 94%); }
.mode-card { text-align: left; border: 2px solid var(--green-dark); background: #fff; border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.mode-card b { display: block; }
.mode-card small { color: var(--muted); }
.mode-card.sel { background: #e8f5e9; outline: 2px solid var(--green); }
.level-grid { display: grid; gap: 8px; width: min(560px, 94%); }
.level-card { text-align: left; border: 2px solid var(--green-dark); background: #fff; border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.level-card b { display: block; }
.level-card small { color: var(--muted); }
.intro-kicker { font-size: .8rem; font-weight: 800; letter-spacing: .08em; color: var(--green-dark); margin: 0; }
.settings-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; width: min(440px, 94%); background: #f3f4f6; border-radius: 10px; padding: 8px 12px; }
.hidden { display: none !important; }
select.hidden { display: none !important; }
button.primary {
  background: var(--green); color: #fff; border: none; border-radius: 999px;
  padding: 12px 22px; font-size: 1.05rem; font-weight: 800; cursor: pointer;
}
button.primary:hover { background: var(--green-dark); }
.screen button:not(.primary) {
  border: 2px solid var(--green-dark); background: #fff; border-radius: 999px;
  padding: 10px 16px; cursor: pointer; font-weight: 700;
}
.best { color: var(--muted); }
kbd { background: #111827; color: #fff; border-radius: 6px; padding: 1px 6px; font-size: .85em; }
.legend { text-align: left; max-width: 520px; }
/* Organized field guide: grouped obstacle key, shared by menu + overlay */
.legend-grid { display: grid; gap: 8px; text-align: left; max-width: 560px; }
.legend-group { background: #f3f4f6; border-radius: 10px; padding: 8px 10px; }
.legend-group h4 { margin: 0 0 6px; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--green-dark); }
.legend-group ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.legend-group li { display: flex; align-items: center; gap: 8px; font-size: .92rem; }
.chip { display: inline-block; min-width: 34px; text-align: center; font-size: .78rem; font-weight: 800; border-radius: 999px; padding: 2px 8px; }
#legend-overlay {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(255,253,245,.98); border: 3px solid var(--green-dark);
  border-radius: 14px; padding: 14px 16px; z-index: 8; width: min(560px, 92%);
  max-height: 86%; overflow-y: auto; box-shadow: 0 12px 32px rgba(0,0,0,.3);
}
#legend-overlay.hidden { display: none; }
#legend-overlay h3 { margin: 0 0 8px; }
#legend-overlay button { margin-top: 10px; border: 2px solid var(--green-dark); background: #fff; border-radius: 999px; padding: 8px 16px; cursor: pointer; font-weight: 700; }
/* Combo pill pulses when a combo is live */
.hud-item.combo { background: #f97316; color: #fff; border-radius: 999px; padding: 2px 10px; animation: pop .3s ease; }
.hud-item.combo.hidden { display: none; }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.2); } 100% { transform: scale(1); } }
.stats { display: grid; gap: 4px; background: #f3f4f6; border-radius: 10px; padding: 10px 16px; min-width: min(420px, 90%); }
/* Leaderboard: plain rows, medal tint for top 3, gold outline for your new row */
#menu-board-wrap, #end-board-wrap { width: min(440px, 94%); }
#menu-board-wrap h3, #end-board-wrap h3 { margin: 6px 0 4px; font-size: 1rem; }
.board { display: grid; gap: 3px; text-align: left; }
.board-row {
  display: grid; grid-template-columns: 2rem 1fr auto auto; gap: 8px; align-items: center;
  background: #f3f4f6; border-radius: 8px; padding: 4px 10px; font-size: .9rem;
}
.board-row .rank { font-weight: 800; color: var(--muted); text-align: center; }
.board-row.r1 { background: #fdf3d7; } .board-row.r1 .rank { color: #a16207; }
.board-row.r2 { background: #eef0f2; } .board-row.r2 .rank { color: #52525b; }
.board-row.r3 { background: #f7e8d5; } .board-row.r3 .rank { color: #9a5b26; }
.board-row.mine { outline: 2px solid var(--gold); }
.board-row .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-row .who small { display: block; color: var(--muted); font-size: .75rem; }
.board-row .pts { font-weight: 800; }
.board-empty { color: var(--muted); font-size: .9rem; background: #f3f4f6; border-radius: 8px; padding: 8px 12px; }
.link-btn { background: none; border: none; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: .8rem; padding: 2px; }
/* Arcade initials form */
#score-form { width: min(440px, 94%); }
.form-row { display: flex; gap: 8px; justify-content: center; }
#score-name {
  font-size: 1rem; padding: 10px 12px; border-radius: 10px; text-transform: uppercase;
  border: 2px solid var(--green-dark); background: #fff; width: min(220px, 60%);
}
/* End-of-run grade: one big letter, no noise */
#end-grade { display: flex; align-items: baseline; gap: 10px; }
#end-grade.hidden { display: none; }
#end-grade-letter { font-size: 3rem; font-weight: 900; line-height: 1; color: var(--green-dark); }
#end-grade.gS #end-grade-letter { color: #a16207; }
#end-grade.gC #end-grade-letter, #end-grade.gF #end-grade-letter { color: #6b7280; }
#end-grade-title { font-weight: 700; color: var(--muted); }
/* Touch */
#touch {
  position: absolute; left: 0; right: 0; bottom: 8px;
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 12px; pointer-events: none; z-index: 6;
}
#touch.hidden { display: none; }
.dpad { display: grid; gap: 4px; justify-items: center; pointer-events: auto; }
.dpad-mid { display: flex; gap: 4px; }
#touch button {
  width: 56px; height: 56px; border-radius: 14px; font-size: 1.3rem;
  border: 2px solid #111827; background: rgba(255,255,255,.85); cursor: pointer;
}
/* pointer-events is inherited, and #touch sets it to none so the middle of the
   screen stays click-through. Only .dpad re-enabled it — so #touch-sprint,
   which is a direct child of #touch rather than of .dpad, could never receive
   a pointer event. Mobile players had no sprint at all: 185 px/s against the
   keyboard player's 277 px/s. This line is the whole fix. */
#touch-sprint { pointer-events: auto; }
#touch-sprint { background: #fef3c7 !important; border-color: var(--gold) !important; font-weight: 800; }
#touch-sprint small { display: block; font-size: .6rem; }
/* Held state, so the player can see sprint is actually engaged. */
#touch-sprint.held { background: var(--gold) !important; color: #111827; }
footer { text-align: center; margin-top: 8px; color: #37503d; }
@media (max-width: 640px) {
  .level-tag { margin-left: 0; }
  select { min-width: 160px; }
}

/* ── Campus Rush refinement: stronger HUD, clearer controls, campus feel ── */
#hud {
  border-bottom: 4px solid var(--green-dark);
  box-shadow: 0 4px 0 rgba(0,0,0,.12);
}
.hud-item { gap: 8px; }
.bar { width: 110px; height: 12px; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; background: #22301f; }
#hud-energy-fill { height: 100%; background: repeating-linear-gradient(90deg, #fbbf24 0 10px, #eeb01e 10px 20px); transition: width .2s ease; }
@media (prefers-reduced-motion: reduce) { #hud-energy-fill { transition: none; } }
.bar::after { content: ""; } /* keeps bar layout stable when empty */

/* Make the destination the unmissable wayfinding anchor. */
.dest-tag {
  margin-left: auto;
  background: var(--gold);
  color: #3b2c00;
  padding: 3px 12px;
  border-radius: 999px;
  font-weight: 800;
  font-size: .95rem;
  border: 2px solid #7a5300;
  box-shadow: 2px 2px 0 #3b2c00;
}
.boost-chip {
  background: #b08414;
  color: #fff;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: .8rem;
  font-weight: 800;
  border: 2px solid #7a5300;
  box-shadow: 1px 1px 0 #3b2c00;
}

/* Event toast: unmissable but brief. */
#event-toast {
  border: 2px solid var(--gold);
  box-shadow: 2px 2px 0 var(--ink);
  font-size: 1rem;
}

/* Mode / level cards: clearer selected state and tap target. */
.mode-card, .level-card {
  border: 2.5px solid var(--line);
  border-radius: 12px;
  transition: background .15s, border-color .15s, transform .05s;
}
.mode-card.sel, .level-card.sel {
  background: #e8f5e9;
  border-color: var(--green);
  box-shadow: inset 3px 3px 0 rgba(46,125,50,.15);
}
.mode-card:active, .level-card:active { transform: translate(1px,1px); }

/* Touch D-pad: larger, clearer, held-state feedback. */
#touch button {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  font-size: 1.5rem;
  border: 3px solid #111827;
  background: #fff;
  color: #111827;
  font-weight: 800;
  box-shadow: 3px 3px 0 #111827;
}
#touch button:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 #111827; }
#touch-sprint {
  background: #fef3c7 !important;
  border-color: var(--gold) !important;
  font-weight: 800;
  color: #3b2c00;
  box-shadow: 3px 3px 0 #7a5300;
}
#touch-sprint.held {
  background: var(--gold) !important;
  border-color: #7a5300 !important;
  color: #111827;
  box-shadow: inset 2px 2px 0 #7a5300;
}

/* End grade: keep the big letter, add a soft tint. */
#end-grade { gap: 12px; }
#end-grade-letter { text-shadow: 2px 2px 0 rgba(0,0,0,.25); }
#end-stats { border: 2px dashed var(--green-dark); border-radius: 10px; padding: 10px 14px; background: #f3f4f6; }

/* How-to: number the steps so the order is obvious. */
#screen-how ol { counter-reset: steps; padding-left: 20px; text-align: left; display: inline-block; }
#screen-how ol li { counter-increment: steps; margin-bottom: 8px; }
#screen-how ol li::marker { font-weight: 800; color: var(--green-dark); }

/* Reduced motion: keep feedback, drop the pulse. */
@media (prefers-reduced-motion: reduce) {
  .hud-item.combo { animation: none; }
}

/* ── Accessibility (from the source tree, merged 2026-10-29) ── */
/* Keyboard focus: clear, high-contrast ring on every interactive control. */
button:focus-visible, select:focus-visible, input:focus-visible, [role="button"]:focus-visible {
  outline: 3px solid var(--green-dark);
  outline-offset: 2px;
}

/* Touch targets: no interactive control smaller than 44px. */
button, select, input, [role="button"] {
  min-height: 44px;
}

/* Reduced motion: disable the combo pulse and hover lifts. */
@media (prefers-reduced-motion: reduce) {
  .hud-item.combo { animation: none; }
  button:hover, .ghost-btn:hover, .mode-card:hover { transform: none; }
  .screen { scroll-behavior: auto; }
}

/* Embedded in Campus Chaos (game.js EMBED): one level, no menus or boards;
   the semester shows its own "back" button. */
.embed #btn-retry, .embed #btn-next, .embed #btn-menu, .embed #end-board,
.embed #score-form, .embed #end-newbest { display: none !important; }
