/* VB TrainingForm chalk: Resources\SQUEAKYCHALKSOUND.TTF → play/resources/ui/ via sync-from-vb.ps1 (same filename; case matters on Linux hosts). */
@font-face {
  font-family: FactrisChalk;
  src: url("./resources/ui/SQUEAKYCHALKSOUND.TTF") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: FactrisDigital;
  src: url("./resources/ui/Digital_tech.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  /* VB Form1 Panel1 chalk green */
  --chalk: rgb(239, 247, 215);
  /* VB TrainingForm chalk stack: FactrisChalk + fallbacks (Chalkduster early for iOS; avoid Apple Chancery — too italic for + ( ) if webfont misses). */
  --practice-chalk-font: FactrisChalk, Chalkduster, "Segoe Print", "Segoe Script", "Bradley Hand ITC", "Comic Sans MS", cursive;
  /* Home canvas menu labels (Learn the Basics, Log in, etc.) */
  --factris-menu-btn-font: "Segoe UI", system-ui, -apple-system, Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif;
  --factris-digital-font: FactrisDigital, "Share Tech Mono", "Segoe UI Mono", Consolas, monospace;
  --chalk-deep: rgb(210, 222, 175);
  --wood-dark: #3d2914;
  --wood-mid: #6b4423;
  --ink: #1a1f14;
  --ink-muted: #3d4530;
  --frame: #5c3d1e;
  --btn-face: linear-gradient(180deg, #f8faf0 0%, #dce8c4 45%, #c5d4a8 100%);
  --btn-border: #4a5a2a;
  --shadow: rgba(30, 25, 15, 0.35);
  /* VB Resources → play/resources/ui/ via sync-from-vb.ps1 */
  --factris-blank-btn-up: url("./resources/ui/blank_button_up.png");
  --factris-blank-btn-down: url("./resources/ui/blank_button_down.png");
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  margin: 0;
  min-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* iOS Safari zooms the page when focusing inputs below 16px and often stays zoomed after blur. */
@media (hover: none) and (pointer: coarse) {
  html {
    touch-action: manipulation;
  }

  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="hidden"]):not([type="image"]):not([type="file"]),
  select,
  textarea {
    font-size: 16px;
  }
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--wood-dark);
  color: var(--ink);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

#app {
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.shell {
  min-height: 100%;
  min-height: 100dvh;
}

/**
 * Our shells use display:flex — that wins over the default [hidden] { display:none }
 * from the UA stylesheet, so Practice would appear on top of Home on initial load.
 */
#shell-home[hidden],
.shell-home[hidden],
#shell-game[hidden],
.shell-game[hidden],
#shell-practice[hidden],
.shell-practice[hidden] {
  display: none !important;
}

#shell-home.shell-home {
  flex: 1 1 auto;
  min-height: 0;
}

/* --- Home (VB chalk table + wood trim) --- */
.shell-home {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.home-backdrop {
  position: absolute;
  inset: 0;
  background-color: var(--chalk);
  /* Omit bitmap — VB asset contained oversized slogan text behind the layout */
  filter: saturate(1.05);
}

.home-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(239, 247, 215, 0.15) 0%, rgba(239, 247, 215, 0.55) 100%);
  pointer-events: none;
}

.home-content {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 4vw, 2.5rem);
  text-align: center;
}

.home-header {
  max-width: 36rem;
  margin-bottom: clamp(1.25rem, 4vw, 2.5rem);
}

.home-title {
  margin: 0;
  font-size: clamp(2.4rem, 8vw, 3.8rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}

.home-sub {
  margin: 0.75rem 0 0;
  font-size: clamp(0.95rem, 2.8vw, 1.1rem);
  color: var(--ink-muted);
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

/* VB-style canvas home (Form1 Panel1) */
.home-vb-column {
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: 0;
  padding: max(env(safe-area-inset-top, 0px), clamp(0.2rem, 0.8vw, 0.5rem)) clamp(0.5rem, 2vw, 1.25rem) 0.5rem;
  max-width: none;
  margin: 0 auto;
  width: 100%;
}

.home-play-hint {
  display: none;
  margin: 0 0 0.75rem;
  padding: 0.65rem 0.85rem;
  max-width: 56rem;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--ink-muted);
  background: rgba(255, 255, 255, 0.35);
  border: 1px solid rgba(74, 90, 42, 0.25);
  border-radius: 10px;
}

body.play-dev .home-play-hint {
  display: block;
}

.home-player-card {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  align-self: stretch;
  margin: 0 0 0.35rem;
  padding: 0.28rem 0.5rem;
  width: 100%;
  box-sizing: border-box;
  border: 2px solid rgba(74, 90, 42, 0.45);
  border-radius: 14px;
  background: rgba(250, 252, 244, 0.84);
  box-shadow: 0 6px 18px rgba(30, 25, 15, 0.14);
}

.home-player-card-inner {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem 0.55rem;
  width: 100%;
  min-width: 0;
  font-weight: 700;
}

.home-hud-main {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 0.05rem;
  min-width: 0;
}

.home-hud-end {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
}

.home-player-name {
  flex: 0 1 auto;
  min-width: 0;
  max-width: min(12rem, 28vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
  font-size: 0.92em;
}

.game-hud-stat {
  flex: 0 0 auto;
  white-space: nowrap;
}

.home-hud-main .game-hud-stat {
  line-height: 1.15;
}

.home-hud-main .game-hud-stat--best {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game-hud-stat strong {
  font-weight: inherit;
}

.home-lives-grid {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1.45rem));
  grid-template-rows: repeat(2, minmax(0, 1.45rem));
  gap: 0;
  width: calc(6 * 1.45rem);
  max-width: min(calc(6 * 1.45rem), 42vw);
  border: 1px solid rgba(26, 31, 20, 0.55);
  box-sizing: border-box;
  background: rgba(130, 130, 130, 0.2);
}

.home-life-heart {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: fill;
  image-rendering: pixelated;
  vertical-align: top;
}

/* Single flex child: canvas bitmap size is set in JS from this box (ResizeObserver). */
.home-canvas-area {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  width: 100%;
  display: block;
  position: relative;
}

.home-canvas-area canvas {
  display: block;
  width: 100%;
  height: 100%;
  vertical-align: top;
  border-radius: 0;
  box-shadow: none;
  touch-action: manipulation;
}

/* Sound / volume (VB-style chalk green panel over canvas) */
.home-audio-dock {
  position: absolute;
  right: max(4px, env(safe-area-inset-right));
  bottom: max(4px, env(safe-area-inset-bottom));
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  pointer-events: none;
}

.home-audio-dock > * {
  pointer-events: auto;
}

.home-audio-toggle {
  font: inherit;
  font-weight: 600;
  min-height: 40px;
  padding: 0.38rem clamp(0.6rem, 1.6vw, 0.9rem);
  border-radius: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.home-audio-toggle:hover:not(:disabled):not(:active) {
  filter: brightness(1.06);
}

.home-audio-panel {
  width: min(18rem, calc(100vw - 2.5rem));
  padding: 0.55rem 0.65rem 0.65rem;
  border: 2px solid #1a1f14;
  border-radius: 6px;
  background: linear-gradient(180deg, rgb(232, 244, 210) 0%, rgb(210, 226, 175) 100%);
  box-shadow: 0 4px 12px var(--shadow);
  font-size: 0.82rem;
}

.home-audio-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
  gap: 0.5rem;
}

.home-audio-panel-title {
  font-weight: 700;
  color: var(--ink);
}

.home-audio-close {
  flex: 0 0 auto;
  width: 1.65rem;
  height: 1.65rem;
  padding: 0;
  line-height: 1;
  font-size: clamp(0.95rem, 2.6vw, 1.15rem);
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.home-audio-row {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
  color: var(--ink);
}

.home-audio-row input[type="range"] {
  width: 100%;
  accent-color: #2563eb;
}

.home-audio-mutes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 0.25rem;
  padding-top: 0.35rem;
  border-top: 1px dashed rgba(26, 31, 20, 0.35);
}

.home-audio-check {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  color: var(--ink);
  font-size: 0.8rem;
}

.home-audio-check input {
  width: 1rem;
  height: 1rem;
  accent-color: #2563eb;
}

.home-footer-vb {
  flex: 0 0 auto;
  margin-top: auto;
  padding-top: 0.85rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 0.5rem 0.85rem;
  width: 100%;
  max-width: none;
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.factris-global-footer {
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr);
  column-gap: 0.85rem;
}

.home-footer-share.game-share-links.game-share-links--icons {
  padding-right: 0.85rem;
  border-right: 1px solid rgba(45, 51, 33, 0.28);
}

.home-footer-tools {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  padding-left: 0.15rem;
}

.factris-footer-menu-btn {
  min-height: 34px;
  padding: 0.28rem 0.65rem;
  font-size: 0.82rem;
}

.home-audio-dock--footer {
  position: relative;
  right: auto;
  bottom: auto;
  z-index: 6;
  pointer-events: none;
}

.home-audio-dock--footer > * {
  pointer-events: auto;
}

.home-audio-toggle--icon {
  width: 2.35rem;
  height: 2.35rem;
  min-height: 2.35rem;
  padding: 0.2rem;
  border-radius: 8px;
  background-color: transparent !important;
  background-image: none !important;
  box-shadow: none;
  color: inherit;
  text-shadow: none;
}

.home-audio-toggle--icon:hover:not(:disabled):not(:active) {
  filter: none;
  background-color: rgba(30, 25, 15, 0.08) !important;
}

.home-audio-toggle--icon:active:not(:disabled) {
  background-color: rgba(30, 25, 15, 0.14) !important;
  background-image: none !important;
  transform: none;
}

.home-audio-toggle__icon {
  display: block;
  width: 1.65rem;
  height: 1.65rem;
  object-fit: contain;
  pointer-events: none;
  background: transparent;
}

.shell-home:has(#btn-home-options:not([hidden])) #btn-home-footer-options {
  display: none !important;
}

.home-audio-dock--footer .home-audio-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.35rem);
}

.home-footer-share.game-share-links.game-share-links--icons {
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.24rem;
  max-width: 100%;
}

.home-footer-share .game-share-icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: transparent;
}

.home-footer-share .game-share-icon-btn:hover {
  background: rgba(30, 25, 15, 0.08);
}

.home-footer-share .game-share-icon-btn:active {
  background: rgba(30, 25, 15, 0.12);
}

.home-footer-share .game-share-svg {
  width: 17px;
  height: 17px;
}

.home-footer-share .game-share-copy-btn {
  min-height: 30px;
  padding: 0 0.28rem;
  font-size: 12px;
  background: transparent;
  border-color: rgba(102, 126, 234, 0.78);
}

.home-footer-share .game-share-copy-btn:hover {
  background: rgba(102, 126, 234, 0.12);
}

.shell-practice > .shell-practice-footer.home-footer-vb,
.shell-game > .shell-game-footer.home-footer-vb {
  flex-shrink: 0;
  margin-top: auto;
  padding-top: 0.65rem;
  padding-bottom: max(0.35rem, env(safe-area-inset-bottom));
  border-top: 2px solid rgba(45, 51, 33, 0.42);
  background: linear-gradient(180deg, rgba(240, 244, 228, 0.55) 0%, rgba(218, 228, 198, 0.42) 100%);
}

.shell-game > .shell-game-footer.home-footer-vb {
  padding-left: clamp(0.65rem, 2.2vw, 1rem);
  padding-right: clamp(0.65rem, 2.2vw, 1rem);
}

@media (max-width: 720px) {
  .home-footer-vb,
  .factris-global-footer {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .home-footer-share.game-share-links.game-share-links--icons {
    padding-right: 0;
    border-right: none;
  }

  .home-footer-link {
    justify-self: center;
  }

  .home-footer-copy {
    text-align: center;
    justify-self: center;
  }

  .home-footer-tools {
    justify-self: center;
    padding-left: 0;
  }
}

@media (min-width: 861px) {
  .factris-footer-menu-btn {
    display: inline-flex;
  }

  .shell-home .factris-footer-menu-btn {
    display: inline-flex;
  }

  .shell-practice .factris-footer-menu-btn {
    display: inline-flex;
  }
}

@media (max-width: 860px) {
  .factris-footer-menu-btn {
    display: none !important;
  }

  .shell-game-footer.home-footer-vb {
    display: none !important;
  }

  .shell-home .home-footer-vb.factris-global-footer .home-footer-link,
  .shell-home .home-footer-vb.factris-global-footer .home-footer-share,
  .shell-home .home-footer-vb.factris-global-footer .home-footer-copy {
    display: none;
  }

  .shell-home .home-footer-vb.factris-global-footer {
    grid-template-columns: 1fr;
    padding-top: 0.35rem;
    padding-bottom: max(0.25rem, env(safe-area-inset-bottom));
    border-top: none;
    background: transparent;
  }

  .shell-home .home-footer-tools,
  .shell-practice .home-footer-tools {
    justify-content: flex-end;
    justify-self: stretch;
    width: 100%;
    padding-right: max(0.35rem, env(safe-area-inset-right));
  }

  .shell-home .home-audio-dock--footer,
  .shell-practice .home-audio-dock--footer {
    align-items: flex-end;
  }

  /* Footer speaker sits bottom-right; panel anchors to viewport so it cannot clip left */
  .shell-home .home-audio-dock--footer .home-audio-panel,
  .shell-practice .home-audio-dock--footer .home-audio-panel {
    position: fixed;
    right: max(0.5rem, env(safe-area-inset-right));
    bottom: max(0.45rem, env(safe-area-inset-bottom));
    top: auto;
    left: auto;
    z-index: 1300;
    width: min(18rem, calc(100vw - 1rem));
  }

  .shell-practice .shell-practice-footer.factris-global-footer .home-footer-link,
  .shell-practice .shell-practice-footer.factris-global-footer .home-footer-share,
  .shell-practice .shell-practice-footer.factris-global-footer .home-footer-copy {
    display: none;
  }

  .shell-practice .shell-practice-footer.factris-global-footer {
    grid-template-columns: 1fr;
    padding-top: 0.35rem;
    border-top: none;
    background: transparent;
  }
}

/* Developer tools inside account modal — only on ?dev=1 or play/test.html */
body:not(.play-dev) .account-modal-dev {
  display: none !important;
}

body:not(.play-dev) .banner-dev,
body:not(.play-dev) #session-dev-summary,
body:not(.play-dev) #panel-profile,
body:not(.play-dev) #panel-audio,
body:not(.play-dev) #panel-tiles,
body:not(.play-dev) .foot-dev {
  display: none !important;
}

.home-player-card[hidden] {
  display: none !important;
}

.home-footer-link {
  justify-self: start;
  color: #1d4ed8;
  text-decoration: underline;
}

.home-footer-link:hover {
  color: #1e40af;
}

.home-footer-copy {
  justify-self: end;
  text-align: right;
}

.session-dev-summary {
  margin: 0 0 0.75rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  background: rgba(30, 41, 59, 0.65);
  border: 1px solid #475569;
  font-size: 0.9rem;
  color: #e2e8f0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.btn-chalk {
  appearance: none;
  font: inherit;
  font-weight: 600;
  padding: 0.65rem 1.15rem;
  border-radius: 0;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  font-size: clamp(0.96rem, 0.82rem + 0.55vw, 1.22rem);
}

.btn-chalk:not(.ghost):active {
  transform: translateY(1px);
}

.btn-chalk.ghost:active {
  transform: translateY(1px);
}

.btn-chalk.primary {
  padding-left: 1.75rem;
  padding-right: 1.75rem;
  font-size: clamp(1.05rem, 0.92rem + 0.6vw, 1.32rem);
}

.btn-chalk.ghost {
  background-image: none !important;
  background-color: rgba(255, 255, 255, 0.35);
  border: 2px solid rgba(74, 90, 42, 0.55);
  color: var(--ink);
  text-shadow: none;
  box-shadow: none;
}

.btn-chalk.ghost:active:not(:disabled) {
  background-image: none !important;
  background-color: rgba(255, 255, 255, 0.26);
}

/* Account modal overlay */
.account-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(env(safe-area-inset-top), 0.75rem) max(env(safe-area-inset-right), 0.75rem)
    max(env(safe-area-inset-bottom), 0.75rem) max(env(safe-area-inset-left), 0.75rem);
}

