/* element detail panel */
.detail-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  background: rgba(15, 15, 25, 0.98);
  backdrop-filter: blur(30px);
  border: 1px solid rgba(0, 212, 255, 0.3);
  padding: 2rem;
  border-radius: 28px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
  width: 90%;
  max-width: 650px;
  max-height: 85vh;
  overflow-y: auto;
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.2, 0.9, 0.4, 1.1);
}

.detail-panel:not(.hidden) {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

/* mobile 768px */
@media (max-width: 768px) {
  .detail-panel {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
    padding: 1rem !important;
    transform: none !important;
  }
  .detail-panel:not(.hidden) {
    transform: none !important;
  }
}

/* close detail */
.close-detail-btn {
  position: sticky;
  top: 0;
  left: 0;
  float: left;
  background: linear-gradient(135deg, #ef476f, #ff6b35);
  color: white;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.2s ease;
  z-index: 10;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-detail-btn:hover {
  transform: scale(1.05) rotate(90deg);
}

/* detail title */
.detail-title {
  text-align: center;
  margin-bottom: 1.5rem;
  margin-top: 0;
  clear: both;
  font-size: 1.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, #00d4ff, #05d9e8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* detail info */
.detail-info-box {
  background: rgba(255, 255, 255, 0.05);
  padding: 1.2rem;
  border-radius: 20px;
  margin-bottom: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.detail-info-box p {
  margin: 0.6rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.85rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.detail-info-box strong {
  min-width: 110px;
  color: #00d4ff;
  font-weight: 700;
  font-size: 0.85rem;
  text-align: right;
}

.detail-info-box span {
  color: rgba(255, 255, 255, 0.85);
  text-align: left;
  flex: 1;
  word-break: break-word;
}

/* detail uses */
.detail-uses-list {
  padding-right: 1.5rem;
  margin-top: 0.5rem;
  margin-bottom: 0;
  width: 100%;
}

.detail-uses-list li {
  margin-bottom: 0.4rem;
  color: rgba(255, 255, 255, 0.8);
  padding-right: 0.5rem;
  line-height: 1.5;
  font-size: 0.8rem;
}

/* detail image */
.detail-image-container {
  text-align: center;
  margin-bottom: 1rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* detail element */
.detail-element-image {
  max-width: 150px;
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  transition: transform 0.3s ease;
}

.detail-element-image:hover {
  transform: scale(1.05);
}

/* no image */
.no-image-icon {
  font-size: 2.5rem;
  opacity: 0.5;
  margin-bottom: 0.3rem;
}

/* detail model */
.detail-model-section {
  margin-top: 1rem;
  padding-top: 0.8rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
}

.detail-model-section h3 {
  color: #00d4ff;
  font-size: 0.9rem;
  margin-bottom: 0.8rem;
  font-weight: 600;
}

/* atomic model */
.atomic-model-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: .6rem;
  min-height: 280px;
  overflow: visible;
  visibility: visible;
  opacity: 1;
}

/* atom fit */
.atom-fit {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.atom-fit .atom-stage { transform-origin: center center; }

/* atom count */
.atom-count {
  margin: 0;
  font-size: .78rem;
  font-weight: 600;
  color: #00d4ff;
}

body.light-theme .atom-count { color: #0b5cad; }

.atom-stage,
.atom-shell,
.atom-electron,
.atom-nucleus,
/* atom overflow */
.atom-overflow {
  visibility: visible;
}

/* atom stage */
.atom-stage {
  position: relative;
  flex-shrink: 0;
  transform: translateZ(0);
}

/* atom shell */
.atom-shell {
  position: absolute;
  border: 1.5px solid rgba(0, 212, 255, 0.4);
  border-radius: 50%;
  animation-name: atomSpin;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  animation-duration: 20s;
  will-change: transform;
  contain: layout style;
  backface-visibility: hidden;
}

/* atom static */
.atom-static .atom-shell {
  animation: none;
  will-change: auto;
  contain: none;
}

@keyframes atomSpin {
  to { transform: rotate(360deg); }
}

html[data-perf-tier="high"] .atom-shell,
/* atom shell */
html[data-perf-tier="very-high"] .atom-shell {
  will-change: transform;
}

/* atom electron */
.atom-electron {
  position: absolute;
  background: #05d9e8;
  border-radius: 50%;
  display: block;
  backface-visibility: hidden;
}

/* pointer */
@media (pointer: coarse) {
  html[data-perf-tier="high"] .atom-electron,
  html[data-perf-tier="very-high"] .atom-electron { box-shadow: none; }
}

html[data-perf-tier="high"] .atom-electron,
/* atom electron */
html[data-perf-tier="very-high"] .atom-electron {
  box-shadow: 0 0 7px #05d9e8;
}

/* dense atom: glow moves to the ring, not to each dot */
.atom-dense .atom-electron,
html[data-perf-tier="high"] .atom-dense .atom-electron,
html[data-perf-tier="very-high"] .atom-dense .atom-electron {
  box-shadow: none;
}

html[data-perf-tier="high"] .atom-dense .atom-shell,
html[data-perf-tier="very-high"] .atom-dense .atom-shell {
  box-shadow: 0 0 12px rgba(5, 217, 232, .22);
}

/* dense rings stay off the compositor, weak gpus run out of layers */
.atom-dense .atom-shell,
html[data-perf-tier="high"] .atom-dense .atom-shell,
html[data-perf-tier="very-high"] .atom-dense .atom-shell {
  will-change: auto;
  contain: none;
}

/* atom nucleus */
.atom-nucleus {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff8fb3, #ff2a6d);
  color: #fff;
  font-weight: 800;
  z-index: 5;
}

html[data-perf-tier="high"] .atom-nucleus,
html[data-perf-tier="very-high"] .atom-nucleus {
  box-shadow: 0 0 18px rgba(255, 42, 109, 0.55);
  animation: atomNucleusPulse 4s ease-in-out infinite;
}

@keyframes atomNucleusPulse {
  0%, 100% { box-shadow: 0 0 18px rgba(255, 42, 109, 0.5); }
  50% { box-shadow: 0 0 28px rgba(255, 42, 109, 0.78); }
}

/* light theme */
body.light-theme .atom-shell {
  border-color: rgba(0, 102, 204, 0.45) !important;
}

/* atom electron */
body.light-theme .atom-electron {
  background: #0077dd;
}

html[data-perf-tier="high"] body.light-theme .atom-electron,
/* body */
html[data-perf-tier="very-high"] body.light-theme .atom-electron {
  box-shadow: 0 0 6px rgba(0, 119, 221, 0.7);
}

/* atom nucleus */
body.light-theme .atom-nucleus {
  background: radial-gradient(circle at 35% 30%, #f07ba0, #d01a5d);
}

/* atom overflow */
.atom-overflow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.6rem;
  color: #00d4ff;
  background: rgba(0, 0, 0, 0.6);
  padding: 1px 6px;
  border-radius: 999px;
  white-space: nowrap;
  z-index: 4;
}

body.light-theme .atom-overflow {
  background: rgba(255, 255, 255, 0.85);
  color: #0066cc;
}

/* detail icon */
.detail-icon {
  width: 1em;
  height: 1em;
  fill: currentColor;
  flex-shrink: 0;
}

/* detail info */
.detail-info-box strong {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.detail-info-box strong .detail-icon {
  opacity: 0.85;
  font-size: 0.95em;
}

.detail-uses-box h3,
/* detail model */
.detail-model-section h3 {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  color: #00d4ff;
  font-size: 0.9rem;
  font-weight: 700;
  margin: 0 0 0.7rem;
}

/* detail uses */
.detail-uses-box h3 {
  justify-content: flex-start;
}

body.light-theme .detail-uses-box h3,
/* detail model */
body.light-theme .detail-model-section h3 {
  color: #0066cc;
}

/* detail latin */
.detail-latin {
  text-align: center;
  margin: -0.9rem 0 1.2rem;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  opacity: 0.55;
  direction: ltr;
}

/* detail empty */
.detail-empty {
  opacity: 0.55;
  font-size: 0.8rem;
  margin: 0;
}

/* close detail */
.close-detail-btn .detail-icon {
  width: 0.9em;
  height: 0.9em;
}

/* body */
body.detail-open {
  overflow: hidden;
}

/* mobile 768px */
@media (max-width: 768px) {
  .detail-title {
    font-size: 1.3rem;
    margin-bottom: 0.8rem;
  }
  .detail-info-box {
    padding: 0.8rem;
  }
  .detail-info-box p {
    font-size: 0.75rem;
    margin: 0.4rem 0;
    padding: 0.3rem 0;
  }
  .detail-info-box strong {
    min-width: 90px;
    font-size: 0.75rem;
  }
  .detail-info-box span {
    font-size: 0.75rem;
  }
  .detail-uses-list li {
    font-size: 0.7rem;
  }
  .detail-element-image {
    max-width: 100px;
  }
  .atomic-model-container {
    min-height: 200px;
  }
  .close-detail-btn {
    width: 32px;
    height: 32px;
    font-size: 1rem;
  }
}

/* mobile 480px */
@media (max-width: 480px) {
  .detail-panel {
    padding: 0.8rem !important;
  }
  .detail-title {
    font-size: 1.1rem;
  }
  .detail-info-box strong {
    min-width: 80px;
    font-size: 0.7rem;
  }
  .detail-element-image {
    max-width: 80px;
  }
}

/* detail panel */
body.light-theme .detail-panel {
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(0, 102, 204, 0.3);
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
}

/* detail info */
body.light-theme .detail-info-box {
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

body.light-theme .detail-info-box strong {
  color: #0066cc;
}

body.light-theme .detail-info-box span {
  color: #333;
}

body.light-theme .detail-info-box p {
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

/* detail uses */
body.light-theme .detail-uses-list li {
  color: #555;
}

/* detail title */
body.light-theme .detail-title {
  background: linear-gradient(135deg, #0066cc, #0099ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
/* detail hero */
.detail-hero {
  position: relative;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 1.1rem 1.15rem;
  border-radius: 18px;
  margin-bottom: .9rem;
  overflow: hidden;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--tint-a) 34%, transparent),
                            color-mix(in srgb, var(--tint-b) 26%, transparent));
  border: 1px solid color-mix(in srgb, var(--tint-a) 40%, transparent);
}

.detail-hero::after {
  content: "";
  position: absolute;
  inset-block: -40%;
  inset-inline-end: -12%;
  width: 55%;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--tint-b) 40%, transparent), transparent 68%);
  pointer-events: none;
}

/* hero tile */
.hero-tile {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  width: 84px;
  height: 92px;
  border-radius: 15px;
  padding: .5rem .4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .1rem;
  color: #fff;
  background: linear-gradient(150deg, var(--tint-a), var(--tint-b));
  box-shadow: 0 10px 24px color-mix(in srgb, var(--tint-a) 45%, transparent);
}

.hero-number { font-size: .74rem; font-weight: 700; opacity: .9; align-self: flex-start; }
.hero-symbol { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.hero-mass { font-size: .66rem; opacity: .88; direction: ltr; }

.hero-text { position: relative; z-index: 1; flex: 1; min-width: 0; }
.hero-text h2 { font-size: 1.35rem; font-weight: 800; margin: 0 0 .15rem; }

/* hero latin */
.hero-latin {
  font-size: .82rem;
  color: var(--color-text-muted, #a0a0c0);
  direction: ltr;
  text-align: start;
  margin-bottom: .5rem;
}

/* hero chip */
.hero-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .74rem;
  font-weight: 600;
  padding: .25rem .7rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, .28);
  border: 1px solid rgba(255, 255, 255, .16);
}

body.light-theme .hero-chip { background: rgba(255, 255, 255, .7); border-color: rgba(20, 26, 56, .12); }

/* hero photo */
.hero-photo {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  width: 78px;
  height: 78px;
  border-radius: 15px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, .22);
  box-shadow: 0 8px 20px rgba(0, 0, 0, .3);
}

.hero-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* detail tabs */
.detail-tabs {
  display: flex;
  gap: .3rem;
  padding: .28rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .08);
  margin-bottom: .9rem;
}

body.light-theme .detail-tabs {
  background: rgba(20, 26, 56, .04);
  border-color: rgba(20, 26, 56, .09);
}

/* detail tab */
.detail-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  border: none;
  background: none;
  color: var(--color-text-muted, #a0a0c0);
  font-family: inherit;
  font-size: .8rem;
  font-weight: 600;
  padding: .5rem .4rem;
  border-radius: 11px;
  cursor: pointer;
  transition: background .18s ease, color .18s ease;
}

.detail-tab:hover { color: var(--color-text, #f0f0ff); }

.detail-tab.active {
  color: #fff;
  background: linear-gradient(135deg, #7c5cff, #00d4ff);
}

/* no fill mode: content stays visible even if the frame never paints */
.detail-tab-panel { display: none; }

.detail-tab-panel.active {
  display: block;
  opacity: 1;
  visibility: visible;
  animation: detailFade .22s ease;
}

/* opacity only: a transform here would layerise the whole atom */
@keyframes detailFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* stat grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: .5rem;
  margin-bottom: .9rem;
}

/* stat card */
.stat-card {
  position: relative;
  padding: .7rem .6rem .65rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, .08);
  background: rgba(255, 255, 255, .04);
  text-align: center;
  overflow: hidden;
}

body.light-theme .stat-card {
  border-color: rgba(20, 26, 56, .09);
  background: rgba(20, 26, 56, .03);
}

.stat-card::before {
  content: "";
  position: absolute;
  inset-inline: 0;
  top: 0;
  height: 2px;
  background: linear-gradient(90deg, #7c5cff, #00d4ff);
  opacity: .6;
}

.stat-card.accent-p::before { background: linear-gradient(90deg, #ff5f6d, #ff8e35); }
.stat-card.accent-n::before { background: linear-gradient(90deg, #8b93a5, #cfd6ec); }
.stat-card.accent-e::before { background: linear-gradient(90deg, #00d4ff, #5bffbc); }

/* stat icon */
.stat-icon {
  display: block;
  margin-bottom: .3rem;
  color: #00d4ff;
}

.stat-card.accent-p .stat-icon { color: #ff7a85; }
.stat-card.accent-n .stat-icon { color: #b6bdd2; }
.stat-card.accent-e .stat-icon { color: #5bffbc; }
.stat-icon .detail-icon { width: 1.05rem; height: 1.05rem; }

/* stat value */
.stat-value {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.stat-value small { font-size: .62rem; opacity: .65; margin-inline-start: .15rem; }

/* stat label */
.stat-label {
  display: block;
  font-size: .68rem;
  color: var(--color-text-muted, #a0a0c0);
  margin-top: .1rem;
}

/* detail block */
.detail-block {
  padding: .85rem .9rem;
  border-radius: 15px;
  border: 1px solid rgba(255, 255, 255, .08);
  background: rgba(255, 255, 255, .035);
  margin-bottom: .7rem;
}

body.light-theme .detail-block {
  border-color: rgba(20, 26, 56, .09);
  background: rgba(20, 26, 56, .025);
}

.detail-block h3 {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .84rem;
  font-weight: 700;
  margin-bottom: .7rem;
  color: var(--color-accent, #00d4ff);
}

.detail-block h3 .detail-icon { width: .9rem; height: .9rem; }

/* shell strip */
.shell-strip {
  display: flex;
  align-items: flex-end;
  gap: .4rem;
  height: 96px;
}

/* shell col */
.shell-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .22rem;
  height: 100%;
  justify-content: flex-end;
}

.shell-count { font-size: .7rem; font-weight: 700; }

/* shell bar */
.shell-bar {
  width: 100%;
  max-width: 26px;
  flex: 1;
  display: flex;
  align-items: flex-end;
  border-radius: 6px;
  background: rgba(255, 255, 255, .06);
  overflow: hidden;
}

body.light-theme .shell-bar { background: rgba(20, 26, 56, .07); }

.shell-bar i {
  display: block;
  width: 100%;
  border-radius: 6px;
  background: linear-gradient(180deg, #00d4ff, #7c5cff);
  transition: height .35s cubic-bezier(.3, .8, .3, 1);
}

.shell-name { font-size: .66rem; color: var(--color-text-muted, #a0a0c0); font-weight: 600; }

/* shell sum */
.shell-sum {
  margin-top: .6rem;
  text-align: center;
  font-size: .78rem;
  direction: ltr;
  color: var(--color-text-muted, #a0a0c0);
  letter-spacing: .04em;
}

.detail-note { font-size: .85rem; line-height: 2; }

/* use grid */
.use-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .5rem;
}

/* use card */
.use-card {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .7rem .8rem;
  border-radius: 13px;
  border: 1px solid rgba(255, 255, 255, .08);
  background: rgba(255, 255, 255, .04);
  font-size: .82rem;
  line-height: 1.8;
}

body.light-theme .use-card {
  border-color: rgba(20, 26, 56, .09);
  background: rgba(20, 26, 56, .03);
}

.use-card .detail-icon { width: 1rem; height: 1rem; color: #ffc46b; flex-shrink: 0; }

/* atom legend */
.atom-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .45rem;
  margin-top: .8rem;
}

/* legend item */
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .74rem;
  font-weight: 600;
  padding: .3rem .75rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .1);
  background: rgba(255, 255, 255, .05);
}

body.light-theme .legend-item {
  border-color: rgba(20, 26, 56, .1);
  background: rgba(20, 26, 56, .04);
}

.legend-item .detail-icon { width: .82rem; height: .82rem; }
.legend-item.accent-p .detail-icon { color: #ff7a85; }
.legend-item.accent-n .detail-icon { color: #b6bdd2; }
.legend-item.accent-e .detail-icon { color: #5bffbc; }

/* mobile 640px */
@media (max-width: 640px) {
  .detail-hero { flex-wrap: wrap; gap: .75rem; padding: .9rem; }
  .hero-tile { width: 68px; height: 78px; }
  .hero-symbol { font-size: 1.6rem; }
  .hero-text h2 { font-size: 1.15rem; }
  .hero-photo { width: 58px; height: 58px; }
  .detail-tab span { display: none; }
  .detail-tab { padding: .55rem .3rem; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: .4rem; }
  .stat-value { font-size: .92rem; }
  .shell-strip { height: 78px; }
  .use-grid { grid-template-columns: 1fr; }
}
