/* ============================================================
   LEY·LINES — Help / How to Play overlay
   Depends on CSS custom properties defined in styles.css (:root).
   ============================================================ */

/* ================================================================
   CONTAINER  (#help lives inside #ui-root which is pointer-events:none)
   ================================================================ */
#help {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 200;
}

/* ================================================================
   TRIGGER BUTTON — "?" fixed top-right
   ================================================================ */
.help-trigger {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(233, 196, 106, 0.38);
  background: rgba(10, 7, 18, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--gold);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 0 14px rgba(233, 196, 106, 0.12),
    0 2px 8px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
  transition:
    border-color 150ms ease-out,
    box-shadow 150ms ease-out,
    background 150ms ease-out,
    transform 100ms ease-out;
  user-select: none;
  -webkit-user-select: none;
}

.help-trigger:hover {
  border-color: rgba(233, 196, 106, 0.7);
  box-shadow:
    0 0 24px rgba(233, 196, 106, 0.28),
    0 2px 12px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  background: rgba(14, 10, 28, 0.85);
  transform: scale(1.08);
}

.help-trigger:active { transform: scale(0.95); }

.help-trigger:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

/* ================================================================
   MODAL SHELL — full-screen scrim + centered panel
   ================================================================ */
.help-modal {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 260ms ease-out, visibility 260ms ease-out;
}

.help-modal.is-open {
  opacity: 1;
  visibility: visible;
}

/* Scrim */
.help-scrim {
  position: absolute;
  inset: 0;
  background: rgba(5, 4, 12, 0.72);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  cursor: pointer;
}

/* ================================================================
   PANEL
   ================================================================ */
.help-panel {
  position: relative;
  width: min(760px, 94vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: rgba(9, 6, 18, 0.90);
  border: 1px solid transparent;
  border-radius: 18px;
  backdrop-filter: blur(22px) saturate(1.6);
  -webkit-backdrop-filter: blur(22px) saturate(1.6);
  box-shadow:
    0 0 0 1px rgba(233, 196, 106, 0.22),
    0 0 60px rgba(123, 108, 246, 0.18),
    0 8px 60px rgba(0, 0, 0, 0.8),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
  transform: translateY(20px) scale(0.97);
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
  overflow: hidden;
}

/* Gold gradient border via pseudo-element */
.help-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 18px;
  padding: 1px;
  background: linear-gradient(
    160deg,
    rgba(233, 196, 106, 0.55) 0%,
    rgba(123, 108, 246, 0.28) 40%,
    rgba(233, 196, 106, 0.18) 80%,
    rgba(233, 196, 106, 0.45) 100%
  );
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.help-modal.is-open .help-panel {
  transform: translateY(0) scale(1);
}

/* Top shimmer line */
.help-panel::after {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent 5%,
    rgba(233, 196, 106, 0.5) 50%,
    transparent 95%
  );
  pointer-events: none;
  border-radius: 18px 18px 0 0;
}

/* ================================================================
   PANEL HEADER
   ================================================================ */
.help-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 26px 16px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(233, 196, 106, 0.12);
}

.help-title-block { flex: 1; }

.help-title-sub {
  font-family: var(--font-body);
  font-size: 0.6rem;
  font-variant: small-caps;
  letter-spacing: 0.28em;
  color: var(--arcane-bright);
  text-transform: uppercase;
  opacity: 0.75;
  margin-bottom: 4px;
}

.help-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  letter-spacing: 0.22em;
  color: var(--gold-bright);
  text-shadow: 0 0 22px rgba(233, 196, 106, 0.4), 0 0 4px rgba(255, 255, 255, 0.2);
  line-height: 1.1;
}

/* Close button */
.help-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink-dim);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 140ms ease-out, background 140ms ease-out, border-color 140ms ease-out;
  margin-top: 2px;
}

.help-close:hover {
  color: var(--ink);
  background: rgba(255, 84, 112, 0.15);
  border-color: rgba(255, 84, 112, 0.35);
}
.help-close:active { transform: scale(0.92); }
.help-close:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ================================================================
   SCROLLABLE BODY
   ================================================================ */
.help-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 26px 8px;
  display: flex;
  flex-direction: column;
  gap: 0;
  scroll-behavior: smooth;

  /* Styled scrollbar */
  scrollbar-width: thin;
  scrollbar-color: rgba(233, 196, 106, 0.22) transparent;
}

.help-body::-webkit-scrollbar { width: 5px; }
.help-body::-webkit-scrollbar-track { background: transparent; }
.help-body::-webkit-scrollbar-thumb {
  background: rgba(233, 196, 106, 0.22);
  border-radius: 3px;
}
.help-body::-webkit-scrollbar-thumb:hover { background: rgba(233, 196, 106, 0.42); }

/* Fade-out at the bottom to hint scrollability */
.help-body::after {
  content: '';
  display: block;
  height: 1px;
  flex-shrink: 0;
}

