/* ==========================================================================================================
   App shell (js/app.js) and the auth / onboarding screens (js/auth/*): page background decoration, top bar, navigation
   (top bar on wide screens, bottom tab bar on tablets and phones), boot screen, offline banner, login / register cards,
   PIN pad, theme cards, avatar picker.
   ========================================================================================================== */

/* ------------------------------------------------------------------------------------------ page background */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: var(--deco-pattern) 0 0 / 260px 260px repeat;
  opacity: var(--deco-opacity);
}

.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.app-main { flex: 1 1 auto; min-width: 0; outline: none; }
.view-page { min-height: 40vh; outline: none; }

/* ------------------------------------------------------------------------------------------ boot screen */
.boot {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-4);
  background: var(--bg); color: var(--text-muted); font-weight: 800; font-size: var(--fs-md);
  transition: opacity 0.25s var(--ease);
}
.boot.is-leaving { opacity: 0; pointer-events: none; }
.boot svg { width: 96px; height: 96px; animation: boot-bob 1.4s ease-in-out infinite; }
.boot .boot-eyes { transform-origin: center; animation: boot-blink 3.2s infinite; }
@keyframes boot-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes boot-blink { 0%, 92%, 100% { transform: scaleY(1); } 96% { transform: scaleY(0.1); } }
.boot-error { max-width: 440px; text-align: center; padding: 0 var(--sp-4); }
.boot-error .btn { margin-top: var(--sp-3); }

/* ------------------------------------------------------------------------------------------ top bar */
.topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: var(--header-h);
  padding: 6px var(--gutter);
  background: var(--header-bg);
  color: var(--header-fg);
  border-bottom: 3px solid var(--header-border);
  box-shadow: var(--sh-1);
}
.topbar > * { position: relative; }
.topbar :focus-visible { outline-color: var(--header-focus); }
.brand {
  display: inline-flex; align-items: center; gap: 10px; flex: none;
  min-height: 48px; padding: 0 6px 0 0; border-radius: var(--r-md);
  color: var(--header-fg); text-decoration: none; font-weight: 900; font-size: 1.55rem; letter-spacing: -0.02em;
}
.brand:hover { color: var(--header-fg); }
.brand svg { width: 42px; height: 42px; flex: none; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.2)); }
.brand:active svg { transform: rotate(-8deg) scale(0.96); }
.topbar-deco {
  flex: 1 1 0; min-width: 0; align-self: stretch; margin: -6px 0; pointer-events: none;
  background: var(--deco-header) right center / auto 100% no-repeat;
}
.topbar-user { display: flex; align-items: center; gap: var(--sp-2); flex: none; }
.user-link {
  display: inline-flex; align-items: center; gap: var(--sp-2); min-height: 48px; padding: 0 var(--sp-2) 0 4px;
  border-radius: var(--r-pill); color: var(--header-fg); text-decoration: none; font-weight: 800;
}
.user-link:hover { background: var(--header-hover-bg); color: var(--header-fg); }
.user-link .avatar { --size: 40px; border-width: 2px; }
.user-name { max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: var(--fs-xs); font-weight: 700; color: var(--header-fg-muted); display: block; line-height: 1; }
.topbar .btn-ghost { --btn-fg: var(--header-fg); }
.topbar .btn-ghost:hover { background: var(--header-hover-bg); color: var(--header-fg); }

.stat-pills { display: flex; align-items: center; gap: 6px; flex: none; }
.stat-pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px;
  border-radius: var(--r-pill); font-weight: 900; font-size: var(--fs-md); font-variant-numeric: tabular-nums;
  background: var(--surface); color: var(--text); box-shadow: var(--sh-1); border: 2px solid var(--border);
  white-space: nowrap;
}
.stat-pill svg { width: 20px; height: 20px; }
.stat-pill .pill-ico { font-size: 1.1em; line-height: 1; }
.stat-pill.is-level { background: var(--primary); color: var(--on-primary); border-color: var(--primary-dark); }
.stat-pill.is-coins svg { color: #d98c00; fill: #ffc400; stroke: #b36d00; }
.stat-pill.is-pop { animation: pill-pop 0.6s var(--ease-bounce); }
@keyframes pill-pop { 40% { transform: scale(1.18); } }

/* ------------------------------------------------------------------------------------------ navigation */
.nav { display: flex; align-items: center; gap: 4px; min-width: 0; }
.nav-link {
  position: relative;
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  min-height: 48px; padding: 0 14px; border-radius: var(--r-pill);
  color: var(--header-fg); text-decoration: none; font-weight: 800; font-size: var(--fs-md);
  border: 2px solid transparent;
}
.nav-link:hover { background: var(--header-hover-bg); color: var(--header-fg); }
.nav-link .icon { width: 24px; height: 24px; flex: none; }
.nav-link[aria-current="page"] { background: var(--header-active-bg); color: var(--header-active-fg); }
.nav-link[aria-current="page"]:hover { color: var(--header-active-fg); filter: brightness(1.05); }
.nav-badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 999px; background: var(--danger); color: var(--on-danger); font-size: var(--fs-xs); font-weight: 900; line-height: 1;
  border: 2px solid var(--surface);
}
.nav-badge[hidden] { display: none; }

