/* ASMODEVS palette and type, from docs/design/ASMODEVS_glitch_demo.html */

@font-face {
  font-family: "Chakra Petch";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/chakra-petch-400.woff2") format("woff2");
}

@font-face {
  font-family: "Chakra Petch";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/chakra-petch-600.woff2") format("woff2");
}

:root {
  --bg: #070405;
  --panel: rgba(16, 9, 10, 0.9);
  --line: #2a1416;
  --line-strong: #4a2226;
  --text: #e8d4d0;
  --text-muted: #8e6f6b;
  --red: #ff4034;
  --red-deep: #b00e16;
  --ghost-dark: #6c060e;
  --ghost-pink: #ff3460;
  --cell: 26px;
  --gap: 2px;
  /* Cut corners, like the demo's buttons */
  --cut: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  --cut-sm: polygon(5px 0, 100% 0, 100% calc(100% - 5px), calc(100% - 5px) 100%, 0 100%, 0 5px);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Chakra Petch", "Segoe UI", system-ui, sans-serif;
}

:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

::selection { background: var(--red-deep); color: var(--text); }

* { scrollbar-color: var(--line-strong) transparent; scrollbar-width: thin; }

/* Shared panel chrome */

.molecules, .library, .periodic-table {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 2px solid var(--red-deep);
  border-radius: 0;
  backdrop-filter: blur(8px);
  z-index: 10;
}

.molecules-title, .panel-title, .pt-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* The diamond from the demo's slider thumb */
.molecules-title::before, .panel-title::before, .pt-title::before {
  content: "";
  width: 7px;
  height: 7px;
  background: var(--red);
  transform: rotate(45deg);
}

/* Sandbox */

.sandbox {
  position: fixed;
  inset: 0;
}

.sandbox canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* Molecules panel */

.molecules {
  position: fixed;
  left: 16px;
  bottom: 16px;
  width: min(300px, calc(100vw - 144px));
  padding: 10px 12px;
}

.molecules-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.molecules-actions { display: flex; align-items: center; gap: 6px; }
.molecules.is-collapsed { width: auto; }
.molecules.is-collapsed .molecules-body { display: none; }

.molecules-clear {
  padding: 5px 10px;
  border: 0;
  background: var(--red);
  color: var(--bg);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
  cursor: pointer;
  clip-path: var(--cut-sm);
}
.molecules-clear:hover { background: #ff5a4f; }
.molecules-clear:active { transform: translateY(1px); }

.molecules-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 8px 0;
  padding: 0;
  list-style: none;
  max-height: 96px;
  overflow: auto;
}

.molecules-list li { color: var(--text-muted); font-size: 12px; }
.molecules-list li.is-empty { padding: 0; }

.molecules-list button {
  padding: 2px 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  clip-path: var(--cut-sm);
}
.molecules-list li.is-molecule { color: var(--text); }
.molecules-list li.is-molecule button { border-color: var(--line-strong); background: rgba(176, 14, 22, 0.12); }
.molecules-list button:hover { border-color: var(--red); color: var(--text); }
.molecules-list button:focus-visible { outline: none; border-color: var(--red); background: rgba(255, 64, 52, 0.18); }

.bond-legend {
  display: grid;
  grid-template-columns: repeat(2, auto);
  justify-content: start;
  gap: 4px 16px;
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
  color: var(--text-muted);
  font-size: 11px;
}

.bond-legend li { display: flex; align-items: center; gap: 6px; }
.bond-legend svg { width: 28px; height: 12px; stroke: var(--text); stroke-width: 2; stroke-linecap: square; }

.sandbox-tooltip {
  position: absolute;
  padding: 4px 9px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-left: 2px solid var(--red);
  color: var(--text);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
}

.sandbox-tooltip[hidden] { display: none; }

.molecules-help {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  align-items: center;
  margin: 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 11px;
}

.molecules-help dt { color: var(--text-muted); white-space: nowrap; }
.molecules-help dd { margin: 0; color: var(--text); }

.molecules-help kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 10px;
}


/* Molecule library */

.library {
  position: fixed;
  top: 16px;
  left: 16px;
  width: min(260px, calc(100vw - 32px));
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px 8px 14px;
}

.library.is-collapsed { width: auto; }
.library.is-collapsed .library-body { display: none; }

.library-body { padding: 0 10px 10px; border-top: 1px solid var(--line); }

