: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; }

/* 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); }

/* 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;
}

/* 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;
}
.game-stage canvas:focus-visible {
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.55);
}

/* ===== 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; }

/* ===== 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; }

/* ===== 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%; object-fit: cover; flex: none;
  background: var(--primary); color: #fff; display: inline-flex;
  align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700;
}
.pwl-avatar.sm { width: 22px; height: 22px; font-size: 0.7rem; }
.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; }

/* 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-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; }
.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-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; }
.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 { font: inherit; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); resize: vertical; }
.pwl-share-form input:focus, .pwl-share-form textarea: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;
}

.sprite-table-wrap { overflow-x: auto; margin: 14px 0 18px; }
.sprite-table { border-collapse: collapse; }
.sprite-table th, .sprite-table td {
  border: 1px solid var(--border); padding: 8px 16px; text-align: left; vertical-align: middle;
}
.sprite-table th { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); background: var(--bg); }
.sprite-pic { width: 56px; }
.sprite-pic svg { width: 40px; height: 40px; display: block; }

/* 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; }