/* tablets, phones and small laptops (< 1300px): the student navigation becomes a tab bar at the bottom (thumb friendly) */
@media (max-width: 1299px) {
  :root { --bottom-nav-h: 70px; }
  body.has-bottom-nav .app-main { padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px)); }
  .nav.nav-bottom {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 120;
    justify-content: space-around; align-items: stretch; gap: 2px;
    height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
    background: var(--surface); border-top: 3px solid var(--border-strong);
    box-shadow: 0 -6px 18px rgba(20, 30, 60, 0.12);
  }
  .nav-bottom .nav-link {
    flex: 1 1 0; min-width: 0; flex-direction: column; justify-content: center; gap: 2px;
    padding: 2px 2px; min-height: 54px; border-radius: var(--r-md);
    color: var(--text-muted); font-size: 0.75rem; line-height: 1.05; text-align: center;
  }
  .nav-bottom .nav-link:hover { background: var(--surface-2); color: var(--text); }
  .nav-bottom .nav-link .icon { width: 26px; height: 26px; }
  .nav-bottom .nav-link .nav-text { display: block; max-width: 100%; overflow-wrap: anywhere; hyphens: auto; }
  .nav-bottom .nav-link[aria-current="page"] { background: var(--primary-soft); color: var(--primary-dark); }
  .nav-bottom .nav-link[aria-current="page"]:hover { color: var(--primary-dark); }
  .nav-bottom .nav-badge { position: absolute; top: 0; right: calc(50% - 26px); }
  .brand { font-size: 1.35rem; }
}
@media (min-width: 1300px) {
  .nav-bottom .nav-badge { margin-left: 2px; }
  .nav-link { padding: 0 12px; gap: 6px; }
}
/* 1300-1599px: the six links + the three pills + avatar + logout do not fit at full size (the last link ran under the pills) */
@media (min-width: 1300px) and (max-width: 1599px) {
  .nav { gap: 2px; }
  .nav-link { padding: 0 9px; gap: 5px; font-size: var(--fs-sm); }
}
/* focus screens (onboarding, forced password change): only the brand and the logout button stay */
body.is-minimal { --bottom-nav-h: 0px; }
body.is-minimal .nav, body.is-minimal .stat-pills, body.is-minimal .user-link { display: none; }
/* the name next to the avatar only where there is plenty of room (students) / not on phones (staff) */
body.is-student .user-name { display: none; }
body.is-student .user-link { padding: 0 4px; }
@media (min-width: 1600px) { body.is-student .user-name { display: inline; } body.is-student .user-link { padding: 0 var(--sp-2) 0 4px; } }
@media (max-width: 699px) { body.is-staff .user-name, body.is-staff .user-role { display: none; } body.is-staff .user-link { padding: 0 4px; } }
@media (max-width: 440px) {
  .nav.nav-bottom { padding-left: 2px; padding-right: 2px; gap: 0; }
  .nav-bottom .nav-link { font-size: 0.6875rem; padding: 2px 0; }
  .nav-bottom .nav-link .nav-text { overflow-wrap: normal; hyphens: manual; word-break: keep-all; }
}
@media (max-width: 520px) {
  .stat-pill.is-streak { display: none; }
  .brand span { display: none; }
  .stat-pill { padding: 0 10px; font-size: var(--fs-sm); }
  .topbar { gap: var(--sp-2); padding-left: 10px; padding-right: 10px; }
}

/* ------------------------------------------------------------------------------------------ offline banner */
.offline-banner {
  position: sticky; top: var(--header-h); z-index: 90;
  display: flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4); background: var(--warning); color: var(--on-warning);
  font-weight: 800; text-align: center; border-bottom: 3px solid rgba(0, 0, 0, 0.15);
}
.offline-banner.is-back { background: var(--success); color: var(--on-success); }