.library-search {
  width: 100%;
  margin: 10px 0 6px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
.library-search::placeholder { color: var(--text-muted); }
.library-search:focus { border-color: var(--red); outline: none; }

.library-list {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: min(46vh, 420px);
  overflow: auto;
}

.library-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.library-item:hover, .library-item:focus-visible { background: var(--line); border-left-color: var(--red); outline: none; }

.library-formula { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.library-empty { padding: 6px 8px; color: var(--text-muted); font-size: 12px; }

.library-source { margin: 6px 0 0; color: var(--text-muted); font-size: 10.5px; }
.library-source a { color: var(--text-muted); text-decoration-color: var(--red-deep); }
.library-source a:hover { color: var(--red); }

/* Periodic table widget */

.periodic-table {
  position: fixed;
  top: 16px;
  right: 16px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  overflow: auto;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}

.pt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px 8px 14px;
  border-bottom: 1px solid var(--line);
}

.periodic-table.is-collapsed .pt-header { border-bottom: 0; }
.periodic-table.is-collapsed .pt-body { display: none; }

.pt-toggle {
  width: 24px;
  height: 24px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.pt-toggle:hover { background: var(--red-deep); border-color: var(--red-deep); }

.pt-body { padding: 10px 12px 12px; }

.pt-grid {
  display: grid;
  grid-template-columns: repeat(18, var(--cell));
  grid-template-rows: repeat(7, var(--cell)) 8px repeat(2, var(--cell));
  gap: var(--gap);
}

.pt-cell, .pt-marker {
  grid-column: var(--col);
  grid-row: var(--row);
}

.pt-cell {
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--c) 50%, transparent);
  border-radius: 0;
  background: color-mix(in srgb, var(--c) 14%, transparent);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: transform 0.1s, background 0.1s, opacity 0.15s;
}

.pt-cell:hover, .pt-cell:focus-visible {
  background: color-mix(in srgb, var(--c) 45%, transparent);
  transform: scale(1.18);
  z-index: 1;
}

.pt-cell.is-selected, .atom-preview {
  background: var(--c);
  color: var(--bg);
  box-shadow: 0 0 0 2px var(--red);
}

.pt-grid.is-filtering .pt-cell:not(.is-match) { opacity: 0.18; }

.pt-num { position: absolute; top: 1px; left: 2px; font-size: 6.5px; opacity: 0.75; }
.pt-sym { font-size: 11px; font-weight: 600; margin-top: 3px; }

.pt-marker {
  display: grid;
  place-items: center;
  border: 1px dashed color-mix(in srgb, var(--c) 50%, transparent);
  color: var(--text-muted);
  font-size: 6px;
}

/* Gap between groups 3 and 12 in periods 1–3 */
.pt-info {
  grid-column: 3 / 13;
  grid-row: 1 / 4;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  font-size: 11px;
}

.pt-info-hint { color: var(--text-muted); width: 100%; text-align: center; letter-spacing: 0.04em; }

.pt-info-symbol {
  flex: none;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 1px solid var(--c);
  background: color-mix(in srgb, var(--c) 20%, transparent);
  font-size: 22px;
  font-weight: 600;
  clip-path: var(--cut);
}

.pt-info-text { display: grid; gap: 2px; min-width: 0; }
.pt-info-text strong { font-size: 13px; font-weight: 600; }
.pt-info-text span { color: var(--text-muted); }
.pt-info-text .pt-info-cat { color: var(--c); }

.pt-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  max-width: calc(18 * var(--cell) + 17 * var(--gap));
  font-size: 10px;
  color: var(--text-muted);
}

.pt-legend li { display: flex; align-items: center; gap: 5px; cursor: default; }
.pt-legend li::before {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--c);
}
.pt-legend li:hover { color: var(--text); }

/* Selected atom: the same cell as in the table, larger */

.atom-preview {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  font: inherit;
  cursor: pointer;
  clip-path: var(--cut);
  z-index: 10;
}

.atom-preview:hover { filter: brightness(1.1); }

.atom-preview[hidden] { display: none; }

.atom-preview .pt-num { top: 8px; left: 12px; font-size: 14px; }
.atom-preview .pt-sym { font-size: 42px; margin-top: 8px; }

/* Brand: ASMODEVS logo with the demo's ghost glitch */

.brand {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  z-index: 10;
}

.brand-logo { display: block; width: 64px; height: auto; }
.brand:hover .brand-logo, .brand:focus-visible .brand-logo { animation: brand-glitch-burst 0.42s steps(1, end) 1; }

.brand-text { display: grid; gap: 2px; line-height: 1; }
.brand-name { color: var(--text); font-size: 15px; font-weight: 600; letter-spacing: 0.24em; }
.brand:hover .brand-by { color: var(--red); }

/* Only on hover, so it doesn't distract. Ghosts sit left (maroon) and right (pink), as in the demo's glitch stack */
@keyframes brand-glitch-burst {
  0%   { filter: drop-shadow(-3px 0 var(--ghost-dark)) drop-shadow(3px 0 var(--ghost-pink)); transform: translateX(2px); }
  20%  { filter: none; transform: none; }
  35%  { filter: drop-shadow(-4px 0 var(--ghost-dark)) drop-shadow(2px 0 var(--ghost-pink)); transform: translateX(-3px) skewX(-8deg); }
  60%  { filter: drop-shadow(-2px 0 var(--ghost-dark)) drop-shadow(4px 0 var(--ghost-pink)); transform: translateX(1px); }
  80%, 100% { filter: none; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .brand:hover .brand-logo, .brand:focus-visible .brand-logo { animation: none; }
}

/* No room between the bottom panels on narrow screens */
@media (max-width: 760px) {
  .brand { display: none; }
}
