:root {
  --bg: #040704;
  --bg-2: #0a120a;
  --card: rgba(12, 22, 12, 0.82);
  --card-hover: rgba(18, 32, 18, 0.92);
  --border: rgba(45, 255, 106, 0.16);
  --border-strong: rgba(45, 255, 106, 0.45);
  --text: #e8f2e8;
  --muted: #9db39f;
  --matrix: #2dff6a;
  --btn: #72ff5c;
  --btn-text: #041004;
  --ph: #e6ff4d;
  --ph-filled: #72ff5c;
  --radius: 14px;
  --font: "IBM Plex Sans", Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}
body.no-scroll { overflow: hidden; }

#matrix {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.18;
}

.wrap { width: 100%; max-width: 1160px; margin: 0 auto; padding: 0 16px; position: relative; z-index: 1; }
main.wrap { flex: 1; padding-bottom: 48px; }

a { color: var(--matrix); }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--matrix); outline-offset: 2px; }

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 10;
  background: rgba(4, 7, 4, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-size: 17px; }
.brand-mark { color: var(--matrix); font-family: "IBM Plex Mono", Consolas, monospace; font-weight: 700; }
.brand strong { color: var(--matrix); font-weight: 600; }
.header-link { font-size: 14px; color: var(--muted); text-decoration: none; border: 1px solid var(--border); padding: 6px 12px; border-radius: 999px; }
.header-link:hover { color: var(--matrix); border-color: var(--border-strong); }

/* Hero */
.hero { padding: 48px 0 24px; max-width: 780px; }
.hero h1 { font-size: clamp(28px, 5vw, 46px); line-height: 1.15; margin: 0 0 14px; font-weight: 700; letter-spacing: -0.01em; }
.accent { color: var(--matrix); text-shadow: 0 0 24px rgba(45, 255, 106, 0.35); }
.lead { color: var(--muted); font-size: clamp(16px, 2.2vw, 18px); margin: 0; }

/* Toolbar */
.toolbar {
  position: sticky; top: 60px; z-index: 5;
  padding: 14px 0;
  background: linear-gradient(var(--bg) 75%, rgba(4, 7, 4, 0));
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
}
.search { position: relative; flex: 1 1 320px; min-width: 0; }
.search input {
  width: 100%;
  height: 48px;
  padding: 0 44px 0 44px;
  font: inherit; font-size: 16px;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  -webkit-appearance: none; appearance: none;
}
.search input::placeholder { color: #6f866f; }
.search input:focus { outline: none; border-color: var(--matrix); box-shadow: 0 0 0 3px rgba(45, 255, 106, 0.18); }
.search input::-webkit-search-cancel-button { display: none; }
.search-icon { position: absolute; left: 14px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); fill: none; stroke: var(--matrix); stroke-width: 2; stroke-linecap: round; }
.search-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border: 0; background: none; color: var(--muted); font-size: 24px; cursor: pointer; border-radius: 8px; }
.search-clear:hover { color: var(--text); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  height: 40px; padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--muted);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip[aria-pressed="true"] { background: rgba(45, 255, 106, 0.12); color: var(--matrix); border-color: var(--matrix); }
.fav-count { font-size: 12px; background: rgba(45, 255, 106, 0.15); padding: 1px 7px; border-radius: 999px; }

/* Views */
.view-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; margin: 12px 0 16px; }
.view-head h2 { margin: 0; font-size: 22px; }
.result-count { color: var(--muted); font-size: 14px; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; font-size: 14px; margin: 8px 0 4px; }
.back:hover { color: var(--matrix); }

.domain-head { margin: 4px 0 20px; max-width: 820px; }
.domain-head h2 { font-size: clamp(24px, 4vw, 34px); margin: 4px 0 8px; }
.domain-head p { color: var(--muted); margin: 0; }
.domain-num { font-family: "IBM Plex Mono", Consolas, monospace; color: var(--matrix); font-size: 13px; letter-spacing: 0.08em; }

