/* ==========================================================================
   KP Stellar Astro — shared components
   Depends on static/theme.css (must be linked first). Every value here comes
   from a theme.css token; there is no raw hex in this file except third-party
   brand marks, which are commented /* raw: reason */.
   ========================================================================== */

/* ---- reset / base ---------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; overflow-x: hidden; max-width: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img { max-width: 100%; }
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--r-sm);
}
/* The ONE page container (home-theme plan, owner 2026-10-01: one width on every page).
   Matches docs/mockups/kp_home_theme/theme.css: .wrap { max-width: 1180px; margin: 0 auto; padding-inline: 16px }.
   Pages that still define their own local .wrap keep it until their unit re-wires them.
   box-sizing is set on .wrap itself because this file's own universal reset never applies: the stray
   raw-colour note in the header comment closes that comment early and swallows the reset rule.
   Fixing that globally is a separate, layout-affecting change. */
.wrap { box-sizing: border-box; max-width: var(--page-max); margin: 0 auto; padding-inline: 16px; }

/* ---- buttons ---------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: var(--ctl-h, 36px);
  padding-inline: var(--s-5);
  border-radius: var(--r-md);
  font-weight: 700; font-size: var(--fs-sm);
  cursor: pointer; text-decoration: none;
  border: 1px solid transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-1); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--card); color: var(--primary); border-color: var(--line-strong); }
.btn-ghost:hover { border-color: var(--primary); background: var(--primary-soft); }
.btn-subtle { background: var(--primary-soft); color: var(--primary); }
.btn-subtle:hover { background: var(--line); }
.btn-danger { background: var(--danger); color: var(--on-status); }
.btn-danger:hover { filter: brightness(.92); }
.btn-sm { height: 28px; padding-inline: var(--s-3); font-size: var(--fs-xs); border-radius: var(--r-sm); }
.btn-lg { height: 44px; padding-inline: var(--s-6); font-size: var(--fs-md); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; color: var(--on-primary);
  animation: kp-spin .7s linear infinite;
}
.btn-ghost.is-loading::after, .btn-subtle.is-loading::after { color: var(--primary); }
@keyframes kp-spin { to { transform: rotate(360deg); } }

/* ---- card / panel ------------------------------------------------------ */
.card, .panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}
.card-head { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line); }

/* ---- header / nav ------------------------------------------------------- */
header.site-header, header.kp-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--card) 90%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.nav { display: flex; align-items: center; gap: var(--s-4); max-width: 1180px; margin: 0 auto; padding: var(--s-4) var(--s-5); }
.nav .brand { display: flex; align-items: center; gap: var(--s-3); text-decoration: none; }
.nav .brand img { width: 34px; height: 34px; }
.nav .brand b { font-size: 1.05rem; color: var(--heading); letter-spacing: -.01em; }
.nav .spacer { flex: 1; }
.nav .navlinks { display: flex; gap: var(--s-6); font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); margin-right: var(--s-2); }
.nav .navlinks a { text-decoration: none; }
.nav .navlinks a:hover, .nav .navlinks a.active { color: var(--primary); }
@media (max-width: 760px) { .nav .navlinks { display: none; } }

/* ---- footer -------------------------------------------------------------- */
footer.site-footer { border-top: 1px solid var(--line); color: var(--text-muted); font-size: var(--fs-sm); padding: var(--s-6) var(--s-5); }
footer.site-footer a { color: var(--text-muted); text-decoration: none; }
footer.site-footer a:hover { color: var(--primary); }

/* ---- form controls ------------------------------------------------------- */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  height: var(--ctl-h, 36px); padding-inline: var(--s-3);
}
textarea { height: auto; padding-block: var(--s-2); }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: var(--focus-ring); outline: none; }
input.is-error, select.is-error, textarea.is-error { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: var(--fs-xs); margin-top: var(--s-1); }
label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); }

input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--primary); }

.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; background: var(--line-strong); border-radius: var(--r-pill);
  transition: background var(--dur) var(--ease);
}
.switch .track::before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px;
  background: #fff; border-radius: 50%; transition: transform var(--dur) var(--ease);
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::before { transform: translateX(18px); }

/* ---- pill / chip / verdict ------------------------------------------------ */
.pill, .chip {
  display: inline-flex; align-items: center; gap: var(--s-1);
  padding: 2px var(--s-3); border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .02em;
  background: var(--primary-soft); color: var(--on-soft-primary);
}
.pill.favour, .chip.favour, .verdict-favour { background: var(--favour-soft); color: var(--favour); }
.pill.against, .chip.against, .verdict-against { background: var(--against-soft); color: var(--against); }
.pill.neutral, .chip.neutral, .verdict-neutral { background: var(--neutral-soft); color: var(--neutral); }

