/* Bus Call — STEMstarters style: League Spartan + Poppins, rounded everything, chip badges */
:root {
  --primary: #9246DD;
  --accent: #FC52B3;
  --bg: #fdf6e3;
  --ink: #2b2d42;
  --card: #fff;
  --muted: #5c5f78;
  --radius: 28px;
  --shadow: 0 12px 28px -16px rgba(58, 15, 101, .45);
  --head: "League Spartan", "Montserrat", "Segoe UI", system-ui, sans-serif;
  --body: "Poppins", "Segoe UI", system-ui, sans-serif;
  --c-purple: #9246DD; --c-pink: #FC52B3; --c-teal: #2FC2A3; --c-yellow: #F8C631;
  font-family: var(--body);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--ink); font-size: 17px; line-height: 1.4; }
h1, h2, h3 { font-family: var(--head); font-weight: 800; margin: 0 0 .4em; line-height: 1.05; }
h1 { font-size: 2.2rem; }
h2 { font-size: 1.6rem; }
a { color: inherit; }
code { background: rgba(0,0,0,.07); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.err { color: #c1121f; font-weight: 600; min-height: 1.2em; margin: 0; }
.loading { text-align: center; padding: 30vh 0; font-size: 1.6rem; font-family: var(--head); }
.es { opacity: .8; font-weight: 500; }
.d-status .es, .d-sub .es, .popup-sub .es, .center-card h2 .es { display: block; }
.d-status .sep, .d-sub .sep, .popup-sub .sep, .center-card h2 .sep { display: none; }
.d-card.go .d-status .es { font-size: 1.3rem; }

/* ---------- layout ---------- */
.page, .home, .display { max-width: 1180px; margin: 0 auto; padding: 28px 24px 60px; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 26px 28px; border: 4px solid color-mix(in srgb, var(--ink) 10%, transparent);
}
.card.step.s1 { border-color: var(--c-purple); }
.card.step.s2 { border-color: var(--c-pink); }
.card.step.s3 { border-color: var(--c-teal); }
.card.step.s4 { border-color: var(--c-yellow); }
.card.step.s5 { border-color: var(--c-purple); }
.card h2 { display: flex; align-items: center; gap: 14px; }
.center-card { max-width: 640px; margin: 7vh auto; text-align: center; border-color: var(--primary); }
.center-card h2 { display: block; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.row.spread { justify-content: space-between; }
.row.center, .center-card .row { justify-content: center; }

/* ---------- purple header ---------- */
.head-block {
  position: relative; overflow: hidden; isolation: isolate;
  background: var(--primary); color: #fff; border-radius: 36px;
  display: flex; align-items: center; justify-content: space-between; gap: 28px; flex-wrap: wrap;
  padding: 34px 44px; margin-bottom: 28px; min-height: 200px;
  box-shadow: 0 16px 30px -18px rgba(58, 15, 101, .7);
}
.head-block .blob { position: absolute; border-radius: 50%; z-index: -1; pointer-events: none; }
.head-block .b1 { right: -60px; top: -80px; width: 260px; height: 260px; background: var(--accent); opacity: .35; }
.head-block .b2 { left: 38%; bottom: -110px; width: 220px; height: 220px; background: #8DEFDA; opacity: .25; }
.head-text { min-width: 0; }
.head-block h1 { color: #fff; font-size: clamp(2.2rem, 5vw, 4.2rem); margin: 0; }
.head-pill {
  display: inline-flex; align-items: center; gap: 8px; background: var(--c-yellow); color: #3A0F65;
  font-weight: 700; font-size: .95rem; padding: 6px 16px; border-radius: 999px; margin-bottom: 12px;
}
.head-sub { margin: 10px 0 0; font-weight: 500; font-size: 1.25rem; color: #fff; opacity: .92; max-width: 640px; }
.head-bus { width: 220px; flex: none; }
.head-right { position: relative; flex: none; }
.head-block .back { display: flex; margin-bottom: 14px; }
.head-block.compact { min-height: 0; padding: 22px 32px; border-radius: 30px; }
.head-block.compact h1 { font-size: clamp(1.8rem, 3.6vw, 2.8rem); }
.head-block.compact .head-pill { margin-bottom: 8px; font-size: .85rem; }
.head-block.compact .b1 { width: 180px; height: 180px; top: -70px; right: -40px; }

/* ---------- chip badges (like 3D Print Quest) ---------- */
.nchip {
  flex: none; position: relative; width: 64px; height: 64px; border-radius: 50%; border: 5px solid;
  display: grid; place-items: center; box-shadow: 0 8px 18px -12px rgba(58, 15, 101, .6);
}
.nchip b { font: 800 1.9rem/1 var(--head); margin-top: 3px; }
.nchip.c0 { color: #6B2FB3; border-color: #9246DD; background: #F3EAFD; transform: rotate(-6deg); }
.nchip.c1 { color: #B8127A; border-color: #FC52B3; background: #FFE9F5; transform: rotate(5deg); }
.nchip.c2 { color: #13806B; border-color: #2FC2A3; background: #E1FBF5; transform: rotate(-4deg); }
.nchip.c3 { color: #7A5A00; border-color: #F8C631; background: #FFF6D6; transform: rotate(6deg); }
.nchip.sm { width: 46px; height: 46px; border-width: 4px; }
.nchip.sm b { font-size: 1.3rem; }

/* ---------- controls ---------- */
.btn {
  font: 600 1rem/1.2 var(--body); cursor: pointer; min-height: 44px;
  border: 3px solid var(--ink); border-radius: 999px; padding: 8px 20px;
  background: var(--card); color: var(--ink);
  box-shadow: 0 4px 0 var(--ink); transition: transform .08s, box-shadow .08s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.danger { background: #ffe1e4; color: #b3001b; border-color: #b3001b; box-shadow: 0 4px 0 #b3001b; }
.btn.big { font-size: 1.1rem; padding: 12px 26px; }
.btn.huge { font: 800 1.8rem/1 var(--head); padding: 18px 50px; box-shadow: 0 7px 0 var(--ink); }
.btn.small { font-size: .9rem; padding: 6px 16px; min-height: 40px; }
.btn.light { background: #fff; color: #3A0F65; border-color: #3A0F65; box-shadow: 0 4px 0 #3A0F65; }
.icon-btn {
  font: inherit; width: 44px; height: 44px; flex: none; border-radius: 50%; cursor: pointer;
  border: 3px solid var(--ink); background: #fff; color: var(--ink); display: grid; place-items: center; padding: 0;
}
.icon-btn:disabled { opacity: .25; cursor: default; }
input, select {
  font: 500 1.05rem var(--body); color: #2b2d42; background: #fffdf3;
  border: 3px solid var(--ink); border-radius: 16px; padding: 9px 14px; width: 100%; min-height: 48px;
}
input:focus, select:focus { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 2px; }
input[type=color] { width: 52px; height: 48px; padding: 3px; flex: none; cursor: pointer; background: #fff; }
input[type=checkbox] { width: 26px; height: 26px; min-height: 0; accent-color: var(--primary); }
input.tiny { width: 84px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 1.05rem; text-align: left; margin-bottom: 6px; }
label.check { flex-direction: row; align-items: center; gap: 12px; }
label.color-pick { flex-direction: row; align-items: center; gap: 8px; }
.code-input { font: 800 2.2rem var(--head); text-align: center; letter-spacing: .3em; text-transform: uppercase; }

/* ---------- home ---------- */
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 28px; }
.hero-bus { width: 220px; margin: 0 auto; }
.hero-bus.small { width: 150px; }

/* ---------- settings ---------- */
.settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px; align-items: start; }
.settings .wide { grid-column: 1 / -1; }
.settings .card { display: flex; flex-direction: column; gap: 12px; }
.settings .card h2 { margin-bottom: 4px; }
.settings .card p { margin: 0; }
.settings-foot { text-align: center; display: flex; flex-direction: column; gap: 12px; }
.list { display: flex; flex-direction: column; gap: 10px; margin: 4px 0; }
.list-row { display: flex; align-items: center; gap: 10px; }
.mini-bus { width: 72px; flex: none; }
.swatch {
  font: 600 .95rem var(--body); display: flex; gap: 6px; align-items: center; padding: 6px 14px; min-height: 44px;
  border-radius: 999px; border: 3px solid; cursor: pointer; color: #2b2d42;
}
.swatch[data-theme=Night] { color: #fff; }
.swatch span { width: 16px; height: 16px; border-radius: 50%; display: inline-block; }
@media (max-width: 820px) { .settings { grid-template-columns: minmax(0, 1fr); } }

/* ---------- share ---------- */
.share { display: flex; flex-direction: column; gap: 12px; text-align: left; margin: 16px 0; }
.share-row { display: flex; gap: 12px; justify-content: space-between; align-items: center; background: #F3EAFD; padding: 14px 18px; border-radius: 20px; }
.big-code { font: 800 2.6rem var(--head); letter-spacing: .22em; color: var(--primary); }
.link { font-family: ui-monospace, monospace; font-size: .9rem; word-break: break-all; }
.created h1 { margin-top: 10px; }

/* ---------- live dot ---------- */
.live-dot { width: 12px; height: 12px; border-radius: 50%; background: #2dc653; box-shadow: 0 0 0 3px rgba(255,255,255,.7); flex: none; display: inline-block; }
.live-dot.offline { background: #f4a259; animation: pulse 1s infinite alternate; }

/* ---------- master panel ---------- */
.group-bar {
  display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin-bottom: 24px;
  background: var(--card); border-radius: var(--radius); padding: 18px 22px; box-shadow: var(--shadow); border: 4px solid var(--c-pink);
}
.bar-label { width: 100%; font-weight: 500; }
.group-call {
  font: 800 1.5rem/1.05 var(--head); padding: 12px 26px; background: var(--primary); color: #fff;
  display: flex; flex-direction: column; align-items: center; border-radius: 22px;
}
.group-call .count { font: 600 .8rem var(--body); opacity: .95; }
.group-call.done { background: var(--card); color: var(--muted); }
.bus-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; margin-bottom: 24px; }
.bus-card { padding: 18px; display: flex; flex-direction: column; gap: 12px; transition: border-color .2s; }
.bus-card.arrived { border-color: var(--primary); }
.bus-head { display: flex; gap: 12px; align-items: center; }
.bus-head .bus-svg { width: 100px; flex: none; }
.bus-name { font: 800 1.7rem/1 var(--head); }
.arrive-btn { width: 100%; font-size: 1.05rem; }
.arrive-btn.on { background: var(--primary); color: #fff; }
.cells { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 8px; }
.cell {
  font: 800 1.1rem/1.1 var(--head); cursor: pointer; border-radius: 18px; padding: 10px 4px; min-height: 56px;
  border: 3px dashed color-mix(in srgb, var(--ink) 30%, transparent); background: transparent; color: var(--ink);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.cell small { font: 500 .72rem var(--body); color: var(--muted); }
.cell.next { border: 3px solid var(--c-teal); background: #E1FBF5; animation: nudge 1.4s ease-in-out infinite; }
.cell.called { border: 3px solid #2b9348; background: #d8f3dc; color: #1b4332; }
.cell.called small { color: #1b4332; }
.log-card h2 { margin: 0; }
.log { list-style: none; padding: 0; margin: 12px 0 0; max-height: 260px; overflow: auto; display: flex; flex-direction: column; gap: 4px; }

/* ---------- classroom display ---------- */
.chip {
  font: 700 1.1rem var(--body); background: #fff; color: #3A0F65; border: 3px solid #3A0F65;
  border-radius: 999px; padding: 8px 20px; cursor: pointer; box-shadow: 0 4px 0 #3A0F65; min-height: 44px;
}
.chip .muted { color: #6B2FB3; }
.group-pick { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin: 18px 0; }
.group-pick .btn.big { font: 800 1.8rem var(--head); min-width: 130px; border-radius: 22px; }
.message { margin: 0 0 18px; font-size: 1.25rem; font-weight: 600; background: #FFF6D6; border: 3px solid var(--c-yellow); border-radius: 20px; padding: 10px 18px; }

.road {
  position: relative; margin: 0 0 20px; min-height: 130px; border-radius: var(--radius);
  background: #5c6378; display: flex; align-items: flex-end; gap: 12px; padding: 14px 18px 20px; overflow: hidden;
  box-shadow: var(--shadow);
}
.road-line { position: absolute; left: 0; right: 0; bottom: 10px; height: 0; border-top: 5px dashed #F8C631; opacity: .8; }
.road.empty::after { content: attr(data-empty); color: #fff; opacity: .85; font-weight: 600; position: absolute; inset: 0; display: grid; place-items: center; }
.road-bus { position: relative; z-index: 1; width: 140px; text-align: center; color: #fff; font: 800 1.05rem var(--head); }
.road-bus span { display: block; margin-top: -2px; text-shadow: 0 1px 2px rgba(0,0,0,.5); }

.d-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 20px; }
.d-card {
  background: var(--card); border-radius: var(--radius); padding: 18px; text-align: center; box-shadow: var(--shadow);
  border: 4px solid color-mix(in srgb, var(--ink) 10%, transparent); transition: transform .3s, border-color .3s;
}
.d-bus { width: 80%; margin: 0 auto; }
.d-name { font: 800 2.1rem/1 var(--head); margin-top: 4px; }
.d-status { font-size: 1.1rem; font-weight: 600; margin-top: 6px; color: var(--muted); }
.d-sub { font-size: .95rem; color: var(--muted); }
.d-card.here { border-color: color-mix(in srgb, var(--bus) 70%, transparent); }
.d-card.here .d-status { color: var(--ink); }
.d-card.go { border-color: var(--bus); background: color-mix(in srgb, var(--bus) 20%, var(--card)); transform: scale(1.04); animation: glow 1.2s ease-in-out infinite alternate; }
.d-card.go .d-status { font: 800 2.1rem/1.05 var(--head); color: var(--ink); }
.d-card.go .d-sub { color: var(--ink); font-weight: 600; }
.d-card.sent { opacity: .75; }
.d-card.sent .d-status { color: #2b9348; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 8px; }
.g-chip { padding: 3px 12px; border-radius: 999px; border: 3px solid color-mix(in srgb, var(--ink) 25%, transparent); font: 800 .95rem var(--head); }
.g-chip.go { background: var(--bus); border-color: var(--ink); animation: pulse .8s infinite alternate; }
.g-chip.sent { background: #d8f3dc; color: #1b4332; border-color: #2b9348; }

/* ---------- full-screen bus overlay ---------- */
.popup-layer:empty { display: none; }
.popup-layer {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; cursor: pointer; overflow: hidden;
  background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--bus, #F8C631) 45%, #fff) 0, var(--bus, #F8C631) 70%);
  animation: fade .25s;
}
.popup-layer::before {
  content: ""; position: absolute; inset: -50%; pointer-events: none;
  background: repeating-conic-gradient(from 0deg at 50% 50%, rgba(255,255,255,.18) 0 10deg, transparent 10deg 20deg);
  animation: spinbg 30s linear infinite;
}
.road-strip {
  position: absolute; left: 0; right: 0; bottom: 0; height: 22vh; background: #5c6378;
  border-top: 8px solid #3A0F65; overflow: hidden;
}
.road-strip::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 8px dashed #F8C631; }
.road-strip span { position: absolute; bottom: 2vh; width: 22vh; z-index: 1; left: -30vh; animation: across 7s linear calc(var(--d) * 2.3s) infinite; }
.popup {
  position: relative; z-index: 2; overflow: hidden; width: min(980px, 92vw); max-height: 72vh; text-align: center; color: #2b2d42;
  background: #fff; border: 8px solid #2b2d42; border-radius: 48px; padding: 3vh 28px 2.4vh; margin-bottom: 16vh;
  box-shadow: 0 18px 0 rgba(0,0,0,.25); animation: pop .5s cubic-bezier(.2, 1.6, .4, 1);
  display: flex; flex-direction: column; align-items: center;
}
.popup-bus { width: min(52%, 38vh * 1.7); margin: 0 auto; }
.popup-title { font: 800 clamp(2.8rem, 9vh, 6rem)/1 var(--head); margin-top: 1vh; }
.popup-group { display: inline-block; margin: 1.6vh 0; font: 800 clamp(2rem, 6.5vh, 4.2rem)/1.15 var(--head); background: var(--bus); color: #2b2d42; border: 5px solid #2b2d42; border-radius: 999px; padding: 6px 40px 0; }
.popup-sub { font-size: clamp(1.3rem, 3.6vh, 2.2rem); font-weight: 700; }
.confetti i {
  position: absolute; top: -20px; left: calc(var(--i) * 4.2%); width: 14px; height: 14px; background: var(--c); border-radius: 50%;
  animation: fall 2.4s calc(var(--i) * 0.06s) ease-in forwards; opacity: .9;
}

/* ---------- waiting video ---------- */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#video-wrap { margin-bottom: 20px; }
.video-card .v-icon { flex: none; width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; background: #FFE9F5; color: #B8127A; border: 4px solid var(--c-pink); transform: rotate(5deg); }
.v-form { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.v-form input { flex: 1 1 320px; }
.video-card.playing { display: flex; flex-direction: column; gap: 10px; }
.video-frame {
  position: relative; width: 100%; max-width: calc(62vh * 16 / 9); margin: 0 auto; aspect-ratio: 16 / 9;
  border-radius: var(--radius); overflow: hidden; background: #000; border: 5px solid var(--primary); box-shadow: var(--shadow);
}
.video-frame iframe, .video-frame > div { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-tools { gap: 10px; }
/* with a video playing: video on the left, compact bus list on the right */
.has-video .road { display: none; }
.has-video .d-main { display: grid; grid-template-columns: minmax(0, 2.3fr) minmax(260px, 1fr); gap: 22px; align-items: start; }
.has-video #video-wrap { margin: 0; }
.has-video .video-frame { max-width: none; }
.has-video .d-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
.has-video .d-card { display: grid; grid-template-columns: 96px minmax(0, 1fr); column-gap: 12px; align-items: center; text-align: left; padding: 10px 14px; border-radius: 22px; }
.has-video .d-card > * { grid-column: 2; }
.has-video .d-bus { grid-column: 1; grid-row: 1 / span 4; width: 100%; margin: 0; }
.has-video .d-name { font-size: 1.4rem; margin: 0; }
.has-video .d-status { font-size: .95rem; margin-top: 2px; }
.has-video .d-sub { font-size: .8rem; }
.has-video .d-card.go { transform: none; }
.has-video .d-card.go .d-status { font-size: 1.35rem; }
.has-video .d-card.go .d-status .es { font-size: 1rem; }
.has-video .chips { justify-content: flex-start; }
@media (max-width: 900px) { .has-video .d-main { grid-template-columns: minmax(0, 1fr); } }

/* ---------- bus svg animation ---------- */
.bus-svg { display: block; width: 100%; height: auto; overflow: visible; }
.bus-svg.faded { opacity: .35; filter: grayscale(.6); }
.bus-svg.drive-in { animation: drive 1s cubic-bezier(.2, .9, .3, 1.2) both; }
.bus-svg.bounce { animation: drive 1s cubic-bezier(.2, .9, .3, 1.2) both, bounce .6s 1s ease-in-out infinite alternate; }

/* ---------- modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(40,15,70,.45); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal { max-width: 540px; width: 100%; animation: pop .3s; border-color: var(--primary); }
.lead { font-size: 1.2rem; font-weight: 600; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #3A0F65; color: #fff; padding: 12px 22px; border-radius: 999px; z-index: 70; font-weight: 600; }
.demo-banner { background: #3A0F65; color: #F8C631; text-align: center; padding: 6px 12px; font-size: .85rem; font-weight: 500; }
.demo-banner code { background: rgba(255,255,255,.15); }

@keyframes drive { from { transform: translateX(-120%) rotate(-2deg); } 70% { transform: translateX(6%) rotate(1deg); } to { transform: none; } }
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-8px); } }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pulse { from { opacity: 1; } to { opacity: .55; } }
@keyframes glow { from { box-shadow: var(--shadow); } to { box-shadow: 0 0 0 8px color-mix(in srgb, var(--bus) 35%, transparent), var(--shadow); } }
@keyframes nudge { 0%, 100% { transform: none; } 50% { transform: translateY(-2px); } }
@keyframes across { to { transform: translateX(calc(100vw + 60vh)); } }
@keyframes spinbg { to { transform: rotate(360deg); } }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

@media (max-width: 640px) {
  .page, .home, .display { padding: 16px 12px 40px; }
  .head-block { padding: 26px 24px; border-radius: 28px; }
  .head-bus { width: 160px; }
  .card { padding: 20px; }
  .d-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
