/* ============================================================
   Muse Playbook — design tokens
   ============================================================ */
:root {
  --font-sans: ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 22px;

  --wrap: 1180px;
  --header-h: 64px;

  --ease: cubic-bezier(.22, .61, .36, 1);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0d12;
  --bg-soft: #0f1219;
  --surface: #141821;
  --surface-2: #1a1f2b;
  --surface-3: #232936;
  --line: #262d3b;
  --line-soft: #1e242f;
  --text: #e8ebf2;
  --text-dim: #9aa3b5;
  --text-faint: #6b7488;
  --accent: #8b7cf6;
  --accent-soft: rgba(139, 124, 246, .14);
  --accent-line: rgba(139, 124, 246, .38);
  --accent-ink: #ffffff;
  --good: #4ade9b;
  --warn: #f4b860;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 12px 32px -12px rgba(0,0,0,.7);
  --glow: radial-gradient(60% 60% at 50% 0%, rgba(139,124,246,.18), transparent 70%);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f7fa;
  --bg-soft: #ffffff;
  --surface: #ffffff;
  --surface-2: #f3f3f8;
  --surface-3: #ebebf2;
  --line: #e2e3ec;
  --line-soft: #ececf3;
  --text: #14161c;
  --text-dim: #565d6e;
  --text-faint: #868da0;
  --accent: #6b5ce0;
  --accent-soft: rgba(107, 92, 224, .09);
  --accent-line: rgba(107, 92, 224, .3);
  --accent-ink: #ffffff;
  --good: #17945f;
  --warn: #a86608;
  --shadow: 0 1px 2px rgba(16,20,40,.05), 0 10px 28px -14px rgba(16,20,40,.22);
  --glow: radial-gradient(60% 60% at 50% 0%, rgba(107,92,224,.10), transparent 70%);
}

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

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 18px); }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { line-height: 1.2; letter-spacing: -.018em; margin: 0; font-weight: 650; }
p { margin: 0; }
a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

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

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ============================================================
   Top bar
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  display: flex; align-items: center; gap: 18px;
  padding: 0 clamp(14px, 3vw, 30px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  display: inline-flex; align-items: center; gap: 9px;
  text-decoration: none; font-weight: 700; letter-spacing: -.02em;
  white-space: nowrap;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #1b1640));
  color: var(--accent-ink); font-size: 14px; font-weight: 800;
  box-shadow: 0 4px 14px -4px color-mix(in srgb, var(--accent) 70%, transparent);
}
.brand-text { font-size: 15px; }

.search-wrap {
  position: relative; flex: 1 1 320px; max-width: 520px; margin: 0 auto;
  display: flex; align-items: center;
}
.search-icon {
  position: absolute; left: 12px; width: 16px; height: 16px;
  color: var(--text-faint); pointer-events: none;
}
#search {
  width: 100%; height: 40px;
  padding: 0 38px 0 36px;
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: border-color .15s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease);
  -webkit-appearance: none; appearance: none;
}
#search::-webkit-search-cancel-button { display: none; }
#search::placeholder { color: var(--text-faint); }
#search:focus {
  outline: none;
  border-color: var(--accent-line);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-clear {
  position: absolute; right: 6px; width: 26px; height: 26px; font-size: 17px; line-height: 1;
}

.topnav { display: flex; gap: 4px; }
.topnav a {
  padding: 7px 11px; border-radius: 8px;
  font-size: 13.5px; color: var(--text-dim); text-decoration: none;
  transition: color .15s var(--ease), background .15s var(--ease);
}
.topnav a:hover { color: var(--text); background: var(--surface-2); }

.topbar-actions { display: flex; gap: 6px; }

.icon-btn {
  width: 34px; height: 34px; padding: 0;
  display: inline-grid; place-items: center;
  color: var(--text-dim); background: transparent;
  border: 1px solid transparent; border-radius: 9px;
  cursor: pointer; transition: all .15s var(--ease);
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); border-color: var(--line); }
.lang-btn { font-size: 13px; font-weight: 600; font-family: var(--font-sans); }

html[data-theme="dark"] .i-moon { display: none; }
html[data-theme="light"] .i-sun { display: none; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 38px; padding: 0 14px;
  font: inherit; font-size: 13.5px; font-weight: 560;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: all .15s var(--ease);
}
.btn:hover { background: var(--surface-3); border-color: var(--text-faint); }
.btn svg { width: 15px; height: 15px; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }

.btn-primary {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: transparent;
  box-shadow: 0 6px 20px -8px color-mix(in srgb, var(--accent) 80%, transparent);
}
.btn-primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, white);
  border-color: transparent;
}

.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-ghost[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.count-pill {
  min-width: 18px; height: 18px; padding: 0 5px;
  display: inline-grid; place-items: center;
  font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--surface-3); color: var(--text-dim);
  border-radius: 999px;
}
.btn-ghost[aria-pressed="true"] .count-pill { background: var(--accent); color: var(--accent-ink); }