/* ---- badges --------------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; padding: 1px var(--s-2); border-radius: var(--r-sm); font-size: var(--fs-xs); font-weight: 700; background: var(--gold); color: var(--gold-ink); }
.badge-admin { background: var(--primary); color:var(--on-primary); }

/* ---- tables --------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table th { text-align: left; font-size: var(--fs-xs); letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); padding: var(--s-2) var(--s-3); }
table td { padding: var(--s-2) var(--s-3); border-top: 1px solid var(--line); }

/* ---- tabs (kptabs) --------------------------------------------------------- */
.kptabs, .tabs { display: flex; gap: var(--s-2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.kptabs button, .tabs button {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: var(--s-3) var(--s-4); font-weight: 600; color: var(--text-muted); cursor: pointer;
}
.kptabs button.active, .tabs button.active, .kptabs button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }

/* ---- modal / bottom sheet ------------------------------------------------- */
.modal-bg { position: fixed; inset: 0; background: var(--overlay); z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal {
  background: var(--card); border-radius: var(--r-xl); box-shadow: var(--shadow-3);
  max-width: 520px; width: calc(100% - var(--s-6)); max-height: 86vh; overflow: auto; padding: var(--s-6);
}
@media (max-width: 640px) {
  .modal-bg { align-items: flex-end; }
  .modal { width: 100%; border-radius: var(--r-xl) var(--r-xl) 0 0; max-height: 92vh; }
}

/* ---- toast / banner --------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: var(--s-6); transform: translateX(-50%);
  background: var(--text); color: var(--card); padding: var(--s-3) var(--s-5);
  border-radius: var(--r-md); box-shadow: var(--shadow-2); font-size: var(--fs-sm); z-index: 300;
}
.banner { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-5); border-radius: var(--r-md); font-size: var(--fs-sm); background: var(--info-soft); color: var(--info); border: 1px solid var(--line); }
.banner.warning { background: var(--warning-soft); color: var(--warning); }
.banner.danger { background: var(--danger-soft); color: var(--danger); }

/* ---- skeleton loader --------------------------------------------------------- */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 37%, var(--surface-2) 63%);
  background-size: 400% 100%; border-radius: var(--r-sm);
  animation: kp-skeleton 1.4s ease infinite;
}
@keyframes kp-skeleton { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---- empty state --------------------------------------------------------------- */
.empty-state { text-align: center; padding: var(--s-8) var(--s-5); color: var(--text-muted); }
.empty-state h3 { color: var(--heading); margin: var(--s-3) 0 var(--s-1); }

/* ---- mobile bottom bar ----------------------------------------------------------- */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: none; justify-content: space-around; align-items: center;
  background: var(--card); border-top: 1px solid var(--line); box-shadow: var(--shadow-2);
  padding: var(--s-2) 0 max(var(--s-2), env(safe-area-inset-bottom));
}
@media (max-width: 760px) { .bottom-bar { display: flex; } }
.bottom-bar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: var(--fs-xs); color: var(--text-muted); text-decoration: none; }
.bottom-bar a.active { color: var(--primary); }

/* ---- shared guide/article template (about/features/learn/etc.) ------------------- */
.crumbs { font-family: var(--font-mono); font-size: .74rem; color: var(--text-faint); }
.crumbs a { color: var(--text-muted); text-decoration: none; }
.crumbs a:hover { color: var(--primary); }
article.guide, .feature-card, .pan-card, .hub-card { box-shadow: none; }
article.guide { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 36px 40px 40px; margin: 20px 0 40px; }
@media (max-width: 640px) { article.guide { padding: 24px 20px 28px; } }
.guide .eyebrow { display: block; background: none; padding: 0; border-radius: 0; color: var(--text-faint);
  font-size: .68rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; margin-bottom: 14px; }
