:root {
  --bg: #f7f4ee;
  --ink: #20231f;
  --muted: #6d7168;
  --line: #d8d0c4;
  --panel: #fffdf8;
  --shadow: 0 18px 48px rgba(46, 38, 25, 0.12);
  --alkali: #d95f59;
  --alkaline: #e09b45;
  --transition: #49a89d;
  --post-transition: #78aa58;
  --metalloid: #8b70b7;
  --nonmetal: #5b9bd5;
  --halogen: #d8b23f;
  --noble: #6678c7;
  --lanthanide: #d77aa3;
  --actinide: #b06f45;
  --unknown: #92978f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0)),
    radial-gradient(circle at 20% 12%, rgba(73, 168, 157, 0.18), transparent 34%),
    radial-gradient(circle at 76% 20%, rgba(217, 95, 89, 0.15), transparent 30%),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  align-items: end;
  gap: 24px;
  padding: 28px clamp(18px, 3vw, 42px) 16px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4.2vw, 4.6rem);
  line-height: 0.98;
}

h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.stats span {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.76);
}

.top-actions {
  display: flex;
  justify-content: end;
}

.language-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.82);
}

.language-switch button {
  min-width: 48px;
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 850;
  cursor: pointer;
}

.language-switch button.is-active {
  background: #1f2a27;
  color: #fffdf8;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  padding: 0 clamp(14px, 3vw, 42px) 34px;
}

.controls {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(220px, 360px) 1fr auto;
  align-items: end;
  gap: 14px;
  padding: 12px 0 4px;
}

.search {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.search input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: var(--panel);
  outline: none;
}

.search input:focus {
  border-color: #49a89d;
  box-shadow: 0 0 0 3px rgba(73, 168, 157, 0.18);
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.filter-chip,
.toggle,
.primary-action {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
  color: var(--ink);
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  cursor: pointer;
}

.filter-chip::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--chip-color);
}

.filter-chip.is-active {
  border-color: #1f2a27;
  background: #1f2a27;
  color: #fffdf8;
}

.toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 10px;
  color: var(--muted);
  white-space: nowrap;
}

.table-wrap {
  overflow: auto;
  padding-bottom: 10px;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: #bdb4a7 transparent;
}

.periodic-table {
  display: grid;
  grid-template-columns: repeat(18, minmax(64px, 1fr));
  grid-auto-rows: minmax(72px, auto);
  min-width: 1180px;
  gap: 6px;
  align-items: stretch;
}

.element {
  position: relative;
  display: grid;
  grid-template-rows: 16px 1fr auto;
  min-height: 72px;
  border: 1px solid color-mix(in srgb, var(--cat-color), #151515 8%);
  border-radius: 8px;
  padding: 6px;
  color: #151515;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.76), rgba(255, 255, 255, 0.45)),
    color-mix(in srgb, var(--cat-color), white 55%);
  box-shadow: 0 8px 20px rgba(42, 39, 31, 0.08);
  cursor: pointer;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    opacity 160ms ease;
}

.element:hover,
.element:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(42, 39, 31, 0.16);
  outline: none;
}

.element.is-selected {
  border-color: #151515;
  box-shadow: 0 0 0 3px rgba(32, 35, 31, 0.18), 0 16px 28px rgba(42, 39, 31, 0.15);
}

.element.is-found {
  border-color: #2f8b58;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.34)),
    #bfe9cc;
}

.element.is-found::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2f8b58;
}

.element.is-dimmed {
  opacity: 0.2;
}

.number {
  color: rgba(21, 21, 21, 0.68);
  font-size: 0.68rem;
  font-weight: 800;
}

.symbol {
  align-self: center;
  font-size: 1.55rem;
  font-weight: 900;
  line-height: 1;
}

.name {
  overflow: hidden;
  color: rgba(21, 21, 21, 0.72);
  font-size: 0.72rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.periodic-table.hide-names .name {
  display: none;
}

.side-panel {
  display: grid;
  grid-template-columns: minmax(300px, 1.2fr) repeat(2, minmax(260px, 1fr));
  align-content: start;
  gap: 14px;
}

.element-card,
.quiz-card,
.guide {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
}

.detail-head {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}

.detail-symbol {
  display: grid;
  place-items: center;
  width: 86px;
  height: 86px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.66), rgba(255, 255, 255, 0.24)),
    var(--cat-color);
  color: #151515;
  font-size: 2.45rem;
  font-weight: 950;
}

.detail-name {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.12;
}

.detail-english {
  margin: 4px 0 0;
  color: var(--muted);
}

.data-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 14px;
}

.datum {
  border: 1px solid #ebe3d6;
  border-radius: 8px;
  padding: 9px;
  background: rgba(255, 255, 255, 0.56);
}

.datum span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
}

.datum strong {
  display: block;
  margin-top: 3px;
  font-size: 0.98rem;
}

.common-form {
  margin-top: 12px;
}

.common-form strong {
  line-height: 1.55;
}

