:root {
  --bg: #eef3f0;
  --panel: #ffffff;
  --ink: #17211c;
  --muted: #65716a;
  --line: #cdd8d1;
  --accent: #0b7c86;
  --accent-dark: #075a61;
  --good: #247a45;
  --warn: #9a5b00;
  --bad: #b02a37;
  --metal: #e5f1fb;
  --nonmetal: #e7f6dc;
  --noble: #efe7fb;
  --alkali: #ffe7d1;
  --alkaline: #fff0bb;
  --metalloid: #d8f1ed;
  --halogen: #fce1ec;
  --transition: #e9edf5;
  --lanthanide: #e4f4ff;
  --actinide: #f4e6df;
  --selected: #ffd166;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 0%, rgba(11, 124, 134, 0.13), transparent 32rem),
    linear-gradient(135deg, #eef3f0 0%, #f7faf8 48%, #eef1f7 100%);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.6rem, 3vw, 2.8rem);
  line-height: 1.05;
}

h2 {
  margin-bottom: 8px;
  font-size: 1.2rem;
}

.scoreboard {
  display: grid;
  min-width: 104px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: center;
  box-shadow: 0 8px 24px rgba(23, 33, 28, 0.08);
}

.scoreboard span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.scoreboard strong {
  font-size: 1.7rem;
}

.workspace {
  display: grid;
  grid-template-columns: 310px minmax(780px, 1fr);
  gap: 18px;
  align-items: stretch;
}

.challenge-panel,
.molecule-panel {
  min-height: 640px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 12px 36px rgba(23, 33, 28, 0.08);
}

.compound-title {
  margin-top: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.player-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbf9;
}

.player-panel label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.player-row {
  display: grid;
  grid-template-columns: 1fr 78px;
  gap: 8px;
}

.player-row input {
  min-width: 0;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  font: inherit;
  font-weight: 750;
}

.player-row input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(11, 124, 134, 0.16);
}

.compact-btn {
  min-height: 40px;
}

.full-btn {
  width: 100%;
  margin-top: 10px;
}

.record-banner {
  margin-top: 12px;
  padding: 10px;
  border-radius: 8px;
  background: #fff7d8;
  color: #735000;
  font-weight: 900;
  line-height: 1.35;
}

.leaderboard {
  display: grid;
  gap: 6px;
  margin: 12px 0 0;
  padding-left: 22px;
}

.leaderboard li {
  padding: 6px 8px;
  border-radius: 6px;
  background: white;
  color: var(--ink);
  font-weight: 800;
}

.leaderboard .empty-rank {
  color: var(--muted);
  list-style: none;
}

.compound-title span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #dff2f4;
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 800;
}

.compound-title h2 {
  margin-top: 12px;
  font-size: 1.55rem;
}

.compound-title p {
  margin-bottom: 0;
  color: var(--accent-dark);
  font-size: 2rem;
  font-weight: 900;
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.mode-tab {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  cursor: pointer;
  font-weight: 850;
}

.mode-tab.active {
  border-color: var(--accent);
  background: #dff2f4;
  color: var(--accent-dark);
}

.target-box,
.selected-box {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbf9;
}

.target-box p,
.selected-head p {
  margin-bottom: 10px;
  color: var(--muted);
  font-weight: 800;
}

.selected-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.atom-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 34px;
  align-items: center;
}

.atom-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #edf6f4;
  color: var(--ink);
  font-weight: 850;
}

.empty {
  color: var(--muted);
  font-weight: 700;
}

.feedback {
  min-height: 76px;
  margin-top: 18px;
  padding: 14px;
  border-radius: 8px;
  background: #eef6f4;
  color: var(--accent-dark);
  font-weight: 800;
  line-height: 1.4;
}

.feedback.good {
  background: #e1f4e8;
  color: var(--good);
}

.feedback.bad {
  background: #fde7e9;
  color: var(--bad);
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.primary-btn,
.secondary-btn,
.icon-btn {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 850;
}

.primary-btn {
  background: var(--accent);
  color: white;
}

.secondary-btn {
  border-color: var(--line);
  background: white;
  color: var(--ink);
}

.icon-btn {
  width: 38px;
  min-height: 38px;
  border-color: var(--line);
  background: white;
  color: var(--accent-dark);
  font-size: 1.1rem;
}

.periodic-area {
  overflow: auto;
  min-height: 640px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 12px 36px rgba(23, 33, 28, 0.07);
}

.molecule-panel {
  grid-column: 2;
  min-height: auto;
}

.element-info {
  display: grid;
  grid-template-columns: minmax(220px, 0.65fr) 1fr minmax(220px, 0.8fr);
  gap: 14px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbf9;
}

.atom-model {
  width: 100%;
  min-height: 170px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 50%, rgba(11, 124, 134, 0.16), transparent 62%),
    #ffffff;
}

.element-info-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.element-info-main > span {
  display: grid;
  place-items: center;
  width: 66px;
  height: 66px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: var(--nonmetal);
  color: var(--ink);
  font-size: 2rem;
  font-weight: 950;
}

.element-info-main h2 {
  margin-bottom: 0;
  font-size: 1.45rem;
}

.element-facts {
  display: grid;
  grid-template-columns: repeat(6, minmax(82px, 1fr));
  gap: 8px;
  margin: 0;
}

.element-facts div {
  min-width: 0;
  padding: 8px;
  border-radius: 6px;
  background: white;
}

.element-facts dt {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 850;
}