.account-modal[hidden] {
  display: none !important;
}

.account-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
}

.account-modal-dialog {
  position: relative;
  z-index: 1;
  width: min(26rem, 100%);
  max-height: min(90dvh, 40rem);
  overflow: auto;
  border-radius: 14px;
  border: 3px solid #72623f;
  background: var(--chalk);
  color: var(--ink);
  font-family: var(--factris-menu-btn-font);
  padding: 1rem 1.1rem 1.15rem;
  box-shadow:
    0 24px 48px rgba(0, 0, 0, 0.35),
    inset 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.account-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.account-modal-header h2 {
  margin: 0;
  font-size: clamp(1.05rem, 0.95rem + 0.45vw, 1.25rem);
  font-weight: 700;
  color: var(--ink);
}

.account-modal-close {
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
  margin: -0.35rem -0.35rem 0 0;
  padding: 0;
  border: none;
  border-radius: 0;
  appearance: none;
  background-color: #2d3318;
  background-image: var(--factris-blank-btn-up);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  color: #fff;
  font-family: var(--factris-menu-btn-font);
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.92);
  cursor: pointer;
}

.account-modal-close:active {
  background-image: var(--factris-blank-btn-down);
}

.account-modal-status {
  margin: 0 0 0.65rem;
  min-height: 0;
  font-size: clamp(0.88rem, 0.8rem + 0.35vw, 1rem);
  color: #7f1d1d;
}

.account-modal-status:empty {
  display: none;
}

.account-view {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.account-view[hidden],
.account-wizard-step[hidden],
.account-google-extra[hidden],
.account-google-block[hidden],
.account-legacy-block[hidden],
#account-field-text-wrap[hidden],
#account-field-pass-wrap[hidden],
#account-wizard-email-actions[hidden],
#btn-forgot-password[hidden],
#btn-show-legacy-login[hidden],
#google-hint:empty,
#google-username-hint:empty {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.account-wizard-teacher-link {
  margin-top: 0.5rem;
}

.account-wizard-form {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin: 0;
}

.account-wizard-prompt {
  margin: 0 0 0.5rem;
  font-size: clamp(0.95rem, 0.88rem + 0.35vw, 1.08rem);
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
}

.account-chalk-field {
  margin: 0.35rem 0 0.55rem;
}

.account-chalkboard {
  position: relative;
  overflow: hidden;
  padding: 0.85rem 0.9rem 0.95rem;
  border-radius: 14px;
  border: 3px solid #72623f;
  background-color: rgba(45, 52, 36, 0.95);
  background-image:
    url("./resources/ui/chalkboard.png"),
    radial-gradient(circle at 18% 20%, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.03) 20%, rgba(0, 0, 0, 0) 42%),
    linear-gradient(180deg, rgba(83, 93, 63, 0.35) 0%, rgba(40, 48, 31, 0.55) 100%);
  background-size: 100% 100%, auto, auto;
  background-position: center, 18% 20%, 50% 0%;
  background-repeat: no-repeat, no-repeat, no-repeat;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.05),
    inset 0 18px 30px rgba(255, 255, 255, 0.05),
    inset 0 -20px 32px rgba(0, 0, 0, 0.22);
}

.account-chalkboard--compact {
  padding: 0.65rem 0.75rem 0.75rem;
}

.account-chalk-input {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0.15rem 0.1rem;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--chalk);
  font-size: clamp(0.95rem, 3vw, 1.45rem);
  line-height: 1.4;
  outline: none;
  box-shadow: none;
  caret-color: var(--chalk);
}

.account-chalk-input::placeholder {
  color: rgba(239, 247, 215, 0.42);
}

.account-chalk-input:focus {
  outline: none;
}

.account-modal .account-wizard-btn {
  width: 100%;
  max-width: 100%;
  min-height: 38px;
  margin-top: 0.35rem;
  padding: 0.3rem 0.75rem;
  font-family: var(--factris-menu-btn-font);
  font-weight: 600;
  font-size: clamp(0.82rem, 0.72rem + 0.4vw, 0.98rem);
}

.account-wizard-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.35rem;
}

.account-wizard-link {
  margin: 0.25rem 0 0;
  padding: 0;
  border: none;
  background: none;
  color: var(--ink);
  font-size: clamp(0.85rem, 0.78rem + 0.3vw, 0.95rem);
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  align-self: flex-end;
}

.account-wizard-link:hover {
  color: #3d4a24;
}

.account-wizard-email-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

.account-chalk-label {
  display: block;
  margin: 0 0 0.35rem;
  font-size: clamp(0.95rem, 0.88rem + 0.35vw, 1.08rem);
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
}

.account-signup-inbox-hint {
  margin-top: 0.5rem;
  line-height: 1.45;
  color: var(--ink);
}

.account-signup-or-email {
  margin: 0.35rem 0 0.5rem;
  line-height: 1.45;
  color: var(--ink);
}

.account-view-signup .account-chalk-field:first-of-type {
  margin-top: 0.15rem;
  padding-top: 0.55rem;
  border-top: 2px dashed rgba(74, 90, 42, 0.45);
}

.game-demo-account-gate__note {
  margin: 0 0 0.65rem;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--ink);
}

.account-field {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--ink);
  margin: 0.45rem 0;
}

/* Chalk typography only inside chalkboard inputs (login / signup fields). */
.account-email-handoff-wrap {
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px dashed rgba(0, 0, 0, 0.2);
}

.account-chalk-input--code {
  font-family: ui-monospace, 'Cascadia Code', monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.account-modal .account-chalk-input {
  font-family: var(--practice-chalk-font);
  font-style: normal;
  font-synthesis: none;
}

.account-google-block {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.account-google-hint {
  margin: 0 0 0.35rem !important;
}

.account-google-btn-wrap {
  display: flex;
  justify-content: center;
  margin: 0.15rem 0 0;
}

.account-google-extra {
  margin-top: 0.15rem;
  padding: 0;
  border: none;
  background: transparent;
}

.account-google-username-hint {
  margin: 0.25rem 0 0;
  color: var(--ink);
}

.account-legacy-block {
  margin-top: 0.35rem;
  padding-top: 0.55rem;
  border-top: 2px dashed rgba(74, 90, 42, 0.45);
}

.account-legacy-toggle {
  align-self: center;
  margin: 0.5rem 0 0.15rem;
}

.account-primary-btn {
  margin-top: 0.35rem;
  appearance: none;
  box-sizing: border-box;
  width: 100%;
  padding: 0.65rem 1rem;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #ef4444 0%, #b91c1c 100%);
  color: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.account-primary-btn:active {
  transform: translateY(1px);
}

.account-secondary-btn {
  margin-top: 0.65rem;
  appearance: none;
  border: none;
  background: transparent;
  color: #93c5fd;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  text-align: center;
  padding: 0.35rem;
}

.account-modal-dialog .hint {
  color: var(--ink);
  font-size: clamp(0.82rem, 0.75rem + 0.3vw, 0.95rem);
}

.account-modal-dialog code {
  color: #3d4a24;
}

.account-modal-dev {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(148, 163, 184, 0.22);
}

.account-modal-dev .grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  gap: 1rem;
}

.account-modal-dev .card {
  background: rgba(24, 20, 14, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 1rem 1rem 1.1rem;
  backdrop-filter: blur(6px);
}

.account-modal-dev .card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  color: #f3f4f6;
}

.account-modal-dev label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: #9ca3af;
  margin: 0.55rem 0;
}

.account-modal-dev input {
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid #374151;
  background: #111827;
  color: #e5e7eb;
}

.banner-dev {
  margin: 0 0 1rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid #4b5563;
  background: rgba(55, 65, 81, 0.5);
  font-size: 0.88rem;
  color: #d1d5db;
}

.tag-dev {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #422006;
  color: #fdba74;
  vertical-align: middle;
}

.hint {
  font-size: 0.85rem;
  color: #9ca3af;
  margin: 0.35rem 0 0.5rem;
}

code {
  font-size: 0.85em;
  color: #bae6fd;
}

.out {
  margin: 0.75rem 0 0;
  padding: 0.65rem;
  border-radius: 8px;
  border: 1px dashed #374151;
  background: #0b1220;
  max-height: 220px;
  overflow: auto;
  font-size: 0.82rem;
  color: #e5e7eb;
}

.foot {
  margin-top: 1rem;
  color: #9ca3af;
  font-size: 0.9rem;
}

.foot-dev {
  display: block;
}

.tile-demo {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 72px;
  padding: 8px;
  border-radius: 10px;
  border: 1px dashed #374151;
  background: #0b1220;
  align-items: center;
}

.tile-demo span {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  border: 1px solid #1f2937;
  background-size: cover;
  background-position: center;
  image-rendering: crisp-edges;
}

/* --- Practice zone --- */
.shell-practice {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  height: 100dvh;
  min-height: 100dvh;
  max-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--chalk);
  color: var(--ink);
}

/* VB-style default chrome: blank_button_up / blank_button_down (copy via play/resources/sync-from-vb.ps1) */
:is(
  .shell-practice button.practice-btn,
  .shell-game button.practice-btn,
  .shell-home .home-player-card-actions button.practice-btn,
  .shell-home .home-footer-tools button.practice-btn,
  .shell-practice .home-footer-tools button.practice-btn,
  .shell-game .home-footer-tools button.practice-btn,
  .shell-practice button.practice-key,
  .shell-home .home-audio-toggle:not(.home-audio-toggle--icon),
  .shell-practice .home-audio-toggle:not(.home-audio-toggle--icon),
  .shell-game .home-audio-toggle:not(.home-audio-toggle--icon),
  .shell-home .home-audio-close,
  .shell-practice .home-audio-close,
  .shell-game .home-audio-close,
  .btn-chalk:not(.ghost),
  .account-modal .account-wizard-btn,
  .account-modal-dev section.card button
) {
  appearance: none;
  box-sizing: border-box;
  border: none;
  background-color: #2d3318;
  background-image: var(--factris-blank-btn-up);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.92);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 600;
  font-size: clamp(0.88rem, 0.72rem + 1.1vw, 1.38rem);
  line-height: 1.12;
  box-shadow: none;
  cursor: pointer;
}

/* Logged-in home player card: same family as canvas menu (Learn the Basics), smaller / lighter. */
.shell-home .home-player-card-actions button.practice-btn {
  font-family: var(--factris-menu-btn-font);
  font-weight: 500;
  font-size: clamp(0.68rem, 0.58rem + 0.32vw, 0.8rem);
  min-height: 28px;
  padding: 0.2rem 0.48rem;
  line-height: 1.1;
}

/*
 * That block's `display: inline-flex` beats the UA `[hidden] { display: none }` cascade on
 * buttons, so toggling `.hidden` / the `hidden` attribute would not actually hide header controls
 * (e.g. Return to Game vs ← Home). Force display off when marked hidden.
 */
.shell-practice button.practice-btn[hidden],
.shell-game button.practice-btn[hidden],
.shell-home .home-player-card-actions button.practice-btn[hidden],
.shell-home .home-footer-tools button.practice-btn[hidden],
.shell-practice .home-footer-tools button.practice-btn[hidden],
.shell-game .home-footer-tools button.practice-btn[hidden] {
  display: none !important;
}

.shell-home .home-footer-tools button.practice-btn,
.shell-practice .home-footer-tools button.practice-btn,
.shell-game .home-footer-tools button.practice-btn {
  min-height: 34px;
  padding: 0.28rem 0.75rem;
  font-size: 0.82rem;
}

:is(
    .shell-practice button.practice-btn,
    .shell-game button.practice-btn,
    .shell-home .home-player-card-actions button.practice-btn,
    .shell-home .home-footer-tools button.practice-btn,
    .shell-practice .home-footer-tools button.practice-btn,
    .shell-game .home-footer-tools button.practice-btn,
    .shell-practice button.practice-key,
    .shell-home .home-audio-toggle:not(.home-audio-toggle--icon),
    .shell-practice .home-audio-toggle:not(.home-audio-toggle--icon),
    .shell-game .home-audio-toggle:not(.home-audio-toggle--icon),
    .shell-home .home-audio-close,
    .shell-practice .home-audio-close,
    .shell-game .home-audio-close,
    .btn-chalk:not(.ghost),
    .account-modal .account-wizard-btn,
    .account-modal-dev section.card button
  ):disabled {
  opacity: 0.52;
  cursor: default;
}

:is(
    .shell-practice button.practice-btn,
    .shell-game button.practice-btn,
    .shell-home .home-player-card-actions button.practice-btn,
    .shell-home .home-footer-tools button.practice-btn,
    .shell-practice .home-footer-tools button.practice-btn,
    .shell-game .home-footer-tools button.practice-btn,
    .shell-practice button.practice-key,
    .shell-home .home-audio-toggle:not(.home-audio-toggle--icon),
    .shell-practice .home-audio-toggle:not(.home-audio-toggle--icon),
    .shell-game .home-audio-toggle:not(.home-audio-toggle--icon),
    .shell-home .home-audio-close,
    .shell-practice .home-audio-close,
    .shell-game .home-audio-close,
    .btn-chalk:not(.ghost),
    .account-modal .account-wizard-btn,
    .account-modal-dev section.card button
  ):active:not(:disabled) {
  background-image: var(--factris-blank-btn-down);
}

:is(
    .shell-practice button.practice-btn,
    .shell-game button.practice-btn,
    .shell-home .home-player-card-actions button.practice-btn,
    .shell-home .home-footer-tools button.practice-btn,
    .shell-practice .home-footer-tools button.practice-btn,
    .shell-game .home-footer-tools button.practice-btn,
    .shell-practice button.practice-key,
    .shell-home .home-audio-toggle:not(.home-audio-toggle--icon),
    .shell-practice .home-audio-toggle:not(.home-audio-toggle--icon),
    .shell-game .home-audio-toggle:not(.home-audio-toggle--icon),
    .shell-home .home-audio-close,
    .shell-practice .home-audio-close,
    .shell-game .home-audio-close,
    .btn-chalk:not(.ghost),
    .account-modal .account-wizard-btn,
    .account-modal-dev section.card button
  ):focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.account-modal-dev section.card button {
  padding: 0.55rem 1rem;
  min-height: 44px;
}

.practice-header {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.45rem 0.75rem 0.4rem;
  border-bottom: 2px solid var(--frame);
  background: rgba(255, 255, 255, 0.35);
}