.summary {
  margin-bottom: 0;
  color: #42473f;
  line-height: 1.62;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.quiz-question {
  margin-bottom: 12px;
  color: #42473f;
  line-height: 1.5;
}

.quiz-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.quiz-option {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 850;
  cursor: pointer;
}

.quiz-option.correct {
  border-color: #2f8b58;
  background: #dff2e7;
}

.quiz-option.wrong {
  border-color: #bd4542;
  background: #f8ddda;
}

.quiz-feedback {
  min-height: 22px;
  margin: 10px 0;
  color: var(--muted);
  font-weight: 750;
}

.primary-action {
  width: 100%;
  padding: 10px 12px;
  background: #1f2a27;
  color: #fffdf8;
  cursor: pointer;
}

.guide ul {
  margin: 0;
  padding-left: 18px;
  color: #42473f;
  line-height: 1.7;
}

.game-zone {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(320px, 1.2fr);
  gap: 16px;
  align-items: stretch;
  border: 1px solid color-mix(in srgb, var(--line), #6678c7 28%);
  border-radius: 8px;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(102, 120, 199, 0.13), rgba(73, 168, 157, 0.12)),
    rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
}

.game-copy p:last-child {
  margin-bottom: 0;
  color: #42473f;
  line-height: 1.62;
}

.game-panel {
  display: grid;
  gap: 12px;
  border: 1px solid rgba(216, 208, 196, 0.9);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 253, 248, 0.92);
}

.game-score {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 1.1rem;
  font-weight: 900;
}

.game-input-label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.game-input-label input {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: #fffdf8;
  outline: none;
}

.game-input-label input:focus {
  border-color: #6678c7;
  box-shadow: 0 0 0 3px rgba(102, 120, 199, 0.16);
}

.game-feedback {
  min-height: 24px;
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.game-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.game-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 13px;
  background: #fffdf8;
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.game-button.primary {
  border-color: #1f2a27;
  background: #1f2a27;
  color: #fffdf8;
}

.found-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 34px;
}

.found-chip {
  border: 1px solid #b9dcc5;
  border-radius: 999px;
  padding: 5px 8px;
  background: #e7f6ec;
  color: #244f35;
  font-size: 0.78rem;
  font-weight: 850;
}

.learning-lab {
  display: grid;
  gap: 14px;
  border-top: 1px solid rgba(216, 208, 196, 0.8);
  padding-top: 6px;
}

.learning-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
}

.source-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--ink);
  background: rgba(255, 253, 248, 0.9);
  font-size: 0.9rem;
  font-weight: 800;
  text-decoration: none;
}

.learning-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.study-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
}

.study-card h3 {
  margin: 0 0 10px;
  font-size: 1.08rem;
}

.study-card p,
.study-card li {
  color: #42473f;
  line-height: 1.62;
}

.study-card ul {
  margin: 0;
  padding-left: 18px;
}

.study-card .mini-table {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.mini-row {
  display: grid;
  grid-template-columns: minmax(82px, 0.8fr) minmax(0, 1.8fr);
  gap: 10px;
  border: 1px solid #ebe3d6;
  border-radius: 8px;
  padding: 9px;
  background: rgba(255, 255, 255, 0.55);
}

.mini-row strong {
  color: var(--ink);
}

.formula {
  font-weight: 900;
}

.ad-zone {
  display: grid;
  gap: 14px;
  margin-top: 6px;
  padding: 22px;
  border: 1px solid color-mix(in srgb, var(--line), #49a89d 25%);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(73, 168, 157, 0.14), rgba(216, 178, 63, 0.12)),
    rgba(255, 253, 248, 0.92);
  box-shadow: var(--shadow);
}

.ad-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
}

.ad-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.ad-card {
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: 100%;
  border: 1px solid rgba(216, 208, 196, 0.9);
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 253, 248, 0.92);
}

.ad-card h3 {
  margin: 0;
  font-size: 1.45rem;
}

.ad-card p {
  margin-bottom: 0;
  color: #42473f;
  line-height: 1.62;
}

.ad-card ul {
  margin: 0;
  padding-left: 18px;
  color: #42473f;
  line-height: 1.7;
}

.ad-badge {
  width: fit-content;
  border-radius: 999px;
  padding: 6px 10px;
  color: #151515;
  background: #e8f2ef;
  font-size: 0.78rem;
  font-weight: 900;
}

.notes-ad .ad-badge {
  background: #f3e8bd;
}

.ad-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.ad-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 8px;
  padding: 10px 13px;
  font-weight: 900;
  text-decoration: none;
}

.ad-button.primary {
  border: 1px solid #1f2a27;
  background: #1f2a27;
  color: #fffdf8;
}

.ad-button.secondary {
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
}

.partner-zone {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: center;
  margin-top: 8px;
  border: 1px solid #dde4e8;
  border-radius: 8px;
  padding: clamp(22px, 3vw, 34px);
  background:
    linear-gradient(135deg, rgba(102, 120, 199, 0.09), rgba(255, 255, 255, 0.75) 46%),
    rgba(255, 255, 255, 0.92);
  box-shadow: 0 22px 54px rgba(38, 47, 54, 0.1);
}

