:root {
  --confusion-low: #e7efe7;
  --confusion-high: #c0392b;
  --load-low: #eef2f7;
  --load-high: #6c3483;
  --floor: #fbf8f1;
  --route: #1f6feb;
  --warn: #b26a00;
  --ink: #3a3550;
  --muted: #8a84a3;
  --card: #ffffff;
  --mint: #bfe8d4;
  --lav: #dcd0ff;
  --peach: #ffd9b8;
  --sky: #bfe2ff;
  --accent: #ff8f7a;
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; color: var(--ink);
  font: 14px/1.45 ui-rounded, "SF Pro Rounded", "Nunito", "Quicksand", system-ui, sans-serif;
  background:
    radial-gradient(900px 500px at 12% -10%, #e9ddff 0%, transparent 60%),
    radial-gradient(800px 460px at 95% 0%, #d7f6e7 0%, transparent 55%),
    radial-gradient(700px 500px at 50% 110%, #ffe6d8 0%, transparent 60%),
    #f7f4fb;
  min-height: 100vh;
  display: flex; justify-content: center; align-items: flex-start;
}
.app {
  display: grid; grid-template-columns: 240px minmax(0, 1fr) 296px; gap: 14px;
  padding: 14px 18px; max-width: 1560px; width: 100%; align-items: start;
}
.brand { display: flex; align-items: center; gap: 10px; margin: 2px 2px 6px; }
.brand .mascot {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  font-size: 22px; background: var(--sky); box-shadow: inset 0 0 0 3px #fff, 0 4px 12px rgba(111,96,158,.18);
}
.brand h1 { font-size: 19px; margin: 0; letter-spacing: .01em; }
.brand p { margin: 0; font-size: 11.5px; color: var(--muted); }
.panel {
  background: var(--card); border-radius: var(--radius); padding: 13px 13px 14px;
  box-shadow: 0 8px 24px rgba(111, 96, 158, .10), 0 2px 6px rgba(111, 96, 158, .06);
}
.panel + .panel { margin-top: 14px; }
h2 {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--muted); margin: 0 0 8px;
}
label { display: block; margin: 9px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
select, button {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--ink);
  background: #fbfaff; border: 1.5px solid #e8e3f2; border-radius: 12px;
  transition: border-color .15s ease, box-shadow .15s ease, transform .05s ease;
}
select:focus-visible, button:focus-visible { outline: none; border-color: #b9a8ee; box-shadow: 0 0 0 4px rgba(155, 130, 235, .18); }
button { cursor: pointer; }
button:active { transform: translateY(1px); }

/* walkers */
#avatar-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.avatar-chip {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 6px;
  background: #fbfaff; border: 1.5px solid #e8e3f2; border-radius: 999px;
  font-size: 12px; color: var(--ink);
}
.avatar-face {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-size: 17px; flex: none; box-shadow: inset 0 0 0 2px #fff;
}
.avatar-chip.selected { border-color: #9b82eb; box-shadow: 0 0 0 3px rgba(155, 130, 235, .18); background: #f7f2ff; }
.walker-note { margin: 8px 2px 0; font-size: 10.5px; color: var(--muted); line-height: 1.35; }

/* material palette */
#material-palette { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
#material-palette button {
  display: flex; align-items: center; gap: 7px; padding: 6px 7px; font-size: 11.5px; text-align: left;
}
.sw {
  width: 18px; height: 18px; border-radius: 6px; flex: none;
  border: 1px solid rgba(58, 53, 80, .16);
  background-size: cover; background-position: center; image-rendering: pixelated;
}
#material-palette button.selected {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 143, 122, .22); background: #fff7f4;
}

/* stage */
.center { display: flex; flex-direction: column; gap: 10px; }
.stage {
  position: relative; background: var(--card); border-radius: var(--radius); padding: 10px;
  box-shadow: 0 12px 30px rgba(111, 96, 158, .12);
}
canvas {
  display: block; width: 100%; height: auto; border-radius: 12px;
  background: var(--floor); image-rendering: pixelated;
  box-shadow: inset 0 0 0 1.5px #e9e4f1;
}
.map-expand {
  position: absolute; top: 18px; right: 18px; z-index: 3; width: auto;
  padding: 5px 11px; font-size: 11px; font-weight: 700; color: #5b5478;
  background: rgba(255, 255, 255, .93); border: 1.5px solid #e8e3f2;
  border-radius: 999px; box-shadow: 0 4px 12px rgba(111, 96, 158, .16);
}
.map-expand:hover { border-color: #b9a8ee; }
body.map-open { overflow: hidden; }
.stage.expanded {
  position: fixed; inset: 0; z-index: 60; border-radius: 0;
  padding: 12px 16px 8px; display: flex; flex-direction: column; gap: 6px;
  background: var(--card); box-shadow: none;
}
.stage.expanded canvas {
  width: auto; height: auto; max-width: 100%; max-height: calc(100vh - 78px);
  margin: auto; border-radius: 8px;
}
.stage.expanded .map-expand { top: 16px; right: 20px; }
.goal-badge {
  position: absolute; z-index: 2; pointer-events: none; white-space: nowrap;
  padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700;
  color: #1c4fa1; background: rgba(255, 255, 255, .95);
  border: 1.5px solid rgba(31, 111, 235, .35);
  box-shadow: 0 3px 10px rgba(31, 111, 235, .18);
  transform: translate(8px, -135%);
}
.goal-badge[data-side="left"] { transform: translate(calc(-100% - 8px), -135%); }
.goal-badge[data-vert="below"] { transform: translate(8px, 45%); }
.goal-badge[data-side="left"][data-vert="below"] { transform: translate(calc(-100% - 8px), 45%); }
.stage-foot { display: flex; gap: 14px; align-items: center; padding: 8px 4px 0; font-size: 11.5px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.stage-foot .hint { margin-left: auto; }

/* scores + legends */
.score-row { display: flex; gap: 10px; margin-top: 2px; }
.score-card { flex: 1; border-radius: 14px; padding: 9px 10px 8px; }
.score-card.confusion { background: #fff0ed; }
.score-card.load { background: #f3edff; }
.score { font-size: 32px; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.score-card.confusion .score { color: #cf4b36; }
.score-card.load .score { color: #7d54b8; }
.score-label { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.explainer { margin: 9px 1px 0; font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.legend { margin-top: 11px; }
.legend-bar { height: 9px; border-radius: 999px; }
.legend-bar.confusion { background: linear-gradient(90deg, var(--confusion-low), var(--confusion-high)); }
.legend-bar.load { background: linear-gradient(90deg, var(--load-low), var(--load-high)); }
.legend-ends { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--muted); margin-top: 3px; }

/* routing */
.check {
  display: flex; align-items: center; gap: 8px; margin-top: 9px;
  font-size: 12.5px; text-transform: none; letter-spacing: 0; color: var(--ink);
}
.check input { width: auto; accent-color: #9b82eb; }
.check input:disabled + span { color: var(--muted); }
#route-info {
  font-size: 12px; margin-top: 9px; padding: 8px 10px; border-radius: 11px;
  background: #f5f2fc; color: #5b5478; min-height: 34px;
}
#audit-summary { font-size: 11.5px; margin-top: 7px; color: #a06a2c; }
.cute-btn {
  margin-top: 11px; background: linear-gradient(180deg, #ff9f8c, #ff8571); color: #fff;
  border: none; font-weight: 700; letter-spacing: .02em; box-shadow: 0 5px 14px rgba(255, 133, 113, .35);
}
.cute-btn:hover { filter: brightness(1.03); }

@media (max-width: 1280px) {
  body { align-items: flex-start; }
  .app { grid-template-columns: 240px minmax(0, 1fr); }
  .right { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
  .right .panel + .panel { margin-top: 0; }
}
