* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --emerald: #059669;
  --gold: #d97706;
  --gold-light: #fbbf24;
  --bg: #0a0a0a;
  --bg-alt: #111827;
  --card: #1f2937;
  --border: #374151;
  --text: #f3f4f6;
  --text-muted: #9ca3af;

  --c-alkali: #f87171; --c-alkaline: #fb923c; --c-transition: #fbbf24;
  --c-post: #a3e635; --c-metalloid: #34d399; --c-nonmetal: #60a5fa;
  --c-halogen: #a78bfa; --c-noble: #f472b6; --c-lanthanide: #fcd34d;
  --c-actinide: #fda4af; --c-unknown: #9ca3af;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

[dir="rtl"] body { font-family: 'Noto Naskh Arabic', 'Segoe UI', Tahoma, sans-serif; }

.site-header {
  background: rgba(10,10,10,0.92);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.nav {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.logo svg { height: 28px; display: block; }

.nav-links {
  display: flex;
  gap: 4px;
  list-style: none;
  flex-wrap: wrap;
  flex: 1;
}

.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: all .2s;
}

.nav-links a:hover, .nav-links a.active {
  color: var(--gold-light);
  background: rgba(217,119,6,0.12);
}

.lang-switcher {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .2s;
}

.lang-switcher:hover { border-color: var(--emerald); }

.lang-switcher:focus {
  outline: none;
  border-color: var(--emerald);
  box-shadow: 0 0 0 3px rgba(5,150,105,0.15);
}

main {
  flex: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 40px 20px;
  width: 100%;
}

.hero {
  text-align: center;
  padding: 30px 0 40px;
}

.hero h1 {
  font-size: clamp(28px, 5vw, 44px);
  font-weight: 800;
  margin-bottom: 10px;
  background: linear-gradient(135deg, var(--gold-light) 0%, var(--emerald) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}

.hero p {
  color: var(--text-muted);
  font-size: 16px;
}

.periodic-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

#searchInput {
  flex: 1;
  min-width: 220px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

#searchInput:focus {
  outline: none;
  border-color: var(--emerald);
  box-shadow: 0 0 0 3px rgba(5,150,105,0.15);
}

.filter-pills { display: flex; gap: 6px; flex-wrap: wrap; }

.filter-pill {
  padding: 8px 14px;
  border-radius: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}

.filter-pill.active, .filter-pill:hover {
  background: var(--emerald);
  border-color: var(--emerald);
  color: #fff;
}

.periodic-grid-wrap {
  overflow-x: auto;
  padding: 10px 0;
}

/* Periodic table always LTR — chemistry standard */
.periodic-grid,
.f-block-grid,
.f-block-label {
  direction: ltr;
}

.periodic-grid {
  display: grid;
  grid-template-columns: repeat(18, minmax(54px, 1fr));
  grid-template-rows: repeat(7, minmax(54px, auto));
  gap: 4px;
  min-width: 1000px;
}

.f-block-label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 16px 0 6px;
  min-width: 1000px;
  text-align: left;
}

.f-block-grid {
  display: grid;
  grid-template-columns: repeat(15, minmax(54px, 1fr));
  gap: 4px;
  min-width: 900px;
  margin-bottom: 12px;
}

.element-card {
  aspect-ratio: 1;
  background: var(--card);
  border: 2px solid var(--cat-color, var(--border));
  border-radius: 8px;
  padding: 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, opacity .2s;
  color: var(--text);
  font-family: inherit;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.element-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--cat-color);
  opacity: 0.08;
  pointer-events: none;
}

.element-card:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  z-index: 5;
}

.element-card.dimmed { opacity: 0.15; pointer-events: none; }

.f-block-jump { cursor: pointer; }
.f-block-jump:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  z-index: 5;
}

.flash-highlight { animation: flashPulse 0.4s ease 4; }

@keyframes flashPulse {
  0%, 100% { transform: scale(1); box-shadow: none; }
  50% { transform: scale(1.15); box-shadow: 0 0 24px var(--cat-color); }
}

.el-z { font-size: 8px; color: var(--text-muted); line-height: 1; position: relative; }
.el-symbol { font-size: 16px; font-weight: 800; line-height: 1; position: relative; }
.el-name {
  font-size: 7px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1;
  position: relative;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.2);
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.78);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal.modal-open { display: flex; }

