/* ==========================================================================
   NEON DRAFT — base reset, typography scale, and shared components
   ========================================================================== */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body, h1, h2, h3, h4, p, figure, blockquote, dl, dd, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img, svg, picture { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
a { color: inherit; text-decoration: none; }
html { -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; overflow-x: hidden; }

/* ---------- Page background ---------- */
html, body { background: var(--c-bg); }
body {
  position: relative;
  color: var(--c-text);
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: 1.55;
}
body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
/* 1px grid layer */
body::before {
  background-image:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.016) 0 1px, transparent 1px 48px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.016) 0 1px, transparent 1px 48px);
}
/* radial gold vignette */
body::after {
  background: radial-gradient(1200px 700px at 50% -10%, rgba(212, 165, 55, 0.07), transparent 60%);
}
#app, .app-header { position: relative; z-index: 1; }
#modal-root { position: relative; z-index: 200; }

/* ---------- Typography scale ---------- */
.t-display {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-display);
  line-height: 0.95;
  letter-spacing: -0.01em;
  text-transform: uppercase;
}
.t-h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-h1);
  line-height: 1.05;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.t-h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--fs-h2);
  line-height: 1.15;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.t-h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--fs-h3);
  line-height: 1.2;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.t-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--fs-label);
  line-height: 1;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--c-text-3);
}
.t-body {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: var(--fs-body);
  line-height: 1.55;
}
.t-small {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: var(--fs-small);
  line-height: 1.45;
}
.t-mono {
  font-family: var(--font-mono);
}
.t-num {
  font-family: var(--font-mono);
  font-weight: 700;
}
.stat-num {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--fs-stat-num);
}
.stat-num-sm {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--fs-stat-num-sm);
}

/* ---------- Layout ---------- */
.container {
  max-width: 1320px;
  margin-inline: auto;
  padding-inline: var(--s-5);
}
@media (max-width: 760px) {
  .container { padding-inline: var(--s-4); }
}

.divider {
  border: none;
  border-top: var(--bw) solid var(--c-line);
  margin: var(--s-4) 0;
}

.is-hidden { display: none !important; }

/* ---------- Panel ---------- */
.panel {
  position: relative;
  background: var(--c-panel);
  border: var(--bw) solid var(--c-line);
  border-radius: var(--r-md);
}
.panel::before,
.panel::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  opacity: 0.5;
  pointer-events: none;
}
.panel::before {
  top: -1px;
  left: -1px;
  border-top: 2px solid var(--c-gold-dim);
  border-left: 2px solid var(--c-gold-dim);
}
.panel::after {
  bottom: -1px;
  right: -1px;
  border-bottom: 2px solid var(--c-gold-dim);
  border-right: 2px solid var(--c-gold-dim);
}
.panel__head {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--fs-label);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--c-text-3);
  padding: var(--s-3) var(--s-4);
  border-bottom: var(--bw) solid var(--c-line);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.8125rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 12px 22px;
  border-radius: var(--r-sm);
  background: transparent;
  border: var(--bw) solid var(--c-line-2);
  color: var(--c-text);
  min-height: 40px;
  transition:
    border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease),
    background-color var(--dur) var(--ease),
    color var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}
.btn:hover {
  border-color: var(--c-gold);
  color: var(--c-gold-bright);
  box-shadow: var(--glow-sm);
}
.btn:active {
  transform: translateY(1px);
  box-shadow: none;
}
.btn:focus-visible {
  outline: 2px solid var(--c-gold-bright);
  outline-offset: 2px;
}
/* Focus programmatically restored to a modal trigger on close (see
   ND.modal.close in ui.js) — real DOM focus for a11y, but not a live
   keyboard-navigation ring, so don't paint it gold. Cleared on the
   user's next pointer/keyboard interaction. */
.btn.is-focus-restore:focus-visible {
  outline: none;
}
.btn[disabled],
.btn.is-disabled {
  opacity: 0.32;
  cursor: not-allowed;
}

.btn--primary {
  border: 2px solid var(--c-gold);
  color: var(--c-gold-bright);
  background: linear-gradient(180deg, rgba(212, 165, 55, 0.14), rgba(212, 165, 55, 0.04));
}
.btn--primary:hover {
  box-shadow: var(--glow-md);
  background: linear-gradient(180deg, rgba(212, 165, 55, 0.22), rgba(212, 165, 55, 0.06));
}

