:root {
  --solvent-color: #0d6efd;
  --solute-color: #fd7e14;
  --bg-color: #f5f7fb;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #dbe2ea;
  --success: #198754;
  --warning: #fd7e14;
  --danger: #dc3545;
  --purple: #6f42c1;
  --teal: #0f766e;
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
  --yt-red: #ff0000;

  --alkali: #ffb3b3;
  --alkaline: #ffdead;
  --transition: #add8e6;
  --post-trans: #98fb98;
  --metalloid: #e6e6fa;
  --nonmetal: #ffff99;
  --noble: #ffb6c1;
  --lanthanide: #d8bfd8;
  --actinide: #ffc0cb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg-color);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
}

.app-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: 100vh;
}

.nav-tabs {
  position: fixed;
  top: 16px;
  right: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  z-index: 1000;
  max-width: calc(100vw - 370px);
  justify-content: flex-end;
}

.tab-btn {
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: white;
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
  transition: 0.2s ease;
  white-space: nowrap;
}

.tab-btn:hover { transform: translateY(-1px); }

.tab-btn.active {
  background: var(--solvent-color);
  color: white;
  border-color: var(--solvent-color);
}

.sidebar {
  background: var(--panel);
  padding: 28px;
  border-right: 1px solid var(--border);
  min-height: 100vh;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.04);
  position: relative;
}

.sidebar-scroll {
  overflow-y: auto;
  max-height: calc(100vh - 56px);
  padding-right: 4px;
  padding-bottom: 120px;
}

.sidebar h2 {
  margin-top: 0;
  font-size: 22px;
  border-bottom: 2px solid var(--solvent-color);
  padding-bottom: 8px;
}

.sidebar h3 {
  color: var(--solvent-color);
  font-size: 16px;
  margin: 20px 0 8px;
}

.sidebar p {
  font-size: 14px;
  line-height: 1.6;
  color: #374151;
  margin: 0 0 12px;
}

.math-block,
.info-box {
  background: #f0f7ff;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #d0e3ff;
  font-size: 12px;
  line-height: 1.5;
}

.math-block { font-family: "Courier New", monospace; }

.yt-promo {
  position: fixed;
  left: 18px;
  bottom: 18px;
  width: 280px;
  background: #fff5f5;
  border: 1px solid #ffd6da;
  padding: 16px;
  border-radius: 12px;
  text-align: center;
  box-shadow: var(--shadow);
  z-index: 1100;
}

.yt-btn {
  background: var(--yt-red);
  color: white;
  text-decoration: none;
  padding: 10px 15px;
  border-radius: 8px;
  display: inline-block;
  font-size: 14px;
  font-weight: 700;
}

.content {
  width: 100%;
  padding: 92px 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

#periodic-container {
  width: 100%;
  max-width: 1180px;
  display: block;
}

.hero {
  text-align: center;
  margin-bottom: 12px;
}

.hero h1 {
  margin: 0;
  font-size: 24px;
}