.guide h1, .hero h1, .card h1 { font-family: var(--font-serif); font-weight: 600; color: var(--text); letter-spacing: -.005em; text-wrap: balance; margin: 0 0 10px; font-size: var(--fs-2xl); line-height: var(--lh-tight); }
.guide h2 { font-family: var(--font-serif); font-weight: 600; color: var(--text); padding-top: 18px; border-top: 1px solid var(--line); margin: 34px 0 12px; font-size: var(--fs-xl); }
.guide h3, .card h2, .card h3, .pan-card h3, .gl-term h3 { color: var(--text); }
.card h2, .pan-card h3, .gl-term h3 { font-family: var(--font-serif); font-weight: 600; }
.guide p, .guide li { color: var(--text); font-size: .98rem; }
.guide ul, .guide ol { margin: 0 0 16px; padding-left: 22px; }
.guide li { margin-bottom: 6px; }
.guide .dek { color: var(--text-muted); margin: 0 0 28px; font-size: 1.05rem; }
.guide strong { color: var(--text); }
.guide p a, .guide li a { color: var(--primary); }
.callout { background: var(--sheet); border: 1px solid var(--line); border-left: 3px solid var(--gold); border-radius: var(--r-md); color: var(--text); padding: 16px 18px; margin: 20px 0; font-size: .92rem; }
.callout b { color: var(--text); }
.callout.warn { border-left-color: var(--accent); }
.callout.danger { border-left-color: var(--danger); }
.related a, .related-links a { background: var(--card); border: 1px solid var(--line); color: var(--text); }
.related a:hover, .related-links a:hover { background: var(--sheet); border-color: var(--line-strong); }
.hub-card { background: var(--card); border: 1px solid var(--line); border-bottom: 3px solid var(--line-strong); border-radius: var(--r-md); }
.hub-card:hover { border-color: var(--line-strong); }
.hub-card h3 { color: var(--text); font-weight: 600; }
.faq-item summary { font-family: var(--font-serif); font-weight: 600; font-size: 1rem; color: var(--text); }
.faq-item summary::after { font-family: var(--font-mono); color: var(--text-faint); }
.faq-item[open] summary::after { content: "\2212"; color: var(--accent); }
.docnav-title { color: var(--text-faint); letter-spacing: .09em; }
.docnav-link { color: var(--text-muted); }
.docnav-link.current { background: var(--sheet); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.card { background: var(--card); border-color: var(--line); }
/* legal pages: readable long-form measure, serif headings, ruled sections */
body.legal { font-size: 16px; }
body.legal .wrap { max-width: 760px; }
body.legal header { background: var(--bg); border-bottom: 1px solid var(--line); }
body.legal h1 { font-family: var(--font-serif); font-weight: 600; font-size: 2.2rem; line-height: 1.15; color: var(--text); text-wrap: balance; }
body.legal h2 { font-family: var(--font-serif); font-weight: 600; font-size: 1.3rem; color: var(--text); }
body.legal .updated { font-family: var(--font-mono); font-size: .76rem; color: var(--text-faint); }
body.legal .card { background: none; border: none; border-radius: 0; padding: 22px 0 0; margin: 22px 0 0; border-top: 1px solid var(--line); }
body.legal .card:first-of-type { border-top: none; margin-top: 8px; padding-top: 0; }
body.legal p, body.legal li { max-width: 68ch; line-height: 1.7; color: var(--text); }
body.legal .notice, body.legal .grievance { background: var(--sheet); border: 1px solid var(--line); border-left: 3px solid var(--gold); border-radius: var(--r-md); padding: 14px 16px; }
body.legal table { border-collapse: collapse; }
body.legal th { background: transparent; color: var(--text-faint); font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; border-bottom: 1px solid var(--line-strong); }
body.legal td { border-bottom: 1px solid var(--line); }

/* ---- admin stat tiles (Apple-style redesign) ------------------------------------- */
.stat-tile {
  background: color-mix(in srgb, var(--card) 72%, var(--bg));
  border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s-4);
}
.stat-tile .stat-value { font-size: var(--fs-2xl); font-weight: 700; color: var(--heading); font-variant-numeric: tabular-nums; }
.stat-tile .stat-label { font-size: var(--fs-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

/* ---- "Night sky" theme additions (home-theme plan, unit 1) -----------------------
   Values taken verbatim from docs/mockups/kp_home_theme/theme.css. Only classes that
   no existing page uses are added here; the generic U2 answer-card names (.chip, .tl,
   .step, .rows, .kv, .tag, .q ...) are already styled by static/index.html and are
   adopted in the unit that rebuilds that surface. */
.num, table { font-variant-numeric: tabular-nums; }
h1, h2, .display { font-optical-sizing: auto; }
.theme-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--card); color: var(--text); border-radius: var(--r-pill); padding: 0 12px; min-height: 36px; font-size: .88rem; font-weight: 600; cursor: pointer; font-family: inherit; }
.theme-btn svg { width: 16px; height: 16px; }
.theme-btn:hover { border-color: var(--primary); }
.btn.gold { background: var(--sky-gold); border-color: var(--sky-gold); color: var(--on-sky-gold); }
.btn.on-sky { background: transparent; border-color: rgba(244, 241, 232, .45); color: var(--on-sky); }
.sky { position: relative; overflow: hidden; color: var(--on-sky); background: radial-gradient(1200px 600px at 85% 40%, var(--sky-bg-2), transparent 70%), linear-gradient(180deg, var(--sky-bg), var(--sky-bg) 60%, var(--sky-bg-2)); }
/* low specificity (:where) so components on the band keep their own colours */
.sky :where(h1, h2, h3) { color: var(--on-sky); }
:where(.sky) p { color: var(--on-sky-muted); }
:where(.sky) a:where(:not(.btn)) { color: var(--sky-gold); }
:where(.sky) :where(.card, .frame) { color: var(--text); }
:where(.sky) :where(.card, .frame) p { color: var(--text); }
.sky :where(.card, .frame) :where(h1, h2, h3) { color: var(--heading); }
:where(.sky) :where(.card, .frame) a:where(:not(.btn)) { color: var(--primary); }
.stars, .stars::after { position: absolute; inset: 0; pointer-events: none; background-image:
  radial-gradient(1.3px 1.3px at 22px 38px, var(--sky-star) 50%, transparent 51%),
  radial-gradient(1px 1px at 120px 90px, var(--sky-star) 50%, transparent 51%),
  radial-gradient(1.6px 1.6px at 200px 20px, var(--sky-star) 50%, transparent 51%),
  radial-gradient(1px 1px at 60px 150px, var(--sky-star) 50%, transparent 51%),
  radial-gradient(1.2px 1.2px at 170px 170px, var(--sky-star) 50%, transparent 51%);
  background-size: 240px 200px; opacity: .55; }