.modal-content {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  animation: modalIn .22s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

[dir="rtl"] .modal-close { right: auto; left: 12px; }

.modal-close:hover { background: var(--border); }

.modal-content h3 {
  color: var(--gold-light);
  font-size: 24px;
  margin-bottom: 24px;
  font-weight: 700;
  padding-right: 40px;
}

[dir="rtl"] .modal-content h3 { padding-right: 0; padding-left: 40px; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.detail-grid > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.detail-value {
  font-size: 15px;
  color: var(--text);
  font-weight: 600;
  word-break: break-word;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 40px;
}

.site-footer p { margin: 2px 0; }

@media (max-width: 720px) {
  .nav-links { order: 3; width: 100%; justify-content: center; }
  .detail-grid { grid-template-columns: 1fr; }
  .periodic-grid { min-width: 900px; }
}

/* ============ REACTIONS PAGE ============ */
.reactions-hero {
  text-align: center;
  padding: 30px 0 30px;
}

.reactions-hero h1 {
  font-size: clamp(28px, 5vw, 44px);
  font-weight: 800;
  margin-bottom: 10px;
  background: linear-gradient(135deg, var(--gold-light) 0%, var(--emerald) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}

.reactions-hero p {
  color: var(--text-muted);
  font-size: 16px;
  max-width: 600px;
  margin: 0 auto;
}

.reactions-stats {
  display: flex;
  justify-content: center;
  gap: 40px;
  flex-wrap: wrap;
  margin: 24px 0 32px;
  padding: 20px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.stat-item {
  text-align: center;
}

.stat-item .stat-val {
  font-size: 28px;
  font-weight: 800;
  color: var(--gold-light);
  display: block;
  line-height: 1;
}

.stat-item .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 6px;
  display: block;
}

.reactions-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.reactions-controls input {
  flex: 1;
  min-width: 220px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

.reactions-controls input:focus {
  outline: none;
  border-color: var(--emerald);
  box-shadow: 0 0 0 3px rgba(5,150,105,0.15);
}

.category-pills,
.difficulty-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.category-pill,
.difficulty-pill {
  padding: 8px 14px;
  border-radius: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}

.category-pill:hover,
.difficulty-pill:hover {
  border-color: var(--emerald);
  color: var(--text);
}

.category-pill.active,
.difficulty-pill.active {
  background: var(--emerald);
  border-color: var(--emerald);
  color: #fff;
}

.reactions-section-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  margin-bottom: 8px;
}

.reactions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.reaction-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: transform .2s, box-shadow .2s, border-color .2s;
}

.reaction-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--reaction-color, var(--emerald));
}

.reaction-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  border-color: var(--emerald);
}

.reaction-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.reaction-category-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #fff;
  background: var(--reaction-color, var(--emerald));
}

.reaction-difficulty-badge {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.difficulty-basic {
  background: rgba(52,211,153,0.15);
  color: #34d399;
}

.difficulty-intermediate {
  background: rgba(251,191,36,0.15);
  color: #fbbf24;
}

.difficulty-advanced {
  background: rgba(248,113,113,0.15);
  color: #f87171;
}

.reaction-equation {
  font-family: 'Courier New', monospace;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  padding: 12px;
  background: rgba(5,150,105,0.08);
  border-radius: 8px;
  margin-bottom: 12px;
  word-break: break-word;
  line-height: 1.5;
}

.reaction-equation .arrow {
  color: var(--gold-light);
  margin: 0 4px;
  font-weight: 900;
}

.reaction-description {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 12px;
}

.reaction-meta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}

.reaction-meta-item {
  color: var(--text-muted);
}

.reaction-meta-item strong {
  color: var(--gold-light);
  font-weight: 700;
}

.reaction-hazard {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(248,113,113,0.12);
  color: #f87171;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  margin-top: 10px;
}

.reaction-hazard svg {
  flex-shrink: 0;
}

.no-results {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.no-results h3 {
  font-size: 20px;
  margin-bottom: 8px;
  color: var(--text);
}

.reactions-count {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 12px;
}

.reactions-count strong {
  color: var(--gold-light);
}

@media (max-width: 720px) {
  .reactions-grid { grid-template-columns: 1fr; }
  .reactions-stats { gap: 20px; padding: 16px; }
  .stat-item .stat-val { font-size: 22px; }
}