/* Domain cards */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.domain-card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text); text-decoration: none;
  transition: border-color .15s, background .15s, transform .15s;
}
.domain-card:hover { border-color: var(--border-strong); background: var(--card-hover); transform: translateY(-2px); }
.domain-card h3 { margin: 0; font-size: 18px; }
.domain-card p { margin: 0; color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.domain-card .meta { margin-top: auto; padding-top: 6px; font-size: 13px; color: var(--matrix); }

/* Prompt cards */
.prompt-list { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.prompt-card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .15s, background .15s;
  min-width: 0;
}
.prompt-card:hover { border-color: var(--border-strong); background: var(--card-hover); }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag { font-size: 12px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.tag-beginner { color: #9dffb6; border-color: rgba(45, 255, 106, 0.35); }
.tag-advanced { color: var(--ph); border-color: rgba(230, 255, 77, 0.4); }
.tag-domain { text-decoration: none; }
.tag-domain:hover { color: var(--matrix); }
.prompt-card h3 { margin: 0; font-size: 17px; line-height: 1.35; }
.prompt-card h3 button { all: unset; cursor: pointer; }
.prompt-card h3 button:hover { color: var(--matrix); }
.prompt-card h3 button:focus-visible { outline: 2px solid var(--matrix); outline-offset: 2px; }
.prompt-card .what { margin: 0; color: var(--muted); font-size: 14.5px; }
.prompt-card .snippet {
  margin: 0; font-size: 13.5px; color: #c7d6c7;
  background: rgba(0, 0, 0, 0.35);
  border-left: 2px solid var(--border-strong);
  padding: 8px 10px; border-radius: 6px;
}
.prompt-card .snippet span.clamp {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere; line-height: 1.55;
}
.prompt-card .snippet .ph { padding: 0; }
.card-actions { margin-top: auto; display: flex; gap: 8px; flex-wrap: wrap; padding-top: 4px; }

.star {
  flex: none;
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: #4d5f4d;
  font-size: 20px; line-height: 1;
  cursor: pointer;
  transition: color .15s, border-color .15s, transform .1s;
}
.star:hover { color: var(--ph); border-color: var(--border-strong); }
.star[aria-pressed="true"] { color: var(--ph); border-color: rgba(230, 255, 77, 0.5); text-shadow: 0 0 10px rgba(230, 255, 77, 0.5); }
.star:active { transform: scale(0.92); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 42px; padding: 0 18px;
  border-radius: 10px;
  font-size: 15px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  border: 1px solid transparent;
  transition: filter .15s, background .15s, border-color .15s;
}
.btn-primary { background: var(--btn); color: var(--btn-text); }
.btn-primary:hover { filter: brightness(1.08); box-shadow: 0 0 18px rgba(114, 255, 92, 0.35); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { border-color: var(--matrix); color: var(--matrix); }
.btn.copied { background: #1d5e2b; color: #eaffea; }
.link-btn { background: none; border: 0; color: var(--muted); font-size: 14px; cursor: pointer; padding: 6px 0; text-decoration: underline; }
.link-btn:hover { color: var(--matrix); }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border); background: transparent; color: var(--text); font-size: 26px; line-height: 1; cursor: pointer; }
.icon-btn:hover { border-color: var(--matrix); color: var(--matrix); }

/* Placeholders */
.ph { color: var(--ph); background: rgba(230, 255, 77, 0.1); border-radius: 4px; padding: 0 2px; font-weight: 500; }
.ph-filled { color: var(--ph-filled); background: rgba(114, 255, 92, 0.12); }

/* Empty / CTA */
.empty { text-align: center; padding: 48px 16px; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty strong { color: var(--text); display: block; font-size: 18px; margin-bottom: 6px; }

.mastery-cta {
  margin-top: 28px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(120deg, rgba(45, 255, 106, 0.07), rgba(4, 7, 4, 0.6));
}
.mastery-cta p { margin: 0; color: var(--muted); font-size: 15px; flex: 1 1 280px; }
.mastery-cta strong { color: var(--text); }
.nudge { margin: 0 0 14px; position: relative; padding-right: 52px; }
.nudge .icon-btn { position: absolute; top: 10px; right: 10px; width: 32px; height: 32px; font-size: 20px; }
.nudge.mastery-cta { margin-top: 0; }

/* Builder */
.builder { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 24px; }
.builder[hidden] { display: none; }
.builder-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.72); }
.builder-panel {
  position: relative;
  width: 100%; max-width: 1040px; max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
  background: #071007;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.6), 0 0 40px rgba(45, 255, 106, 0.08);
  overflow: hidden;
}
.builder-head { display: flex; justify-content: space-between; gap: 16px; padding: 20px 22px 14px; border-bottom: 1px solid var(--border); }
.builder-head h2 { margin: 4px 0 4px; font-size: 21px; line-height: 1.3; }
.builder-meta { margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.builder-what { margin: 0; color: var(--muted); font-size: 14.5px; }
.builder-head-actions { display: flex; gap: 8px; align-items: flex-start; }
.builder-head-actions .star { width: 40px; height: 40px; }
.builder-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); overflow: hidden; flex: 1; min-height: 0; }
.builder-form, .builder-preview { padding: 18px 22px; overflow-y: auto; min-height: 0; }
.builder-form { border-right: 1px solid var(--border); }
.builder-body h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--matrix); font-weight: 600; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 14px; margin-bottom: 6px; color: var(--text); }
.field label .hint { color: var(--muted); }
.field input, .field textarea {
  width: 100%;
  font: inherit; font-size: 16px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.field textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--matrix); box-shadow: 0 0 0 3px rgba(45, 255, 106, 0.15); }
