:root {
  /* PyWebLib palette: indigo chrome, amber accents, light surfaces. */
  --bg: #f7f8fb;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #586079;
  --border: #e3e8f2;
  --primary: #4f46e5;       /* indigo */
  --primary-dark: #4338ca;  /* darker indigo */
  --accent: #ffd43b;        /* python yellow */
  --accent-ink: #1e1b4b;    /* text colour over yellow */
  --highlight: #9900ff;
  --success: #1f9d55;
  --success-bg: #e4f6ec;
  --danger: #d23c3c;
  --danger-bg: #fbe6e6;
  --code-bg: #0f1226;
  --code-text: #e6e7ef;
  --shadow-sm: 0 1px 2px rgba(20, 22, 50, 0.06);
  --shadow-md: 0 8px 24px rgba(20, 22, 50, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }

.container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
}
.logo-mark {
  width: 32px;
  height: 32px;
  display: inline-block;
  vertical-align: middle;
}
.header-link {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 8px 12px;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}
.header-link:hover { color: var(--text); background: var(--bg); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 20px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
  font-family: inherit;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface); border-color: var(--muted); }

/* Sections */
.section { padding: 60px 0; }
/* First block on a page that has no hero above it: the 60px would leave the
   editor floating oddly far below the header. */
.section-top { padding-top: 28px; }

/* Present to a screen reader and to a crawler, invisible on screen. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Page hero */
.page-hero {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 48px 0 36px;
}
.page-hero h1 {
  font-size: clamp(1.8rem, 3.5vw, 2.6rem);
  margin: 8px 0 12px;
  letter-spacing: -0.02em;
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
}
.lead {
  color: var(--muted);
  font-size: 1.1rem;
  max-width: 52ch;
  margin: 0 0 24px;
}

/* ===== Live Python sandbox ===== */
.sandbox-shell {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: stretch;
}
.sandbox-editor,
.sandbox-output {
  background: var(--code-bg);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 360px;
  box-shadow: var(--shadow-md);
}
.sandbox-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--code-text);
}
.sandbox-title {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  opacity: 0.85;
}
.sandbox-code {
  display: block;
  flex: 1;
  background: transparent;
  color: var(--code-text);
  padding: 14px 18px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  line-height: 1.55;
  outline: none;
  overflow: auto;
  white-space: pre;
  tab-size: 4;
  -moz-tab-size: 4;
  caret-color: var(--accent);
  min-height: 280px;
  word-break: normal;
}
.sandbox-code:focus { outline: none; }

