/* Chemical Element Explorer — styles */
* { box-sizing: border-box; }
:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0e17;
  --bg2: #111524;
  --panel: #151a2c;
  --panel2: #1b2138;
  --line: #2a3350;
  --text: #e8ecf6;
  --muted: #93a0bd;
  --accent: #7c9df2;
  --tile-bg: #171d31;
  --tile-line: #2c3552;
  --shadow: 0 18px 50px rgba(0,0,0,.5);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f4fb;
  --bg2: #e7eaf6;
  --panel: #ffffff;
  --panel2: #f3f5fc;
  --line: #d5dbeb;
  --text: #1c2334;
  --muted: #5b667f;
  --accent: #3f63c8;
  --tile-bg: #ffffff;
  --tile-line: #dbe1ef;
  --shadow: 0 18px 40px rgba(30,40,80,.18);
}
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(124,157,242,.12), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(224,138,208,.10), transparent 60%),
    var(--bg);
  color: var(--text);
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
.no-scroll { overflow: hidden; }

/* ---------- layout ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; }
.app-main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  gap: 14px;
  padding: 0 14px 14px;
  min-height: 0;
}
.table-pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: auto;
  padding: 16px 12px 22px;
  overscroll-behavior: contain;
}

/* ---------- header ---------- */
header {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; flex-wrap: wrap;
}
.logo { display: flex; align-items: baseline; gap: 8px; margin-right: 4px; }
.logo b { font-size: 19px; letter-spacing: .2px; }
.logo b em { font-style: normal; color: var(--accent); }
.logo span { color: var(--muted); font-size: 12.5px; }
.search-wrap { position: relative; display: flex; align-items: center; gap: 8px; }
#search {
  width: 230px; padding: 8px 12px 8px 32px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; outline: none;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,157,242,.25); }
.search-wrap::before { content: "⌕"; position: absolute; left: 10px; color: var(--muted); pointer-events: none; font-size: 16px; }
#search-count { font-size: 12px; color: var(--muted); white-space: nowrap; }
#btn-theme {
  margin-left: auto; padding: 8px 12px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line);
}
#btn-theme:hover { border-color: var(--accent); }

.toolbar { display: flex; gap: 10px 16px; align-items: flex-start; padding: 2px 16px 12px; flex-wrap: wrap; }
.tb-label { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); display: block; margin-bottom: 5px; }
#filters { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px; font-size: 12.5px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  transition: all .15s;
}
.chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--c, #888); display: inline-block; }
.chip.on { color: var(--text); border-color: var(--line); background: var(--panel2); box-shadow: inset 0 0 0 1px rgba(124,157,242,.35); }
.chip:not(.on) { opacity: .55; }
.chip:hover { border-color: var(--accent); }
.chip.bump, #inspect-fab.bump { animation: bump .45s; }
@keyframes bump { 30% { transform: scale(1.12); } }
#heat-controls { display: flex; flex-wrap: wrap; gap: 6px; }
#heat-controls button {
  padding: 5px 11px; border-radius: 999px; font-size: 12.5px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
}
#heat-controls button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#heat-controls button:hover { border-color: var(--accent); }

#legend[hidden] { display: none; }
#legend { display: flex; align-items: flex-start; gap: 8px; font-size: 12px; color: var(--muted); padding: 14px 16px 10px; flex-wrap: wrap; }
#legend-bar { width: 160px; height: 10px; border-radius: 5px; border: 1px solid var(--line); position: relative; }
#legend-mid {
  position: absolute; left: 50%; top: -15px; transform: translateX(-50%);
  font-size: 10.5px; color: var(--muted); background: var(--bg);
  padding: 0 4px; line-height: 1.2; border-radius: 3px; white-space: nowrap;
}
#legend-unit { flex-basis: 100%; }