.practice-header-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.65rem;
  width: 100%;
  position: relative;
}

.practice-header-meta {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
  gap: 0.45rem 0.65rem;
  flex-wrap: wrap;
}

.practice-header-end {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.45rem;
  margin-left: auto;
}

.practice-header-tools-stack {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.45rem;
}

.practice-header-tools-row {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
}

.practice-header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-left: 0;
  justify-content: flex-end;
}

.practice-btn-menu {
  gap: 0.45rem;
  white-space: nowrap;
}

/* Blanket `button.practice-btn { display: inline-flex }` overrides plain `.practice-btn-menu { display:none }`. */
#practice-header-menu-toggle {
  display: none !important;
}

.practice-btn-menu-icon {
  width: 0.95rem;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  box-shadow:
    0 -0.32rem 0 currentColor,
    0 0.32rem 0 currentColor;
}

.practice-btn-menu-text {
  font-size: 0.95em;
}

.practice-btn-menu--icon-only {
  gap: 0;
  justify-content: center;
  min-width: 2.35rem;
  min-height: 2.35rem;
  padding: 0.35rem 0.45rem;
}

.practice-name {
  font-weight: 700;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.practice-level-label {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  margin: 0;
  font-weight: 600;
}

.practice-level-word {
  flex: 0 0 auto;
  font-size: 0.92em;
}

.practice-level-control {
  display: inline-flex;
  align-items: stretch;
  border-radius: 6px;
  border: 1px solid var(--btn-border);
  overflow: hidden;
  background: linear-gradient(180deg, #ffffff 0%, #eef2e4 100%);
}

.practice-level-step {
  flex: 0 0 auto;
  width: 1.65rem;
  min-width: 1.65rem;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: linear-gradient(180deg, #f4f7ee 0%, #dbe4cc 100%);
  font: inherit;
  font-weight: 800;
  font-size: 0.95rem;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}

.practice-level-step:hover {
  background: linear-gradient(180deg, #fafdf4 0%, #e6efd6 100%);
}

.practice-level-step:active {
  background: linear-gradient(180deg, #dbe4cc 0%, #c9d4b4 100%);
}

.practice-level-step:disabled {
  opacity: 0.45;
  cursor: default;
}

.practice-level-input {
  width: 2.15rem;
  min-width: 2.15rem;
  margin: 0;
  padding: 0.2rem 0;
  border: none;
  border-left: 1px solid var(--btn-border);
  border-right: 1px solid var(--btn-border);
  border-radius: 0;
  background: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  text-align: center;
  color: var(--ink);
  line-height: 1.2;
  -moz-appearance: textfield;
  appearance: textfield;
}

.practice-level-input::-webkit-outer-spin-button,
.practice-level-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.shell-practice button.practice-btn,
.shell-game button.practice-btn {
  padding: clamp(0.38rem, 0.9vw, 0.55rem) clamp(0.65rem, 1.8vw, 1rem);
  min-height: 44px;
  touch-action: manipulation;
}

.practice-btn:disabled,
.practice-key:disabled {
  opacity: 0.55;
  cursor: default;
}

.practice-btn-small {
  font-size: clamp(0.82rem, 0.68rem + 0.75vw, 1.12rem);
  min-height: 38px;
}

/**
 * ChalkButton.js `variant: 'red'` — matches home canvas primary actions (VB-style bevel).
 */
.practice-btn--chalk-red {
  appearance: none;
  box-sizing: border-box;
  border: 2px solid #1a1a1a;
  border-radius: 4px;
  background: linear-gradient(180deg, #ff5a4a 0%, #d62828 48%, #9b1111 100%);
  background-image: none;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.92);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 700;
  font-size: clamp(0.9rem, 0.75rem + 1vw, 1.25rem);
  line-height: 1.12;
  min-height: 44px;
  padding: clamp(0.38rem, 0.9vw, 0.55rem) clamp(1rem, 2.5vw, 1.35rem);
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.38);
}

.practice-btn--chalk-red:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
  filter: brightness(0.94);
}

.practice-btn--chalk-red:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.practice-history-panel {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--frame);
  background: rgba(255, 255, 255, 0.5);
}

.practice-history-list {
  margin: 0.25rem 0 0.5rem;
  padding-left: 1.25rem;
  font-size: 0.9rem;
  max-height: 160px;
  overflow: auto;
}

.practice-problem {
  margin: 0;
  font-size: clamp(1.05rem, 2.6vw, 1.38rem);
  font-weight: 700;
}

.practice-header-problem {
  margin: 0.1rem 0 0;
  padding: 0 0.15rem;
  line-height: 1.25;
  width: 100%;
}

.practice-zero-pair-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0 0.75rem 0.5rem;
}

.practice-zero-pair-tools[hidden] {
  display: none !important;
}

.practice-workspace {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
}

.practice-zero-pair-modal {
  position: fixed;
  inset: 0;
  z-index: 85;
  pointer-events: none;
}

.practice-zero-pair-modal:not([hidden]) {
  pointer-events: auto;
}

.practice-zero-pair-modal[hidden] {
  display: none !important;
}

.practice-zero-pair-modal-backdrop {
  position: absolute;
  inset: 0;
  background: transparent;
}

.practice-zero-pair-modal-dialog {
  position: absolute;
  box-sizing: border-box;
  min-width: 210px;
  max-width: calc(100vw - 24px);
  padding: 0.65rem 0.75rem 0.55rem;
  border-radius: 10px;
  border: 2px solid #8f968a;
  background: linear-gradient(180deg, #eceee9 0%, #d5dad2 55%, #c9cfc4 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.75),
    inset 0 -1px 0 rgba(0, 0, 0, 0.06),
    0 6px 18px rgba(0, 0, 0, 0.28);
}

.practice-zero-pair-modal-title {
  margin: 0 0 0.45rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: lowercase;
  letter-spacing: 0.03em;
  color: #2a3028;
  text-align: center;
}

.practice-zero-pair-modal-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: center;
  align-items: stretch;
  margin-bottom: 0.55rem;
}

.practice-zero-pair-choice {
  margin: 0;
  padding: 0.35rem 0.45rem;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.35);
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.practice-zero-pair-choice:focus-visible {
  outline: 2px solid #3d6ee8;
  outline-offset: 2px;
}

.practice-zero-pair-choice:active {
  transform: scale(0.98);
}

.practice-zero-pair-choice--x .practice-zp-tile,
.practice-zero-pair-choice--unit .practice-zp-tile {
  vertical-align: middle;
}

.practice-zp-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 1px;
  border: 2px solid #111;
  font-weight: 700;
  color: #fff;
  font-family: Tahoma, sans-serif;
}

.practice-zero-pair-choice--x .practice-zp-tile {
  width: calc(28px * var(--practice-zp-scale, 1));
  height: calc(76px * var(--practice-zp-scale, 1));
  font-size: clamp(0.78rem, 2.6vw, 0.92rem);
}

.practice-zero-pair-choice--unit .practice-zp-tile {
  width: calc(40px * var(--practice-zp-scale, 1));
  height: calc(40px * var(--practice-zp-scale, 1));
  font-size: clamp(0.85rem, 2.8vw, 1rem);
}

.practice-zp-tile--x {
  background: #c62828;
}

.practice-zp-tile--nx {
  background: #1565c0;
}

.practice-zp-tile--u {
  background: #c62828;
}

.practice-zp-tile--nu {
  background: #1565c0;
}

.practice-zero-pair-cancel {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0.38rem 0.6rem;
  border-radius: 999px;
  border: 1px solid #b8bfb4;
  background: linear-gradient(180deg, #ffffff 0%, #eef1ea 100%);
  font: inherit;
  font-size: 0.84rem;
  text-transform: lowercase;
  cursor: pointer;
  color: #1a1f14;
}

.practice-zero-pair-cancel:active {
  transform: scale(0.99);
}

.practice-board-wrap {
  position: relative;
  z-index: 0;
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  margin: 0 0.5rem 0.5rem;
  border-radius: 10px;
  overflow: hidden;
  border: 3px solid #1a1f14;
  background-color: var(--chalk);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.12) 0%, rgba(255, 255, 255, 0) 40%);
  touch-action: none;
  overscroll-behavior: contain;
}

.practice-board-wrap .practice-audio-dock.home-audio-dock {
  z-index: 4;
}

/* Tall minimum only when factoring UI is hidden — otherwise panel + board exceed one viewport */
.shell-practice:not(.practice-factor-open) .practice-board-wrap {
  flex: 1 1 0;
  min-height: min(64vh, 780px);
}

.practice-board-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.12);
}

.practice-board-bg[hidden] {
  display: none !important;
}

.practice-canvas-wrap {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  width: 100%;
  min-height: 260px;
}

.practice-canvas-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.shell-practice.practice-factor-open .practice-canvas-wrap {
  min-height: min(200px, 28vh);
}

.practice-canvas-stage #practice-canvas {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.shell-practice.practice-factor-open .practice-canvas-stage #practice-canvas {
  min-height: 0;
}

.practice-factor-success-check {
  position: absolute;
  right: clamp(0.35rem, 3.5vw, 1.35rem);
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;
  font-size: clamp(2.25rem, 10vmin, 4rem);
  font-weight: 800;
  line-height: 1;
  color: #22c55e;
  text-shadow:
    0 2px 0 rgba(0, 0, 0, 0.2),
    0 0 14px rgba(34, 197, 94, 0.45);
  pointer-events: none;
}

.practice-factor-success-check[hidden] {
  display: none !important;
}

.practice-factor-success-equation {
  box-sizing: border-box;
  position: absolute;
  z-index: 2;
  margin: 0;
  padding: 0.15rem 0.5rem 0;
  text-align: center;
  font-family: var(--practice-chalk-font);
  font-style: normal;
  font-size: clamp(0.88rem, 2.9vw, 1.12rem);
  font-weight: 600;
  line-height: 1.28;
  color: #141814;
  background: transparent;
  border: none;
  pointer-events: none;
  white-space: nowrap;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.55),
    0 0 12px rgba(255, 255, 255, 0.35);
}

.practice-factor-success-equation[hidden] {
  display: none !important;
}

.practice-intro-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 0.75rem;
  background: rgba(30, 35, 20, 0.55);
  overflow: auto;
}

.practice-intro-overlay[hidden] {
  display: none !important;
}

.practice-intro-fallback {
  margin: 0.5rem 1rem 0;
  max-width: 36rem;
  padding: 0.75rem 1rem;
  text-align: center;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--chalk);
  background: rgba(0, 0, 0, 0.35);
  border-radius: 10px;
}

.practice-intro-fallback code {
  font-size: 0.85em;
  word-break: break-all;
}

.practice-intro-visual {
  position: relative;
  max-width: 100%;
  max-height: calc(100% - 4rem);
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.practice-intro-canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.practice-intro-canvas[hidden] {
  display: none !important;
}

.practice-intro-visual .practice-intro-img {
  max-width: 100%;
  max-height: calc(100% - 4rem);
  object-fit: contain;
  border-radius: 8px;
}

.practice-got-it {
  margin-top: 0.75rem;
}

/* display:grid here must not defeat the HTML hidden attribute */
#practice-factor-panel[hidden],
.practice-factor-panel[hidden] {
  display: none !important;
}

.practice-factor-panel {
  position: relative;
  z-index: 2;
  margin: 0 0.75rem 0.6rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 2px solid var(--frame);
  background: rgba(255, 255, 255, 0.55);
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(0, 2.1fr);
  grid-template-areas: "keypad chalk";
  gap: 0.75rem 1rem;
  align-items: stretch;
  flex: 0 1 auto;
  height: min(44vh, 580px);
  max-height: min(44vh, 580px);
  min-height: 0;
  overflow: hidden;
}

.shell-practice.practice-factor-open .practice-factor-panel {
  max-height: min(40vh, 520px);
  height: min(40vh, 520px);
}

.practice-factor-panel .practice-chalkboard {
  grid-area: chalk;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.practice-factor-panel .practice-chalk-display {
  flex: 0 1 auto;
}

.practice-factor-panel .practice-keypad {
  grid-area: keypad;
  min-height: 0;
  min-width: 0;
}

.practice-factor-prompt {
  margin: 0 0 0.5rem;
  padding: 0 0.35rem;
  color: var(--chalk);
  font-size: clamp(1.15rem, 3vw, 1.5rem);
  font-weight: 400;
  font-style: normal;
  line-height: 1.35;
  font-family: var(--practice-chalk-font);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.08);
  text-align: center;
}

.practice-factor-msg {
  margin: 0.5rem 0 0;
  min-height: 1.35rem;
  font-weight: 600;
  color: #dce9bf;
  text-align: center;
}

.practice-factor-panel .practice-factor-msg {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0.35rem 0.35rem 0.55rem;
  min-height: 2.75rem;
  font-size: clamp(0.92rem, 2.4vw, 1.12rem);
  line-height: 1.25;
}

.practice-factor-msg.practice-factor-msg--correct {
  font-size: clamp(2.25rem, 8vmin, 4rem);
  font-weight: 800;
  color: #f4ffd8;
  text-shadow:
    0 2px 0 rgba(0, 0, 0, 0.45),
    0 0 18px rgba(255, 255, 255, 0.18);
  line-height: 1.08;
  letter-spacing: 0.02em;
}

/* Falling-game → factor step: minimal practice chrome (same textures / keypad as practice). */
.shell-practice.practice-game-factor .practice-header-problem,
.shell-practice.practice-game-factor .practice-header-end {
  display: none !important;
}

.shell-practice.practice-game-factor #practice-history-panel {
  display: none !important;
}

.shell-practice.practice-game-factor .practice-zero-pair-tools {
  display: none !important;
}

.practice-board-wrap .practice-audio-dock {
  display: none !important;
}

.shell-practice.practice-game-factor.practice-factor-open .practice-board-wrap {
  background: #ffffff;
  border-color: rgba(90, 98, 104, 0.45);
}

.practice-factor-score-celebration {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: rgba(12, 14, 18, 0.28);
}

.practice-factor-score-celebration[hidden] {
  display: none !important;
}

.practice-factor-score-celebration__box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 1rem 1.75rem 1.15rem;
  border-radius: 14px;
  border: 3px solid rgba(220, 180, 60, 0.95);
  background: linear-gradient(180deg, rgba(26, 32, 22, 0.96) 0%, rgba(14, 18, 12, 0.98) 100%);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.practice-factor-score-celebration__label {
  font-size: clamp(0.82rem, 2.5vw, 1rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 248, 210, 0.85);
}

.practice-factor-score-celebration__value {
  font-family: var(--factris-digital-font);
  font-size: clamp(2.5rem, 12vmin, 4.5rem);
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: #fffbe6;
  text-shadow:
    0 3px 0 rgba(0, 0, 0, 0.35),
    0 0 22px rgba(255, 230, 120, 0.35);
}

.practice-chalk-input {
  caret-color: transparent;
}