.partner-copy {
  display: grid;
  gap: 14px;
}

.partner-badge {
  width: fit-content;
  border-radius: 999px;
  padding: 8px 12px;
  background: #e7f4ee;
  color: #2b6b5c;
  font-size: 0.9rem;
  font-weight: 950;
}

.partner-copy h2 {
  font-size: clamp(1.32rem, 2.3vw, 1.85rem);
}

.partner-copy p {
  max-width: 900px;
  margin-bottom: 0;
  color: #5c6670;
  font-size: clamp(1rem, 1.7vw, 1.25rem);
  font-weight: 750;
  line-height: 1.62;
}

.partner-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  border-radius: 8px;
  padding: 14px 24px;
  background: #347d72;
  color: #ffffff;
  font-size: clamp(1rem, 1.5vw, 1.22rem);
  font-weight: 950;
  text-decoration: none;
  white-space: nowrap;
}

.legal-zone {
  display: grid;
  gap: 14px;
  margin-top: 4px;
  border-top: 1px solid var(--line);
  padding: 20px 0 4px;
}

.legal-brand {
  display: block;
}

.legal-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.legal-card {
  border: 1px solid rgba(216, 208, 196, 0.86);
  border-radius: 8px;
  padding: 0;
  background: rgba(255, 253, 248, 0.74);
  overflow: hidden;
}

.legal-card summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 13px 14px;
  color: var(--ink);
  font-size: 0.98rem;
  font-weight: 900;
  cursor: pointer;
  list-style: none;
}

.legal-card summary::-webkit-details-marker {
  display: none;
}

.legal-card summary::after {
  content: "+";
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-weight: 900;
}

.legal-card[open] summary {
  border-bottom: 1px solid rgba(216, 208, 196, 0.86);
}

.legal-card[open] summary::after {
  content: "-";
}

.legal-card p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.58;
}

.legal-card p {
  padding: 13px 14px 14px;
}

.footer-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 28px;
  margin-top: 6px;
  padding: 22px 30px;
  background: #12323d;
  color: #d5e2e4;
  font-size: clamp(1rem, 2vw, 1.42rem);
  font-weight: 750;
}

.footer-bar strong {
  color: #ffffff;
  font-weight: 950;
}

@media (max-width: 1020px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .stats {
    grid-column: 1 / -1;
    justify-content: start;
  }

  .controls {
    grid-template-columns: minmax(220px, 320px) 1fr;
  }

  .toggle {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .learning-grid {
    grid-template-columns: 1fr;
  }

  .game-zone {
    grid-template-columns: 1fr;
  }

  .ad-grid {
    grid-template-columns: 1fr;
  }

  .legal-grid {
    grid-template-columns: 1fr;
  }

  .partner-zone {
    grid-template-columns: 1fr;
  }

  .partner-button {
    justify-self: start;
  }
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 14px;
    padding-top: 22px;
  }

  h1 {
    font-size: clamp(2.05rem, 13vw, 3.2rem);
  }

  .stats {
    justify-content: start;
    font-size: 0.84rem;
  }

  .top-actions {
    justify-content: start;
  }

  .language-switch {
    width: min(100%, 310px);
  }

  .controls {
    grid-template-columns: 1fr;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 10px 0;
    background:
      linear-gradient(120deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.76)),
      var(--bg);
    backdrop-filter: blur(12px);
  }

  .segmented {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  .filter-chip {
    flex: 0 0 auto;
    min-height: 40px;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .periodic-table {
    min-width: 930px;
    grid-template-columns: repeat(18, 48px);
    grid-auto-rows: minmax(62px, auto);
    gap: 5px;
  }

  .element {
    min-height: 62px;
    padding: 5px;
  }

  .symbol {
    font-size: 1.28rem;
  }

  .name {
    font-size: 0.64rem;
  }

  .element-card,
  .quiz-card,
  .guide {
    padding: 14px;
  }

  .detail-head {
    grid-template-columns: 72px 1fr;
  }

  .detail-symbol {
    width: 72px;
    height: 72px;
    font-size: 2rem;
  }

  .data-grid {
    grid-template-columns: 1fr;
  }

  .learning-header {
    display: grid;
    align-items: start;
  }

  .source-link {
    justify-self: start;
  }

  .study-card {
    padding: 14px;
  }

  .game-zone {
    padding: 14px;
  }

  .game-actions {
    display: grid;
  }

  .game-button {
    width: 100%;
  }

  .mini-row {
    grid-template-columns: 1fr;
  }

  .ad-zone {
    padding: 14px;
  }

  .ad-heading {
    display: grid;
    align-items: start;
  }

  .ad-card {
    padding: 14px;
  }

  .ad-actions {
    display: grid;
  }

  .ad-button {
    width: 100%;
  }

  .footer-bar {
    gap: 10px;
    padding: 18px 16px;
    font-size: 1rem;
  }

  .partner-button {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .workspace {
    padding-inline: 12px;
  }

  .topbar {
    padding-inline: 12px;
  }

  .stats span {
    padding: 7px 8px;
  }
}