/* ------------------------------------------------------------------------------------------ auth screens */
.auth-page {
  display: grid; align-items: center; align-content: center; justify-items: center;
  gap: var(--sp-6); padding: var(--sp-6) var(--gutter) var(--sp-10);
  max-width: 1040px; margin: 0 auto; min-height: calc(100dvh - var(--header-h) - 12px);
}
.auth-hero {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); text-align: center; width: 100%;
}
.auth-hero .robi-stage { position: relative; width: min(100%, 360px); }
.auth-hero .robi-stage .theme-hero { display: flex; align-items: flex-end; justify-content: center; min-height: 190px; padding: var(--sp-3); }
.auth-hero .robi-stage svg.robot { width: 130px; height: 130px; filter: drop-shadow(0 6px 4px rgba(0, 0, 0, 0.18)); animation: boot-bob 2.6s ease-in-out infinite; }
.speech {
  position: relative; background: var(--surface); color: var(--text); border: 3px solid var(--border-strong);
  border-radius: var(--r-lg); padding: var(--sp-3) var(--sp-4); font-weight: 800; max-width: 340px; box-shadow: var(--sh-1);
}
.speech::before {
  content: ""; position: absolute; top: -12px; left: 50%; width: 20px; height: 20px; margin-left: -10px; transform: rotate(45deg);
  background: var(--surface); border-left: 3px solid var(--border-strong); border-top: 3px solid var(--border-strong); border-radius: 4px 0 0 0;
}
.auth-card {
  width: 100%; max-width: 480px; background: var(--surface); border: 3px solid var(--border);
  border-radius: var(--r-xl); box-shadow: var(--sh-2); padding: var(--sp-6);
}
.auth-card h1 { font-size: var(--fs-xl); margin-bottom: var(--sp-1); }
.auth-card .subtitle { color: var(--text-muted); margin-bottom: var(--sp-5); }
.auth-card .btn-lg { width: 100%; }
.auth-forgot { margin: var(--sp-3) 0 0; font-size: 0.95rem; }
.auth-links { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--sp-2) var(--sp-4); margin-top: var(--sp-4); }
/* 4.0.0: staff registration, legal pages */
.radio-row { border: 0; padding: 0; margin: 0 0 var(--sp-3); min-width: 0; }
.radio-row legend { padding: 0; margin-bottom: var(--sp-2); }
.radio { display: flex; align-items: center; gap: var(--sp-3); min-height: var(--tap); cursor: pointer; font-weight: 600; }
.radio input { width: 24px; height: 24px; accent-color: var(--primary); flex: none; margin: 0; }
.check a { text-decoration: underline; }
.check { font-weight: 600; }
.legal-links { margin: var(--sp-3) 0 0; }
.legal-links a { display: inline-block; padding: var(--sp-2) 0; }
.legal-text { max-width: 46rem; }
.legal-text h2 { font-size: 1.25rem; margin: var(--sp-5) 0 var(--sp-2); }
.legal-text p { line-height: 1.6; overflow-wrap: anywhere; }
.code-input { text-transform: uppercase; letter-spacing: .15em; font-weight: 700; }
.auth-card .segmented { display: flex; width: 100%; margin-bottom: var(--sp-5); }
.auth-card .segmented button { flex: 1 1 0; min-height: 48px; font-size: var(--fs-md); }
.segmented [role="tab"][aria-selected="true"] { background: var(--surface); color: var(--primary-dark); box-shadow: var(--sh-1); }
.auth-notice { text-align: center; }
.auth-notice .state-icon { font-size: 4.5rem; line-height: 1.2; }
.auth-notice h1 { font-size: var(--fs-xl); }
.countdown { font-size: var(--fs-display); font-weight: 900; font-variant-numeric: tabular-nums; color: var(--primary); line-height: 1; margin: var(--sp-3) 0; }
.reg-done-name { display: inline-block; background: var(--primary-soft); color: var(--primary-dark); border-radius: var(--r-md); padding: 0.1em 0.6em; font-weight: 900; font-family: var(--font-mono); }
/* login form: pad under the fields (narrow) or beside them (wide and short screens) */
.login-grid { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-areas: "user" "pad" "err" "submit"; }
.login-grid > .lg-user { grid-area: user; }
.login-grid > .lg-pad { grid-area: pad; }
.login-grid > .lg-err { grid-area: err; }
.login-grid > .lg-submit { grid-area: submit; width: 100%; }
.login-grid > .lg-mascot { display: none; grid-area: mascot; }
@media (min-width: 900px) {
  .auth-page.has-hero { grid-template-columns: minmax(300px, 1fr) minmax(400px, 480px); gap: var(--sp-10); }
  .auth-page.has-hero .auth-hero .robi-stage { width: min(100%, 440px); }
  .auth-page.has-hero .auth-hero .theme-hero { min-height: 280px; }
  .auth-page.has-hero .auth-hero svg.robot { width: 170px; height: 170px; }
}
@media (min-width: 900px) and (max-height: 880px) {
  .auth-page.has-hero { grid-template-columns: minmax(0, 1fr); padding: var(--sp-3) var(--gutter); }
  .auth-page.has-hero .auth-hero { display: none; }
  .auth-page .auth-card { max-width: 780px; padding: var(--sp-4) var(--sp-6); }
  .auth-card h1 { font-size: var(--fs-lg); }
  .auth-card .subtitle { margin-bottom: var(--sp-3); }
  .auth-card .segmented { margin-bottom: var(--sp-3); }
  .auth-card .field { margin-bottom: var(--sp-3); }
  .auth-links { margin-top: var(--sp-2); }
  .login-grid.is-student { grid-template-columns: minmax(0, 1fr) minmax(0, 330px); grid-template-rows: auto 1fr auto auto; grid-template-areas: "user pad" "mascot pad" "err pad" "submit pad"; column-gap: var(--sp-8); align-items: start; }
  .login-grid.is-student > .lg-mascot { display: flex; align-self: center; justify-self: center; }
  .login-grid.is-student > .lg-mascot svg { filter: drop-shadow(0 6px 4px rgba(0, 0, 0, 0.18)); animation: boot-bob 2.6s ease-in-out infinite; }
  .login-grid.is-student > .lg-submit { align-self: end; }
  .login-grid .pinpad { margin-bottom: 0; gap: var(--sp-3); }
  .pin-key { min-height: 54px; font-size: 1.65rem; }
  .pin-dot { width: 26px; height: 26px; }
}
@media (max-width: 899px) {
  .auth-page.has-hero { gap: var(--sp-4); }
  .auth-hero .speech { display: none; }
  .auth-hero .robi-stage .theme-hero { min-height: 150px; }
  .auth-hero .robi-stage svg.robot { width: 104px; height: 104px; }
}
@media (max-width: 520px) {
  .auth-card { padding: var(--sp-5) var(--sp-4); border-radius: var(--r-lg); }
  .auth-card .segmented button { font-size: var(--fs-sm); padding: 0 0.4em; }
}
@media (max-height: 640px) and (max-width: 899px) {
  .auth-hero .robi-stage .theme-hero { min-height: 120px; }
  .auth-hero .robi-stage svg.robot { width: 84px; height: 84px; }
  .auth-hero .speech { display: none; }
}