.practice-chalkboard {
  --practice-chalkboard-image: none;
  position: relative;
  overflow: hidden;
  padding: 1.05rem 1rem 1.15rem;
  border-radius: 14px;
  border: 3px solid #72623f;
  font-family: var(--practice-chalk-font);
  font-style: normal;
  font-synthesis: none;
  background-color: rgba(45, 52, 36, 0.95);
  background-image:
    var(--practice-chalkboard-image, none),
    radial-gradient(circle at 18% 20%, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.03) 20%, rgba(0, 0, 0, 0) 42%),
    linear-gradient(180deg, rgba(83, 93, 63, 0.35) 0%, rgba(40, 48, 31, 0.55) 100%);
  background-size: 100% 100%, auto, auto;
  background-position: center, 18% 20%, 50% 0%;
  background-repeat: no-repeat, no-repeat, no-repeat;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.05),
    inset 0 18px 30px rgba(255, 255, 255, 0.05),
    inset 0 -20px 32px rgba(0, 0, 0, 0.22);
}

.practice-chalk-display {
  position: relative;
  flex: 1 1 auto;
  min-height: 6.25rem;
  min-width: 0;
  padding: 0.65rem clamp(2rem, 5vw, 2.75rem) 0.85rem;
  border-radius: 2px;
  border: none;
  background: transparent;
}

/* Answer row: placeholder centered; while typing, line is left-aligned and JS sets margin-left from measured full answer width */
.practice-chalk-line {
  width: 100%;
  text-align: center;
}

.practice-chalk-display:not(.practice-chalk-display--empty) .practice-chalk-line {
  text-align: left;
}

.practice-chalk-line-inner {
  display: inline-block;
  max-width: 100%;
  text-align: left;
  vertical-align: top;
}

.practice-chalk-display--empty .practice-chalk-line-inner {
  text-align: center;
}

/* Hidden duplicate of answer typography for measuring canonical answer width (practice-app.js) */
.practice-chalk-measure {
  position: absolute;
  left: 0;
  top: 0;
  visibility: hidden;
  pointer-events: none;
  white-space: nowrap;
  display: inline-block;
  font-size: clamp(1.25rem, 4vw, 1.95rem);
  line-height: 1.45;
  font-family: var(--practice-chalk-font);
  font-style: normal;
  font-synthesis: none;
}

.practice-chalk-placeholder {
  display: block;
}

.practice-chalk-placeholder,
.practice-chalk-answer {
  font-size: clamp(1.25rem, 4vw, 1.95rem);
  line-height: 1.45;
  font-family: var(--practice-chalk-font);
  font-style: normal;
  font-synthesis: none;
  word-break: break-word;
}

.practice-chalk-placeholder {
  color: rgba(239, 247, 215, 0.45);
}

.practice-chalk-placeholder[hidden] {
  display: none !important;
}

.practice-chalk-answer {
  display: inline;
  color: var(--chalk);
  white-space: pre-wrap;
  vertical-align: baseline;
}

.practice-chalk-caret-anchor {
  display: inline;
  width: 0;
  margin: 0;
  padding: 0;
  font-size: inherit;
  line-height: inherit;
  vertical-align: baseline;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
}

.practice-chalk-char-new {
  display: inline;
}

/* FactrisChalk is not CSS-italic, but + ( ) − are very slanted on small screens; touch UIs use a clearer hand stack for those glyphs only. */
.practice-chalk-op {
  font-style: normal;
  font-synthesis: none;
}

@media (hover: none) and (pointer: coarse) {
  .practice-chalk-op {
    font-family: Chalkduster, "Segoe Print", "Comic Sans MS", cursive;
  }
}

@keyframes practice-chalk-stroke {
  0% {
    opacity: 0.2;
    transform: translateY(2px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.practice-chalk-display.practice-writing .practice-chalk-char-new {
  animation: practice-chalk-stroke 0.28s ease-out;
}

.practice-chalk-eraser {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  transform-origin: 70% 60%;
  opacity: 0;
  transition: opacity 90ms ease;
}

.practice-chalk-eraser.practice-chalk-eraser-on {
  opacity: 1;
}

.practice-chalk-eraser-img {
  display: block;
  width: auto;
  height: clamp(1.75rem, 5vw, 2.35rem);
  max-width: min(42vw, 180px);
  object-fit: contain;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

.practice-chalk-cursor {
  position: absolute;
  left: 0.5rem;
  top: auto;
  bottom: 0.45rem;
  width: 1.75rem;
  height: 0.7rem;
  border-radius: 6px;
  background: linear-gradient(180deg, #f9f9f0 0%, #d7d8cd 100%);
  box-shadow:
    0 3px 6px rgba(0, 0, 0, 0.22),
    inset -4px 0 0 rgba(76, 92, 67, 0.2);
  opacity: 0.9;
  transform: rotate(-18deg);
  transform-origin: center center;
  transition:
    left 120ms ease,
    top 120ms ease,
    bottom 120ms ease,
    transform 120ms ease,
    opacity 120ms ease;
}

.practice-chalk-cursor.practice-chalk-cursor-asset {
  width: clamp(0.85rem, 2.4vw, 1.05rem);
  height: clamp(2.1rem, 6.2vw, 2.75rem);
  border-radius: 0;
  background-color: transparent;
  background-repeat: no-repeat;
  background-position: 50% 45%;
  background-size: contain;
  box-shadow: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.22));
  transform: rotate(0deg);
  /* Pivot near chalk tail so the writing tip tracks the caret line */
  transform-origin: 82% 92%;
}

.practice-chalk-cursor::after {
  content: "";
  position: absolute;
  right: -0.18rem;
  top: 0.14rem;
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: rgba(239, 247, 215, 0.85);
  box-shadow: 0 0 12px rgba(239, 247, 215, 0.45);
}

.practice-chalk-cursor.practice-chalk-cursor-asset::after {
  display: none;
}

.practice-chalk-display.practice-writing .practice-chalk-cursor {
  transform: translateY(-1px) rotate(-10deg);
}

.practice-chalk-display.practice-writing .practice-chalk-cursor.practice-chalk-cursor-asset {
  transform: translateY(-1px) rotate(6deg);
}

.practice-chalk-display.practice-chalk-erase-ui .practice-chalk-cursor {
  opacity: 0 !important;
  visibility: hidden;
}

.practice-keypad {
  container-type: size;
  container-name: practice-keypad;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 0.45rem;
  align-items: stretch;
  height: 100%;
  max-height: 100%;
  min-height: 0;
}

.practice-keypad-main {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: clamp(2px, 1cqmin, 6px);
  min-height: 0;
  height: 100%;
}

.practice-keypad-side {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr)) minmax(0, 1.15fr);
  gap: clamp(2px, 1cqmin, 6px);
  min-height: 0;
  height: 100%;
}

.shell-home .home-audio-toggle,
.shell-practice .home-audio-toggle,
.shell-game .home-audio-toggle {
  font-size: clamp(0.82rem, 0.68rem + 0.55vw, 1.08rem);
}

.practice-key {
  min-width: 0;
  min-height: 0;
  height: 100%;
  align-self: stretch;
  padding: clamp(2px, 1.2cqmin, 8px) clamp(2px, 1.5cqmin, 8px);
  font-weight: 800;
  font-size: clamp(0.62rem, min(3.6cqi, 5.2cqh), 1.48rem);
  line-height: 1.05;
  cursor: pointer;
  touch-action: manipulation;
}

.practice-key:active:not(:disabled) {
  transform: none;
}

.practice-key-submit {
  grid-column: 1 / -1;
}

@media (max-width: 860px) {
  .practice-header-bar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: start;
    gap: 0.35rem 0.45rem;
  }

  #practice-btn-back {
    grid-column: 1;
    grid-row: 1;
  }

  .practice-header-meta {
    grid-column: 2;
    grid-row: 1;
    flex-direction: row;
    align-items: center;
    align-self: center;
    padding-top: 0;
    min-width: 0;
  }

  .practice-header-end {
    grid-column: 3;
    grid-row: 1 / 3;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    margin-left: 0;
    min-width: 0;
  }

  .practice-header-tools-stack {
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
  }

  .practice-header-tools-row {
    justify-content: flex-end;
  }

  .practice-level-label {
    margin: 0;
    padding: 0;
    background: transparent;
    border-radius: 0;
    font-size: 0.85rem;
  }

  .practice-level-word {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  #practice-header-menu-toggle {
    display: inline-flex !important;
    min-height: 44px;
    padding-inline: 0.7rem;
  }

  .practice-header-actions {
    position: absolute;
    top: calc(100% + 0.4rem);
    right: 0;
    z-index: 8;
    width: min(15.5rem, calc(100vw - 1rem));
    margin-left: 0;
    padding: 0.45rem;
    border: 2px solid var(--frame);
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(250, 252, 244, 0.98) 0%, rgba(232, 239, 216, 0.98) 100%);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
    display: none !important;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
  }

  .shell-practice.practice-header-menu-open .practice-header-actions {
    display: flex !important;
  }

  .shell-practice.practice-header-menu-open .practice-btn-menu {
    background-image: var(--factris-blank-btn-down);
  }

  .practice-header-actions .practice-btn {
    width: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 780px) {
  .practice-header {
    gap: 0.4rem;
    padding: 0.45rem 0.55rem 0.45rem;
  }

  .practice-header-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    padding-top: 0.05rem;
  }

  .practice-level-label {
    gap: 0.35rem;
  }

  .practice-level-step {
    min-height: 2.1rem;
    width: 1.85rem;
    min-width: 1.85rem;
    font-size: 1rem;
  }

  .practice-level-input {
    min-height: 2.1rem;
    width: 2.35rem;
    min-width: 2.35rem;
    font-size: 1rem;
  }

  .practice-problem {
    font-size: clamp(1rem, 4.8vw, 1.25rem);
  }

  .practice-workspace {
    gap: 0.65rem;
    padding: 0 0.5rem 0.75rem;
  }

  .practice-factor-panel {
    margin: 0;
    padding: 0.6rem;
    grid-template-columns: 1fr;
    grid-template-areas: "chalk" "keypad";
    gap: 0.65rem;
    height: auto;
    max-height: none;
  }

  .practice-chalkboard {
    padding: 0.75rem 0.8rem 0.9rem;
  }

  .practice-board-wrap {
    margin: 0;
    flex: 1 1 0;
    min-height: 0;
  }

  .shell-practice:not(.practice-factor-open) .practice-board-wrap {
    flex: 1 1 auto;
    min-height: min(52vh, 560px);
  }

  .shell-practice.practice-factor-open .practice-workspace {
    display: grid;
    grid-template-columns: minmax(7.2rem, 0.9fr) minmax(0, 1.1fr);
    grid-template-areas:
      "board chalk"
      "keypad keypad";
    align-items: stretch;
  }

  .shell-practice.practice-factor-open .practice-factor-panel {
    display: contents;
  }

  .shell-practice.practice-factor-open .practice-board-wrap {
    grid-area: board;
    min-height: clamp(11rem, 27vh, 16.5rem);
    border-width: 2px;
    border-radius: 18px;
    box-shadow:
      0 10px 24px rgba(0, 0, 0, 0.14),
      inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  }

  .shell-practice.practice-factor-open .practice-canvas-wrap {
    min-height: 0;
  }

  .shell-practice.practice-factor-open .practice-chalkboard {
    grid-area: chalk;
    min-height: clamp(11rem, 27vh, 16.5rem);
    /* Extra top inset so “Factor: …” clears the painted wood frame on the chalkboard asset */
    padding: 1.35rem 0.75rem 0.9rem;
    border-radius: 18px;
    box-shadow: 0 10px 24px rgba(33, 39, 23, 0.18);
  }

  .shell-practice.practice-factor-open .practice-factor-prompt {
    margin-top: 0.15rem;
    margin-bottom: 0.35rem;
    padding: 0 0.1rem;
    font-size: clamp(0.95rem, 3.2vw, 1.1rem);
    line-height: 1.25;
  }

  .shell-practice.practice-factor-open .practice-chalk-display {
    min-height: 0;
    padding: 0.45rem 1rem 0.7rem;
  }

  .shell-practice.practice-factor-open .practice-chalk-placeholder,
  .shell-practice.practice-factor-open .practice-chalk-answer,
  .shell-practice.practice-factor-open .practice-chalk-measure {
    font-size: clamp(1rem, 3.8vw, 1.45rem);
    line-height: 1.35;
  }

  .shell-practice.practice-factor-open .practice-factor-msg {
    min-height: 2.15rem;
    padding: 0.25rem 0.2rem 0.1rem;
    font-size: clamp(0.86rem, 2.8vw, 1rem);
  }

  .shell-practice.practice-factor-open .practice-keypad {
    grid-area: keypad;
    min-height: clamp(14.25rem, 33vh, 19rem);
    height: clamp(14.25rem, 33vh, 19rem);
    padding: 0.55rem;
    gap: 0.5rem;
    border: 2px solid var(--frame);
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(252, 252, 248, 0.88) 0%, rgba(235, 241, 218, 0.96) 100%);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.14);
  }

  .shell-practice.practice-factor-open .practice-keypad-main,
  .shell-practice.practice-factor-open .practice-keypad-side {
    gap: 0.45rem;
  }

  .shell-practice.practice-factor-open .practice-key {
    font-size: clamp(0.9rem, 4.2vw, 1.3rem);
    padding: clamp(4px, 1.2cqmin, 8px);
  }

  .shell-practice.practice-factor-open .home-audio-toggle {
    padding: 0.28rem 0.5rem;
    font-size: 0.8rem;
  }

  .shell-practice.practice-factor-open .home-audio-panel {
    width: min(14rem, calc(100vw - 1.5rem));
  }
}

@media (max-width: 430px) {
  .practice-workspace {
    padding: 0 0.35rem 0.65rem;
  }

  .shell-practice.practice-factor-open .practice-workspace {
    grid-template-columns: minmax(6.2rem, 0.86fr) minmax(0, 1.14fr);
    gap: 0.5rem;
  }

  .practice-keypad {
    gap: 0.35rem;
  }

  .practice-key {
    min-height: 0;
    padding: clamp(2px, 1cqmin, 6px);
  }

  .shell-practice.practice-factor-open .practice-keypad {
    padding: 0.45rem;
  }

  .shell-practice.practice-factor-open .practice-keypad-main,
  .shell-practice.practice-factor-open .practice-keypad-side {
    gap: 0.35rem;
  }
}

/* --- Game shell --- */
.shell-game {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  padding-bottom: 0;
  background:
    radial-gradient(circle at 18% 8%, rgba(250, 252, 244, 0.38), transparent 30rem),
    linear-gradient(180deg, var(--chalk) 0%, var(--chalk-deep) 100%);
}

.game-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.75rem;
  padding-top: calc(0.55rem + env(safe-area-inset-top, 0px));
  padding-right: clamp(0.65rem, 2.2vw, 1rem);
  padding-bottom: 0.55rem;
  padding-left: clamp(0.65rem, 2.2vw, 1rem);
  border-bottom: 3px solid var(--frame);
  background: rgba(250, 252, 244, 0.9);
}

.game-header-more-options {
  display: none !important;
}

.game-mobile-transport {
  display: none;
}

@media (min-width: 861px) {
  #game-menu-toggle {
    display: none !important;
  }
}