/* ================================================================
   SECTION DIVIDER
   ================================================================ */
.help-rule {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(233, 196, 106, 0.16), transparent);
  margin: 14px 0;
  flex-shrink: 0;
}

/* ================================================================
   SECTION
   ================================================================ */
.help-section { display: flex; flex-direction: column; gap: 10px; }

.help-section-head {
  display: flex;
  align-items: center;
  gap: 9px;
}

.help-section-icon {
  font-size: 1.05rem;
  filter: drop-shadow(0 0 5px var(--arcane));
  flex-shrink: 0;
  width: 22px;
  text-align: center;
  color: var(--arcane-bright);
}

.help-section-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.2em;
  color: var(--gold);
  text-transform: uppercase;
  text-shadow: 0 0 14px rgba(233, 196, 106, 0.3);
}

/* ================================================================
   BODY TEXT
   ================================================================ */
.help-body-text {
  margin: 0;
  font-family: var(--font-body);
  font-size: 0.82rem;
  line-height: 1.65;
  color: var(--ink-dim);
}

.help-body-text--small { font-size: 0.76rem; }

/* ================================================================
   KEY/VALUE LIST  (Building section)
   ================================================================ */
.help-kv-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.help-kv-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--font-body);
  font-size: 0.78rem;
  line-height: 1.5;
}

.help-kv-key {
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--ink);
  flex-shrink: 0;
  min-width: 180px;
}

.help-kv-desc {
  color: var(--ink-dim);
}

/* ================================================================
   SPIRE GRID
   ================================================================ */
.help-spires-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
}

.help-spire-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 11px 13px 10px;
  border-radius: 11px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(14, 10, 28, 0.55);
  position: relative;
  overflow: hidden;
  transition: border-color 160ms ease-out, box-shadow 160ms ease-out;
}

.help-spire-card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    color-mix(in srgb, var(--spire-color, var(--gold)) 45%, transparent),
    transparent
  );
}

.help-spire-card:hover {
  border-color: color-mix(in srgb, var(--spire-color, var(--gold)) 35%, transparent);
  box-shadow: 0 0 16px color-mix(in srgb, var(--spire-color, var(--gold)) 18%, transparent);
}

.help-spire-header {
  display: flex;
  align-items: center;
  gap: 9px;
}

.help-spire-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--spire-color, var(--gold));
  box-shadow: 0 0 8px var(--spire-color, var(--gold));
}

.help-spire-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--ink);
  line-height: 1.2;
}

.help-spire-tag {
  font-family: var(--font-body);
  font-size: 0.58rem;
  font-variant: small-caps;
  letter-spacing: 0.16em;
  color: var(--spire-color, var(--gold));
  opacity: 0.85;
}

.help-spire-status {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}

.help-spire-badge {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--spire-color, var(--gold)) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--spire-color, var(--gold)) 38%, transparent);
  color: var(--spire-color, var(--gold));
  white-space: nowrap;
  flex-shrink: 0;
}

.help-spire-desc {
  font-family: var(--font-body);
  font-size: 0.68rem;
  color: var(--ink-dim);
  line-height: 1.4;
}

/* ================================================================
   REACTION MATRIX
   ================================================================ */
.help-reaction-matrix {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.help-reaction-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 11px;
  border-radius: 8px;
  background: rgba(14, 10, 28, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: background 140ms ease-out, border-color 140ms ease-out;
}

.help-reaction-row:hover {
  background: rgba(20, 14, 40, 0.65);
  border-color: color-mix(in srgb, var(--rx-color, var(--gold)) 28%, transparent);
}

.help-reaction-lhs {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  min-width: 200px;
}

.help-rx-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  box-shadow: 0 0 5px currentColor;
  flex-shrink: 0;
}

.help-rx-el {
  font-family: var(--font-body);
  font-size: 0.68rem;
  font-variant: small-caps;
  letter-spacing: 0.1em;
  color: var(--ink-dim);
  text-transform: capitalize;
}

.help-rx-plus {
  font-family: var(--font-display);
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.25);
  padding: 0 2px;
}

.help-rx-arrow {
  font-family: var(--font-display);
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.2);
  padding: 0 4px;
}

.help-reaction-rhs {
  display: flex;
  align-items: baseline;
  gap: 7px;
  flex: 1;
  flex-wrap: wrap;
}

.help-rx-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.07em;
  color: var(--rx-color, var(--gold));
  text-shadow: 0 0 10px color-mix(in srgb, var(--rx-color, var(--gold)) 50%, transparent);
  white-space: nowrap;
}

.help-rx-desc {
  font-family: var(--font-body);
  font-size: 0.68rem;
  color: var(--ink-dim);
}

/* Tip callout */
.help-tip {
  margin: 6px 0 0;
  padding: 8px 12px;
  border-radius: 8px;
  border-left: 2px solid var(--frost);
  background: rgba(95, 208, 255, 0.05);
  font-family: var(--font-body);
  font-size: 0.75rem;
  color: var(--frost);
  line-height: 1.5;
}

