:root {
  --bg: #f5f5f5;
  --surface: #fff;
  --border: #ddd;
  --text: #222;
  --text2: #555;
  --accent: #2196f3;
  --header-bg: #1a237e;
  --header-text: #fff;
  --cell-size: 56px;
  --gap: 3px;
}
body.dark {
  --bg: #1a1a2e;
  --surface: #16213e;
  --border: #333;
  --text: #eee;
  --text2: #aaa;
  --header-bg: #0d0d1a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Header */
header { background: var(--header-bg); color: var(--header-text); padding: 0 16px; position: sticky; top: 0; z-index: 100; }
#top-nav { display: flex; align-items: center; gap: 16px; height: 48px; }
.logo { color: #fff; font-weight: 700; font-size: 1.1rem; text-decoration: none; white-space: nowrap; }
.nav-tabs { display: flex; gap: 4px; }
.tab { color: rgba(255,255,255,0.75); text-decoration: none; padding: 6px 14px; border-radius: 4px; font-size: 0.9rem; transition: background 0.2s; }
.tab:hover, .tab.active { background: rgba(255,255,255,0.2); color: #fff; }
.nav-controls { margin-left: auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toggle { color: rgba(255,255,255,0.8); font-size: 0.85rem; cursor: pointer; display: flex; align-items: center; gap: 4px; }
#search-input { padding: 4px 10px; border-radius: 4px; border: none; font-size: 0.85rem; width: 160px; background: rgba(255,255,255,0.15); color: #fff; }
#search-input::placeholder { color: rgba(255,255,255,0.5); }
#search-input:focus { outline: none; background: rgba(255,255,255,0.25); }
#property-select { font-size: 0.82rem; padding: 4px 8px; border: none; border-radius: 4px; background: rgba(255,255,255,0.15); color: #fff; cursor: pointer; }
#property-select option { background: #1a237e; color: #fff; }

/* Layout */
main { display: flex; gap: 0; min-height: calc(100vh - 48px); }
#table-container { flex: 1; padding: 16px; overflow-x: auto; }
.page-intro {
  margin-bottom: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.page-intro h1 {
  font-size: 1.5rem;
  line-height: 1.2;
  margin-bottom: 8px;
}
.page-description {
  color: var(--text2);
  font-size: 0.95rem;
  line-height: 1.6;
}
.noscript-tip {
  margin-bottom: 14px;
  padding: 10px 12px;
  background: #fff3cd;
  border: 1px solid #ffe69c;
  border-radius: 6px;
  color: #7a5d00;
  font-size: 0.9rem;
}
.seo-section {
  margin-top: 18px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.seo-section h2 {
  font-size: 1.1rem;
  margin-bottom: 10px;
}
.seo-section p {
  color: var(--text2);
  line-height: 1.7;
  font-size: 0.95rem;
}
.seo-list {
  padding-left: 18px;
  color: var(--text2);
  line-height: 1.8;
  font-size: 0.95rem;
}
.faq-section {
  margin-bottom: 24px;
}
.faq-item + .faq-item {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.faq-item h3 {
  font-size: 0.98rem;
  margin-bottom: 6px;
}
#periodic-table {
  display: grid;
  grid-template-columns: repeat(18, var(--cell-size));
  grid-template-rows: repeat(10, var(--cell-size));
  gap: var(--gap);
  min-width: calc(18 * (var(--cell-size) + var(--gap)));
}

/* Element cells */
.element {
  width: var(--cell-size); height: var(--cell-size);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 3px; cursor: pointer; position: relative;
  border: 1px solid rgba(0,0,0,0.15);
  transition: transform 0.1s, box-shadow 0.1s, opacity 0.2s;
  font-size: 0.65rem; color: #111;
  user-select: none;
  padding: 3px 2px;
}
.element:hover { transform: scale(1.15); box-shadow: 0 4px 12px rgba(0,0,0,0.3); z-index: 10; }
.element.selected { outline: 3px solid #ff5722; z-index: 5; }
.element.dimmed { opacity: 0.25; }
.element.compound-selected { outline: 3px solid #4caf50; }
.el-num { font-size: 0.55rem; align-self: flex-start; padding-left: 3px; opacity: 0.8; }
.el-sym { font-size: 1.1rem; font-weight: 700; line-height: 1; }
.el-name {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.05;
  margin-top: 2px;
  max-width: 100%;
}
.el-name-cn,
.el-name-en {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.el-name-cn { font-size: 0.45rem; font-weight: 700; opacity: 0.95; }
.el-name-en { font-size: 0.38rem; opacity: 0.8; }
.el-mass { font-size: 0.48rem; opacity: 0.7; }

/* Category colors */
.cat-alkali-metal { background: #ff8a65; }
.cat-alkaline-earth-metal { background: #ffcc02; }
.cat-transition-metal { background: #90caf9; }
.cat-post-transition-metal { background: #a5d6a7; }
.cat-metalloid { background: #ce93d8; }
.cat-diatomic-nonmetal, .cat-polyatomic-nonmetal { background: #80cbc4; }
.cat-noble-gas { background: #f48fb1; }
.cat-lanthanide { background: #ffab91; }
.cat-actinide { background: #bcaaa4; }
.cat-unknown { background: #e0e0e0; }

/* Lanthanide/Actinide separator */
.la-ac-label {
  display: flex; align-items: center; justify-content: center;
  font-size: 0.55rem; color: var(--text2); background: var(--surface);
  border: 1px dashed var(--border); border-radius: 3px;
}

/* 3D Model */
#model-container { position: relative; background: #0a0a1a; border-radius: 6px; margin-bottom: 12px; overflow: hidden; }
#model-toggle { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; }
.mtbtn { padding: 2px 10px; font-size: 0.75rem; border: 1px solid rgba(255,255,255,0.4); border-radius: 3px; background: rgba(0,0,0,0.5); color: #fff; cursor: pointer; }
.mtbtn.active { background: rgba(255,255,255,0.25); }

/* Detail panel */
#detail-panel {
  width: 300px; min-width: 260px; background: var(--surface);
  border-left: 1px solid var(--border); padding: 16px;
  overflow: visible; max-height: none;
}
#detail-header {
  text-align: center; padding: 12px; border-radius: 6px;
  margin-bottom: 12px; background: #90caf9; color: #111;
}
#detail-number { font-size: 0.8rem; opacity: 0.7; }
#detail-symbol { font-size: 3rem; font-weight: 700; line-height: 1; }
#detail-name {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 1rem;
  font-weight: 600;
}
.detail-name-cn { font-size: 1rem; font-weight: 700; }
.detail-name-en { font-size: 0.85rem; opacity: 0.85; }
#detail-mass { font-size: 0.8rem; opacity: 0.7; margin-top: 2px; }
#detail-summary-section {
  margin-bottom: 12px;
  padding: 10px 12px;
  background: rgba(33, 150, 243, 0.06);
  border: 1px solid var(--border);
  border-radius: 6px;
}
#detail-summary {
  font-size: 0.84rem;
  line-height: 1.65;
  color: var(--text2);
}
.more-content-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}
.more-content-link:hover {
  filter: brightness(0.95);
}

.view-content { display: none; }
.view-content.active { display: block; }

/* Properties table */
#props-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
#props-table tr { border-bottom: 1px solid var(--border); }
#props-table td { padding: 5px 4px; }
#props-table td:first-child { color: var(--text2); width: 45%; }
#props-table td:last-child { font-weight: 500; }

/* Electron canvas */
#electron-canvas { display: block; margin: 0 auto; }
#electron-config { text-align: center; font-size: 0.85rem; margin-top: 8px; color: var(--text2); }

/* Isotopes */
#isotope-list { font-size: 0.82rem; }
.isotope-item { padding: 6px 0; border-bottom: 1px solid var(--border); }
.isotope-item strong { color: var(--accent); }

/* Compounds */
#compound-selected { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; min-height: 32px; }
.compound-tag {
  background: #4caf50; color: #fff; padding: 3px 10px;
  border-radius: 12px; font-size: 0.8rem; cursor: pointer;
}
.compound-tag:hover { background: #388e3c; }
#compound-results { font-size: 0.82rem; }
.compound-item { padding: 5px 0; border-bottom: 1px solid var(--border); }
.compound-item .formula { font-weight: 700; color: var(--accent); }
.compound-item .cname { color: var(--text2); font-size: 0.78rem; }

/* Property bar */
#property-bar {
  height: 24px; background: var(--surface);
  display: flex; align-items: center; justify-content: center; gap: 12px; padding: 4px 8px; font-size: 0.82rem;
}
#color-scale { display: flex; align-items: center; gap: 4px; }
.scale-bar { width: 120px; height: 14px; border-radius: 3px; }
.scale-label { font-size: 0.75rem; color: var(--text2); }

/* Legend */
#legend { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.legend-item { display: flex; align-items: center; gap: 4px; font-size: 0.72rem; }
.legend-dot { width: 12px; height: 12px; border-radius: 2px; }

/* Highlight for search */
.element.highlight { outline: 3px solid #ff9800; z-index: 5; }

@media (max-width: 900px) {
  :root { --cell-size: 40px; }
  #detail-panel { width: 220px; }
  .el-name-cn { font-size: 0.38rem; }
  .el-name-en { font-size: 0.32rem; }
  .page-intro h1 { font-size: 1.2rem; }
  .page-description { font-size: 0.88rem; }
}