@media (max-width: 860px) {
  .game-header {
    --game-header-btn-h: clamp(2rem, 7.5vw, 2.25rem);
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    gap: 0.22rem;
  }

  .game-header button.practice-btn {
    min-height: var(--game-header-btn-h);
  }

  .game-header > #game-btn-home.practice-btn {
    padding: 0.12rem 0.42rem;
    font-size: 0.82rem;
  }

  .game-title-block {
    min-height: var(--game-header-btn-h);
  }

  .game-problem {
    font-size: clamp(1.08rem, 3.4vw, 1.55rem);
    overflow-wrap: normal;
    word-break: normal;
  }

  .game-mobile-transport {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: flex-end;
    gap: 0.18rem;
  }

  .game-mobile-transport .game-vb-btn--aux,
  .game-mobile-transport .home-audio-toggle--icon,
  .game-header #game-menu-toggle.practice-btn-menu--icon-only {
    box-sizing: border-box;
    width: var(--game-header-btn-h);
    min-width: var(--game-header-btn-h);
    height: var(--game-header-btn-h);
    min-height: var(--game-header-btn-h);
    max-height: var(--game-header-btn-h);
    padding: 0.08rem;
  }

  .game-mobile-transport .game-vb-btn--aux .game-vb-btn__img {
    max-width: 100%;
    max-height: 100%;
  }

  .game-mobile-transport .home-audio-toggle__icon {
    width: 1.35rem;
    height: 1.35rem;
  }

  .game-header #game-menu-toggle.practice-btn-menu--icon-only {
    justify-content: center;
    min-width: var(--game-header-btn-h);
    padding: 0.08rem;
  }

  .game-mobile-transport .home-audio-dock {
    position: relative;
    align-items: center;
  }

  /* In-game header: open downward (footer rule opens upward and would clip off-screen) */
  .game-mobile-transport .home-audio-panel {
    position: fixed;
    top: max(3.15rem, calc(env(safe-area-inset-top) + 2.85rem));
    right: max(0.5rem, env(safe-area-inset-right));
    bottom: auto;
    left: auto;
    z-index: 1300;
    width: min(18rem, calc(100vw - 1rem));
  }

  .game-mobile-drawer {
    display: none !important;
  }
}

@media (min-width: 861px) {
  .game-mobile-transport {
    display: none !important;
  }
}

.game-title-block {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 2.85rem;
  padding: 0.2rem 0;
  text-align: center;
}

.game-problem {
  display: block;
  margin: 0;
  padding: 0.12em 0 0.06em;
  overflow-wrap: anywhere;
  word-break: break-word;
  color: var(--ink, #1a1f14);
  font-family: var(--practice-chalk-font);
  font-size: clamp(1.35rem, 4.2vw, 2.35rem);
  /* FactrisChalk @font-face is 400 only; synthetic bold breaks superscripts and + alternates. */
  font-weight: 400;
  font-synthesis: none;
  line-height: 1.2;
  letter-spacing: 0.02em;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.45),
    0 0 1px rgba(0, 0, 0, 0.18);
  /* Stylistic / contextual alternates for + and related glyphs when the font provides them (VB chalk). */
  font-feature-settings: "ss01" 1, "salt" 1, "calt" 1;
}

.game-layout {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(15rem, 19rem);
  gap: 0.85rem;
  padding: 0.85rem;
}

.game-board-panel,
.game-card {
  border: 3px solid var(--frame);
  border-radius: 18px;
  background: rgba(250, 252, 244, 0.86);
  box-shadow: 0 12px 26px rgba(30, 25, 15, 0.16);
}

.game-board-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  /**
   * Desktop hides .game-undo-mobile (in canvas wrap). Without explicit areas, auto-placement
   * can put the canvas on the 2nd row and the touch bar on the 3rd row (stealing height).
   */
  grid-template-areas:
    'hud'
    'board'
    'touch';
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 0.45rem 0.5rem 0.95rem;
  overflow: hidden;
  position: relative;
}

.game-hud {
  grid-area: hud;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.45rem 0.8rem;
  padding-bottom: 0.55rem;
  font-weight: 700;
}

.game-hud-lives {
  display: contents;
}

.game-lives-summary {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.game-lives-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 0;
  width: min(8.8rem, 28vw);
}

.game-life-heart {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  background: transparent;
  object-fit: fill;
  image-rendering: pixelated;
  vertical-align: top;
}

.game-canvas-wrap {
  position: relative;
  grid-area: board;
  align-self: stretch;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  min-width: 0;
  min-height: 0;
  aspect-ratio: auto;
  overflow: hidden;
  border: 3px solid #1a1f14;
  border-radius: 0;
  background: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.game-canvas-wrap:focus {
  outline: none;
}

/* Only the main board canvas fills the wrap; intro canvas lives in the controls overlay. */
#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  max-width: none;
  max-height: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Success overlay: backdrop uses pointer-events:none elsewhere — without this, skipped hit-tests fall
   through to the canvas; desktop mouse then triggers pointer capture on the board and breaks "Next Challenge". */
.game-canvas-wrap:has(#game-success-interstitial:not([hidden])) #game-canvas {
  pointer-events: none;
}

.game-canvas-wrap:has(#game-demo-account-gate:not([hidden])) #game-canvas {
  pointer-events: none;
}

/* Legacy hook — pause UI is drawn on #game-canvas (VB transparent_pause), not this layer. */
.game-overlay {
  display: none !important;
}

.game-overlay[hidden] {
  display: none !important;
}

/* Game / practice: no document scroll or pull-to-refresh while playing */
html.factris-shell-game,
html.factris-shell-practice {
  overscroll-behavior: none;
  height: 100%;
  height: 100dvh;
}

html.factris-shell-game body,
html.factris-shell-practice body {
  overscroll-behavior: none;
  overflow: hidden;
  height: 100%;
  height: 100dvh;
  /* Document-level horizontal pans become browser tab/back gestures; board uses pointer events. */
  touch-action: pan-y pinch-zoom;
}

html.factris-shell-game #app,
html.factris-shell-practice #app {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

/* First-session controls intro (game canvas area) */
.game-controls-intro {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: max(0.5rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right))
    max(0.5rem, env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-left));
  pointer-events: auto;
}

.game-controls-intro[hidden] {
  display: none !important;
}

.game-controls-intro__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(22, 28, 18, 0.72);
  backdrop-filter: blur(2px);
}

.game-controls-intro__panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  width: min(28rem, 100%);
  max-width: 100%;
  max-height: none;
  margin: auto;
  flex: 0 0 auto;
  overflow-x: hidden;
  overflow-y: visible;
  padding: 0.85rem 1rem 1rem;
  border: 3px solid var(--frame, #2d331f);
  border-radius: 16px;
  background: rgba(250, 252, 244, 0.97);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

.game-controls-intro__heading {
  margin: 0;
  font-size: clamp(1rem, 3.2vw, 1.2rem);
  font-weight: 800;
  text-align: center;
  color: #1a1f14;
}

.game-controls-intro__canvas {
  display: block;
  width: 100%;
  flex: 1 1 auto;
  min-height: 160px;
  max-height: 240px;
  border-radius: 10px;
  background: rgba(239, 247, 215, 0.55);
  border: 2px solid rgba(26, 31, 20, 0.2);
}

.game-controls-intro__caption {
  margin: 0;
  min-height: 2.75em;
  font-size: clamp(0.88rem, 2.8vw, 1rem);
  font-weight: 700;
  text-align: center;
  line-height: 1.35;
  color: #1a1f14;
}

.game-controls-intro__static {
  width: 100%;
  font-size: clamp(0.88rem, 2.8vw, 1rem);
  font-weight: 700;
  color: #1a1f14;
}

.game-controls-intro__static-list {
  margin: 0;
  padding-left: 1.25rem;
  text-align: left;
  line-height: 1.45;
}

.game-controls-intro__static-arrows {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.game-controls-intro__static-arrow-img {
  height: 40px;
  width: auto;
  image-rendering: auto;
}

.game-controls-intro__got-it {
  flex-shrink: 0;
  min-width: 7rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.practice-btn--primary {
  font-weight: 800;
}

/* Instructional spotlight (VB tutorial.vb washout + hint_command) — full game shell */
.game-spotlight {
  position: absolute;
  inset: 0;
  z-index: 140;
  pointer-events: auto;
  overflow: hidden;
}

.game-spotlight[hidden] {
  display: none !important;
}

.game-spotlight__dim {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.game-spotlight__mask-dim {
  fill: rgba(12, 18, 14, 0.46);
}

.game-spotlight__ring {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  border: 3px solid #2a9d4a;
  background: transparent;
  box-sizing: border-box;
  box-shadow:
    0 0 6px rgba(255, 255, 255, 0.88),
    0 0 16px rgba(255, 255, 255, 0.52),
    0 0 28px rgba(255, 255, 255, 0.28);
}

.game-spotlight__svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.game-spotlight__connector {
  stroke: #2a9d4a;
  stroke-width: 4;
  stroke-linecap: round;
}

.game-spotlight__bubble {
  position: absolute;
  z-index: 3;
  max-width: calc(100% - 1rem);
  padding: 0.75rem 0.9rem 0.65rem;
  border: 3px solid #2a9d4a;
  border-radius: 12px;
  background: rgba(252, 255, 248, 0.97);
  box-shadow:
    0 0 6px rgba(255, 255, 255, 0.85),
    0 0 18px rgba(255, 255, 255, 0.48),
    0 8px 28px rgba(0, 0, 0, 0.18);
  color: #1a2418;
}

.game-spotlight__title {
  margin: 0 0 0.35rem;
  font-size: clamp(1rem, 0.92rem + 0.35vw, 1.12rem);
  font-weight: 800;
  line-height: 1.25;
}

.game-spotlight__body {
  margin: 0 0 0.65rem;
  font-size: clamp(0.86rem, 0.8rem + 0.25vw, 0.95rem);
  line-height: 1.45;
  font-weight: 600;
}

.game-spotlight__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.65rem;
}

.game-spotlight__skip-hints {
  border: none;
  background: transparent;
  color: #3d5c42;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  padding: 0.2rem 0;
}

.game-spotlight__skip-hints:hover {
  color: #1a5c28;
}

@media (prefers-reduced-motion: reduce) {
  .game-spotlight__mask-dim {
    fill: rgba(12, 18, 14, 0.52);
  }
}

/* Level instruction overlay (VB levelN / levelN_lessdetail) */
.game-level-instructions {
  position: absolute;
  inset: 0;
  z-index: 28;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: max(0.35rem, env(safe-area-inset-top)) max(0.35rem, env(safe-area-inset-right))
    max(0.35rem, env(safe-area-inset-bottom)) max(0.35rem, env(safe-area-inset-left));
  pointer-events: auto;
}

.game-level-instructions[hidden] {
  display: none !important;
}

.game-level-instructions__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.88);
}

.game-level-instructions__panel {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.45rem;
  width: min(100%, 400px);
  max-width: 100%;
  max-height: calc(100% - 0.25rem);
  min-height: 0;
  margin: 0;
}

.game-level-instructions__img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  min-height: 0;
  object-fit: contain;
  border: 2px solid #2a7a3e;
  border-radius: 8px;
  background: #fff;
}

.game-level-instructions__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  flex-shrink: 0;
  width: 100%;
  padding-bottom: 0.05rem;
}

.game-level-instructions__actions .practice-btn {
  min-height: 40px;
  padding: 0.35rem 0.65rem;
  font-size: clamp(0.82rem, 0.74rem + 0.45vw, 0.95rem);
}

/* Pre-drop planning (15s + Begin) */
.game-planning-overlay {
  position: absolute;
  inset: 0;
  z-index: 22;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.92);
  pointer-events: auto;
}

.game-planning-overlay[hidden] {
  display: none !important;
}

.game-planning-overlay__inner {
  text-align: center;
  padding: 1rem;
  max-width: 96%;
}

.game-planning-overlay__trinomial {
  margin: 0 0 0.75rem;
  font-family: var(--practice-chalk-font);
  font-size: clamp(1.35rem, 4.5vw, 2.4rem);
  /* FactrisChalk @font-face is 400 only; synthetic bold distorts glyphs. */
  font-weight: 400;
  font-synthesis: none;
  color: #1a1f14;
  font-feature-settings: "ss01" 1, "salt" 1, "calt" 1;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5),
    0 0 1px rgba(0, 0, 0, 0.2);
}

.game-planning-overlay__count {
  font-family: var(--practice-chalk-font);
  font-size: clamp(2rem, 8vw, 3.2rem);
  font-weight: 400;
  color: #1a8a3a;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.55),
    0 0 1px rgba(8, 70, 30, 0.45);
}

.game-planning-overlay__count-label {
  margin: 0 0 1rem;
}

/* Success interstitial (Next Challenge / Home) */
.game-success-interstitial {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: max(0.75rem, env(safe-area-inset-top));
  pointer-events: auto;
}

.game-success-interstitial[hidden] {
  display: none !important;
}

.game-success-interstitial__backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: rgba(22, 28, 18, 0.25);
  pointer-events: auto;
}

.game-success-interstitial__panel {
  position: relative;
  z-index: 1;
  padding: 0.5rem;
  pointer-events: auto;
}

.game-success-interstitial__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

/* Demo → account gate (before Level 2 when not signed in) */
.game-demo-account-gate {
  position: absolute;
  inset: 0;
  z-index: 38;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(0.5rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right))
    max(0.5rem, env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-left));
  pointer-events: auto;
}

.game-demo-account-gate[hidden] {
  display: none !important;
}

.game-demo-account-gate__backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: rgba(12, 18, 10, 0.55);
  pointer-events: auto;
}

.game-demo-account-gate__panel {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  max-height: min(92vh, 640px);
  overflow: auto;
  padding: 1rem 1.1rem 1.15rem;
  border-radius: 16px;
  border: 3px solid var(--frame, #4a5a38);
  background: rgba(250, 252, 244, 0.98);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
}

.game-demo-account-gate__title {
  margin: 0 0 0.5rem;
  font-size: clamp(1.15rem, 3.5vw, 1.45rem);
  text-align: center;
}

.game-demo-account-gate__lede {
  margin: 0 0 0.65rem;
  font-size: 0.92rem;
  line-height: 1.45;
  color: #2b331f;
}

.game-demo-account-gate__status {
  min-height: 1.25rem;
  margin: 0 0 0.75rem;
  font-size: 0.88rem;
}

.game-demo-account-gate__status:empty {
  display: none;
}

.game-demo-account-gate__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 520px) {
  .game-demo-account-gate__grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem 1rem;
  }
}

.game-demo-account-gate__card {
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid rgba(74, 90, 56, 0.25);
}

.game-demo-account-gate__subhead {
  margin: 0 0 0.55rem;
  font-size: 1rem;
}

.game-demo-account-gate__label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: #2b331f;
}

.game-demo-account-gate__hint {
  font-weight: 400;
  color: #5a6348;
}

.game-demo-account-gate__input {
  display: block;
  width: 100%;
  margin-top: 0.2rem;
  padding: 0.4rem 0.5rem;
  font-size: 0.95rem;
  border: 1px solid #8a9a72;
  border-radius: 8px;
  box-sizing: border-box;
}

.game-demo-account-gate__submit {
  width: 100%;
  margin-top: 0.55rem;
}

/* Unsuccessful build: Retry / New Problem (tray buttons reparented here while visible) */
.game-fail-skip-floater {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 24;
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
  align-items: center;
  pointer-events: auto;
}

.game-fail-skip-floater[hidden] {
  display: none !important;
}

.game-fail-skip-floater .game-vb-btn--aux-wide {
  filter: drop-shadow(0 4px 2px rgba(30, 22, 12, 0.35));
}