.element-facts dd {
  margin: 3px 0 0;
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 900;
}

.periodic-table {
  display: grid;
  grid-template-columns: repeat(18, minmax(44px, 1fr));
  grid-auto-rows: 58px;
  gap: 6px;
  min-width: 980px;
}

.element {
  position: relative;
  display: grid;
  align-content: center;
  justify-items: center;
  border: 1px solid rgba(23, 33, 28, 0.15);
  border-radius: 6px;
  background: var(--metal);
  color: var(--ink);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.element:hover,
.element:focus-visible {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 8px 16px rgba(23, 33, 28, 0.12);
  outline: none;
}

.element.selected {
  border-color: #bc8500;
  background: var(--selected);
}

.element.answer-selected {
  border-color: var(--accent);
  background: #bfeaf0;
  box-shadow: inset 0 0 0 2px rgba(11, 124, 134, 0.25);
}

.element.target-element {
  border-color: var(--bad);
  box-shadow: inset 0 0 0 2px rgba(176, 42, 55, 0.2);
}

.element .number {
  position: absolute;
  top: 4px;
  left: 5px;
  color: rgba(23, 33, 28, 0.72);
  font-size: 0.63rem;
  font-weight: 800;
}

.element .symbol {
  font-size: 1.08rem;
  font-weight: 950;
}

.element .name {
  width: 100%;
  padding: 0 4px;
  overflow: hidden;
  color: rgba(23, 33, 28, 0.78);
  font-size: 0.58rem;
  font-weight: 700;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nonmetal {
  background: var(--nonmetal);
}

.noble {
  background: var(--noble);
}

.alkali {
  background: var(--alkali);
}

.alkaline {
  background: var(--alkaline);
}

.metalloid {
  background: var(--metalloid);
}

.halogen {
  background: var(--halogen);
}

.transition {
  background: var(--transition);
}

.lanthanide {
  background: var(--lanthanide);
}

.actinide {
  background: var(--actinide);
}

.viewer-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #f0f4f2;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.status-pill.done {
  background: #e1f4e8;
  color: var(--good);
}

#moleculeView {
  width: 100%;
  height: min(52vh, 420px);
  min-height: 310px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(205, 216, 209, 0.28) 1px, transparent 1px),
    linear-gradient(90deg, rgba(205, 216, 209, 0.28) 1px, transparent 1px),
    #fbfdfc;
  background-size: 32px 32px;
}

.molecule-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.45;
}

.bond {
  stroke: #8a9690;
  stroke-width: 8;
  stroke-linecap: round;
}

.bond-orbital {
  fill: rgba(11, 124, 134, 0.18);
  stroke: rgba(11, 124, 134, 0.2);
  stroke-width: 2;
}

.interactive-orbital {
  cursor: zoom-in;
}

.interactive-orbital:hover,
.interactive-orbital:focus {
  stroke-width: 4;
  outline: none;
}

.electron-dot {
  fill: #113f67;
  stroke: #ffffff;
  stroke-width: 1.5;
}

.valence-orbit {
  fill: none;
  stroke: rgba(17, 63, 103, 0.28);
  stroke-width: 2;
}

.nucleus {
  fill: #e84c4f;
  stroke: rgba(23, 33, 28, 0.24);
  stroke-width: 3;
}

.electron-cloud {
  fill: rgba(36, 122, 69, 0.12);
  stroke: rgba(36, 122, 69, 0.28);
  stroke-width: 1.5;
}

.orbital-lobe {
  fill: rgba(78, 101, 217, 0.15);
  stroke: rgba(78, 101, 217, 0.25);
  stroke-width: 1.5;
}

.proton {
  fill: #e84c4f;
}

.neutron {
  fill: #8a9690;
}

.partial-charge {
  fill: #075a61;
  font-size: 14px;
  font-weight: 950;
  text-anchor: middle;
}

.orbital-modal[hidden] {
  display: none;
}

.orbital-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(23, 33, 28, 0.42);
}

.orbital-dialog {
  position: relative;
  width: min(860px, 100%);
  max-height: calc(100vh - 44px);
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 24px 70px rgba(23, 33, 28, 0.28);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1;
}

.orbital-zoom {
  width: 100%;
  min-height: 330px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 50%, rgba(11, 124, 134, 0.12), transparent 58%),
    #fbfdfc;
}

.nucleus-label,
.shell-label {
  fill: #17211c;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: central;
}

.shell-line {
  fill: none;
  stroke: rgba(11, 124, 134, 0.32);
  stroke-width: 2;
}

.mixture-ring {
  fill: none;
  stroke: rgba(11, 124, 134, 0.18);
  stroke-width: 3;
  stroke-dasharray: 10 8;
}

.atom-circle {
  stroke: rgba(23, 33, 28, 0.24);
  stroke-width: 3;
}

.atom-label {
  fill: #17211c;
  font-size: 22px;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: central;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 300px 1fr;
  }

  .molecule-panel {
    grid-column: 1 / -1;
    min-height: auto;
  }

  .element-info {
    grid-template-columns: 1fr;
  }

  .element-facts {
    grid-template-columns: repeat(3, minmax(92px, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .scoreboard {
    width: 100%;
  }

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

  .challenge-panel,
  .molecule-panel,
  .periodic-area {
    min-height: auto;
  }

  .periodic-table {
    grid-template-columns: repeat(18, 48px);
  }

  .element-facts {
    grid-template-columns: repeat(2, minmax(100px, 1fr));
  }
}