/* ------------------------------------------------------------------------------------------ PIN pad */
.pinpad { display: flex; flex-direction: column; align-items: center; gap: var(--sp-4); margin: 0 auto var(--sp-4); max-width: 340px; }
.pin-display { display: flex; gap: var(--sp-4); justify-content: center; padding: var(--sp-2) 0; }
.pin-dot {
  width: 30px; height: 30px; border-radius: 50%; background: var(--surface); border: 4px solid var(--border-strong);
  transition: background 0.12s, transform 0.18s var(--ease-bounce), border-color 0.12s;
}
.pin-dot.is-filled { background: var(--primary); border-color: var(--primary-dark); transform: scale(1.12); }
.pinpad.is-error .pin-dot { background: var(--danger); border-color: var(--danger-dark); }
.pinpad.shake { animation: shake 0.45s; }
@keyframes shake { 15% { transform: translateX(-10px); } 35% { transform: translateX(9px); } 55% { transform: translateX(-6px); } 75% { transform: translateX(4px); } }
.pin-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-3); width: 100%; }
.pin-key {
  min-height: 68px; font-size: 1.9rem; font-weight: 900; line-height: 1;
  border-radius: var(--r-lg); background: var(--surface); color: var(--text);
  border: 3px solid var(--border-strong); box-shadow: 0 5px 0 var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  transition: transform 0.06s, box-shadow 0.06s, background 0.1s;
}
.pin-key:hover { background: var(--surface-2); }
.pin-key:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--border-strong); background: var(--primary-soft); }
.pin-key.pin-aux { background: var(--surface-2); color: var(--text-muted); font-size: 1.4rem; }
.pin-key svg { width: 28px; height: 28px; }
.pinpad.is-disabled .pin-key { opacity: 0.5; pointer-events: none; }
.pinpad-compact .pin-key { min-height: 56px; font-size: 1.6rem; }
@media (max-height: 760px) { .pin-key { min-height: 58px; font-size: 1.6rem; } .pin-display { padding: 0; } .pinpad { gap: var(--sp-3); } }

