/*
 * Shared playground design system — daily-post
 * ============================================
 * Link it from any post's playground/index.html (no per-post boilerplate):
 *
 *   <link rel="stylesheet" href="../../../playground/assets/base.css" />
 *
 * The relative path resolves the same locally (posts/<base>/playground/) and on
 * the deployed host (public/posts/<base>/playground/), because build-site.js
 * mirrors this file to public/playground/assets/base.css. For a CodeSandbox
 * --embed, playground.js inlines this file so the single-file sandbox still styles.
 *
 * Then write ONLY the demo-specific CSS in your inline <style>. Everything below
 * — tokens, layout, panels, buttons, toggles, sliders, code blocks, status/log,
 * banners, presets — comes for free and looks consistent across every post.
 *
 * Theme-aware: dark by default, light via prefers-color-scheme AND a
 * [data-theme] override on <html> (so a toggle can force either). Accessible:
 * real focus rings, adequate contrast, reduced-motion honored.
 */

/* ---------- design tokens ---------- */
:root {
  --bg: #0d1117;
  --bg-grid: #ffffff0a;
  --panel: #161b22;
  --panel-2: #0b0e14;
  --card: #0b0e14;
  --ink: #e8ebf2;
  --muted: #9aa4b2;
  --faint: #6b7688;
  --line: #232a35;
  --line-soft: #ffffff12;
  --accent: #7c9cff;
  --accent-ink: #0b0e14;
  --good: #3fb950;
  --warn: #f0883e;
  --bad: #f85149;
  --info: #58a6ff;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 30px #0006;
  --shadow-sm: 0 4px 14px #0005;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: dark;
}

/* Light theme — system preference, overridable by [data-theme] on <html>. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f6fb;
    --bg-grid: #00000008;
    --panel: #ffffff;
    --panel-2: #f0f3f9;
    --card: #f7f9fc;
    --ink: #131722;
    --muted: #5b6472;
    --faint: #8a93a3;
    --line: #e2e7f0;
    --line-soft: #00000010;
    --accent: #2f6df0;
    --accent-ink: #ffffff;
    --good: #1a7f37;
    --warn: #bc4c00;
    --bad: #cf222e;
    --info: #0969da;
    --shadow: 0 8px 30px #0000001f;
    --shadow-sm: 0 4px 14px #00000014;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-grid: #00000008;
  --panel: #ffffff;
  --panel-2: #f0f3f9;
  --card: #f7f9fc;
  --ink: #131722;
  --muted: #5b6472;
  --faint: #8a93a3;
  --line: #e2e7f0;
  --line-soft: #00000010;
  --accent: #2f6df0;
  --accent-ink: #ffffff;
  --good: #1a7f37;
  --warn: #bc4c00;
  --bad: #cf222e;
  --info: #0969da;
  --shadow: 0 8px 30px #0000001f;
  --shadow-sm: 0 4px 14px #00000014;
  color-scheme: light;
}

/* ---------- reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(circle at 1px 1px, var(--bg-grid) 1px, transparent 0) 0 0 / 24px 24px,
    var(--bg);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: clamp(14px, 3vw, 26px);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* The single content column. */
.pg {
  width: 100%;
  max-width: 860px;
}