.game-touch-controls--vb {
  --game-tray-btn-h: clamp(2.75rem, 9vw, 3.35rem);
  grid-area: touch;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  padding-top: 0.65rem;
  padding-bottom: 0.15rem;
  min-height: 4.5rem;
}

.game-touch-controls__cross {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 3.5rem));
  gap: 0.35rem;
  justify-items: center;
  align-items: center;
}

.game-cross-placeholder {
  min-height: 2.8rem;
}

.game-vb-btn {
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  line-height: 0;
}

.game-vb-btn--round {
  width: clamp(2.75rem, 9vw, 3.35rem);
  height: clamp(2.75rem, 9vw, 3.35rem);
  filter: drop-shadow(0 4px 2px rgba(30, 22, 12, 0.35));
}

.game-vb-btn__img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.game-vb-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.game-touch-controls__aux {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  align-items: center;
  width: 100%;
}

/* Desktop: flatten rows so pause/play/retry/new share one tray; Sound docks bottom-right of panel. */
.game-touch-controls__row {
  display: contents;
}

.game-touch-controls__aux #game-btn-zeropair {
  order: 1;
}

.game-touch-controls__aux #game-btn-ingame-retry {
  order: 4;
}

.game-touch-controls__aux #game-btn-ingame-new {
  order: 5;
}

.game-rail-transport {
  display: none;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.55rem;
  padding-top: 0.45rem;
  border-top: 1px dashed rgba(45, 51, 33, 0.35);
}

.game-rail-skip-row {
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
  margin-top: 0.55rem;
  padding-top: 0.45rem;
  border-top: 1px dashed rgba(45, 51, 33, 0.35);
}

.game-rail-skip-row .game-vb-btn--aux-wide {
  width: 100%;
  max-width: none;
}

.game-rail-controls .game-rail-transport .game-vb-btn--aux {
  height: clamp(2.35rem, 7vw, 2.85rem);
  min-height: clamp(2.35rem, 7vw, 2.85rem);
  max-height: clamp(2.35rem, 7vw, 2.85rem);
}

.game-rail-controls .game-rail-skip-row .game-vb-btn--aux {
  height: clamp(2.35rem, 7vw, 2.85rem);
  min-height: clamp(2.35rem, 7vw, 2.85rem);
  max-height: clamp(2.35rem, 7vw, 2.85rem);
}

@media (min-width: 861px) {
  .game-rail-transport,
  .game-rail-skip-row {
    display: flex;
  }

  .game-touch-controls--vb {
    display: none !important;
  }

  .game-board-panel {
    grid-template-areas:
      'hud'
      'board';
    grid-template-rows: auto minmax(0, 1fr);
    padding-bottom: 0.45rem;
  }

  .game-touch-controls {
    display: none;
  }
}

@media (max-width: 860px) {
  .game-rail-skip-row {
    display: none !important;
  }

  .game-touch-controls__row--mobile-skip {
    display: flex;
  }
}

.game-touch-controls__aux .game-vb-btn[hidden] {
  display: none !important;
}

.game-vb-btn--aux {
  box-sizing: border-box;
  height: var(--game-tray-btn-h, clamp(2.75rem, 9vw, 3.35rem));
  min-height: var(--game-tray-btn-h, clamp(2.75rem, 9vw, 3.35rem));
  max-height: var(--game-tray-btn-h, clamp(2.75rem, 9vw, 3.35rem));
  width: auto;
  min-width: var(--game-tray-btn-h, clamp(2.75rem, 9vw, 3.35rem));
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.game-vb-btn--aux .game-vb-btn__img {
  width: auto;
  height: 100%;
  max-height: 100%;
  object-fit: contain;
}

.game-vb-btn--aux-wide {
  max-width: min(11.5rem, 52vw);
}

.game-vb-btn--zeropair {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 4px 2px rgba(30, 22, 12, 0.35));
}

.game-undo-mobile {
  display: none;
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  gap: 0.2rem;
  flex-shrink: 0;
  pointer-events: none;
}

.game-undo-mobile > * {
  pointer-events: auto;
}

.game-undo-mobile-btn {
  display: inline-flex;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  width: clamp(1.5rem, 7.5vw, 1.9rem);
  filter: drop-shadow(0 2px 2px rgba(30, 22, 12, 0.28));
}

.game-undo-mobile-btn img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.game-undo-mobile-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.game-share-dock {
  position: relative;
  z-index: 5;
  flex-shrink: 0;
  align-self: stretch;
  width: 100%;
  box-sizing: border-box;
  padding: 0.25rem 0 0.55rem;
  margin: 0;
  pointer-events: none;
}

.game-share-dock .game-share-links {
  pointer-events: auto;
  padding: 0;
  margin: 0;
  justify-content: center;
  padding-top: 0;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
}

.game-side-rail .game-share-dock .game-share-links.game-share-links--icons {
  justify-content: center;
  gap: 0.18rem;
  max-width: 100%;
}

.game-side-rail .game-share-dock .game-share-icon-btn {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  background: transparent;
}

.game-side-rail .game-share-dock .game-share-icon-btn:hover {
  background: rgba(30, 25, 15, 0.08);
}

.game-side-rail .game-share-dock .game-share-icon-btn:active {
  background: rgba(30, 25, 15, 0.12);
}

.game-side-rail .game-share-dock .game-share-svg {
  width: 14px;
  height: 14px;
}

.game-side-rail .game-share-dock .game-share-copy-btn {
  min-height: 26px;
  padding: 0 0.22rem;
  font-size: 11px;
  border-radius: 5px;
  background: transparent;
  border-color: rgba(102, 126, 234, 0.78);
}

.game-side-rail .game-share-dock .game-share-copy-btn:hover {
  background: rgba(102, 126, 234, 0.12);
}

.game-side-rail .game-share-dock .game-share-copy-text {
  font-size: 11px;
}

.game-share-modal {
  position: fixed;
  inset: 0;
  z-index: 1250;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(0.5rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right))
    max(0.75rem, env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-left));
}

.game-share-modal[hidden] {
  display: none !important;
}

.game-share-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(22, 28, 18, 0.55);
}

.game-share-modal__panel {
  position: relative;
  z-index: 1;
  width: min(22rem, 100%);
  max-height: min(70dvh, 420px);
  overflow: auto;
  padding: 0.75rem 0.85rem 1rem;
  border-radius: 14px;
  border: 3px solid var(--frame, #2d331f);
  background: rgba(250, 252, 244, 0.98);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

.game-share-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.game-share-modal__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
}

.game-share-modal__close {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #c62828;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.game-share-modal__close:hover {
  background: rgba(198, 40, 40, 0.12);
  color: #b71c1c;
}

.game-cheat-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(0.5rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right))
    max(0.75rem, env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-left));
}

.game-cheat-modal[hidden] {
  display: none !important;
}

.game-cheat-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 16, 10, 0.55);
}

.game-cheat-modal__panel {
  position: relative;
  z-index: 1;
  width: min(24rem, 100%);
  padding: 1rem 1.1rem 1.1rem;
  border-radius: 14px;
  border: 3px solid var(--frame, #2d331f);
  background: rgba(250, 252, 244, 0.98);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

.game-cheat-modal__title {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  font-weight: 800;
}

.game-cheat-modal__hint {
  margin: 0 0 0.75rem;
  font-size: 0.88rem;
  line-height: 1.45;
  color: #333;
}

.game-cheat-modal__label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.game-cheat-modal__input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.45rem 0.5rem;
  font-size: 1rem;
  border-radius: 8px;
  border: 2px solid #888;
  margin-bottom: 0.75rem;
}

.game-cheat-modal__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.game-cheat-modal__kbd-hint {
  margin: 0.65rem 0 0;
  font-size: 0.78rem;
  color: #555;
}

.factris-image-flash-root {
  position: fixed;
  inset: 0;
  /* Above practice score celebration (120), game overlays (~140), demo gate (38); below modals (1200+). */
  z-index: 1100;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.factris-image-flash-root--badge {
  /* Above modals/tooltips; body-mounted so parent overflow cannot clip. */
  z-index: 2147483600;
  background: rgba(12, 14, 18, 0.52);
}

.factris-image-flash-root--badge.factris-image-flash-root--visible {
  opacity: 1 !important;
  visibility: visible !important;
}

.factris-image-flash-root--interactive {
  pointer-events: auto;
  cursor: pointer;
}

.factris-image-flash-root--visible {
  opacity: 1;
}

.factris-image-flash-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  max-width: min(92vw, 440px);
}

.factris-image-flash-img {
  display: block;
  pointer-events: none;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.45));
}

.factris-image-flash-fallback {
  display: grid;
  place-items: center;
  width: min(178px, 42vw);
  height: min(178px, 42vw);
  border-radius: 50%;
  border: 4px solid #c9a227;
  background: radial-gradient(circle at 35% 28%, #fff6d8 0%, #e8c96a 42%, #9a7420 100%);
  color: #3d2914;
  font-size: clamp(2.4rem, 10vw, 3.4rem);
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.factris-image-flash-caption {
  margin: 0;
  padding: 0 0.5rem;
  text-align: center;
  font-size: clamp(0.82rem, 2.6vw, 0.98rem);
  line-height: 1.35;
  color: #fff8ef;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.75);
  pointer-events: none;
}

.game-rail-top .game-rail-icons {
  display: flex;
  gap: 0.65rem;
  justify-content: center;
  align-items: flex-start;
  margin-bottom: 0.45rem;
}

.game-rail-icon-tile {
  position: relative;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  line-height: 0;
}

.game-rail-icon-tile img {
  width: clamp(2.75rem, 8vw, 3.25rem);
  height: clamp(2.75rem, 8vw, 3.25rem);
  object-fit: contain;
  filter: drop-shadow(0 2px 3px rgba(30, 22, 12, 0.25));
}

.game-rail-icon-tile--badges .game-badge-shield {
  display: block;
  margin: 0 auto;
}

.game-badge-count {
  position: absolute;
  left: 50%;
  top: 54%;
  transform: translate(-50%, -50%);
  font-size: 0.72rem;
  font-weight: 900;
  color: #c62828;
  text-shadow: 0 0 3px #fff;
  pointer-events: none;
}

.game-leaderboard-heading {
  margin: 0 0 0.45rem;
  font-size: clamp(0.88rem, 2vw, 1rem);
  text-align: center;
  font-weight: 800;
}

.game-share-links.game-share-links--icons {
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
  gap: 0.28rem;
  padding-top: 0;
  max-width: 100%;
}

.game-share-icon-btn {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: rgb(245, 245, 245);
  color: rgb(51, 51, 51);
  text-decoration: none;
  flex-shrink: 0;
  cursor: pointer;
  transition:
    background 0.15s ease,
    transform 0.12s ease;
}

.game-share-icon-btn:hover {
  background: rgb(235, 235, 235);
}

.game-share-icon-btn:active {
  transform: scale(0.96);
}

.game-share-svg {
  display: block;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.game-share-copy-btn {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.35rem;
  min-height: 34px;
  border-radius: 6px;
  border: 1px solid rgb(102, 126, 234);
  background: rgb(248, 249, 255);
  color: rgb(102, 126, 234);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease;
}

.game-share-copy-btn:hover {
  background: rgb(240, 242, 255);
}

.game-share-copy-inner {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.game-share-copy-text {
  white-space: nowrap;
}

.game-touch-controls,
.game-undo-row,
.game-share-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  padding-top: 0.65rem;
}

.game-card-title-with-icon {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.game-card-title-with-icon img {
  width: 2.5rem;
  height: 2.5rem;
  object-fit: contain;
}

.game-side-rail {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 0;
}

.game-side-rail-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0.65rem;
}

.game-side-rail.game-badges-overlay-active {
  overflow: hidden;
}

.game-badges-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: 0.55rem 0.65rem;
  border-radius: 18px;
  background: rgba(250, 252, 244, 0.98);
  border: 3px solid var(--frame);
  box-shadow: 0 12px 26px rgba(30, 25, 15, 0.16);
}

.game-badges-overlay[hidden] {
  display: none !important;
}

.game-badges-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-bottom: 0.35rem;
}

.game-badges-overlay-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.game-badges-close {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 2px solid var(--frame);
  border-radius: 10px;
  background: rgba(250, 252, 244, 0.95);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  font-weight: 800;
}

.game-badges-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.game-badges-scroll .game-badges {
  transform-origin: top center;
  flex-shrink: 0;
}

.game-badges-open-btn {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 2px solid rgba(74, 90, 42, 0.35);
  border-radius: 12px;
  background: rgba(250, 252, 244, 0.95);
  font-weight: 800;
  font-size: 0.98rem;
  cursor: pointer;
}

.game-badges-open-btn:hover {
  border-color: var(--frame);
}

.game-badge-detail {
  display: grid;
  grid-template-columns: 4.2rem minmax(0, 1fr);
  gap: 0.35rem 0.55rem;
  align-items: center;
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px solid rgba(92, 61, 30, 0.28);
  flex-shrink: 0;
}

.game-card {
  padding: 0.7rem;
  margin-bottom: 0.65rem;
  border-width: 2px;
}

.game-card h2 {
  margin: 0 0 0.45rem;
  font-size: 1rem;
}

.game-leaderboard {
  margin: 0;
  padding-left: 1.35rem;
}

.game-badges {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.28rem;
  width: 100%;
}

.game-badge {
  display: block;
  min-width: 0;
  padding: 0;
  border: 2px solid rgba(74, 90, 42, 0.3);
  border-radius: 0;
  background: #eee;
  cursor: pointer;
}

.game-badge img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.game-badge.locked img {
  opacity: 0.82;
}

.game-badge-detail {
  display: grid;
  grid-template-columns: 4.2rem minmax(0, 1fr);
  gap: 0.35rem 0.55rem;
  align-items: center;
  margin-top: 0.55rem;
  padding-top: 0.55rem;
  border-top: 1px solid rgba(92, 61, 30, 0.28);
}

.game-badge-detail[hidden] {
  display: none !important;
}

.game-badge-detail img {
  grid-row: span 2;
  width: 4.2rem;
  height: 4.2rem;
  object-fit: cover;
}

.game-badge-detail strong,
.game-badge-detail span {
  min-width: 0;
}

.game-undo-row {
  align-items: center;
}

.game-undo-btn {
  width: clamp(3.7rem, 7.6vw, 4.9rem);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.game-undo-btn img {
  display: block;
  width: 100%;
  height: auto;
}

.game-undo-btn:disabled {
  cursor: not-allowed;
  filter: grayscale(1) brightness(0.62);
  opacity: 0.58;
}

.game-mobile-drawer {
  position: fixed;
  inset: 0;
  z-index: 32;
  padding: max(0.7rem, env(safe-area-inset-top)) max(0.7rem, env(safe-area-inset-right)) max(0.7rem, env(safe-area-inset-bottom)) max(0.7rem, env(safe-area-inset-left));
  background: rgba(20, 15, 8, 0.45);
}

.game-mobile-drawer-inner {
  margin-left: auto;
  width: min(22rem, 100%);
  max-height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 0.75rem;
  border: 3px solid var(--frame);
  border-radius: 18px;
  background: var(--chalk);
}

.game-mobile-drawer-inner .game-badge,
.game-mobile-drawer-inner .game-share-icon-btn,
.game-mobile-drawer-inner .game-share-copy-btn {
  touch-action: manipulation;
}

/* Mobile menu + achievements modal badges: compact tiles, tooltip on tap */
.game-mobile-badges-stage {
  position: relative;
  overflow: visible;
}

.game-badges--mobile-drawer,
.game-badges--modal-grid,
.game-badges--tap-tooltip {
  overflow: visible;
}

.game-badges--mobile-drawer {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.14rem;
}

/* Badges modal: 15 badges in 3×5 for larger tiles than the old 4-column drawer */
.game-badges--modal-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.22rem;
}

.game-badges--mobile-drawer .game-badge,
.game-badges--modal-grid .game-badge,
.game-badges--tap-tooltip .game-badge {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  border-width: 1px;
  z-index: 0;
  overflow: visible;
}

.game-badges--mobile-drawer .game-badge--tooltip-active,
.game-badges--modal-grid .game-badge--tooltip-active,
.game-badges--tap-tooltip .game-badge--tooltip-active {
  z-index: 6;
}

.game-badges--mobile-drawer .game-badge img,
.game-badges--modal-grid .game-badge img,
.game-badges--tap-tooltip .game-badge img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: auto;
  object-fit: contain;
  object-position: center;
}