/* Prism token colours - a Material-ish palette on the dark editor bg. */
.sandbox-code .token.keyword,
.sandbox-code .token.class-name      { color: #c792ea; }
.sandbox-code .token.string,
.sandbox-code .token.attr-value      { color: #c3e88d; }
.sandbox-code .token.number,
.sandbox-code .token.boolean         { color: #f78c6c; }
.sandbox-code .token.comment         { color: #8b92b0; font-style: italic; }
.sandbox-code .token.operator,
.sandbox-code .token.punctuation     { color: #89ddff; }
.sandbox-code .token.function,
.sandbox-code .token.builtin         { color: #82aaff; }
.sandbox-code .token.decorator       { color: #ffcb6b; }
.sandbox-code .token.namespace       { opacity: 0.7; }
.sandbox-out-body {
  flex: 1;
  margin: 0;
  padding: 14px 18px;
  color: var(--code-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow: auto;
}
.sandbox-run[disabled] { opacity: 0.55; cursor: not-allowed; }
.sandbox-run.is-busy { position: relative; }

/* Stop variant: Run button turns red while code is executing so it's
   obvious you can click it again to terminate. */
.btn.btn-danger {
  background: var(--danger);
  color: white;
  border: 1px solid var(--danger);
}
.btn.btn-danger:hover { background: #b32d2d; border-color: #b32d2d; }
.btn.btn-danger:active { transform: translateY(1px); }

.sandbox-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.sandbox-bar .btn {
  padding: 6px 14px;
  font-size: 0.85rem;
  border-radius: 8px;
}
.sandbox-bar .btn-ghost {
  background: rgba(255, 255, 255, 0.1);
  color: var(--code-text);
  border: 1px solid rgba(255, 255, 255, 0.35);
}
.sandbox-bar .btn-ghost:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.6);
  color: white;
}

.sandbox-out-body .out-stdout { color: var(--code-text); }
.sandbox-out-body .out-stderr { color: #ff8a8a; }
.sandbox-out-body .out-info   { color: #8b92b0; font-style: italic; }

/* Inline, terminal-style input() field and its echoed value. */
.sandbox-out-body .out-stdin { color: var(--accent); }
.sandbox-stdin {
  font: inherit;
  color: var(--accent);
  background: rgba(255, 212, 59, 0.12);
  border: 0;
  border-radius: 3px;
  outline: none;
  padding: 0 2px;
  margin: 0;
  min-width: 1ch;
  caret-color: transparent;   /* hidden in favour of the flashing block cursor */
  vertical-align: baseline;
}
.sandbox-stdin:focus { background: rgba(255, 212, 59, 0.22); }
/* Flashing block cursor shown while input() is waiting. */
.sandbox-cursor {
  display: inline-block;
  width: 0.55ch;
  height: 1.15em;
  margin-left: -2px;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: sandbox-cursor-blink 1.06s steps(1, end) infinite;
}
@keyframes sandbox-cursor-blink {
  0%, 50%      { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .sandbox-cursor { animation: none; }
}

.sandbox-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}
.sandbox-hint kbd {
  display: inline-block;
  padding: 1px 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  color: var(--text);
}

/* Click-to-load snippet cards at the bottom of the page. */
.sandbox-examples {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1.5px solid var(--border);
}
.sandbox-examples-heading {
  margin: 0 0 4px;
  font-size: 1.15rem;
}
.sandbox-examples-sub {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.92rem;
}
.sandbox-examples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.sandbox-example-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  text-align: left;
  font-family: inherit;
  color: var(--text);
  transition: transform 0.1s, border-color 0.1s, box-shadow 0.1s;
}
.sandbox-example-card:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}
.sandbox-example-card:active { transform: translateY(0); }
.sandbox-example-title {
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--primary-dark);
}
.sandbox-example-desc {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}

/* Toast notification (bottom-center, slides up, auto-dismisses). */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 100px);
  background: var(--primary-dark);
  color: white;
  padding: 11px 18px;
  border-radius: 999px;
  box-shadow: 0 12px 28px rgba(20, 22, 50, 0.25);
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: inherit;
  font-size: 0.94rem;
  font-weight: 600;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.22s ease-out;
  max-width: calc(100vw - 32px);
}
.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
  pointer-events: auto;
}
.toast-msg {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast-action {
  background: var(--accent);
  color: var(--primary-dark);
  border: 0;
  padding: 5px 14px;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.78rem;
  cursor: pointer;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: background 0.12s, transform 0.06s;
}
.toast-action:hover { background: white; }
.toast-action:active { transform: translateY(1px); }

/* Responsive */
@media (max-width: 760px) {
  .sandbox-shell { grid-template-columns: 1fr; }
}
@media (max-width: 540px) {
  .header-inner { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 24px 0;
  margin-top: 40px;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: center;
}
.site-footer a { color: var(--primary); text-decoration: none; font-weight: 600; }
.site-footer a:hover { text-decoration: underline; }

/* Header nav */
.site-nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.header-link.active { color: var(--text); background: var(--bg); }

/* Docs dropdown in the header nav */
.nav-dd { position: relative; display: inline-flex; align-items: center; }
.nav-dd > .header-link { display: inline-flex; align-items: center; }
.nav-caret { width: 9px; height: 9px; margin-left: 5px; opacity: 0.7; }
.nav-dd-menu {
  position: absolute; top: calc(100% + 4px); left: 0; min-width: 168px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 30px rgba(15, 18, 38, 0.16); padding: 6px; display: none; z-index: 60;
}
.nav-dd:hover .nav-dd-menu, .nav-dd:focus-within .nav-dd-menu, .nav-dd.open .nav-dd-menu { display: block; }
/* Invisible bridge spanning the 4px gap above the menu, so moving the mouse
   down from the trigger onto the menu never crosses a dead zone that closes it.
   It's a child of the menu (itself a child of .nav-dd), so hovering it keeps
   .nav-dd:hover true; it only exists while the menu is open. */
.nav-dd-menu::before { content: ""; position: absolute; left: 0; right: 0; bottom: 100%; height: 6px; }
.nav-dd-trigger { background: none; border: 0; cursor: pointer; font-family: inherit; }
.nav-caret { transition: transform 0.15s ease; }
.nav-dd.open .nav-caret { transform: rotate(180deg); }
.nav-dd-menu a {
  display: block; padding: 8px 10px; border-radius: 7px; color: var(--text);
  text-decoration: none; font-weight: 600; font-size: 0.9rem; white-space: nowrap;
}
.nav-dd-menu a:hover { background: var(--bg); }
.nav-dd-menu a.active { color: var(--primary); }

/* Guide landing: one big card per library */
.guide-cards { display: grid; grid-template-columns: 1fr; gap: 20px; }
@media (min-width: 720px) { .guide-cards { grid-template-columns: 1fr 1fr; } }
.guide-lib-card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.guide-lib-media { background: #0b1020; aspect-ratio: 16 / 10; overflow: hidden; }
.guide-lib-media img { display: block; width: 100%; height: 100%; object-fit: cover; }
.guide-lib-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; }
.guide-lib-body h2 { margin: 0; }
.guide-lib-body p { margin: 0; color: var(--muted); }
.guide-lib-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

/* Inline code in prose (hints, hero). */
.sandbox-hint code,
.lead code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 5px;
}

/* ===== Right column: turtle + game windows stacked beside the output ===== */
.sandbox-right {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}
/* The turtle / game panels reuse .sandbox-output's dark box, but must not
   inherit its tall min-height, and stay hidden until the code imports them. */
.turtle-panel,
.game-panel { min-height: 0; }
.turtle-panel[hidden],
.game-panel[hidden] { display: none; }

/* Turtle stage: a faint grid, the drawing canvas, and a sprite overlay. */
.turtle-stage {
  position: relative;
  background:
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 20px 20px;
  background-position: center;
}
.turtle-stage canvas {
  display: block;
  width: 100%;
  height: auto;
}
.turtle-stage canvas + canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* 3D window (import game3d). SPIKE. */
.game3d-panel[hidden] { display: none; }
.game3d-stage {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 8px;
}
.game3d-stage canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  background: #8ec5f0;
  outline: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.game3d-stage canvas:focus-visible { box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.55); }

/* Game window (import game). */
.game-hint {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.78rem;
}
.game-stage {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 8px;
}
.game-stage canvas {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  background: #0b1020;
  outline: none;
  cursor: pointer;
  /* Touch drives the game, not the page: no scroll/zoom/selection on iOS. */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.game-stage canvas:focus-visible {
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.55);
}

/* ===== Fullscreen game: a full-viewport overlay that works even on iPhone
   (whose Safari has no Fullscreen API), plus real fullscreen where available.
   The canvas is sized in JS to the largest aspect-preserving fit. ===== */
.game-stage { position: relative; }
.game-fs-btn { padding: 6px 9px; }
.game-fs-btn svg { display: block; }
.game-fs-exit { display: none; }
body.pwl-game-fs { overflow: hidden; }
/* The game stage itself becomes the full-viewport overlay. It exists on BOTH the
   editor (.game-panel > .game-stage) and the shared community player
   (.pwl-player .game-stage), so fullscreen behaves the same on each. Using inset:0
   rather than 100vw/100vh sidesteps the mobile address-bar height bugs, and the
   opaque background hides the page (bar, output) sitting behind it. */
body.pwl-game-fs .game-stage {
  position: fixed;
  inset: 0;
  z-index: 500;
  margin: 0;
  padding: 0;
  border-radius: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
body.pwl-game-fs .game-stage canvas {
  max-width: none;   /* JS sets the exact letterboxed pixel size */
  height: auto;
  border-radius: 0;
}
body.pwl-game-fs .game-fs-exit {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  z-index: 510;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

/* ===== Snippet categories: collapsible groups so the list is not crowded ===== */
.sandbox-example-groups { display: flex; flex-direction: column; gap: 10px; }
.sandbox-example-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.sandbox-example-group > summary {
  cursor: pointer;
  padding: 11px 14px;
  font-weight: 700;
  color: var(--primary);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 9px;
}
.sandbox-example-group > summary::-webkit-details-marker { display: none; }
.sandbox-example-group > summary::before {
  content: "";
  width: 0; height: 0;
  border-left: 6px solid currentColor;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  transition: transform 0.15s ease;
  flex: none;
}
.sandbox-example-group[open] > summary::before { transform: rotate(90deg); }
.sandbox-example-group > summary:hover { color: var(--primary-dark); }
.sandbox-example-count {
  margin-left: auto;
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--bg);
  border-radius: 999px;
  padding: 1px 9px;
}
.sandbox-example-group .sandbox-examples-grid { padding: 0 14px 14px; }

/* Outer snippet sections ("Stock Python", "PyWebLib"), each holding categories. */
.sandbox-example-section > summary {
  cursor: pointer;
  padding: 4px 2px 10px;
  font-weight: 800;
  font-size: 1.02rem;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 9px;
}
.sandbox-example-section > summary::-webkit-details-marker { display: none; }
.sandbox-example-section > summary::before {
  content: "";
  width: 0; height: 0;
  border-left: 7px solid currentColor;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  transition: transform 0.15s ease;
  flex: none;
}
.sandbox-example-section[open] > summary::before { transform: rotate(90deg); }
.sandbox-example-section > summary:hover { color: var(--primary); }
/* The categories inside a section: indented, and stacked like before. */
.sandbox-example-section > .sandbox-example-group { margin: 0 0 10px 18px; }
.sandbox-example-section + .sandbox-example-section { margin-top: 6px; }

/* ===== Documentation page (docs/) ===== */
.docs-searchbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.docs-search-input {
  flex: 1;
  padding: 12px 18px;
  font: inherit;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
}
.docs-search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12); }
.docs-count { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.docs-jump { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.docs-chip {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  text-decoration: none;
}
.docs-chip:hover { border-color: var(--primary); background: var(--bg); }
.docs-section { margin: 0 0 30px; scroll-margin-top: 84px; }
.docs-section[hidden] { display: none; }
.docs-section-title { margin: 0 0 4px; color: var(--primary-dark); }
.docs-section-blurb { margin: 0 0 14px; color: var(--muted); }
.docs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.docs-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.docs-item[hidden] { display: none; }
.docs-sig {
  align-self: flex-start;
  max-width: 100%;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 3px 8px;
  border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.88rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.docs-desc { margin: 0; font-size: 0.92rem; line-height: 1.45; }
.docs-ex {
  margin: 0;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 8px 10px;
  border-radius: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
}
.docs-empty { color: var(--muted); font-style: italic; }

/* ===== Maximise the code editor: fill the screen to read/write in peace ===== */
.sandbox-max { padding: 6px 10px; }
.sandbox-max svg { display: block; }
.sandbox-max .i-compress { display: none; }
.sandbox-editor.is-max .sandbox-max .i-expand { display: none; }
.sandbox-editor.is-max .sandbox-max .i-compress { display: block; }
.sandbox-editor.is-max {
  position: fixed;
  inset: 0;
  z-index: 200;
  margin: 0;
  min-height: 0;
  border-radius: 0;
}
.sandbox-editor.is-max .sandbox-code { max-height: none; }
body.sandbox-maxed { overflow: hidden; }

/* ===== Collapsible code: cap to the output column's height by default, with a
   faded bottom + an expand pill to open it out. --code-cap is measured in JS. */
.sandbox-editor:not(.is-max):not(.is-expanded) .sandbox-code {
  max-height: var(--code-cap, 420px);
}
.sandbox-expand-fade {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 88px;
  background: linear-gradient(to bottom, rgba(11, 16, 32, 0), var(--code-bg) 82%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 2;
}
.sandbox-editor.can-expand:not(.is-expanded):not(.scrolled-end) .sandbox-expand-fade {
  opacity: 1;
}
.sandbox-expand {
  position: absolute;
  left: 50%; bottom: 10px;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 6px;
  padding: 5px 13px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--code-text);
  border: 1px solid rgba(255, 255, 255, 0.18);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  font: 600 0.8rem ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  cursor: pointer;
  z-index: 3;
  transition: background 0.12s ease;
}
.sandbox-editor.can-expand .sandbox-expand { display: inline-flex; }
.sandbox-expand:hover { background: rgba(255, 255, 255, 0.2); }
.sandbox-expand-chev { display: block; transition: transform 0.15s ease; }
.sandbox-editor.is-expanded .sandbox-expand-chev { transform: rotate(180deg); }
/* When opened out, don't let the grid stretch the output column to match. */
.sandbox-shell.editor-expanded { align-items: start; }
/* Maximised editor already fills the screen: nothing to collapse or expand. */
.sandbox-editor.is-max .sandbox-expand,
.sandbox-editor.is-max .sandbox-expand-fade { display: none; }

/* ===== Editor helpers: block-indent hint strip + inline flags (editor-tools.js) ===== */
.sandbox-editor { position: relative; }
.indent-hint {
  padding: 6px 12px;
  background: #fff3cd;
  color: #6b5200;
  font-size: 0.84rem;
  border-top: 1px solid #e6d9a8;
}
.indent-flag {
  position: absolute;
  pointer-events: none;
  background: rgba(255, 82, 82, 0.14);
  border-left: 3px solid rgba(255, 82, 82, 0.65);
  border-radius: 2px;
  z-index: 2;
}
.name-flag {
  position: absolute;
  pointer-events: none;
  background: rgba(255, 82, 82, 0.16);
  border-bottom: 2px solid #e53935;
  border-radius: 2px;
  z-index: 2;
}

/* ============================ Community layer ============================ */

/* Account control (auth.js) */
.pwl-account { display: inline-flex; align-items: center; }
.btn-google {
  display: inline-flex; align-items: center; gap: 8px;
  background: #fff; color: #3c4043; border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 10px; font-weight: 600; font-size: 0.9rem;
  cursor: pointer; font-family: inherit;
}
.btn-google:hover { background: var(--bg); border-color: var(--muted); }
.g-icon { flex: none; }
.pwl-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: var(--primary); color: #fff; display: inline-flex;
  align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700;
  position: relative; overflow: hidden;
}
.pwl-avatar.sm { width: 22px; height: 22px; font-size: 0.7rem; }
/* A person silhouette shows through when there's no photo, or it fails to load
   (e.g. Google avatars blocked by COEP on Safari). The photo overlays it. */
.pwl-avatar-person { position: absolute; inset: 0; width: 100%; height: 100%; fill: rgba(255, 255, 255, 0.92); }
.pwl-avatar-photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.pwl-acct { position: relative; }
.pwl-acct-btn {
  display: inline-flex; align-items: center; gap: 8px; background: transparent;
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px 4px 4px;
  cursor: pointer; font-family: inherit; font-weight: 600; color: var(--text); font-size: 0.9rem;
}
.pwl-acct-btn:hover { background: var(--bg); }
.pwl-acct-name { max-width: 12ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pwl-acct-menu {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 160px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-md); padding: 6px; display: none; z-index: 50;
}
.pwl-acct[data-open="true"] .pwl-acct-menu { display: block; }
.pwl-acct-item {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0;
  background: transparent; border-radius: 7px; cursor: pointer; font: inherit;
  color: var(--text); text-decoration: none;
}
.pwl-acct-item:hover { background: var(--bg); }

/* Share CTA on the Playground (publish.js) */
.pwl-share { margin-top: 18px; }
.share-cta {
  display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap;
  background: linear-gradient(120deg, rgba(79,70,229,0.08), rgba(255,212,59,0.10));
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 22px;
}
.share-cta h2 { margin: 0 0 2px; font-size: 1.1rem; }
.share-cta p { margin: 0; color: var(--muted); font-size: 0.92rem; max-width: 46ch; }
.share-cta-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* A thicker inline arrow for buttons, replacing the thin -> glyph. */
.btn-arrow { width: 15px; height: 15px; margin-left: 6px; vertical-align: -2px; }

/* Community gallery (community.js) */
.community-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.community-tabs { display: inline-flex; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px; }
.community-tab { border: 0; background: transparent; padding: 7px 16px; border-radius: 999px; cursor: pointer; font: inherit; font-weight: 700; color: var(--muted); }
.community-tab.active { background: var(--primary); color: #fff; }
.community-notice { background: #fff3cd; color: #6b5200; border: 1px solid #e6d9a8; border-radius: var(--radius); padding: 14px 16px; }
.community-empty { color: var(--muted); padding: 24px 2px; }
.community-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
/* Community pager: Prev / page count / Next */
.cc-pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 24px 0 4px; flex-wrap: wrap; }
.cc-page-btn { padding: 8px 15px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.cc-page-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.cc-page-btn:disabled { opacity: 0.45; cursor: default; }
.cc-page-info { font-size: 0.9rem; color: var(--muted); }
.community-card { display: flex; flex-direction: column; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 16px 18px; }
.cc-head { display: flex; align-items: center; gap: 10px; }
.cc-title { margin: 0; font-size: 1.05rem; overflow-wrap: anywhere; }
.cc-desc { margin: 0; color: var(--muted); font-size: 0.9rem; overflow-wrap: anywhere; }
.cc-author { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 0.82rem; }
/* Views counter, pushed to the end of the author line. */
.cc-views, .pg-views { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; color: var(--muted); font-size: 0.8rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cc-views svg, .pg-views svg { display: block; opacity: 0.85; }
.cc-kind { flex: none; font-size: 0.68rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 8px; border-radius: 999px; color: #fff; background: var(--muted); }
.cc-kind-python { background: #3b82f6; }
.cc-kind-turtle { background: #22b45e; }
.cc-kind-game { background: #a855f7; }
.cc-kind-game3d { background: var(--primary); }   /* 3D wears the app's indigo */
.cc-kind.cc-draft { background: #b45309; }   /* amber chip = private draft, only the author sees it */
/* Draft cards read as clearly unpublished: warm tint + amber dashed frame, so a
   private draft never looks the same as a live, published card. */
.community-card.is-draft { border: 1.5px dashed #d9861f; background: #fff8ee; box-shadow: 0 1px 0 #f1ddbf, var(--shadow-sm); }
.community-card.is-draft .cc-thumb { opacity: 0.92; }
/* The go-public buttons (draft card + share dialog) share one deliberate look
   that stands apart from the neutral "Save"/"Edit" buttons. */
.cc-btn.cc-publish, .btn.pwl-publish-alt { border-color: #a855f7; color: #a855f7; font-weight: 700; }
.cc-btn.cc-publish:hover, .btn.pwl-publish-alt:hover { background: #a855f7; color: #fff; }
.cc-btn.cc-publish.armed { background: #a855f7; border-color: #a855f7; color: #fff; }
/* Playground share panel while editing a draft: a subtle amber cue. */
.share-cta.share-cta-draft { border-left: 3px solid #d9861f; padding-left: 15px; }
.cc-actions { display: flex; align-items: center; gap: 8px; margin-top: auto; flex-wrap: wrap; }
.cc-vote { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 5px 12px; cursor: pointer; font: inherit; font-weight: 700; color: var(--muted); }
.cc-vote:hover { border-color: var(--primary); color: var(--primary); }
.cc-vote.voted { background: var(--primary); border-color: var(--primary); color: #fff; }
.cc-arrow { font-size: 0.7rem; }
.cc-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 5px 10px; cursor: pointer; font: inherit; font-size: 0.82rem; color: var(--text); }
.cc-btn:hover { border-color: var(--primary); }

/* Modal: project detail + share dialog */
.pwl-modal-back { position: fixed; inset: 0; background: rgba(15,18,38,0.5); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 200; overflow-y: auto; }
.pwl-modal { position: relative; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 24px 26px; width: 100%; max-width: 560px; }
.pwl-modal-x { position: absolute; top: 12px; right: 14px; border: 0; background: transparent; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--muted); }
.pwl-modal-title { margin: 0 0 6px; padding-right: 24px; }
.pwl-modal-desc { color: var(--muted); margin: 8px 0; overflow-wrap: anywhere; }
.pwl-modal-code { background: var(--code-bg); color: var(--code-text); border-radius: 8px; padding: 12px 14px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.82rem; line-height: 1.5; overflow: auto; max-height: 240px; white-space: pre; margin: 10px 0; }
.pwl-modal-actions { display: flex; gap: 10px; }
/* Sign-in dialog: an Email tab (Google or email + password) and a Class code
   tab (the code + PIN a school student is given). */
.pwl-signin-tabs { display: flex; gap: 4px; margin: 14px 0 16px; border-bottom: 1px solid var(--border); }
.pwl-signin-tab {
  font: inherit; font-weight: 600; font-size: 0.9rem; cursor: pointer;
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 8px 14px; margin-bottom: -1px;
}
.pwl-signin-tab:hover { color: var(--text); }
.pwl-signin-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.pwl-signin-google { width: 100%; justify-content: center; padding: 11px 14px; }
.pwl-signin-or {
  display: flex; align-items: center; gap: 12px;
  margin: 16px 0 4px; color: var(--muted); font-size: 0.85rem;
}
.pwl-signin-or::before, .pwl-signin-or::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}
.pwl-signin-swap { color: var(--muted); font-size: 0.88rem; margin: 4px 0 0; }
.pwl-linkbtn {
  font: inherit; font-weight: 600; color: var(--primary);
  background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline;
}

.pwl-signin-row { display: flex; gap: 10px; align-items: flex-start; }
.pwl-signin-row > label { flex: 1; }
.pwl-signin-row > .pwl-signin-pin { flex: 0 0 88px; }
#pwl-code-form input[name="code"], #pwl-code-form input[name="pin"] {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.08em; text-transform: uppercase; width: 100%;
}
#pwl-code-form input[name="pin"] { text-align: center; letter-spacing: 0.25em; }
#pwl-code-form input::placeholder { letter-spacing: normal; text-transform: none; }

.pwl-share-form { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.pwl-share-form label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 0.88rem; }
.pwl-share-form input, .pwl-share-form textarea, .pwl-share-form select { font: inherit; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); resize: vertical; }
.pwl-share-form select { cursor: pointer; }
.pwl-cap-note { margin: 0; padding: 8px 10px; border-radius: 8px; background: #fef3c7; color: #92400e; font-size: 0.85rem; font-weight: 600; }

/* "My programs" quick-picker under the share panel */
.pwl-myprograms:not(:empty) { margin-top: 12px; }
.pwl-mine { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.pwl-mine-title { font-weight: 700; font-size: 0.92rem; }
.pwl-mine select { font: inherit; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); cursor: pointer; flex: 1; min-width: 220px; }
.pwl-mine select:focus { outline: none; border-color: var(--primary); }
.pwl-share-form input:focus, .pwl-share-form textarea:focus, .pwl-share-form select:focus { outline: none; border-color: var(--primary); }

/* Comments */
.pwl-comments-h { margin: 18px 0 8px; font-size: 1rem; border-top: 1px solid var(--border); padding-top: 16px; }
.pwl-comments { display: flex; flex-direction: column; gap: 12px; }
.pwl-comments-empty { color: var(--muted); font-size: 0.9rem; }
.pwl-comment { display: flex; gap: 9px; align-items: flex-start; }
.pwl-comment-body { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.pwl-comment-name { font-weight: 700; font-size: 0.85rem; }
.pwl-comment-when { color: var(--muted); font-weight: 400; font-size: 0.78rem; margin-left: 4px; }
.pwl-comment-text { font-size: 0.92rem; overflow-wrap: anywhere; }
.pwl-comment-del { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 1.1rem; line-height: 1; }
.pwl-comment-del:hover { color: var(--danger); }
.pwl-comment-form { display: flex; gap: 8px; margin-top: 12px; }
.pwl-comment-form input { flex: 1; font: inherit; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.pwl-comment-form input:focus { outline: none; border-color: var(--primary); }
.pwl-comment-signin { color: var(--muted); font-size: 0.88rem; margin-top: 12px; }

/* Leaderboard (leaderboard.js) */
.leaderboard { display: flex; flex-direction: column; gap: 8px; max-width: 620px; }
.lb-row { display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow-sm); }
.lb-rank { font-weight: 800; color: var(--muted); width: 1.6em; text-align: center; font-size: 1.05rem; }
.lb-top-1 .lb-rank { color: #e0a92e; }
.lb-top-2 .lb-rank { color: #9aa3b2; }
.lb-top-3 .lb-rank { color: #c8894e; }
.lb-name { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-stats { color: var(--muted); font-size: 0.85rem; text-align: right; }
.lb-stats strong { color: var(--text); }

@media (max-width: 640px) {
  .pwl-acct-name { display: none; }
  .community-grid { grid-template-columns: 1fr; }
}

/* ============================ Game guide (docs/game/) ============================ */
.guide { max-width: 760px; margin: 0 auto; }
.guide-jump { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 26px; }
.guide-jump a {
  font-size: 0.82rem; font-weight: 700; color: var(--primary);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 12px; text-decoration: none;
}
.guide-jump a:hover { border-color: var(--primary); background: var(--bg); }
.guide section { margin: 0 0 34px; scroll-margin-top: 80px; }
.guide h2 {
  font-size: 1.5rem; margin: 0 0 12px; letter-spacing: -0.01em;
  border-bottom: 2px solid var(--border); padding-bottom: 8px;
}
.guide h3 { font-size: 1.1rem; margin: 22px 0 8px; }
.guide p { margin: 0 0 14px; line-height: 1.6; }
.guide a:not(.btn) { color: var(--primary); font-weight: 600; }
.guide :not(pre) > code {
  background: #eef0fb; color: #2a2d4a; padding: 2px 6px; border-radius: 5px;
  font-size: 0.9em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.guide kbd {
  display: inline-block; padding: 1px 7px; background: var(--surface);
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem; color: var(--text);
}
.guide-code {
  background: var(--code-bg); color: var(--code-text);
  border-radius: var(--radius-sm); padding: 14px 16px; margin: 0 0 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem; line-height: 1.55; overflow-x: auto; white-space: pre;
}
.guide-code .token.keyword, .guide-code .token.class-name  { color: #c792ea; }
.guide-code .token.string, .guide-code .token.attr-value   { color: #c3e88d; }
.guide-code .token.number, .guide-code .token.boolean      { color: #f78c6c; }
.guide-code .token.comment                                 { color: #8b92b0; font-style: italic; }
.guide-code .token.operator, .guide-code .token.punctuation { color: #89ddff; }
.guide-code .token.function, .guide-code .token.builtin    { color: #82aaff; }

.callout {
  background: #fff7e8; border-left: 4px solid #ffbe0b;
  padding: 12px 16px; border-radius: var(--radius-sm); margin: 12px 0 18px; font-size: 0.97rem;
}
.callout code { background: #fdeccb; }
.key-points { list-style: none; padding: 0; margin: 8px 0 16px; display: grid; gap: 8px; }
.key-points li {
  background: #f6f8fc; border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 0.95rem;
}

/* The built-in sprite gallery: a responsive grid, built from PWL_SPRITES. */
.sprite-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 12px;
  margin: 14px 0 18px;
}
.sprite-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.sprite-cell-pic { width: 52px; height: 52px; }
.sprite-cell-pic svg { width: 100%; height: 100%; display: block; }
.sprite-cell-name { font-size: 0.82rem; color: var(--text); }
.sprite-cell-num {
  position: absolute; top: 6px; left: 9px;
  font-size: 0.72rem; font-weight: 700; color: var(--muted);
}

/* Code textarea in the edit-post dialog (dark + monospace). */
.pwl-share-form textarea.pwl-code-edit {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem; line-height: 1.5;
  background: var(--code-bg); color: var(--code-text);
  border-color: #2a2f57; min-height: 220px; white-space: pre; tab-size: 4; -moz-tab-size: 4;
}
.cc-edit { margin-left: auto; }

/* Community card preview poster (preview.js) */
.community-card { overflow: hidden; }
.cc-thumb-wrap {
  margin: -16px -18px 12px;
  background: #0b1020;
  border-bottom: 1px solid var(--border);
  aspect-ratio: 320 / 180;
  overflow: hidden;
}
.cc-thumb { display: block; width: 100%; height: 100%; }
.cc-arrow { display: inline-flex; }
.cc-arrow svg, .cc-comment-btn svg { display: block; }
.cc-comment-btn { display: inline-flex; align-items: center; gap: 5px; }
.pwl-share-preview-wrap { margin: 8px 0 2px; border-radius: var(--radius-sm); overflow: hidden; background: #0b1020; border: 1px solid var(--border); aspect-ratio: 320 / 180; max-width: 360px; }
.pwl-share-preview { display: block; width: 100%; height: 100%; }
/* "No thumbnail yet, run it first" callout in the Share dialog. */
.pwl-share-runfirst {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  margin: 8px 0 4px; padding: 8px 10px;
  background: rgba(255, 212, 59, 0.14);
  border: 1px solid rgba(255, 212, 59, 0.45);
  border-radius: var(--radius-sm);
}
.pwl-share-runfirst span { color: var(--text); font-size: 0.82rem; }
.pwl-share-runfirst .pwl-runfirst-btn { flex: none; white-space: nowrap; padding: 5px 12px; font-size: 0.82rem; }
.pwl-share-runfirst.bypassed { opacity: 0.5; }
/* Escape hatch under the run-first callout: a quiet text link. */
.pwl-publish-anyway {
  display: block; margin: 2px 0 4px; padding: 0;
  border: 0; background: none; cursor: pointer;
  color: var(--muted); font: inherit; font-size: 0.78rem; text-decoration: underline;
}
.pwl-publish-anyway:hover { color: var(--text); }
/* A disabled Publish (gated on a thumbnail or the program cap) reads as inactive. */
.pwl-modal-actions .btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Play button on a community card's title line */
.cc-title { flex: 1; }
.cc-play { flex: none; display: inline-flex; align-items: center; gap: 5px; padding: 6px 11px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--primary); font-weight: 700; font-size: 0.82rem; cursor: pointer; }
.cc-play:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.cc-play svg { width: 10px; height: 10px; }

/* Inline player: the community Play modal and the program page */
.pwl-player-modal { max-width: 640px; }
.pwl-player { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.pwl-player-bar { display: flex; align-items: center; gap: 10px; min-height: 34px; }
.pwl-player-hint { color: var(--muted); font-size: 0.8rem; }
.pwl-player-run { margin-left: auto; }
.pwl-player-stage { display: flex; justify-content: center; background: #0b1020; border-radius: var(--radius-sm); padding: 10px; overflow: hidden; }
.pwl-player-stage .turtle-stage, .pwl-player-stage .game-stage { margin: 0; max-width: 100%; }
/* The run output is a real terminal: keep the dark code background so the
   light text reads, instead of light-grey-on-white on the page/modal. */
.pwl-player-out {
  max-height: 140px;
  overflow: auto;
  margin: 0;
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}
.pwl-player-out:empty { display: none; }

/* Program page (/game/?id=) */
.pg-view { display: flex; flex-direction: column; gap: 14px; max-width: 720px; }
.pg-title { margin: 0; font-size: 1.5rem; overflow-wrap: anywhere; }
.pg-desc { margin: 0; overflow-wrap: anywhere; }
.pg-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pg-h { margin: 6px 0 0; font-size: 1.05rem; }
.pg-poster { position: relative; display: inline-block; max-width: 480px; width: 100%; border-radius: var(--radius-sm); overflow: hidden; background: #0b1020; }
.pg-poster-canvas { display: block; width: 100%; height: auto; }
.pg-play-btn { position: absolute; inset: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; background: rgba(11, 16, 32, 0.28); color: #fff; border: 0; font-size: 1.3rem; font-weight: 800; cursor: pointer; }
.pg-play-btn svg { width: 24px; height: 24px; }
.pg-play-btn:hover { background: rgba(79, 70, 229, 0.42); }
.pg-code { max-height: 320px; }
/* Collapsible "Code" panel: keeps the game, leaderboard and comments the focus,
   collapsed by default for games (see program.js). */
.pg-code-wrap { margin: 2px 0; }
.pg-code-summary { cursor: pointer; font-size: 1.05rem; font-weight: 700; margin: 6px 0; list-style: none; display: inline-flex; align-items: center; gap: 8px; user-select: none; }
.pg-code-summary::-webkit-details-marker { display: none; }
.pg-code-summary::before { content: "\25B6"; font-size: 0.62rem; color: var(--muted); transition: transform 0.15s ease; }
.pg-code-wrap[open] .pg-code-summary::before { transform: rotate(90deg); }
.pg-code-wrap .pg-code { margin-top: 8px; }
.pg-stage { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.pg-stage .pg-play { flex: 1 1 320px; min-width: 0; }
.pg-leaderboard { flex: 0 0 210px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.pg-lb-title { margin: 0 0 8px; font-size: 1rem; }
.pg-lb-body { display: flex; flex-direction: column; gap: 3px; }
.pg-lb-row { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 7px; font-size: 0.88rem; }
.pg-lb-row.me { background: rgba(79, 70, 229, 0.1); font-weight: 700; }
.pg-lb-rank { width: 18px; text-align: right; color: var(--muted); font-weight: 700; }
.pg-lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pg-lb-score { font-weight: 700; font-variant-numeric: tabular-nums; }
.pg-lb-empty, .pg-lb-signin { color: var(--muted); font-size: 0.82rem; margin: 6px 0 0; }

/* ===== Asset studio (assets/) ===== */
.asset-studio {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 210px;
  gap: 18px;
  align-items: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
@media (max-width: 820px) { .asset-studio { grid-template-columns: 1fr; } }
.asset-tools { display: flex; flex-direction: column; gap: 12px; }
.asset-tool-row { display: flex; flex-wrap: wrap; gap: 6px; }
.asset-tool {
  width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); cursor: pointer;
}
.asset-tool.is-on { background: var(--primary); color: #fff; border-color: var(--primary); }
.asset-swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; max-width: 172px; }
.asset-swatch { width: 100%; aspect-ratio: 1; border-radius: 6px; border: 1px solid rgba(0, 0, 0, 0.18); cursor: pointer; padding: 0; }
.asset-custom-color { display: flex; align-items: center; gap: 8px; font-size: 0.84rem; color: var(--muted); }
.asset-custom-color input { width: 42px; height: 28px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: none; cursor: pointer; }
.asset-line-width { display: flex; align-items: center; gap: 8px; font-size: 0.84rem; color: var(--muted); }
.asset-line-width input { flex: 1; min-width: 88px; cursor: pointer; }
.asset-edit-actions .btn { padding: 6px 10px; font-size: 0.82rem; }
.asset-stage-wrap { display: flex; justify-content: center; }
.asset-stage {
  width: 100%; max-width: 360px; aspect-ratio: 1 / 1;
  background-color: #fbfbfe;
  background-image:
    linear-gradient(rgba(79, 70, 229, 0.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(79, 70, 229, 0.09) 1px, transparent 1px);
  background-size: 12.5% 12.5%;
  border: 1px solid var(--border); border-radius: 12px; touch-action: none; cursor: crosshair;
}
.asset-side { display: flex; flex-direction: column; gap: 12px; }
.asset-preview { border: 1px solid var(--border); border-radius: 12px; padding: 10px; background: #0b1020; }
.asset-preview-title { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: #8aa0d0; margin-bottom: 8px; }
.asset-preview-row { display: flex; align-items: center; gap: 12px; min-height: 64px; }
.asset-name-label { display: flex; flex-direction: column; gap: 4px; font-size: 0.84rem; color: var(--muted); }
.asset-name-label input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit; }
.asset-msg { margin: 0; font-size: 0.84rem; overflow-wrap: anywhere; }
.asset-msg.is-ok { color: #1f7a4a; }
.asset-msg.is-err { color: #c0392b; }
/* Right-click menu on the drawing canvas (copy / duplicate / paste). */
.asset-ctx {
  position: fixed; z-index: 1000; min-width: 156px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 12px 30px rgba(15, 18, 38, 0.18); font-size: 0.88rem;
}
.asset-ctx-item {
  display: block; width: 100%; text-align: left; padding: 7px 10px;
  background: none; border: 0; border-radius: 5px; cursor: pointer;
  font: inherit; color: var(--text);
}
.asset-ctx-item:hover:not(:disabled) { background: var(--bg); }
.asset-ctx-item:disabled { color: var(--muted); opacity: 0.5; cursor: default; }
.asset-ctx-sep { height: 1px; background: var(--border); margin: 4px 2px; }
.asset-library { margin-top: 26px; }
.asset-library h2 { margin: 18px 0 10px; }
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(94px, 1fr)); gap: 12px; }
.asset-card { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 8px 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
/* Paging hides tiles in place: needed because the display:flex above would
   otherwise beat the browser's default [hidden] rule. */
.asset-card[hidden] { display: none; }

/* Zoom controls under the tool row. */
.asset-zoom { display: flex; align-items: center; gap: 6px; }
.asset-zoom .btn { padding: 4px 12px; font-size: 1rem; line-height: 1; font-weight: 700; }
.asset-zoom .btn:disabled { opacity: 0.4; cursor: default; }
.asset-zoom-label {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 5px 0;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.asset-zoom-label:hover { border-color: var(--primary); color: var(--primary); }
/* The pan tool gets a grab cursor on the canvas. */
.asset-stage.is-pan { cursor: grab; }
.asset-stage.is-pan:active { cursor: grabbing; }
.asset-card-pic { width: 52px; height: 52px; cursor: pointer; }
.asset-card-id { font-size: 0.72rem; font-weight: 700; color: var(--muted); border: none; background: none; padding: 0; cursor: pointer; }
.asset-card-id:hover { color: var(--primary); text-decoration: underline; }
.asset-card-pic { cursor: pointer; }
.asset-recent-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.asset-recent-label { font-size: 0.76rem; color: var(--muted); }
.asset-recent { display: flex; flex-wrap: wrap; gap: 5px; }
.asset-recent .asset-swatch { width: 22px; height: 22px; aspect-ratio: auto; }
.asset-import-btn { width: 100%; }
.asset-card-name { font-size: 0.8rem; color: var(--text); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.asset-download {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 5px 12px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--code-text);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.asset-download:hover:not(:disabled) { background: rgba(255, 255, 255, 0.22); border-color: rgba(255, 255, 255, 0.6); color: #fff; }
.asset-download:disabled { opacity: 0.5; cursor: default; }

.asset-card-fit { border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px; font: inherit; font-size: 0.68rem; font-weight: 700; padding: 1px 8px; cursor: pointer; }
.asset-card-fit:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.asset-card-fit:disabled { opacity: 0.5; cursor: default; }
.asset-card-del { position: absolute; top: 3px; right: 6px; border: none; background: none; color: var(--muted); font-size: 17px; line-height: 1; cursor: pointer; }
.asset-card-del:hover { color: #c0392b; }

/* The frame readout under the preview: what shape the artwork really is. */
.asset-frame-info { display: block; margin-top: 8px; font-size: 0.74rem; color: #8aa0d0; font-variant-numeric: tabular-nums; }
.asset-tool-row .btn.is-on { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Snippet subtitle: the qualifier, kept out of the title so names stay short. */
.sandbox-example-sub {
  display: inline-block;
  margin-left: 7px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  vertical-align: 1px;
}

/* Asset library panels: closed by default, so the page is the editor first. */
.asset-lib-group { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden; margin-bottom: 12px; }
.asset-lib-group > summary { cursor: pointer; padding: 13px 16px; font-weight: 800; font-size: 1.02rem; color: var(--text); list-style: none; display: flex; align-items: center; gap: 10px; }
.asset-lib-group > summary::-webkit-details-marker { display: none; }
.asset-lib-group > summary::before { content: ""; width: 0; height: 0; border-left: 7px solid currentColor; border-top: 6px solid transparent; border-bottom: 6px solid transparent; transition: transform 0.15s ease; flex: none; }
.asset-lib-group[open] > summary::before { transform: rotate(90deg); }
.asset-lib-group > summary:hover { color: var(--primary); }
.asset-lib-count { margin-left: auto; font-size: 0.78rem; font-weight: 700; color: var(--muted); background: var(--bg); border-radius: 999px; padding: 1px 9px; }
.asset-lib-group .asset-grid { padding: 0 16px 16px; }
.asset-lib-group .cc-pager { margin: 0 16px 16px; }