.link-btn {
  font: inherit; font-size: 13px; color: var(--accent);
  background: none; border: 0; padding: 0; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
}

/* ============================================================
   Hero
   ============================================================ */
.hero { position: relative; overflow: hidden; border-bottom: 1px solid var(--line-soft); }
.hero::before {
  content: ""; position: absolute; inset: 0;
  background: var(--glow); pointer-events: none;
}
.hero-inner {
  position: relative;
  max-width: var(--wrap); margin: 0 auto;
  padding: clamp(44px, 7vw, 86px) clamp(18px, 4vw, 32px) clamp(40px, 5vw, 60px);
}

.eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 650; letter-spacing: .1em; text-transform: uppercase;
  color: var(--accent);
}
.eyebrow::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft);
}

.hero h1 {
  margin: 16px 0 0;
  font-size: clamp(34px, 6vw, 62px);
  font-weight: 720;
  letter-spacing: -.035em;
  background: linear-gradient(170deg, var(--text) 30%, color-mix(in srgb, var(--text) 55%, var(--accent)));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  max-width: 18ch;
}

.lede {
  margin-top: 16px; max-width: 62ch;
  font-size: clamp(15px, 1.7vw, 18px); color: var(--text-dim);
}

.stats { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 26px; }
.stat {
  padding: 8px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 13px; color: var(--text-dim);
}
.stat b { color: var(--text); font-variant-numeric: tabular-nums; }

/* master prompt card */
.master {
  margin-top: 34px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.master-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.master-head h2 { font-size: 15px; font-weight: 650; }
.master-head p { margin-top: 3px; font-size: 13px; color: var(--text-faint); }
.master-body {
  margin: 0; padding: 18px 20px 20px;
  font-family: var(--font-mono); font-size: 12.8px; line-height: 1.75;
  color: var(--text-dim);
  white-space: pre-wrap; word-break: break-word;
  max-height: 260px; overflow: auto;
}

/* ============================================================
   Sections
   ============================================================ */
.section {
  max-width: var(--wrap); margin: 0 auto;
  padding: clamp(44px, 6vw, 72px) clamp(18px, 4vw, 32px) 0;
}
.section-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  flex-wrap: wrap; gap: 14px;
  margin-bottom: 18px;
}
.section-head h2 { font-size: clamp(22px, 3vw, 30px); letter-spacing: -.025em; }
.section-sub { margin-top: 6px; max-width: 66ch; font-size: 14px; color: var(--text-dim); }
.section-tools { display: flex; flex-wrap: wrap; gap: 8px; }

.select-wrap { position: relative; display: inline-flex; }
#sort {
  height: 38px; padding: 0 30px 0 12px;
  font: inherit; font-size: 13.5px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}
.select-wrap::after {
  content: ""; position: absolute; right: 12px; top: 50%;
  width: 6px; height: 6px; margin-top: -4px;
  border-right: 1.6px solid var(--text-dim); border-bottom: 1.6px solid var(--text-dim);
  transform: rotate(45deg); pointer-events: none;
}

/* category chips */
.chips {
  display: flex; gap: 7px; flex-wrap: wrap;
  padding-bottom: 4px;
}
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  height: 33px; padding: 0 12px;
  font: inherit; font-size: 13px; font-weight: 540; color: var(--text-dim);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; cursor: pointer;
  transition: all .15s var(--ease);
}
.chip:hover { color: var(--text); border-color: var(--text-faint); }
.chip[aria-pressed="true"] {
  color: var(--accent-ink); background: var(--accent); border-color: transparent;
}
.chip .n { font-size: 11.5px; font-variant-numeric: tabular-nums; opacity: .65; }
.chip[aria-pressed="true"] .n { opacity: .8; }

.results-line {
  display: flex; align-items: center; gap: 12px;
  margin: 16px 0 14px;
  font-size: 13px; color: var(--text-faint);
}

/* ============================================================
   Cards
   ============================================================ */
.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
}

.card {
  position: relative;
  display: flex; flex-direction: column;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left; font: inherit; color: inherit;
  transition: transform .18s var(--ease), border-color .18s var(--ease), box-shadow .18s var(--ease);
  animation: rise .32s var(--ease) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
.card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-line);
  box-shadow: var(--shadow);
}
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.card-top {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px;
}
.badge {
  display: inline-flex; align-items: center;
  height: 21px; padding: 0 8px;
  font-size: 11px; font-weight: 650; letter-spacing: .02em;
  color: var(--accent); background: var(--accent-soft);
  border-radius: 6px;
}
.card-star {
  margin-left: auto;
  width: 28px; height: 28px; padding: 0;
  display: grid; place-items: center;
  color: var(--text-faint); background: transparent;
  border: 0; border-radius: 7px; cursor: pointer;
  transition: all .15s var(--ease);
}
.card-star:hover { color: var(--warn); background: var(--surface-2); }
.card-star svg { width: 15px; height: 15px; }
.card-star[aria-pressed="true"] { color: var(--warn); }
.card-star[aria-pressed="true"] svg { fill: currentColor; }