.game-badge-tooltip-popover {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 0.2rem);
  transform: translateX(-50%);
  z-index: 8;
  box-sizing: border-box;
  width: max(9.5rem, min(13.5rem, calc(100vw - 1.25rem)));
  max-width: calc(100vw - 1.25rem);
  padding: 0.38rem 0.48rem;
  border: 2px solid var(--frame);
  border-radius: 10px;
  background: rgba(250, 252, 244, 0.98);
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.28);
  text-align: left;
  line-height: 1.3;
  pointer-events: none;
}

.game-badge-tooltip-popover[hidden] {
  display: none !important;
}

.game-badge-tooltip-popover strong {
  display: block;
  margin-bottom: 0.12rem;
  font-size: 0.76rem;
  font-weight: 800;
  color: #1a1f14;
}

.game-badge-tooltip-popover span {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  color: #2d331f;
}

.game-badge--tooltip-below .game-badge-tooltip-popover {
  bottom: auto;
  top: calc(100% + 0.2rem);
}

.game-badge-tooltip-popover--placed {
  position: fixed;
  left: auto;
  top: auto;
  right: auto;
  bottom: auto;
  transform: none;
  /* Above .teacher-controls-modal (1200); mobile drawer (32) still uses body placement. */
  z-index: 1210;
  width: min(13.5rem, calc(100vw - 1.25rem));
  max-width: calc(100vw - 1.25rem);
}

/* Inline share row in mobile menu (matches desktop side-rail dock, not a nested card/modal). */
.game-mobile-drawer-share.game-share-links.game-share-links--icons {
  justify-content: center;
  gap: 0.18rem;
  max-width: 100%;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 2px solid rgba(74, 90, 42, 0.22);
}

.game-mobile-drawer-share .game-share-icon-btn {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  background: transparent;
}

.game-mobile-drawer-share .game-share-icon-btn:hover {
  background: rgba(30, 25, 15, 0.08);
}

.game-mobile-drawer-share .game-share-icon-btn:active {
  background: rgba(30, 25, 15, 0.12);
}

.game-mobile-drawer-share .game-share-svg {
  width: 14px;
  height: 14px;
}

.game-mobile-drawer-share .game-share-copy-btn {
  min-height: 26px;
  padding: 0 0.22rem;
  font-size: 11px;
  border-radius: 5px;
  background: transparent;
  border-color: rgba(102, 126, 234, 0.78);
}

.game-mobile-drawer-share .game-share-copy-btn:hover {
  background: rgba(102, 126, 234, 0.12);
}

.game-mobile-drawer-share .game-share-copy-text {
  font-size: 11px;
}

@media (max-width: 860px) {
  .shell-home .home-main-layout > .home-player-card {
    align-items: stretch;
    width: 100%;
    margin-bottom: 0.35rem;
    padding: 0.28rem 0.45rem;
    border-radius: 14px;
    border-left: 2px solid rgba(74, 90, 42, 0.45);
    border-right: 2px solid rgba(74, 90, 42, 0.45);
  }

  .home-hud-main {
    gap: 0.04rem;
  }

  .home-hud-main .game-hud-stat {
    font-size: 0.92em;
  }

  .home-lives-grid {
    width: min(calc(6 * 1.2rem), 36vw);
    max-width: min(calc(6 * 1.2rem), 36vw);
    grid-template-columns: repeat(6, minmax(0, 1.2rem));
    grid-template-rows: repeat(2, minmax(0, 1.2rem));
  }

  .game-layout {
    grid-template-columns: 1fr;
    padding: 0.55rem;
    padding-bottom: max(0.85rem, calc(0.55rem + env(safe-area-inset-bottom)));
  }

  .game-board-panel {
    grid-template-areas:
      'hud'
      'board'
      'touch';
    grid-template-rows: auto minmax(0, 1fr) auto;
    padding-bottom: max(0.85rem, env(safe-area-inset-bottom));
  }

  .game-canvas-wrap {
    min-height: 0;
  }

  .game-hud {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, max-content);
    grid-template-rows: auto auto auto;
    align-items: center;
    justify-items: start;
    gap: 0.1rem 0.4rem;
    padding-bottom: 0.25rem;
  }

  .game-hud-lives {
    display: flex;
    align-items: center;
    justify-content: center;
    grid-column: 2;
    grid-row: 3;
    justify-self: center;
  }

  .game-lives-summary {
    display: none;
  }

  #game-player-name {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
    text-align: right;
    font-size: 0.92em;
  }

  .game-hud-stat--score {
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
    text-align: left;
  }

  .game-hud-stat--best {
    grid-column: 1;
    grid-row: 2;
    justify-self: start;
    text-align: left;
    font-size: 0.92em;
  }

  .game-hud-stat--level {
    grid-column: 1;
    grid-row: 3;
    justify-self: start;
    text-align: left;
  }

  .game-undo-mobile {
    grid-column: 3;
    grid-row: 3;
    justify-self: end;
    align-self: center;
    display: flex;
    gap: 0.14rem;
    padding: 0;
    margin: 0;
  }

  .game-side-rail {
    display: none;
  }

  .game-controls-intro__canvas {
    min-height: 120px;
    max-height: min(200px, 38vh);
  }

  .game-controls-intro__panel {
    width: 100%;
    padding: 0.65rem 0.75rem 0.85rem;
    gap: 0.5rem;
  }

  .game-controls-intro__caption {
    min-height: 2.25em;
    font-size: 0.88rem;
  }

  .game-level-instructions {
    padding: max(0.2rem, env(safe-area-inset-top)) max(0.25rem, env(safe-area-inset-right))
      max(0.2rem, env(safe-area-inset-bottom)) max(0.25rem, env(safe-area-inset-left));
  }

  .game-level-instructions__panel {
    width: min(100%, 100%);
    max-height: calc(100% - 0.15rem);
    gap: 0.3rem;
  }

  .game-level-instructions__actions {
    gap: 0.3rem;
  }

  .game-level-instructions__actions .practice-btn {
    flex: 1 1 calc(50% - 0.2rem);
    min-width: 6.75rem;
    max-width: 100%;
    min-height: 38px;
    padding: 0.3rem 0.5rem;
    font-size: 0.82rem;
  }

  /* Mobile game tray: retry/new on top row; zero-pairs when shown. */
  .game-touch-controls__row {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
  }

  .game-touch-controls__aux {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .game-touch-controls__aux #game-btn-pause,
  .game-touch-controls__aux #game-btn-play,
  .game-touch-controls__aux #game-btn-zeropair,
  .game-touch-controls__aux #game-btn-ingame-retry,
  .game-touch-controls__aux #game-btn-ingame-new {
    order: unset;
  }

  .game-touch-controls__row--wide {
    flex: 0 1 auto;
    width: fit-content;
    max-width: 100%;
    margin-inline: auto;
    justify-content: center;
  }

  .game-touch-controls__row--wide .game-vb-btn--aux-wide {
    flex: 0 0 auto;
    max-width: min(11.5rem, 52vw);
  }

  .game-mobile-drawer-tools {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    margin-top: 0.35rem;
  }

  .game-mobile-drawer-transport {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
  }

  .game-mobile-drawer-audio {
    display: flex;
    justify-content: center;
  }

  .game-mobile-drawer-audio .home-audio-dock {
    position: static;
  }

  .game-mobile-drawer-audio .home-audio-panel {
    position: fixed;
    left: 50%;
    bottom: max(1rem, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 1300;
  }
}

/* Teacher class management */
.home-player-card-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.3rem;
  justify-content: flex-end;
  min-width: 0;
  margin-left: auto;
}

.home-player-card-actions .practice-btn {
  margin: 0;
  width: auto;
  flex-shrink: 0;
  white-space: nowrap;
}

.home-player-card-actions #btn-home-options {
  margin-left: 0.15rem;
}

/* Edit my info and teacher controls live in the Factris options menu (fm-control-tile). */

body.tc-modal-open {
  overflow: hidden;
}

.teacher-controls-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

/* Account / teacher tools opened from home or game — above Factris options (fm-controls). */
#account-edit-modal.teacher-controls-modal,
#teacher-controls-modal.teacher-controls-modal {
  z-index: 1260;
}

.teacher-controls-modal[hidden] {
  display: none !important;
}

.teacher-controls-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 16, 10, 0.55);
}

.teacher-controls-dialog {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(720px, 100%);
  height: min(85vh, 780px);
  max-height: min(90vh, 900px);
  overflow: hidden;
  background: var(--chalk);
  border: 3px solid var(--frame);
  border-radius: 12px;
  padding: 1rem 1.15rem 1.25rem;
  box-shadow: 0 12px 40px var(--shadow);
}

.teacher-controls-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.teacher-controls-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.teacher-controls-modal .account-modal-close {
  background: transparent;
  color: #c62828;
}

.teacher-controls-modal .account-modal-close:hover {
  background: rgba(198, 40, 40, 0.12);
  color: #b71c1c;
}

.teacher-controls-status {
  min-height: 1.25rem;
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.teacher-controls-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.tc-nav-btn {
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--btn-border);
  background: #e8efd4;
  cursor: pointer;
  font-size: 0.85rem;
}

.tc-nav-btn--active {
  background: #c5d4a8;
  font-weight: 600;
}

.tc-panels {
  position: relative;
  flex: 1;
  min-height: 0;
  margin-top: 0.15rem;
}

.tc-panel {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding-right: 0.15rem;
}

.tc-panel[hidden] {
  display: none !important;
}

.teacher-controls-dialog .tc-field {
  color: var(--ink-muted);
}

.teacher-controls-dialog .tc-field input,
.teacher-controls-dialog .tc-field select {
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--btn-border);
  background: #fffef8;
  color: var(--ink);
  font: inherit;
}

.teacher-controls-dialog .tc-field select {
  width: 100%;
}

.tc-combobox {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: stretch;
}

.tc-combobox input {
  width: 100%;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
}

.tc-combobox-toggle {
  padding: 0 0.65rem;
  border: 1px solid var(--btn-border);
  border-radius: 0 8px 8px 0;
  background: #e8efd4;
  color: var(--ink);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.tc-combobox-toggle:hover {
  background: #d8e4bc;
}

.tc-combobox-list {
  position: absolute;
  z-index: 2;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  max-height: 11rem;
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  overflow-y: auto;
  border: 1px solid var(--btn-border);
  border-radius: 8px;
  background: #fffef8;
  box-shadow: 0 6px 18px var(--shadow);
}

.tc-combobox-list[hidden] {
  display: none !important;
}

.tc-combobox-option {
  padding: 0.45rem 0.65rem;
  cursor: pointer;
  color: var(--ink);
}

.tc-combobox-option:hover,
.tc-combobox-option--active {
  background: #e8efd4;
}

.tc-combobox-option--create {
  font-style: italic;
  color: var(--ink-muted);
}

.tc-code-label {
  margin: 0.75rem 0 0.2rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.tc-code-display {
  font: 700 1.65rem/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  letter-spacing: 0.12em;
  margin: 0 0 0.65rem;
  color: var(--ink);
}

#tc-btn-code-action {
  width: 100%;
  margin-top: 0.15rem;
}

#tc-btn-code-action:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.tc-section-title {
  margin: 0.85rem 0 0.45rem;
  font-size: 1rem;
  font-weight: 700;
}

.tc-manage-section + .tc-manage-section {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(74, 90, 42, 0.25);
}

.tc-manage-hint {
  margin: 0 0 0.5rem;
}

.tc-student-list-label {
  margin: 0.5rem 0 0.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.tc-manage-student-actions {
  margin-top: 0.75rem;
  padding: 0.65rem 0.75rem;
  background: #eef4dc;
  border: 1px solid rgba(74, 90, 42, 0.3);
  border-radius: 8px;
}

.tc-manage-student-actions[hidden] {
  display: none !important;
}

.tc-selected-student {
  margin: 0 0 0.5rem;
}

.tc-manage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0;
}

.tc-manage-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 0.5rem 0;
}

@media (max-width: 560px) {
  .tc-manage-columns {
    grid-template-columns: 1fr;
  }
}

.tc-student-list {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
  min-height: 3rem;
  max-height: 14rem;
  overflow: auto;
  border: 2px solid var(--btn-border);
  border-radius: 6px;
  background: #f5f9e8;
}

.tc-student-list li {
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  border-bottom: 1px solid rgba(74, 90, 42, 0.15);
}

.tc-student-list li:last-child {
  border-bottom: none;
}

.tc-student-list li.tc-student-selected {
  background: #c5d4a8;
  font-weight: 600;
}

.tc-student-list li.tc-student-empty {
  cursor: default;
  color: var(--ink-muted);
  font-style: italic;
}

.tc-roster-wrap {
  overflow: auto;
  max-height: 16rem;
  margin-top: 0.5rem;
  transition: max-height 0.25s ease;
}

.tc-roster-wrap.tc-roster-wrap--collapsed {
  max-height: 5.5rem;
}

.tc-roster-detail-panel {
  margin-top: 0.65rem;
  padding: 0.65rem 0.75rem;
  background: #f0f6e4;
  border-radius: 6px;
  border: 1px solid rgba(74, 90, 42, 0.25);
}

.tc-roster-detail-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.tc-roster-detail-name {
  margin: 0;
  font-size: 1.05rem;
}

.tc-roster-detail-close {
  flex-shrink: 0;
}

.tc-roster-history {
  margin-top: 0.65rem;
  max-height: min(42vh, 20rem);
  overflow: auto;
  padding-top: 0.15rem;
  border-top: 1px solid rgba(74, 90, 42, 0.18);
}

.tc-roster-history-empty {
  margin: 0.35rem 0 0;
  color: var(--ink-muted);
  font-style: italic;
}

.tc-roster-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.tc-roster-table th,
.tc-roster-table td {
  padding: 0.35rem 0.45rem;
  text-align: left;
  border-bottom: 1px solid rgba(74, 90, 42, 0.2);
  white-space: nowrap;
}

.tc-roster-table td:nth-child(2) {
  white-space: normal;
  min-width: 6rem;
}