.no-fields { color: var(--muted); font-size: 14.5px; margin: 0; }
.preview-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.progress { font-size: 13px; color: var(--muted); }
.prompt-text {
  white-space: pre-wrap; overflow-wrap: anywhere;
  font-size: 15px; line-height: 1.65;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.builder-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); background: #061006; }
.builder-foot .btn { min-width: 160px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60;
  transform: translate(-50%, 20px);
  background: var(--btn); color: var(--btn-text);
  padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #ff6b6b; color: #1a0000; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); padding: 20px 0; color: var(--muted); font-size: 14px; position: relative; z-index: 1; background: rgba(4, 7, 4, 0.85); }
.site-footer p { margin: 0; }

/* Loading / error */
.loading { color: var(--muted); padding: 40px 0; text-align: center; }
.load-error { border: 1px solid rgba(255, 107, 107, 0.4); background: rgba(40, 8, 8, 0.6); border-radius: var(--radius); padding: 20px; }
.load-error h2 { margin-top: 0; font-size: 20px; }
.load-error code { background: rgba(0, 0, 0, 0.5); padding: 2px 6px; border-radius: 4px; color: var(--matrix); }
.load-error pre { background: rgba(0, 0, 0, 0.5); padding: 10px 12px; border-radius: 8px; overflow-x: auto; color: var(--matrix); }

/* Mobile */
@media (max-width: 760px) {
  .hero { padding: 28px 0 12px; }
  .toolbar { position: static; padding: 10px 0 14px; background: none; }
  .header-inner { height: 56px; }
  .prompt-list { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .domain-card { padding: 14px; }
  .domain-card h3 { font-size: 16px; }
  .domain-card p { display: none; }
  .filters { width: 100%; gap: 6px; }
  .chip { height: 36px; padding: 0 12px; font-size: 13.5px; }

  .builder { padding: 0; align-items: stretch; }
  .builder-panel { max-width: none; max-height: none; height: 100%; border-radius: 0; border: 0; }
  .builder-head { padding: 14px 16px 12px; }
  .builder-head h2 { font-size: 18px; }
  .builder-body { display: block; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .builder-form, .builder-preview { overflow: visible; padding: 16px; }
  .builder-form { border-right: 0; border-bottom: 1px solid var(--border); }
  .builder-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .builder-foot .btn { width: 100%; }
}
@media (max-width: 360px) {
  .grid { grid-template-columns: 1fr; }
}

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