.stars::after { content: ""; background-size: 330px 270px; background-position: 90px 40px; opacity: .6; }
.nak-ring { position: absolute; width: min(760px, 130vw); aspect-ratio: 1; border-radius: 50%; right: -18%; top: 50%; translate: 0 -50%; pointer-events: none;
  background: radial-gradient(circle closest-side, transparent 0 59.4%, var(--sky-line) 59.5% 60%, transparent 60.1% 79.4%, var(--sky-line) 79.5% 80%, transparent 80.1% 99.2%, var(--sky-line) 99.3% 100%, transparent 100%);
  animation: nak-turn 400s linear infinite; }
.nak-ring::before, .nak-ring::after { content: ""; position: absolute; inset: 0; border-radius: 50%; }
.nak-ring::before { background: repeating-conic-gradient(var(--sky-line) 0 .35deg, transparent .35deg 13.3333deg);
  -webkit-mask: radial-gradient(circle closest-side, transparent 60%, #000 60.1% 79.9%, transparent 80%); mask: radial-gradient(circle closest-side, transparent 60%, #000 60.1% 79.9%, transparent 80%); }
.nak-ring::after { background: repeating-conic-gradient(var(--sky-line) 0 .35deg, transparent .35deg 30deg);
  -webkit-mask: radial-gradient(circle closest-side, transparent 80%, #000 80.1% 99.2%, transparent 99.3%); mask: radial-gradient(circle closest-side, transparent 80%, #000 80.1% 99.2%, transparent 99.3%); }
@keyframes nak-turn { to { rotate: 360deg; } }
@media (prefers-reduced-motion: reduce) { .nak-ring { animation: none; } }
.doors { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: var(--s-5); }
.door { position: relative; display: flex; flex-direction: column; gap: 10px; padding: var(--s-6); border-radius: var(--r-xl); border: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow-1); text-decoration: none; color: var(--text); }
.door:hover { border-color: var(--primary); box-shadow: var(--shadow-2); }
.door h3 { font-family: var(--font-display); font-size: var(--fs-xl); margin: 0; }
.door ul { margin: 0; padding-left: 18px; color: var(--text-muted); }
.door li { margin: 3px 0; }
.door .go { margin-top: auto; font-weight: 700; color: var(--primary); }
.door.pro { background: linear-gradient(160deg, var(--sky-bg), var(--sky-bg-2)); border-color: transparent; color: var(--on-sky); }
.door.pro h3 { color: var(--on-sky); }
.door.pro ul { color: var(--on-sky-muted); }
.door.pro .go { color: var(--sky-gold); }
.door .door-ico { width: 44px; height: 44px; border-radius: var(--r-md); display: flex; align-items: center; justify-content: center; background: var(--gold-soft); color: var(--gold-ink); font-size: 1.3rem; }
.door.pro .door-ico { background: rgba(240, 201, 106, .15); color: var(--sky-gold); }
.skynow { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: var(--s-5); }
@media (max-width: 820px) { .skynow { grid-template-columns: minmax(0, 1fr); } }
.big-star { font-family: var(--font-display); font-size: var(--fs-xl); color: var(--heading); margin: 0; }
.rp-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--card); }
.kp-table { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 460px; }
.kp-table th, .kp-table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.kp-table th { font-size: .76rem; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); background: var(--surface-2); font-weight: 700; }
.kp-table tr:last-child td { border-bottom: 0; }
.kp-table tr.running td { background: var(--gold-soft); }
.kp-table tr.running td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
.kp-table .pl { font-weight: 700; color: var(--heading); }
/* Dark theme: swap the Cusp mark's navy ring for the light-on-dark variant (same mark, D14). */
:root[data-theme="dark"] img[src$="/logo-mark.svg"] { content: url("/static/logo-mark-dark.svg"); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) img[src$="/logo-mark.svg"] { content: url("/static/logo-mark-dark.svg"); } }