.card h3 {
  font-size: 15px; font-weight: 620; letter-spacing: -.012em;
  margin-bottom: 7px;
}
.card .story {
  font-size: 13px; line-height: 1.6; color: var(--text-dim);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .card-foot {
  display: flex; align-items: center; gap: 8px;
  margin-top: auto; padding-top: 14px;
  font-size: 12px; color: var(--text-faint);
}
.card .handle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .copy-hint {
  margin-left: auto; display: inline-flex; align-items: center; gap: 5px;
  color: var(--accent); font-weight: 560; opacity: 0; transform: translateX(-3px);
  transition: all .18s var(--ease);
}
.card:hover .copy-hint, .card:focus-visible .copy-hint { opacity: 1; transform: none; }
.card .copy-hint svg { width: 13px; height: 13px; }

.sentinel { height: 1px; }
.empty { padding: 56px 0; text-align: center; color: var(--text-dim); }
.empty p { margin-bottom: 14px; font-size: 15px; }

/* ============================================================
   Patterns / guardrails
   ============================================================ */
.pattern-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.pattern {
  padding: 18px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius);
}
.pattern .idx {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  color: var(--accent); letter-spacing: .06em;
}
.pattern h3 { font-size: 14.5px; font-weight: 620; margin: 8px 0 6px; }
.pattern p { font-size: 13px; color: var(--text-dim); line-height: 1.6; }

.guard-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.guard {
  display: grid; grid-template-columns: auto 1fr; gap: 14px;
  padding: 16px 18px;
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius);
}
.guard .gnum {
  font-family: var(--font-mono); font-size: 12px; font-weight: 700;
  color: var(--warn); line-height: 1.9;
}
.guard h3 { font-size: 14px; font-weight: 640; margin-bottom: 4px; }
.guard p { font-size: 13px; color: var(--text-dim); }

/* ============================================================
   Footer
   ============================================================ */
.footer {
  margin-top: clamp(56px, 8vw, 96px);
  border-top: 1px solid var(--line-soft);
  background: var(--bg-soft);
}
.footer-inner {
  max-width: var(--wrap); margin: 0 auto;
  padding: 30px clamp(18px, 4vw, 32px) 46px;
  font-size: 13px; color: var(--text-faint);
}
.footer-inner p + p { margin-top: 8px; }
.footer-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.footer a { color: var(--text-dim); text-decoration: none; border-bottom: 1px solid var(--line); }
.footer a:hover { color: var(--accent); border-color: var(--accent-line); }

/* ============================================================
   Modal
   ============================================================ */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; }
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(4, 6, 12, .62);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  animation: fade .18s var(--ease);
}
@keyframes fade { from { opacity: 0; } }
.modal-card {
  position: relative; width: min(720px, 100%); max-height: min(86vh, 900px);
  overflow: auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 40px 90px -30px rgba(0,0,0,.75);
  animation: pop .22s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.985); } }
.modal-close { position: absolute; top: 12px; right: 12px; font-size: 20px; z-index: 2; }
.modal-body { padding: clamp(22px, 4vw, 34px); }
.modal-body h2 { font-size: clamp(20px, 2.6vw, 26px); letter-spacing: -.025em; margin: 12px 0 10px; }
.modal-story { font-size: 14.5px; color: var(--text-dim); margin-bottom: 20px; }

.prompt-block {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-soft); overflow: hidden;
}
.prompt-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px 10px 16px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-faint);
}
#modal-prompt {
  margin: 0; padding: 16px;
  font-family: var(--font-mono); font-size: 13px; line-height: 1.72;
  white-space: pre-wrap; word-break: break-word; color: var(--text);
}

.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 200;
  transform: translate(-50%, 16px);
  padding: 10px 16px;
  font-size: 13.5px; font-weight: 550; color: var(--accent-ink);
  background: var(--accent);
  border-radius: 999px;
  box-shadow: 0 14px 34px -10px color-mix(in srgb, var(--accent) 70%, transparent);
  opacity: 0; pointer-events: none;
  transition: opacity .2s var(--ease), transform .2s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 860px) {
  .topnav { display: none; }
  .brand-text { display: none; }
  .search-wrap { max-width: none; }
}

@media (max-width: 640px) {
  :root { --header-h: 58px; }
  .grid { grid-template-columns: 1fr; }
  .master-head { flex-direction: column; align-items: stretch; }
  .master-head .btn { justify-content: center; }
  .section-tools { width: 100%; }
  .section-tools .btn, .select-wrap { flex: 1 1 auto; }
  .select-wrap #sort { width: 100%; }
  .modal-actions .btn { flex: 1 1 auto; justify-content: center; }
  .card .copy-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
}
