/* ── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --glass:        rgba(0, 0, 0, 0.45);
  --glass-light:  rgba(255, 255, 255, 0.04);
  --glass-hover:  rgba(255, 255, 255, 0.06);
  --glass-open:   rgba(255, 255, 255, 0.03);
  --glass-detail: rgba(0, 0, 0, 0.35);

  --border:       rgba(255, 255, 255, 0.09);
  --border2:      rgba(255, 255, 255, 0.13);

  --text:         #e8dff0;
  --text-dim:     #a090b8;
  --text-muted:   #5a4870;

  --np:         #7dd3fc;
  --np-bg:      rgba(14, 56, 90, 0.7);
  --plt:        #86efac;
  --plt-bg:     rgba(10, 50, 25, 0.7);
  --pd:         #7dd3fc;
  --pd-bg:      rgba(10, 35, 55, 0.7);
  --st:         #d8b4fe;
  --st-bg:      rgba(55, 15, 80, 0.7);
  --py:         #fcd34d;
  --py-bg:      rgba(70, 45, 5, 0.7);

  --accent:     #f0abfc;
  --radius:     8px;
  --mono:       'IBM Plex Mono', monospace;
  --sans:       'Atkinson Hyperlegible', sans-serif;
}

html { font-size: 14px; scroll-behavior: smooth; }

body {
  background: #05000f; /* solid fallback */
  color: var(--text);
  font-family: var(--sans);
  font-weight: 400;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Animated Background ──────────────────────────────── */
.bg-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(
    to bottom,
    #000005 0%,
    #06001a 15%,
    #130040 35%,
    #1e0060 50%,
    #130040 65%,
    #06001a 85%,
    #000005 100%
  );
  background-size: 100% 300%;
  background-position: 0% 0%;
  will-change: background-position;
}

/* ── Header ───────────────────────────────────────────── */
header {
  background: rgba(5, 0, 15, 0.3);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border);
  padding: 2rem 2.5rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.35);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 3rem;
  flex-wrap: wrap;
}

.header-left { flex: 0 0 auto; }

.header-tag {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  color: var(--accent);
  display: block;
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  opacity: 0.7;
}

h1 {
  font-family: var(--mono);
  font-size: 1.55rem;
  font-weight: 600;
  color: #fff;
  line-height: 1.2;
  letter-spacing: -0.02em;
  text-shadow: 0 2px 16px rgba(180, 80, 255, 0.3);
}

.header-sub {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 0.55rem;
}

.header-right {
  flex: 1;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-top: 0.25rem;
}

/* ── Search ───────────────────────────────────────────── */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  color: var(--text-dim);
  font-size: 1.1rem;
  pointer-events: none;
  line-height: 1;
}

#searchInput {
  width: 100%;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.6rem 5rem 0.6rem 2.2rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#searchInput::placeholder { color: var(--text-muted); }

#searchInput:focus {
  border-color: var(--accent);
  background: rgba(0, 0, 0, 0.55);
  box-shadow: 0 0 0 3px rgba(240, 171, 252, 0.12);
}

