:root {
  --bg: #fff8ec;
  --ink: #2b2140;
  --muted: #6b6280;
  --card: #ffffff;

  --alkali: #ff6b6b;
  --alkaline: #ffa94d;
  --transition: #ffd43b;
  --post: #a9e34b;
  --metalloid: #38d9a9;
  --nonmetal: #4dabf7;
  --halogen: #748ffc;
  --noble: #da77f2;
  --lanthanide: #f783ac;
  --actinide: #ff8787;
}

* { box-sizing: border-box; }

/* Bigger text everywhere: all sizes below are in rem, so this one line scales them all */
html { font-size: 125%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Nunito", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

h1, h2, .sym, .chip { font-family: "Baloo 2", "Nunito", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif; }

.site-header {
  position: relative;
  text-align: center;
  padding: 28px 16px 8px;
}

.lang-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  padding: 6px 16px;
  font: 700 1rem "Baloo 2", "PingFang SC", "Noto Sans SC", sans-serif;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform .1s, box-shadow .1s;
}
.lang-toggle:hover { transform: translateY(-2px); box-shadow: 0 5px 0 var(--ink); }
.lang-toggle:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

/* Chinese names are one character, so show them bigger */
html[lang="zh-CN"] .tile .name { font-size: .95rem; font-weight: 700; }
@media (max-width: 600px) {
  .site-header { padding-top: 64px; }
}
.site-header h1 { margin: 0; font-size: clamp(2rem, 6vw, 3.2rem); }
.tagline { margin: 4px 0 0; font-size: 1.15rem; color: var(--muted); }

main { max-width: 1500px; margin: 0 auto; padding: 16px; }

/* Legend */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 20px;
}
.chip {
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--c);
  cursor: pointer;
  transition: transform .15s;
}
.chip:hover { transform: scale(1.07); }

/* Category colors */
.cat-alkali     { --c: var(--alkali); }
.cat-alkaline   { --c: var(--alkaline); }
.cat-transition { --c: var(--transition); }
.cat-post       { --c: var(--post); }
.cat-metalloid  { --c: var(--metalloid); }
.cat-nonmetal   { --c: var(--nonmetal); }
.cat-halogen    { --c: var(--halogen); }
.cat-noble      { --c: var(--noble); }
.cat-lanthanide { --c: var(--lanthanide); }
.cat-actinide   { --c: var(--actinide); }

/* Periodic table */
.table-scroll { overflow-x: auto; padding-bottom: 8px; }

.periodic-table {
  display: grid;
  grid-template-columns: repeat(18, minmax(72px, 1fr));
  grid-template-rows: repeat(7, auto) 20px repeat(2, auto);
  gap: 5px;
  min-width: 1380px;
}

.tile {
  aspect-ratio: 1;
  border: none;
  border-radius: 10px;
  background: var(--c);
  color: var(--ink);
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,.15);
  transition: transform .15s, opacity .2s, box-shadow .15s;
  font: inherit;
}
.tile:hover, .tile:focus-visible {
  transform: translateY(-3px) scale(1.12);
  box-shadow: 0 6px 12px rgba(0,0,0,.2);
  z-index: 1;
  outline: none;
}
.tile .num  { font-size: .7rem; font-weight: 700; align-self: flex-start; line-height: 1; }
.tile .sym  { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.tile .name { font-size: .6rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tile.dim   { opacity: .2; }

.placeholder {
  cursor: default;
  font-size: .7rem;
  font-weight: 700;
  opacity: .7;
}
.placeholder:hover { transform: none; box-shadow: 0 3px 0 rgba(0,0,0,.15); }

/* Element popup */
.element-dialog {
  border: none;
  border-radius: 24px;
  padding: 28px;
  max-width: 540px;
  width: calc(100% - 32px);
  text-align: center;
  font-size: 1.1rem;
  color: var(--ink);
  background: var(--card);
}
.element-dialog::backdrop { background: rgba(43, 33, 64, .5); }
.element-dialog h2 { margin: 12px 0 4px; font-size: 2.6rem; line-height: 1.1; }
.family { color: var(--muted); }

.big-tile {
  width: 150px;
  height: 150px;
  margin: 0 auto;
  border-radius: 20px;
  background: var(--c);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}
.big-tile .num { position: absolute; top: 8px; left: 12px; font-weight: 700; }
.big-tile .sym { font-size: 3.6rem; font-weight: 800; }

.close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  border: none;
  background: #eee;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1rem;
  cursor: pointer;
}

/* Pronounce button */
.say-btn {
  border: none;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  padding: 8px 20px;
  margin: 4px 0 8px;
  font: 700 1.1rem "Baloo 2", "PingFang SC", "Noto Sans SC", sans-serif;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,.25);
  transition: transform .1s;
}
.say-btn:hover { transform: scale(1.06); }
.say-btn:active { transform: translateY(2px); }
.say-btn.speaking { animation: pulse .6s ease-in-out infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); background: #5f3dc4; } }

/* Back / Next buttons */
.nav-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
}
.nav-btn {
  flex: 1;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  padding: 10px 12px;
  font: 700 1.1rem "Baloo 2", "PingFang SC", "Noto Sans SC", sans-serif;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform .1s, box-shadow .1s;
}
.nav-btn:hover { background: #f3efff; }
.nav-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

/* Minerals section */
.element-dialog { max-width: 880px; max-height: 92vh; overflow-y: auto; }

.minerals {
  margin-top: 20px;
  padding: 16px;
  border-radius: 18px;
  background: #f6f1ff;
}
.minerals h3 {
  margin: 0 0 12px;
  font: 800 1.3rem "Baloo 2", "PingFang SC", "Noto Sans SC", sans-serif;
}
.minerals.none { font-size: 1.05rem; line-height: 1.5; }

.mineral-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}
.mineral {
  margin: 0;
  width: min(250px, 100%);
  background: var(--card);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 3px 0 rgba(0,0,0,.12);
}
.mineral img {
  display: block;
  width: 100%;
  height: 230px;
  object-fit: cover;
  background: #e9e4f5;
  transition: transform .2s;
}
.mineral a:hover img { transform: scale(1.05); }
.mineral figcaption {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 10px;
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.2;
}
.mineral-say {
  flex-shrink: 0;
  border: none;
  background: none;
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 50%;
  padding: 2px 4px;
}
.mineral-say:hover { background: #f3efff; }
.mineral-say.speaking { animation: pulse .6s ease-in-out infinite alternate; }

.credit { margin: 10px 0 0; font-size: .75rem; color: var(--muted); }

/* Discoverer line */
.discovery {
  margin: 16px auto 0;
  padding: 12px 16px;
  border-radius: 14px;
  background: #fff4d6;
  line-height: 1.5;
  max-width: 640px;
}

/* "No sound?" tip */
.sound-tip {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  width: min(480px, calc(100% - 32px));
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--ink);
  color: #fff;
  font-size: 1rem;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
  cursor: pointer;
  z-index: 10;
}

/* Photo of the pure element */
.element-photo {
  margin: 20px 0 0;
  padding: 16px;
  border-radius: 18px;
  background: #eef6ff;
}
.element-photo h3 {
  margin: 0 0 12px;
  font: 800 1.3rem "Baloo 2", "PingFang SC", "Noto Sans SC", sans-serif;
}
.element-photo img {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  border-radius: 14px;
  background: #fff;
}
.element-photo.none { font-size: 1.05rem; line-height: 1.5; }
.glow-note { margin-top: 10px; font-weight: 700; }