/* ---------- header ---------- */
.pg-title {
  font-size: clamp(1.15rem, 1rem + 1vw, 1.4rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.pg-sub {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 0 0 16px;
  max-width: 66ch;
}
.pg-sub strong, .pg-sub b { color: var(--ink); font-weight: 700; }
.pg-sub code { font-family: var(--mono); background: var(--line-soft); color: var(--accent);
  padding: 1px 6px; border-radius: 6px; font-size: 0.85em; }

/* ---------- panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.panel-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 800;
  margin: 0 0 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-label .n {
  display: inline-grid; place-items: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  font-size: 0.66rem; font-weight: 800;
}

/* ---------- layout helpers ---------- */
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.row.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 10px; }
.grow { flex: 1 1 0; min-width: 0; }
.wrap-controls { display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field > .label, .ctl-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 800;
}

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 650; font-size: 0.88rem;
  cursor: pointer; user-select: none;
  border: 1px solid var(--line);
  background: var(--card); color: var(--ink);
  padding: 9px 15px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; gap: 8px;
  transition: background .15s ease, border-color .15s ease, transform .05s ease, color .15s ease;
}
.btn:hover { background: var(--line-soft); border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.good { background: var(--good); border-color: var(--good); color: #04140a; }
.btn.bad  { background: var(--bad);  border-color: var(--bad);  color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 11px; font-size: 0.82rem; }

.btn-row { display: flex; flex-wrap: wrap; gap: 9px; }

/* Segmented control — a row of buttons where one is active (aria-pressed). */
.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 3px; gap: 3px; }
.seg button {
  font: inherit; font-weight: 650; font-size: 0.84rem; cursor: pointer;
  border: none; background: transparent; color: var(--muted);
  padding: 7px 13px; border-radius: 7px;
  transition: background .15s ease, color .15s ease;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Preset chips — worked-example shortcuts. */
.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.presets .btn { background: var(--panel-2); }

/* ---------- toggle switch ---------- */
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer;
  font-size: 0.88rem; font-weight: 600; user-select: none; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch { position: relative; width: 44px; height: 25px; border-radius: 999px; flex: none;
  background: var(--line); border: 1px solid var(--line); transition: background .18s ease; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 19px; height: 19px;
  border-radius: 50%; background: #cfd6e4; transition: transform .18s ease; box-shadow: 0 1px 3px #0006; }
.toggle input:checked + .switch { background: var(--good); border-color: var(--good); }
.toggle input:checked + .switch::after { transform: translateX(19px); background: #fff; }
.toggle input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- range slider ---------- */
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px;
  background: var(--line); border-radius: 999px; outline: none; cursor: pointer; margin: 8px 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 19px; height: 19px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--panel); box-shadow: var(--shadow-sm); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 19px; height: 19px; border-radius: 50%; background: var(--accent);
  border: 2px solid var(--panel); box-shadow: var(--shadow-sm); cursor: pointer;
}
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- text inputs / selects ---------- */
input[type="text"], input[type="number"], input[type="search"], select, textarea {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 11px; width: 100%;
}
textarea { font-family: var(--mono); font-size: 0.85rem; line-height: 1.6; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}

/* ---------- status / output / log ---------- */
.status {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  font-size: 0.9rem; font-weight: 600;
  padding: 11px 14px; border-radius: var(--radius-sm);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink);
}
.status.good { border-color: color-mix(in srgb, var(--good) 55%, var(--line)); }
.status.warn { border-color: color-mix(in srgb, var(--warn) 55%, var(--line)); }
.status.bad  { border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.good { background: var(--good); } .dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); } .dot.info { background: var(--info); }

.output { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 13px 15px; }
.log { font-family: var(--mono); font-size: 0.8rem; line-height: 1.7; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 14px;
  max-height: 220px; overflow-y: auto; white-space: pre-wrap; }

/* ---------- code block + syntax tokens ---------- */
.code {
  font-family: var(--mono); font-size: 0.82rem; line-height: 1.7;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 13px 15px; overflow-x: auto; white-space: pre; tab-size: 2;
}
.code .tok-sel  { color: var(--accent); }
.code .tok-prop { color: #86e29b; }
.code .tok-kw   { color: #ff9bcb; }
.code .tok-str  { color: #f0c674; }
.code .tok-num  { color: #f0883e; }
.code .tok-cmt  { color: var(--faint); font-style: italic; }
.code .hl { background: color-mix(in srgb, var(--good) 22%, transparent); border-radius: 4px; padding: 0 3px; }

/* ---------- hint / caption ---------- */
.hint { font-size: 0.83rem; color: var(--muted); line-height: 1.55; margin: 10px 0 0; }
.hint code { font-family: var(--mono); color: var(--ink); background: var(--line-soft);
  padding: 1px 5px; border-radius: 5px; font-size: 0.86em; }
.hint strong { color: var(--ink); }

/* ---------- banner (feature-support / notices) ---------- */
.banner {
  display: none; margin-bottom: 14px; padding: 11px 14px; border-radius: 11px;
  font-size: 0.85rem; line-height: 1.5;
  color: var(--ink); background: color-mix(in srgb, var(--warn) 12%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--line));
}
.banner.show { display: block; }
.banner.info { background: color-mix(in srgb, var(--info) 12%, var(--panel));
  border-color: color-mix(in srgb, var(--info) 45%, var(--line)); }
.banner code { font-family: var(--mono); background: var(--line-soft); padding: 1px 5px; border-radius: 5px; }

/* ---------- misc atoms ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 0.75rem; font-weight: 700;
  padding: 3px 9px; border-radius: 999px; background: var(--line-soft); color: var(--muted); }
.pill.good { color: var(--good); background: color-mix(in srgb, var(--good) 16%, transparent); }
.pill.bad  { color: var(--bad);  background: color-mix(in srgb, var(--bad) 16%, transparent); }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.big-num { font-family: var(--mono); font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em; }

/* Optional theme toggle button (top-right). Wire it in JS if you want it. */
.theme-btn { position: fixed; top: 12px; right: 12px; z-index: 20; }

/* ---------- responsive ---------- */
@media (max-width: 560px) {
  .panel { padding: 14px; }
  .wrap-controls { gap: 14px; }
  .btn { padding: 9px 13px; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