/* ------------------------------------------------------------------------------------------ onboarding */
.onboard { max-width: 920px; margin: 0 auto; padding: var(--sp-6) var(--gutter) var(--sp-10); }
.onboard-head { text-align: center; margin-bottom: var(--sp-5); }
.onboard-head h1 { margin-bottom: var(--sp-1); }
.onboard-head p { color: var(--text-muted); margin: 0; }
.onboard-steps { display: flex; justify-content: center; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.onboard-steps i { width: 38px; height: 10px; border-radius: 99px; background: var(--surface-3); }
.onboard-steps i.is-on { background: var(--primary); }
.theme-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-5); }
@media (max-width: 640px) { .theme-cards { grid-template-columns: minmax(0, 1fr); } }
.theme-card {
  display: flex; flex-direction: column; text-align: left; padding: 0; overflow: hidden; cursor: pointer;
  background: var(--surface); color: var(--text); border: 4px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--sh-2);
  transition: transform 0.15s var(--ease-bounce), border-color 0.15s, box-shadow 0.15s;
}
.theme-card:hover { transform: translateY(-3px); box-shadow: var(--sh-3); }
.theme-card[aria-checked="true"] { border-color: var(--primary); box-shadow: 0 0 0 5px var(--primary-soft), var(--sh-3); transform: translateY(-2px); }
.theme-card .theme-preview { aspect-ratio: 16 / 8; width: 100%; border-radius: 0; }
.theme-card-body { padding: var(--sp-4) var(--sp-5) var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2); flex: 1; }
.theme-card-title { margin: 0; font-size: var(--fs-xl); display: flex; align-items: center; gap: var(--sp-2); }
.theme-card-desc { margin: 0; color: var(--text-muted); font-size: var(--fs-md); }
.theme-card .pick {
  margin-top: auto; align-self: flex-start; display: inline-flex; align-items: center; gap: 0.4em;
  min-height: 48px; padding: 0 1.2em; border-radius: var(--r-pill); font-weight: 900; font-size: var(--fs-md);
  background: var(--surface-3); color: var(--text);
}
.theme-card[aria-checked="true"] .pick { background: var(--primary); color: var(--on-primary); }
.onboard-actions { display: flex; justify-content: center; gap: var(--sp-3); margin-top: var(--sp-6); flex-wrap: wrap; }
.avatar-stage { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.avatar-stage .avatar { --size: 96px; }
.avatar-stage .avatar-name { font-weight: 900; font-size: var(--fs-lg); }
.avatar-panel { background: var(--surface); border: 3px solid var(--border); border-radius: var(--r-xl); padding: var(--sp-4); box-shadow: var(--sh-1); }

.avatar-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(calc(var(--size, 60px) + 14px), 1fr)); gap: 8px; justify-items: center; }
.avatar-option {
  position: relative; display: inline-flex; padding: 4px; border: 3px solid transparent; border-radius: 50%; background: transparent; cursor: pointer;
  min-width: 48px; min-height: 48px; touch-action: manipulation; transition: transform 0.12s var(--ease-bounce);
}
.avatar-option:hover { transform: scale(1.08); }
.avatar-option[aria-checked="true"] { border-color: var(--primary); background: var(--primary-soft); transform: scale(1.1); }
.avatar-option[aria-checked="true"]::after {
  content: "✓"; position: absolute; right: -2px; bottom: -2px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--primary); color: var(--on-primary); font-weight: 900; font-size: 14px; display: flex; align-items: center; justify-content: center; border: 2px solid var(--surface);
}
.avatar-option .avatar { box-shadow: none; border-width: 0; }