.match-count {
  position: absolute;
  right: 0.75rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ── Filters ──────────────────────────────────────────── */
.filter-wrap {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.filter-btn {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.03em;
  opacity: 0.5;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.filter-btn:hover { opacity: 0.8; transform: translateY(-1px); }
.filter-btn.active { opacity: 1; box-shadow: 0 2px 12px rgba(0,0,0,0.4); }

.filter-btn.tag-np  { background: var(--np-bg);  color: var(--np);  border-color: rgba(125, 211, 252, 0.35); }
.filter-btn.tag-plt { background: var(--plt-bg); color: var(--plt); border-color: rgba(134, 239, 172, 0.35); }
.filter-btn.tag-pd { background: var(--pd-bg); color: var(--pd); border-color: rgba(125, 211, 252, 0.35); }
.filter-btn.tag-st  { background: var(--st-bg);  color: var(--st);  border-color: rgba(216, 180, 254, 0.35); }
.filter-btn.tag-py  { background: var(--py-bg);  color: var(--py);  border-color: rgba(252, 211, 77, 0.35); }

.group-toggle-btn {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-dim);
  border-color: var(--border2);
}
.group-toggle-btn.active {
  background: rgba(240, 171, 252, 0.1);
  color: var(--accent);
  border-color: rgba(240, 171, 252, 0.35);
  opacity: 1;
}

/* ── Main / Table ─────────────────────────────────────── */
main {
  flex: 1;
  padding: 2rem max(80px, 5vw) 3.5rem;
  position: relative;
  z-index: 1;
}

.table-wrap {
  max-width: 1400px;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow:
    0 8px 48px rgba(0, 0, 0, 0.5),
    0 1px 0 rgba(255, 255, 255, 0.06) inset;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead tr {
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid var(--border2);
}

thead th {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 0.75rem 1rem;
  text-align: left;
}

/* column widths */
.col-module { width: 90px; }
.col-term   { width: 150px; }
.col-args   { width: 260px; }
.col-desc   { width: auto; }

th.sortable {
  cursor: pointer;
  user-select: none;
}
th.sortable:hover { color: var(--text); }

.sort-indicator {
  margin-left: 0.45rem;
  font-size: 0.62rem;
  color: var(--accent);
  opacity: 0.65;
  letter-spacing: 0.04em;
}
th.sortable:hover .sort-indicator { opacity: 1; }

/* ── Group header rows ────────────────────────────────── */
tr.group-header td {
  padding: 0.45rem 1rem;
  background: rgba(255, 255, 255, 0.02);
  border-top: 1px solid var(--border2);
  border-bottom: 1px solid var(--border);
  cursor: default;
}
tr.group-header:first-child td { border-top: none; }

/* ── Data Rows ────────────────────────────────────────── */
tr.data-row {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease;
}

tr.data-row:hover { background: var(--glass-hover); }
tr.data-row.open  { background: var(--glass-open); border-bottom-color: transparent; }

tr.data-row td {
  padding: 0.65rem 1rem;
  vertical-align: middle;
}

/* Module tag */
.mod-tag {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 500;
  padding: 0.2rem 0.55rem;
  border-radius: 5px;
  letter-spacing: 0.04em;
  display: inline-block;
  border: 1px solid transparent;
}

.tag-np  { background: var(--np-bg);  color: var(--np);  border-color: rgba(125, 211, 252, 0.25); }
.tag-plt { background: var(--plt-bg); color: var(--plt); border-color: rgba(134, 239, 172, 0.25); }
.tag-pd { background: var(--pd-bg); color: var(--pd); border-color: rgba(125, 211, 252, 0.25); }
.tag-st  { background: var(--st-bg);  color: var(--st);  border-color: rgba(216, 180, 254, 0.25); }
.tag-py  { background: var(--py-bg);  color: var(--py);  border-color: rgba(252, 211, 77, 0.25); }

/* Term */
.col-term code {
  font-family: var(--mono);
  font-size: 0.88rem;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 0 12px rgba(240, 171, 252, 0.2);
}

/* Args */
.args-code {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* Desc */
.col-desc {
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.55;
}

.expand-icon {
  font-size: 0.55rem;
  color: var(--text-muted);
  margin-left: 0.5rem;
  vertical-align: middle;
  transition: color 0.15s;
}

tr.data-row:hover .expand-icon { color: var(--text-dim); }

/* ── Detail Rows ──────────────────────────────────────── */
tr.detail-row {
  display: none;
  background: var(--glass-detail);
  border-bottom: 1px solid var(--border);
}

tr.detail-row.open { display: table-row; }

tr.detail-row td { padding: 0; }

.detail-inner {
  padding: 1.1rem 1.2rem 1.1rem 3.5rem;
  display: flex;
  gap: 2.5rem;
  align-items: flex-start;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
}

.detail-example {
  flex: 0 0 auto;
  min-width: 280px;
  max-width: 520px;
}

.detail-example pre {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--np);
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  white-space: pre;
  overflow-x: auto;
  line-height: 1.7;
  box-shadow: 0 2px 16px rgba(0,0,0,0.3);
}

.detail-text {
  flex: 1;
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.75;
  padding-top: 0.1rem;
  max-width: 540px;
}

/* ── No Results ───────────────────────────────────────── */
.no-results {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.85rem;
}

/* ── Footer ───────────────────────────────────────────── */
footer {
  background: rgba(15, 0, 20, 0.45);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 1rem 2.5rem;
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  font-family: var(--mono);
  color: var(--text-muted);
  position: relative;
  z-index: 1;
}

/* ── Background toggle ───────────────────────────────── */
.bg-toggle-wrap {
  position: absolute;
  top: 50%;
  right: 2.5rem;
  transform: translateY(-50%);
  z-index: 101;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.bg-toggle {
  width: 44px;
  height: 24px;
  border-radius: 12px;
  border: none;
  padding: 0;
  cursor: pointer;
  position: relative;
  background: #27a55a;
  transition: background 0.25s;
  flex-shrink: 0;
}

.bg-toggle.off { background: #c0392b; }

.bg-toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.25s;
  transform: translateX(20px); /* ON: right side (44-18-3-3=20) */
}

.bg-toggle.off .bg-toggle-thumb { transform: translateX(0); }

.bg-toggle-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  text-transform: uppercase;
  white-space: nowrap;
  user-select: none;
}

/* ── Scrollbar ────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); }

/* ── Star column ──────────────────────────────────────── */
.col-star { width: 36px; text-align: center; padding: 0 !important; }

.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.05rem;
  color: var(--text-muted);
  padding: 0.25rem 0.4rem;
  line-height: 1;
  transition: color 0.15s, transform 0.15s;
  display: block;
  margin: 0 auto;
}
.star-btn:hover  { color: var(--py); transform: scale(1.25); }
.star-btn.starred { color: var(--py); }

.filter-btn.starred-btn {
  background: rgba(252, 211, 77, 0.06);
  color: var(--py);
  border-color: rgba(252, 211, 77, 0.3);
}
.filter-btn.starred-btn.active {
  background: rgba(252, 211, 77, 0.14);
  border-color: rgba(252, 211, 77, 0.55);
  opacity: 1;
}

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 700px) {
  header { padding: 1.25rem; }
  main   { padding: 1rem 1rem 2rem; }
  .header-inner { gap: 1rem; }
  h1 { font-size: 1.15rem; }
  .col-args { display: none; }
  .detail-inner { flex-direction: column; gap: 1rem; padding-left: 1rem; }
}

/* ── Code assistant (fix / write) ─────────────────────── */
.assist-btn {
  align-self: flex-start;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--accent);
  background: var(--glass-light);
  border: 1px solid var(--border2);
  border-radius: 999px;
  padding: 0.38rem 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.assist-btn:hover {
  border-color: var(--accent);
  background: var(--glass-hover);
  box-shadow: 0 0 0 3px rgba(240, 171, 252, 0.1);
}

.assist-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(3, 0, 12, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.assist-panel {
  width: min(760px, 100%);
  max-height: min(88vh, 760px);
  overflow-y: auto;
  background: rgba(10, 3, 24, 0.92);
  border: 1px solid var(--border2);
  border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  padding: 1.3rem 1.4rem 1.5rem;
}

.assist-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.assist-head h2 {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.01em;
}
.assist-close {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text-dim);
  border-radius: 8px;
  width: 2rem;
  height: 2rem;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  transition: border-color 0.2s, color 0.2s;
}
.assist-close:hover { border-color: var(--accent); color: var(--text); }

.assist-sub {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin: 0.5rem 0 1.1rem;
  line-height: 1.5;
}

.assist-field { display: block; margin-bottom: 0.9rem; }
.assist-label {
  display: block;
  font-family: var(--mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.assist-field textarea,
.assist-lang {
  width: 100%;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.5;
  padding: 0.6rem 0.7rem;
  outline: none;
  resize: vertical;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.assist-field textarea::placeholder,
.assist-lang::placeholder { color: var(--text-muted); }
.assist-field textarea:focus,
.assist-lang:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(240, 171, 252, 0.12);
}
#assistCode { white-space: pre; overflow-wrap: normal; }

.assist-controls {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.2rem;
}
.assist-lang { flex: 0 0 auto; width: 180px; resize: none; }
.assist-run {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 600;
  color: #1a0526;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  padding: 0.55rem 1.4rem;
  cursor: pointer;
  transition: filter 0.15s, transform 0.12s, opacity 0.15s;
}
.assist-run:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.assist-run:disabled { opacity: 0.5; cursor: default; }

.assist-status {
  min-height: 1.1rem;
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--text-dim);
  margin: 0.8rem 0 0;
}
.assist-status.err { color: #ff9a8f; }

.assist-out {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
  margin-top: 0.9rem;
}
@media (min-width: 640px) { .assist-out { grid-template-columns: 1fr 1fr; } }

.assist-out-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.assist-copy {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 0.15rem 0.5rem;
  font-family: var(--sans);
  font-size: 0.66rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.assist-copy:hover { border-color: var(--border2); color: var(--text); }
.assist-copy.done { color: var(--accent); border-color: var(--accent); }

.assist-out-body {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  min-height: 3rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.assist-out-body.assist-code { white-space: pre; overflow-x: auto; }
.assist-out-body:empty::before { content: "—"; color: var(--text-muted); }
.assist-cursor {
  display: inline-block;
  width: 0.5ch;
  background: var(--accent);
  animation: assistBlink 1s steps(1) infinite;
}
@keyframes assistBlink { 50% { opacity: 0; } }