.btn--xl {
  width: 100%;
  padding: 20px;
  font-size: 1.25rem;
  letter-spacing: 0.22em;
  position: relative;
  overflow: hidden;
}
.btn--xl.is-spinning {
  pointer-events: none;
}
.btn--xl.is-spinning::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 40%;
  height: 2px;
  bottom: auto;
  background: var(--c-gold-bright);
  animation: nd-sweep 700ms linear infinite;
}
@keyframes nd-sweep {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

.btn--ghost {
  border: none;
  color: var(--c-text-3);
  padding: 8px 10px;
  background: transparent;
}
.btn--ghost:hover {
  color: var(--c-gold);
  box-shadow: none;
  border-color: transparent;
}

.btn--sm {
  padding: 6px 12px;
  font-size: 0.6875rem;
  min-height: 32px;
}

/* Selected state, usable on slots/tiles/buttons */
.is-selected {
  border-color: var(--c-gold-bright);
  border-width: 2px;
  box-shadow: inset 0 0 0 1px var(--c-gold-bright), var(--glow-md);
  background: linear-gradient(180deg, var(--c-gold-a10), transparent 65%);
}

.is-empty {
  border: 1px dashed var(--c-line-2);
  background: transparent;
  color: var(--c-text-3);
}

.is-locked,
.is-scrapped {
  position: relative;
  border-color: var(--c-line);
  filter: grayscale(0.5);
  opacity: 0.72;
}
.is-locked::after,
.is-scrapped::after {
  content: "SCRAP";
  position: absolute;
  top: var(--s-1);
  right: var(--s-1);
  font-family: var(--font-display);
  font-size: 0.5625rem;
  letter-spacing: 0.14em;
  padding: 2px 6px;
  border: var(--bw) solid var(--c-line-2);
  border-radius: var(--r-xs);
  color: var(--c-text-3);
}

/* ---------- Chips ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: var(--r-pill);
  border: 1px solid currentColor;
  font-family: var(--font-display);
  font-size: 0.625rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: color-mix(in srgb, currentColor 12%, transparent);
  white-space: nowrap;
}
.chip--prime { color: var(--c-prime); }
.chip--firewall { color: var(--c-firewall); }
.chip--link { color: var(--c-link); }
.chip--ghost { color: var(--c-ghost); }
.chip--loud { color: var(--c-loud); }
.chip--rule { color: var(--c-gold); }

.chip.is-active {
  background: color-mix(in srgb, currentColor 22%, transparent);
}
.chip.is-active::before {
  content: "\25CF";
  margin-right: 4px;
  font-size: 0.5em;
}
.chip.is-redundant {
  opacity: 0.5;
  text-decoration: line-through;
}
.chip.is-broken {
  color: var(--c-bad);
  border-style: dashed;
}

/* ---------- Rule callout ---------- */
.rule-callout {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  border-radius: var(--r-pill);
  border: 1px solid var(--c-gold-dim);
  background: var(--c-gold-a10);
  padding: var(--s-2) var(--s-4);
  font-family: var(--font-display);
  font-size: var(--fs-label);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--c-text-2);
}
.rule-callout::before {
  content: "\25C6";
  color: var(--c-gold);
}

/* ---------- Stat box ---------- */
.stat-box {
  background: var(--c-panel);
  border: var(--bw) solid var(--c-line);
  border-radius: var(--r-md);
  min-height: 104px;
  padding: var(--s-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-1);
  text-align: center;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.stat-box__label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--fs-label);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--c-text-3);
}
.stat-box__value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--c-gold);
  text-transform: uppercase;
}
.stat-box__sub {
  font-family: var(--font-body);
  font-size: var(--fs-small);
  color: var(--c-text-2);
}

/* ---------- Scrollbars ---------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--c-gold-deep) var(--c-panel);
}
*::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
*::-webkit-scrollbar-track {
  background: var(--c-panel);
}
*::-webkit-scrollbar-thumb {
  background: var(--c-gold-deep);
  border-radius: var(--r-pill);
}

::selection {
  background: var(--c-gold-a35);
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--c-overlay);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-5);
  animation: nd-overlay-fade 120ms var(--ease);
}
@keyframes nd-overlay-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal {
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: var(--c-panel);
  border: 1px solid var(--c-gold-dim);
  border-radius: var(--r-lg);
  box-shadow: 0 24px 80px -20px #000, var(--glow-lg);
  animation: nd-modal-in 180ms var(--ease);
}
.modal--wide {
  max-width: 960px;
}
@keyframes nd-modal-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-4) var(--s-5);
  border-bottom: var(--bw) solid var(--c-line);
}
.modal__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-h1);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--c-text);
}
.modal__close {
  width: 32px;
  height: 32px;
  min-height: 32px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: var(--bw) solid var(--c-line);
  border-radius: var(--r-sm);
  color: var(--c-text-2);
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.modal__close:hover {
  border-color: var(--c-gold);
  color: var(--c-gold-bright);
}
.modal__close:focus-visible {
  outline: 2px solid var(--c-gold-bright);
  outline-offset: 2px;
}
.modal__body {
  padding: var(--s-5);
  overflow-y: auto;
  max-height: 70vh;
}

/* ---------- Global header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 64px;
  border-bottom: var(--bw) solid var(--c-line);
  background: var(--c-bg);
}
.app-header__row {
  height: 64px;
  display: flex;
  align-items: center;
  gap: var(--s-5);
}
.app-header__wordmark {
  font-size: 1.15rem;
  letter-spacing: 0.2em;
  margin-right: auto;
}
.app-header__wordmark span {
  color: var(--c-gold);
}
.app-header__crumb {
  color: var(--c-text-2);
}
.app-header__nav {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 60ms !important;
    scroll-behavior: auto !important;
  }
  .btn--xl.is-spinning::after {
    animation: none !important;
    display: none;
  }
}