/* ------------------------------------------------------------------------------------------ small shared bits used by the student / teacher pages */
.stat-tile { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4); background: var(--surface); border: 2px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-1); }
.stat-tile .stat-icon { font-size: 2rem; line-height: 1; }
.stat-tile .stat-value { font-size: var(--fs-xl); font-weight: 900; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-tile .stat-label { color: var(--text-muted); font-size: var(--fs-sm); font-weight: 700; }
.stat-tile .stat-hint { color: var(--text-muted); font-size: var(--fs-xs); }
.link-row { display: flex; flex-wrap: wrap; gap: var(--sp-3); }
.section-title { display: flex; align-items: center; gap: var(--sp-2); margin: var(--sp-6) 0 var(--sp-3); }
.soon-card { text-align: center; }

/* text that sits directly on the decorated page background (placeholders, 404, error pages) gets a calm panel */
.state-page { min-height: 0; margin: var(--sp-8) auto; padding: var(--sp-8) var(--sp-5); background: rgba(255, 255, 255, 0.88); border-radius: var(--r-xl); }

/* ------------------------------------------------------------------------------------------ workbench (game screen, replay, level-editor preview)
   <div class="workbench">
     <section class="wb-board">   board host + .wb-controls + messages   </section>
     <section class="wb-editor">  editor host (createEditor fills it)   </section>
   </div>
   >= 900px wide: board left, editor right, both as tall as the free screen (the board is sticky); narrower: board on top (limited
   height so the cells stay big), editor below. Phones scroll the page. --wb-h = the free height below the shell. */
:root { --chrome-bottom: 0px; }
body.has-bottom-nav { --chrome-bottom: var(--bottom-nav-h); }
.workbench {
  --wb-h: calc(100vh - var(--header-h) - var(--chrome-bottom) - env(safe-area-inset-bottom, 0px) - var(--sp-8));
  display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); align-items: start;
  width: 100%; max-width: 1500px; margin: 0 auto; padding: var(--sp-3) var(--gutter) var(--sp-4);
}
@supports (height: 100dvh) {
  .workbench { --wb-h: calc(100dvh - var(--header-h) - var(--chrome-bottom) - env(safe-area-inset-bottom, 0px) - var(--sp-8)); }
}
.wb-board { --board-max-h: min(43vh, 430px); display: flex; flex-direction: column; gap: var(--sp-3); min-width: 0; }
.wb-board-box { padding: var(--sp-2); background: var(--surface); border: 2px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--sh-1); }
.wb-editor { min-width: 0; height: 520px; }
/* the editor host needs a definite height, otherwise .be-host (height: 100%) grows with its blocks and the page scrolls instead of the workspace */
.wb-editor > * { height: 100%; min-height: 0; }
.wb-controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.wb-controls .btn { flex: 1 1 auto; }
.wb-controls .segmented { flex: 1 1 100%; justify-content: center; }
.wb-controls .segmented button { flex: 1 1 0; }
@media (min-width: 600px) { .wb-controls .segmented { flex: 0 1 auto; } .wb-controls .btn { flex: 0 1 auto; } .wb-controls .btn-lg { flex-grow: 1; } }
.wb-message { padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); background: var(--surface); border: 2px solid var(--border); font-weight: 700; }
.wb-message.is-success { background: var(--success-soft); border-color: var(--success); }
.wb-message.is-fail { background: var(--warning-soft); border-color: var(--warning); }
@media (max-width: 899px) {
  .wb-board-box { padding: 0; background: transparent; border: 0; box-shadow: none; }   /* the board is narrower than the page: no empty white frame around it */
}
@media (min-width: 600px) and (max-width: 899px) {
  .wb-editor { height: max(430px, calc(var(--wb-h) - 520px)); }
}
@media (min-width: 900px) {
  .workbench { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); }
  .wb-board { --board-max-h: max(300px, calc(var(--wb-h) - 190px)); position: sticky; top: calc(var(--header-h) + var(--sp-3)); }
  .wb-editor { height: max(460px, var(--wb-h)); }
  .wb-controls .segmented { flex: 0 1 auto; }
}
@media (max-width: 599px) {
  .wb-board { --board-max-h: min(46vh, 360px); }
  .wb-controls { display: grid; grid-template-columns: 1.7fr 1fr 1fr; gap: var(--sp-2); }
  .wb-controls .btn { min-width: 0; padding-left: 0.4em; padding-right: 0.4em; }
  .wb-controls .btn-lg { font-size: var(--fs-lg); }
  .wb-controls .btn:not(.btn-lg) { font-size: var(--fs-sm); gap: 0.3em; }
  .wb-controls .segmented { grid-column: 1 / -1; }
  .wb-editor { height: max(520px, 72vh); }
  .workbench { padding-left: 10px; padding-right: 10px; }
}