.tc-roster-row {
  cursor: pointer;
}

.tc-roster-row:hover,
.tc-roster-row.tc-roster-row-selected {
  background: #e0ecc8;
}

.tc-roster-sub {
  font-size: 0.8em;
  color: var(--ink-muted);
}

.tc-roster-detail {
  margin-top: 0;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
}

.account-student-hint {
  margin-top: 0.75rem;
}

.account-edit-dialog {
  width: min(520px, 100%);
  height: auto;
  max-height: min(90vh, 720px);
  overflow-y: auto;
}

.account-edit-hint {
  margin: 0 0 0.75rem;
}

.account-edit-field {
  margin-bottom: 0.85rem;
}

.account-edit-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}

.account-edit-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.account-edit-row input,
.account-edit-row select {
  flex: 1 1 12rem;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--btn-border);
  border-radius: 6px;
}

.account-edit-btn {
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--btn-border);
  background: #c94a3a;
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.account-edit-btn--cancel {
  background: #e8efd4;
  color: var(--ink);
}

.account-edit-school {
  margin: 0.5rem 0 1rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid rgba(74, 90, 42, 0.35);
  border-radius: 8px;
}

.account-edit-school legend {
  font-weight: 600;
  padding: 0 0.25rem;
}

.account-edit-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

/* Factris menu modals (controls, leaderboard, stats, FAQ, contact) */
.fm-modal .fm-dialog {
  max-width: min(920px, 96vw);
  max-height: min(92vh, 900px);
  overflow: auto;
}
.fm-modal--wide .fm-dialog {
  max-width: min(1040px, 98vw);
}
#fm-leaderboard-modal.fm-modal--wide .fm-dialog,
#fm-leaderboard-modal .fm-lb-dialog {
  max-width: min(1180px, 98vw);
  width: min(1180px, 98vw);
}
#fm-leaderboard-modal .fm-lb-dialog {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: min(92vh, 900px);
}
.fm-controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 0.65rem;
  padding: 0.5rem 0 0.25rem;
}
.fm-control-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem;
  border: 2px solid rgba(74, 90, 42, 0.45);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
  min-height: 96px;
}
.fm-control-tile img {
  width: 52px;
  height: 52px;
  object-fit: contain;
  background: transparent;
}

.fm-control-tile--disabled {
  opacity: 0.42;
  cursor: not-allowed;
  filter: grayscale(0.55);
  pointer-events: none;
}

.fm-control-tile--disabled span {
  color: rgba(26, 31, 20, 0.55);
}

.fm-faq-cats label.fm-faq-cat--disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.fm-faq-cats label.fm-faq-cat--disabled input {
  pointer-events: none;
}
.fm-control-faq {
  font-size: 2.4rem;
  line-height: 1;
  font-weight: 700;
}
.fm-lb-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.fm-lb-header-globe {
  flex-shrink: 0;
  object-fit: contain;
  background: transparent;
  display: block;
}
.fm-lb-header h2 {
  flex: 1;
  margin: 0;
  min-width: 0;
}
.fm-lb-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-bottom: 0.35rem;
}
.fm-lb-toolbar__status {
  flex: 1;
  min-width: 0;
  margin: 0;
}
.fm-lb-filters-toggle {
  display: none;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  padding: 0.4rem 0.65rem;
  border: 2px solid rgba(74, 90, 42, 0.45);
  border-radius: 8px;
  background: #e8efd4;
  color: var(--ink, #2a3318);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1.2;
}
.fm-lb-filters-toggle__icon {
  display: block;
  flex-shrink: 0;
}
.fm-lb-filters-toggle--active {
  background: #fff;
  border-color: #c9a227;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
.fm-lb-filters-panel {
  flex-shrink: 0;
}
.fm-lb-main {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.fm-lb-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: flex-end;
  margin-bottom: 0.75rem;
  font-size: 0.88rem;
}
.fm-lb-fieldset {
  border: 1px solid rgba(74, 90, 42, 0.35);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  margin: 0;
}
.fm-lb-fieldset--visual {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 10.5rem;
  padding: 0.5rem 0.65rem 0.55rem;
}
.fm-lb-fieldset legend {
  font-weight: 600;
  padding: 0 0.2rem;
  width: 100%;
  text-align: center;
}
.fm-lb-visual-hero {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 5.25rem;
  height: 5.25rem;
  margin: 0.15rem 0 0.35rem;
  padding: 0.2rem;
  border: 2px solid #c9a227;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
.fm-lb-visual-hero img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.fm-lb-radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
}
.fm-lb-radio-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.25rem 0.4rem;
  border: 2px solid rgba(74, 90, 42, 0.35);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.78rem;
  text-align: center;
  min-width: 4.5rem;
  transition:
    border-color 0.15s ease,
    filter 0.15s ease,
    opacity 0.15s ease;
}
.fm-lb-radio-tile input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}
.fm-lb-radio-tile:not(.fm-lb-radio-tile--selected) {
  filter: grayscale(0.85);
  opacity: 0.72;
}
.fm-lb-radio-tile--selected {
  border-color: #c9a227;
  border-width: 3px;
  background: #fff;
  filter: none;
  opacity: 1;
}
.fm-lb-radio-tile--disabled {
  pointer-events: none;
  opacity: 0.4;
  filter: grayscale(1);
}
.fm-lb-check {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  margin: 0.25rem 0;
}
.fm-dialog .fm-lb-check {
  display: flex;
  align-self: flex-start;
  justify-content: flex-start;
}
.fm-lb-select {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.fm-lb-body {
  overflow: visible;
  max-height: none;
}
.fm-lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.fm-lb-table th,
.fm-lb-table td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid rgba(74, 90, 42, 0.2);
  text-align: left;
  vertical-align: top;
}
.fm-lb-table th:nth-child(1),
.fm-lb-table td:nth-child(1) {
  width: 2.5rem;
  white-space: nowrap;
}
.fm-lb-table th:nth-child(2),
.fm-lb-table td:nth-child(2) {
  white-space: nowrap;
}
.fm-lb-table th:nth-child(3),
.fm-lb-table td:nth-child(3) {
  white-space: nowrap;
  min-width: 7.25rem;
}
.fm-lb-empty {
  padding: 1rem;
  text-align: center;
  color: var(--ink-muted, #4a5a2a);
}
.fm-stats-dialog {
  max-width: min(96vw, 56rem);
}

.fm-stats-body {
  max-height: min(60vh, 32rem);
  overflow: auto;
  font-size: 0.92rem;
  padding: 0 0.25rem;
}

.fm-stats-layout {
  display: block;
  min-width: 0;
}

.fm-badges-dialog {
  width: min(21rem, calc(100vw - 1.5rem));
  max-height: min(92vh, 100%);
}

.fm-badges-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: visible;
  padding: 0.2rem 0.15rem 0.4rem;
}

.fm-badges-body .game-badges--modal-grid {
  width: 100%;
  max-width: 100%;
}

.fm-stats-main {
  min-width: 0;
}

.fm-stats-badges-panel {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
  overflow: visible;
}

.fm-stats-badges-scroll {
  max-height: min(52vh, 26rem);
  overflow: auto;
  padding: 0.15rem;
}

.fm-stats-badges-scroll .game-badges {
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
}

.fm-stats-summary h3 {
  margin: 0 0 0.5rem;
}
.fm-stats-log .stats-level {
  margin: 1rem 0 0.35rem;
  font-size: 1.05rem;
}
.fm-stats-log .stats-line {
  margin: 0.2rem 0;
  line-height: 1.45;
}
.stats-ans--wrong {
  color: #c62828;
  font-weight: 600;
}
.stats-ans--right {
  color: #00b050;
  font-weight: 600;
}
.fm-stats-log .stats-sup {
  font-size: 0.78em;
  vertical-align: super;
  line-height: 0;
}

@media (max-width: 720px) {
  #fm-leaderboard-modal.teacher-controls-modal {
    padding: 0;
    align-items: stretch;
  }

  #fm-leaderboard-modal .fm-lb-dialog {
    width: 100%;
    max-width: 100%;
    max-height: 100%;
    height: 100%;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  #fm-leaderboard-modal .fm-lb-filters-toggle {
    display: inline-flex;
  }

  #fm-leaderboard-modal #fm-lb-filters-panel.fm-lb-filters-panel--open {
    display: block;
    max-height: min(42dvh, 320px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 0.5rem;
    padding-bottom: 0.15rem;
    border-bottom: 1px solid rgba(74, 90, 42, 0.2);
  }

  #fm-leaderboard-modal #fm-lb-filters-panel:not(.fm-lb-filters-panel--open) {
    display: none;
  }

  #fm-leaderboard-modal .fm-lb-filters {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
    margin-bottom: 0;
  }

  #fm-leaderboard-modal .fm-lb-fieldset--visual {
    min-width: 0;
    width: 100%;
    max-width: 100%;
  }

  #fm-leaderboard-modal .fm-lb-visual-hero {
    width: 4.25rem;
    height: 4.25rem;
    margin-left: auto;
    margin-right: auto;
  }

  #fm-leaderboard-modal .fm-lb-radio-row {
    justify-content: center;
  }

  #fm-leaderboard-modal .fm-lb-select {
    width: 100%;
  }

  #fm-leaderboard-modal .fm-lb-select select {
    width: 100%;
    max-width: 100%;
  }

  #fm-leaderboard-modal .fm-lb-table {
    font-size: 0.8rem;
  }

  #fm-leaderboard-modal .fm-lb-table th,
  #fm-leaderboard-modal .fm-lb-table td {
    padding: 0.3rem 0.35rem;
  }
}

@media (min-width: 721px) {
  #fm-leaderboard-modal #fm-lb-filters-panel {
    display: block !important;
  }

  #fm-leaderboard-modal #fm-lb-filters-panel[hidden] {
    display: block !important;
  }

  #fm-leaderboard-modal .fm-lb-main {
    max-height: 50vh;
  }
}

/* Home screen: VB-style side rail (leaderboard + badges, no in-game controls) */
.home-main-layout {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.shell-home .home-main-layout > .home-player-card {
  flex-shrink: 0;
}

.shell-home .home-main-layout > .home-vb-column {
  flex: 1 1 0;
  min-height: 0;
}

.shell-home .home-main-layout > .home-footer-vb {
  flex-shrink: 0;
}

@media (min-width: 861px) {
  .shell-home .home-main-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 0.85rem;
    padding: max(env(safe-area-inset-top, 0px), clamp(0.2rem, 0.8vw, 0.5rem))
      clamp(0.85rem, 2vw, 1.25rem) 0.5rem;
    align-items: stretch;
    min-height: 0;
  }

  .shell-home .home-main-layout.home-main-layout--side-rail {
    grid-template-columns: minmax(0, 1fr) minmax(15rem, 19rem);
  }

  .shell-home .home-side-rail .game-side-rail-body[hidden] {
    display: none !important;
  }

  .shell-home .home-main-layout:not(.home-main-layout--side-rail) .home-side-rail {
    display: none !important;
  }

  #home-side-rail[hidden],
  .shell-home .home-side-rail[hidden] {
    display: none !important;
  }

  /* Desktop: player bar + footer span full width; canvas + side rail share the middle row. */
  .shell-home .home-vb-column {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    padding: 0 clamp(0.5rem, 2vw, 1.25rem) 0;
  }

  .shell-home .home-main-layout > .home-player-card {
    grid-column: 1 / -1;
    grid-row: 1;
    align-self: stretch;
    flex-shrink: 0;
    margin-bottom: 0.35rem;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .shell-home .home-main-layout > .home-footer-vb {
    grid-column: 1 / -1;
    grid-row: 3;
    margin-top: 0;
    align-self: end;
    width: 100%;
    box-sizing: border-box;
    padding-left: clamp(0.85rem, 2vw, 1.25rem);
    padding-right: clamp(0.85rem, 2vw, 1.25rem);
    border-top: 2px solid rgba(45, 51, 33, 0.42);
    background: linear-gradient(180deg, rgba(240, 244, 228, 0.55) 0%, rgba(218, 228, 198, 0.42) 100%);
  }

  .shell-home .home-canvas-area {
    flex: 1 1 0;
    min-height: 0;
  }

  .shell-home .home-side-rail {
    display: flex;
    grid-column: 2;
    grid-row: 2;
    align-self: stretch;
    margin-top: 0;
    margin-bottom: 0;
    min-height: 0;
    height: 100%;
  }

  body.play-dev .shell-home .home-main-layout {
    grid-template-rows: auto auto minmax(0, 1fr) auto;
  }

  body.play-dev .shell-home .home-main-layout > .home-player-card {
    grid-row: 1;
  }

  body.play-dev .shell-home .home-vb-column {
    grid-row: 2 / 4;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
  }

  body.play-dev .home-play-hint {
    grid-row: 1;
    margin-bottom: 0;
  }

  body.play-dev .shell-home .home-canvas-area {
    grid-row: 2;
    flex: none;
    min-height: 0;
  }

  body.play-dev .shell-home .home-main-layout > .home-footer-vb {
    grid-row: 4;
  }

  body.play-dev .shell-home .home-side-rail {
    grid-row: 3;
  }
}

@media (max-width: 860px) {
  .shell-home .home-side-rail {
    display: none !important;
  }
}
.fm-about-body {
  display: grid;
  gap: 0.75rem;
}
.fm-about-photo {
  border-radius: 8px;
  justify-self: start;
}
.fm-about-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.fm-about-tab {
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--btn-border);
  background: #e8efd4;
  cursor: pointer;
  font-weight: 600;
}
.fm-about-tab--active {
  background: #c94a3a;
  color: #fff;
}
.fm-about-legal-links {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
}
.fm-about-legal-links a {
  font-weight: 600;
}
.fm-about-legal-links .hint {
  font-weight: 400;
  font-size: 0.88rem;
  color: var(--text-muted, #555);
}
.fm-faq-cats,
.fm-contact-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin: 0.5rem 0;
  font-size: 0.88rem;
}
.fm-faq-layout {
  display: grid;
  grid-template-columns: minmax(160px, 34%) 1fr;
  gap: 0.75rem;
  min-height: 280px;
}
@media (max-width: 640px) {
  .fm-faq-layout {
    grid-template-columns: 1fr;
  }
}
.fm-faq-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 50vh;
  overflow: auto;
  border: 1px solid rgba(74, 90, 42, 0.3);
  border-radius: 8px;
  padding: 0.35rem;
  background: #fff;
}
.fm-faq-q {
  text-align: left;
  padding: 0.45rem 0.5rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  font-size: 0.88rem;
}
.fm-faq-q--active,
.fm-faq-q:hover {
  background: rgba(201, 74, 58, 0.12);
}
.fm-faq-answer {
  overflow: auto;
  max-height: 50vh;
  padding: 0.5rem 0.75rem;
  border: 1px solid rgba(74, 90, 42, 0.3);
  border-radius: 8px;
  background: #fff;
  font-size: 0.9rem;
  line-height: 1.5;
}
.game-success-interstitial__actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.game-stats-trophy-btn {
  border: none;
  background: transparent;
  padding: 0.25rem;
  cursor: pointer;
  border-radius: 8px;
}
.game-stats-trophy-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}
.game-stats-trophy-btn img {
  display: block;
  width: 48px;
  height: 48px;
  object-fit: contain;
  background: transparent;
}