.hero p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.toolbar {
  width: 100%;
  max-width: 1080px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.selection-badges {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.badge {
  padding: 8px 12px;
  border-radius: 999px;
  background: white;
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.badge.solvent { border-color: var(--solvent-color); color: var(--solvent-color); }
.badge.solute { border-color: var(--solute-color); color: var(--solute-color); }

.reset-btn,
.primary-btn {
  border: none;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 12px;
  cursor: pointer;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.reset-btn {
  background: #212529;
  color: white;
  border: 1px solid #111;
}

.primary-btn {
  background: var(--solvent-color);
  color: white;
  width: 100%;
  margin-top: 8px;
}

.legend {
  width: 100%;
  max-width: 1080px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  justify-content: center;
  font-size: 11px;
  color: #374151;
  margin-bottom: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
  border: 1px solid rgba(0,0,0,0.08);
}

.table-scroll {
  width: 100%;
  max-width: 1080px;
  overflow-x: auto;
  overflow-y: visible;
  padding-bottom: 14px;
}

.periodic-table {
  display: grid;
  grid-template-columns: repeat(18, minmax(52px, 1fr));
  gap: 4px;
  width: max-content;
  min-width: 100%;
  padding: 10px;
  background: rgba(255,255,255,0.75);
  border-radius: 16px;
  min-height: 720px;
}

.element {
  aspect-ratio: 1;
  border: 1px solid rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  font-size: 8px;
  border-radius: 8px;
  background: #fff;
  transition: 0.12s ease;
  position: relative;
  text-align: center;
  padding: 3px;
  min-width: 52px;
  min-height: 52px;
}

.element:hover {
  transform: scale(1.08);
  z-index: 100;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.element b { font-size: 12px; }
.element small { font-size: 7px; opacity: 0.85; }

.element.empty {
  background: transparent;
  border: none;
  cursor: default;
  box-shadow: none;
}

.element.empty:hover { transform: none; }

.element.solvent {
  background: var(--solvent-color) !important;
  color: white !important;
  border: 2px solid #084298;
  z-index: 50;
}

.element.solute {
  background: var(--solute-color) !important;
  color: white !important;
  border: 2px solid #b45309;
  z-index: 50;
}

.calc-view {
  display: none;
  width: 100%;
  flex-direction: column;
  align-items: center;
}

.calc-view.active { display: flex; }

.result-grid,
.metrics-grid,
.formula-grid,
.structure-grid,
.triple-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 900px;
  margin-top: 10px;
}

.metrics-grid.three,
.formula-grid.three,
.triple-grid.three {
  grid-template-columns: repeat(3, 1fr);
}

.rule-card,
.summary-card,
.hp-card,
.panel-card,
.metric-card,
.chart-card,
.structure-card,
.phase-card,
.meta-card,
.seo-content {
  background: white;
  border-radius: 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.rule-card,
.metric-card,
.structure-card,
.phase-card,
.panel-card,
.meta-card,
.seo-content {
  padding: 14px;
  font-size: 13px;
}

.rule-card { border-left: 5px solid #cbd5e1; }

.summary-card {
  grid-column: span 2;
  padding: 18px;
  text-align: center;
  font-weight: 800;
  display: none;
}

.summary-card small {
  display: block;
  margin-top: 6px;
  font-weight: 500;
  color: var(--muted);
}

.hp-card,
.panel-card,
.chart-card {
  padding: 24px;
  width: 100%;
  max-width: 900px;
  margin-top: 8px;
}

.hp-card.narrow,
.panel-card.narrow { max-width: 470px; }

.input-row,
.triple-inputs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.triple-inputs { grid-template-columns: repeat(3, 1fr); }

.input-group {
  margin-bottom: 12px;
  text-align: left;
  width: 100%;
}

.input-group label {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
  font-size: 13px;
}

.input-group input,
.input-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: white;
}

.calc-result {
  margin-top: 16px;
  padding: 14px;
  background: #e8f4fd;
  border: 1px solid #cbe7fb;
  border-radius: 12px;
  font-weight: 800;
  color: #0056b3;
  font-size: 16px;
  text-align: center;
  display: none;
}

.pair-meta {
  width: 100%;
  max-width: 900px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.mini-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

.metric-title {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric-value {
  font-size: 24px;
  font-weight: 800;
  margin-top: 6px;
}

.severity-low { color: var(--success); }
.severity-mid { color: var(--warning); }
.severity-high { color: var(--danger); }
.accent-purple { color: var(--purple); }
.accent-teal { color: var(--teal); }

.phase-badge {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 12px;
  margin-bottom: 10px;
}

.badge-success { background: rgba(25, 135, 84, 0.12); color: var(--success); }
.badge-warning { background: rgba(253, 126, 20, 0.14); color: var(--warning); }
.badge-danger { background: rgba(220, 53, 69, 0.12); color: var(--danger); }
.badge-purple { background: rgba(111, 66, 193, 0.12); color: var(--purple); }

canvas {
  width: 100%;
  max-width: 100%;
  border-radius: 12px;
  background: #fbfdff;
  border: 1px solid var(--border);
}

.seo-content {
  max-width: 1000px;
  margin: 40px auto;
}

.seo-content h2 {
  margin-top: 0;
}

@media (max-width: 1200px) {
  .nav-tabs { max-width: calc(100vw - 30px); }
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }

  .sidebar {
    min-height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-scroll {
    max-height: none;
    padding-bottom: 110px;
  }

  .content { padding-top: 112px; }

  .yt-promo {
    left: 16px;
    bottom: 16px;
    width: calc(100% - 32px);
    max-width: 360px;
  }

  .nav-tabs {
    left: 16px;
    right: 16px;
    top: 10px;
    max-width: none;
  }

  .table-scroll {
    max-width: 100%;
  }
}

@media (max-width: 800px) {
  .result-grid,
  .pair-meta,
  .metrics-grid,
  .structure-grid,
  .triple-grid,
  .formula-grid,
  .input-row,
  .triple-inputs,
  .metrics-grid.three,
  .formula-grid.three,
  .triple-grid.three {
    grid-template-columns: 1fr;
  }

  .summary-card { grid-column: span 1; }

  .periodic-table {
    grid-template-columns: repeat(18, minmax(44px, 1fr));
    min-height: 680px;
  }

  .element {
    min-width: 44px;
    min-height: 44px;
  }

  .element b { font-size: 10px; }
}
.badge.explorer {
  border-color: #7c3aed;
  color: #7c3aed;
}

.explorer-grid {
  width: 100%;
  max-width: 1000px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 12px;
}

.explorer-card {
  background: white;
  border-radius: 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 18px;
}

.explorer-card h3 {
  margin-top: 0;
  margin-bottom: 14px;
}

.explorer-top {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.explorer-symbol {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 800;
  border: 1px solid rgba(0,0,0,0.08);
}

.explorer-title {
  font-size: 24px;
  font-weight: 800;
}

.explorer-props-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.explorer-prop {
  background: #f8fbff;
  border: 1px solid #dbe8f6;
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.explorer-prop b {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.explorer-prop span {
  font-size: 15px;
  font-weight: 700;
}

.structure-visual-box {
  min-height: 240px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fbfdff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  text-align: center;
}

@media (max-width: 900px) {
  .explorer-grid {
    grid-template-columns: 1fr;
  }

  .explorer-props-grid {
    grid-template-columns: 1fr;
  }
}