/* ================================================================
   ABILITIES
   ================================================================ */
.help-abilities-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.help-ability-row {
  display: flex;
  align-items: baseline;
  gap: 9px;
  font-family: var(--font-body);
  font-size: 0.78rem;
  flex-wrap: wrap;
}

.help-ability-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 1px solid var(--ab-color, var(--gold));
  background: color-mix(in srgb, var(--ab-color, var(--gold)) 14%, rgba(10, 7, 18, 0.7));
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.72rem;
  color: var(--ab-color, var(--gold));
  box-shadow: 0 0 8px color-mix(in srgb, var(--ab-color, var(--gold)) 30%, transparent);
  flex-shrink: 0;
  line-height: 1;
}

.help-ability-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

.help-ability-desc { color: var(--ink-dim); }

/* ================================================================
   MODES LIST
   ================================================================ */
.help-modes-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.help-mode-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--font-body);
  font-size: 0.78rem;
  line-height: 1.5;
}

.help-mode-icon {
  font-size: 0.9rem;
  color: var(--arcane-bright);
  filter: drop-shadow(0 0 4px var(--arcane));
  flex-shrink: 0;
  width: 18px;
  text-align: center;
}

.help-mode-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  color: var(--ink);
  flex-shrink: 0;
  min-width: 130px;
}

.help-mode-sep {
  color: rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}

.help-mode-desc { color: var(--ink-dim); }

/* ================================================================
   CONTROLS
   ================================================================ */
.help-controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 16px;
}

.help-ctrl-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.help-ctrl-keys {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  min-width: 120px;
  flex-wrap: wrap;
}

.help-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(233, 196, 106, 0.28);
  background: rgba(233, 196, 106, 0.06);
  font-family: var(--font-display);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--gold);
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(233, 196, 106, 0.2);
}

.help-ctrl-action {
  font-family: var(--font-body);
  font-size: 0.72rem;
  color: var(--ink-dim);
  line-height: 1.5;
}

/* ================================================================
   FOOTER / BEGIN BUTTON
   ================================================================ */
.help-footer {
  display: flex;
  justify-content: center;
  padding: 16px 0 6px;
  flex-shrink: 0;
}

.help-begin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 12px 44px;
  border-radius: 11px;
  border: 1px solid rgba(233, 196, 106, 0.5);
  background: linear-gradient(135deg, rgba(123, 108, 246, 0.24), rgba(233, 196, 106, 0.14));
  color: var(--gold);
  cursor: pointer;
  pointer-events: auto;
  position: relative;
  overflow: hidden;
  text-shadow: 0 0 12px rgba(233, 196, 106, 0.45);
  box-shadow:
    0 0 24px rgba(123, 108, 246, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition:
    background 160ms ease-out,
    border-color 160ms ease-out,
    box-shadow 160ms ease-out,
    transform 100ms ease-out;
}

/* Shimmer sweep */
.help-begin-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(233, 196, 106, 0.1), transparent);
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}

.help-begin-btn:hover::before { transform: translateX(100%); }

.help-begin-btn:hover {
  background: linear-gradient(135deg, rgba(123, 108, 246, 0.38), rgba(233, 196, 106, 0.24));
  border-color: rgba(233, 196, 106, 0.75);
  box-shadow:
    0 0 36px rgba(233, 196, 106, 0.3),
    0 0 18px rgba(123, 108, 246, 0.28);
}

.help-begin-btn:active { transform: scale(0.96); }

.help-begin-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

/* ================================================================
   RESPONSIVE — narrow (≤ 760 px)
   ================================================================ */
@media (max-width: 760px) {
  .help-panel-head { padding: 18px 18px 14px; }
  .help-body { padding: 16px 18px 8px; }

  .help-reaction-lhs { min-width: 0; }
  .help-reaction-row { flex-wrap: wrap; gap: 6px; }
  .help-reaction-rhs { flex-wrap: wrap; }

  .help-controls-grid { grid-template-columns: 1fr; }

  .help-spires-grid { grid-template-columns: 1fr 1fr; }

  .help-kv-key { min-width: 130px; }
}

@media (max-width: 500px) {
  .help-trigger { top: 10px; right: 10px; width: 32px; height: 32px; font-size: 0.9rem; }

  .help-panel-head { padding: 14px 14px 12px; }
  .help-body { padding: 12px 14px 6px; }

  .help-spires-grid { grid-template-columns: 1fr; }

  .help-title { font-size: 1.1rem; }
}

/* ================================================================
   ACCESSIBILITY — reduced motion
   ================================================================ */
@media (prefers-reduced-motion: reduce) {
  .help-modal,
  .help-panel,
  .help-trigger,
  .help-begin-btn,
  .help-spire-card {
    transition-duration: 0.001ms !important;
  }
  .help-begin-btn::before { display: none; }
}