/* ---------- periodic table ---------- */
#table {
  display: grid;
  grid-template-columns: repeat(18, minmax(46px, 1fr));
  grid-template-rows: repeat(7, 54px) 12px repeat(2, 54px);
  gap: 4px;
  min-width: 900px;
}
.tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 1px solid var(--tile-line);
  border-radius: 8px;
  background: var(--tile-bg);
  padding: 2px;
  overflow: hidden;
  transition: transform .12s ease, box-shadow .12s ease, opacity .2s, filter .2s;
  transform-style: preserve-3d;
}
.tile::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: var(--cat, #888);
  opacity: .95;
}
.tile .t-num { position: absolute; top: 4px; left: 5px; font-size: 9px; color: var(--muted); }
.tile .t-sym { font-size: 16px; font-weight: 700; line-height: 1.1; margin-top: 4px; }
.tile .t-name { font-size: 8px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; letter-spacing: -.2px; }
.tile:hover { box-shadow: 0 6px 18px rgba(0,0,0,.35); z-index: 3; }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; z-index: 3; }
.tile.selected { outline: 2px solid var(--cat, var(--accent)); outline-offset: 1px; box-shadow: 0 0 16px color-mix(in srgb, var(--cat, #888) 60%, transparent); z-index: 2; }
.tile.filtered-out { opacity: .14; filter: grayscale(.9); }
.tile.search-dim { opacity: .18; }
.tile.search-hit { box-shadow: 0 0 0 2px var(--accent), 0 0 14px rgba(124,157,242,.55); z-index: 2; animation: pulse 1.2s infinite; }
#table.heat .tile.search-hit { outline: 3px solid #fff; outline-offset: 0; box-shadow: 0 0 0 1px #223, 0 0 18px rgba(255,255,255,.7); animation: none; }
@keyframes pulse { 50% { box-shadow: 0 0 0 2px var(--accent), 0 0 4px rgba(124,157,242,.3); } }

/* heat mode */
#table.heat .tile { background: var(--heat, #3a4150); border-color: rgba(255,255,255,.14); }
#table.heat .tile::before { display: none; }
#table.heat .tile .t-num, #table.heat .tile .t-name { color: rgba(255,255,255,.75); }
#table.heat .tile .t-sym { color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.5); }
#table.heat .tile.nodata { background: #3a4150; opacity: .5; }
#table.heat .tile.nodata .t-sym { color: #aab; }
:root[data-theme="light"] #table.heat .tile { border-color: rgba(0,0,0,.12); }

/* category colors */
.cat-alkali{--cat:#f4726f}.cat-alkaline{--cat:#f5a35c}.cat-transition{--cat:#f2cf5b}
.cat-post{--cat:#8ecf7e}.cat-metalloid{--cat:#4fc3a1}.cat-nonmetal{--cat:#56c2e6}
.cat-halogen{--cat:#7c9df2}.cat-noble{--cat:#a98af0}.cat-lanthanide{--cat:#e08ad0}
.cat-actinide{--cat:#ef6f9c}.cat-unknown{--cat:#9aa3b2}
.tile.placeholder { border-style: dashed; color: var(--muted); background: transparent; }
.tile.placeholder .t-sym { font-size: 11px; font-weight: 600; }
.tile.placeholder .t-name { font-size: 8px; }
.tile.placeholder.selected { outline: 2px solid var(--accent); outline-offset: 1px; box-shadow: 0 0 14px rgba(124,157,242,.5); }

/* ---------- hover preview ---------- */
#preview {
  position: fixed; z-index: 50; width: 200px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; pointer-events: none;
  opacity: 0; transform: translateY(6px) scale(.97); transition: opacity .15s, transform .15s;
  box-shadow: var(--shadow);
}
#preview.show { opacity: 1; transform: none; }
#preview .pv-top { display: flex; align-items: baseline; gap: 8px; }
#pv-num { font-size: 11px; color: var(--muted); }
#pv-sym { font-size: 26px; font-weight: 800; }
#pv-name { font-size: 13px; font-weight: 600; }
#pv-cat { font-size: 11px; color: var(--muted); display: block; margin-top: 2px; }
#pv-mass { font-size: 11px; color: var(--muted); display: block; }

/* ---------- inspector ---------- */
.inspector {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.ins-head { display: flex; align-items: flex-start; gap: 14px; padding: 16px 18px 8px; }
#ins-sym { font-size: 44px; font-weight: 800; line-height: 1; }
#ins-num { font-size: 13px; color: var(--muted); }
.ins-title h2 { margin: 0; font-size: 21px; }
.chip.cat-chip { border: 1px solid color-mix(in srgb, var(--chip) 60%, transparent); color: var(--text); background: color-mix(in srgb, var(--chip) 14%, transparent); pointer-events: none; }
.synth {
  margin-left: auto; font-size: 10.5px; color: #f5a35c;
  border: 1px solid rgba(245,163,92,.4); border-radius: 999px; padding: 3px 9px;
  background: rgba(245,163,92,.08); white-space: nowrap;
}
.atom-stage { position: relative; height: 300px; margin: 4px 10px; border-radius: 12px; overflow: hidden;
  background: radial-gradient(600px 300px at 50% 120%, rgba(124,157,242,.14), transparent 70%), #05070f; }
:root[data-theme="light"] .atom-stage { background: radial-gradient(600px 300px at 50% 120%, rgba(63,99,200,.16), transparent 70%), #0a0f22; }
#atom-canvas { width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
#atom-canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.atom-toolbar { position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; }
.atom-toolbar button {
  background: rgba(10,14,26,.72); border: 1px solid rgba(140,160,220,.35); color: #cfd9f5;
  border-radius: 8px; padding: 5px 10px; font-size: 12px; backdrop-filter: blur(4px);
}
.atom-toolbar button.on { background: rgba(124,157,242,.35); border-color: var(--accent); color: #fff; }
.atom-hint { position: absolute; left: 10px; bottom: 8px; font-size: 10.5px; color: rgba(200,210,240,.55); pointer-events: none; }
#atom-fallback { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: #cfd9f5; text-align: center; padding: 20px; }
#atom-fallback[hidden] { display: none; }
.ins-scroll { overflow-y: auto; padding: 4px 18px 18px; min-height: 0; }
#ins-desc { color: var(--muted); font-size: 13.5px; margin: 8px 0 12px; }
.shells-line { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.shells-line b { color: var(--text); font-weight: 600; }
dl#ins-props { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin: 0; }
dl#ins-props dt { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
dl#ins-props dd { margin: -20px 0 0; text-align: right; font-size: 13.5px; font-weight: 550; font-variant-numeric: tabular-nums; }
dl#ins-props dd.na { color: var(--muted); font-style: italic; }
#ins-config { grid-column: 1 / -1; }
#ins-config dd { text-align: left; margin-top: 2px; font-size: 12.5px; word-spacing: 2px; }

/* featured strip */
#featured {
  display: flex; align-items: center; gap: 12px;
  margin: 0 10px 10px; padding: 10px 14px; border-radius: 12px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--feat,#7c9df2) 16%, transparent), transparent 70%);
  border: 1px solid color-mix(in srgb, var(--feat,#7c9df2) 35%, transparent);
}
#featured button { width: 30px; height: 30px; border-radius: 8px; background: var(--panel2); border: 1px solid var(--line); flex: none; }
#featured button:hover { border-color: var(--accent); }
#feat-sym { font-size: 26px; font-weight: 800; }
#featured .f-meta b { display: block; font-size: 13px; }
#featured .f-meta span { font-size: 11px; color: var(--muted); }

/* ---------- overlay (mobile inspector) ---------- */
#inspector-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5,7,15,.66); backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center;
}
#inspector-overlay[hidden] { display: none; }
#inspector-overlay .sheet {
  background: var(--bg2); width: 100%; max-height: 92dvh;
  border-radius: 18px 18px 0 0; border: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden;
  animation: sheetUp .28s cubic-bezier(.2,.9,.3,1);
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } }
#overlay-close {
  position: absolute; top: 10px; right: 12px; z-index: 2;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--panel2); border: 1px solid var(--line); font-size: 16px;
}
#inspect-fab {
  position: fixed; right: 16px; bottom: 18px; z-index: 90;
  padding: 12px 18px; border-radius: 999px;
  background: var(--accent); color: #fff; border: none; font-weight: 600;
  box-shadow: 0 8px 24px rgba(60,90,200,.5);
}
#inspect-fab[hidden] { display: none; }
/* inspector inside bottom sheet fills available height */
#overlay-slot, #overlay-slot .inspector { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#overlay-slot .inspector { border: none; border-radius: 0; background: transparent; }
#desktop-slot { min-height: 0; display: flex; }
#desktop-slot .inspector { flex: 1; }

/* ---------- responsive ---------- */
@media (max-width: 1280px) {
  .app-main { grid-template-columns: minmax(0,1fr) 380px; }
}
@media (max-width: 1023px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100dvh; }
  .app-main { display: block; padding: 0 10px 80px; }
  #desktop-slot { display: none; }
  .table-pane { padding: 12px 8px 16px; }
  #search { width: 150px; }
  .logo span { display: none; }
}
@media (min-width: 1024px) {
  #inspector-overlay, #inspect-fab { display: none !important; }
}
@media (max-width: 560px) {
  header { gap: 8px; padding: 8px 10px; }
  #search { width: 120px; }
  .toolbar { padding: 2px 10px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .tile.search-hit { animation: none; }
  #inspector-overlay .sheet { animation: none; }
  * { scroll-behavior: auto !important; }
}
