:root {
  color-scheme: dark;
  --ink: #f3f8ff;
  --muted: #9eb1c9;
  --deep: #061327;
  --navy: #081d39;
  --panel: rgba(14, 40, 72, 0.82);
  --panel-strong: #102f55;
  --line: rgba(172, 207, 239, 0.18);
  --cyan: #2dd4d7;
  --cyan-dark: #0a747f;
  --blue: #1d75bd;
  --gold: #ffc857;
  --orange: #f58d3d;
  --coral: #ef5d69;
  --green: #62dfa2;
  --danger: #ff8d91;
  --shadow: 0 22px 65px rgba(0, 7, 18, 0.42);
  --radius-lg: 1.5rem;
  --radius-md: 1rem;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--deep);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: ui-rounded, "Avenir Next", "Segoe UI", system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  background:
    radial-gradient(circle at 10% 0%, rgba(45, 212, 215, 0.13), transparent 28rem),
    radial-gradient(circle at 96% 12%, rgba(245, 141, 61, 0.13), transparent 30rem),
    linear-gradient(rgba(83, 135, 181, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(83, 135, 181, 0.045) 1px, transparent 1px),
    linear-gradient(145deg, #061327, #071b35 52%, #06162b);
  background-size: auto, auto, 32px 32px, 32px 32px, auto;
}

button,
summary {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
summary:focus-visible,
.ion-card:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.app-shell {
  width: min(1240px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.25rem 0 3rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  padding: 0.5rem 0 1.1rem;
}

.brand-lockup,
.challenge-actions,
.shelf-heading,
.board-heading,
.board-footer,
.progress-wrap,
.success-card {
  display: flex;
  align-items: center;
}

.brand-lockup {
  gap: 0.85rem;
}

.brand-mark {
  position: relative;
  width: 3.25rem;
  height: 3.25rem;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 1rem;
  background: linear-gradient(135deg, var(--orange) 0 49%, var(--cyan) 51% 100%);
  box-shadow: 0 9px 28px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.brand-mark span {
  position: absolute;
  top: 50%;
  transform: translateY(-51%);
  color: #061327;
  font-weight: 900;
  font-size: 1.45rem;
}

.brand-mark span:first-child { left: 0.58rem; }
.brand-mark span:last-child { right: 0.58rem; }

.eyebrow,
.section-label {
  margin: 0;
  color: var(--cyan);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  line-height: 1.3;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 3vw, 1.85rem);
  line-height: 1.12;
  letter-spacing: -0.035em;
}

h2 {
  margin: 0.25rem 0 0.35rem;
  font-size: clamp(1.8rem, 5vw, 3rem);
  line-height: 1.05;
  letter-spacing: -0.045em;
}

h3 {
  margin: 0.15rem 0 0;
  font-size: 1.25rem;
  line-height: 1.2;
}

.progress-wrap {
  align-items: flex-end;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 13rem;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 700;
}

.progress-track {
  width: 100%;
  height: 0.38rem;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.progress-track span {
  display: block;
  width: 12.5%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), #79efe2);
  transition: width 350ms ease;
}

.challenge-panel,
.ion-shelf,
.bonding-board,
.success-card {
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.challenge-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  padding: 1.35rem 1.5rem;
  border-radius: var(--radius-lg) var(--radius-lg) 0.75rem 0.75rem;
  background:
    linear-gradient(90deg, rgba(45, 212, 215, 0.09), transparent 34%),
    var(--panel);
}

.challenge-copy p:last-child {
  max-width: 48rem;
  margin: 0;
  color: var(--muted);
}

.challenge-copy strong { color: var(--ink); }

.challenge-actions {
  position: relative;
  align-self: flex-start;
  justify-content: flex-end;
  gap: 0.6rem;
  flex: 0 0 auto;
}

.button,
.text-button,
.help-menu summary {
  min-height: 2.75rem;
  border: 0;
  border-radius: 0.75rem;
  cursor: pointer;
  font-weight: 800;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.7rem 1rem;
}

.button svg,
.empty-hint svg,
.success-badge svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.button-quiet,
.help-menu summary {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.button-quiet:hover,
.help-menu summary:hover { background: rgba(255, 255, 255, 0.14); }

.help-menu { position: relative; }

.help-menu summary {
  display: flex;
  align-items: center;
  padding: 0.68rem 1rem;
  list-style: none;
}

.help-menu summary::-webkit-details-marker { display: none; }

.help-card {
  position: absolute;
  z-index: 20;
  top: calc(100% + 0.6rem);
  right: 0;
  width: min(21rem, calc(100vw - 3rem));
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 0.9rem;
  color: var(--muted);
  background: #102d50;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.help-card p { margin-bottom: 0.75rem; }
.help-card p:last-child { margin-bottom: 0; }
.help-card strong { color: var(--ink); }

.ion-shelf {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(3rem, 0.09fr) minmax(0, 1fr);
  gap: 0.9rem;
  margin-top: 0.85rem;
  padding: 1.2rem;
  border-radius: 0.75rem;
  background: rgba(8, 29, 57, 0.82);
}

.shelf-half {
  min-width: 0;
  padding: 0.4rem;
}

.shelf-heading,
.board-heading {
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.charge-key {
  padding: 0.25rem 0.65rem;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.charge-key.positive {
  color: #ffdca0;
  background: rgba(245, 141, 61, 0.16);
}

.charge-key.negative {
  color: #9ff7f0;
  background: rgba(45, 212, 215, 0.14);
}

.shelf-divider {
  display: flex;
  align-items: center;
  justify-content: center;
}

.shelf-divider::before {
  position: absolute;
  top: 1.3rem;
  bottom: 1.3rem;
  width: 1px;
  content: "";
  background: linear-gradient(transparent, var(--line), transparent);
}

.shelf-divider span {
  position: relative;
  display: grid;
  width: 2.35rem;
  height: 2.35rem;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: #0a203d;
  font-weight: 900;
}

.ion-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(7rem, 1fr));
  gap: 0.75rem;
}

.ion-card {
  position: relative;
  display: grid;
  width: 100%;
  min-width: 0;
  min-height: 6.3rem;
  padding: 0;
  border: 0;
  color: #061327;
  background: transparent;
  cursor: grab;
  transition: transform 150ms ease, filter 150ms ease;
  isolation: isolate;
}

.ion-card:hover {
  transform: translateY(-3px);
  filter: brightness(1.07);
}

.ion-card:active {
  transform: translateY(0) scale(0.98);
  cursor: grabbing;
}

.ion-card svg.tile-shape {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 9px 10px rgba(0, 0, 0, 0.22));
}

.ion-card.cation svg.tile-shape { color: var(--orange); }
.ion-card.anion svg.tile-shape { color: var(--cyan); }

.ion-card .tile-sheen {
  opacity: 0.32;
  fill: url(#unused);
}

.ion-card-content {
  position: relative;
  z-index: 1;
  display: grid;
  place-content: center;
  padding: 0.8rem 1.15rem 0.7rem 0.7rem;
  text-align: center;
  pointer-events: none;
}

.ion-card.anion .ion-card-content { padding-left: 1.45rem; padding-right: 0.55rem; }

.ion-symbol {
  display: block;
  font-size: clamp(1.25rem, 2.2vw, 1.65rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.03em;
}

.ion-symbol sub {
  font-size: 0.62em;
  vertical-align: -0.3em;
}

.ion-symbol sup {
  margin-left: 0.05em;
  font-size: 0.58em;
  vertical-align: 0.68em;
}

.ion-name {
  display: block;
  margin-top: 0.42rem;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.15;
}

.ion-count {
  position: absolute;
  z-index: 3;
  top: 0.15rem;
  right: 0.1rem;
  display: none;
  min-width: 1.65rem;
  height: 1.65rem;
  padding: 0 0.35rem;
  place-items: center;
  border: 2px solid #071b35;
  border-radius: 99px;
  color: #071b35;
  background: #fff;
  font-size: 0.75rem;
  font-weight: 900;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
}

.ion-card.has-count .ion-count { display: grid; }

.bonding-board {
  position: relative;
  margin-top: 0.85rem;
  padding: 1.35rem;
  border-radius: 0.75rem var(--radius-lg) var(--radius-lg) var(--radius-lg);
  background:
    radial-gradient(circle at 50% 52%, rgba(45, 212, 215, 0.08), transparent 18rem),
    rgba(7, 25, 49, 0.92);
  overflow: hidden;
}

.bonding-board.drag-over {
  border-color: rgba(45, 212, 215, 0.75);
  box-shadow: var(--shadow), inset 0 0 0 2px rgba(45, 212, 215, 0.25);
}

.text-button {
  padding: 0.45rem 0.7rem;
  color: var(--muted);
  background: transparent;
}

.text-button:hover { color: var(--ink); background: rgba(255,255,255,0.06); }

.drop-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(9rem, 0.46fr) minmax(0, 1fr);
  min-height: 14rem;
  border: 1px dashed rgba(158, 177, 201, 0.28);
  border-radius: 1.15rem;
  background: rgba(3, 16, 34, 0.36);
  overflow: hidden;
}

.selected-zone {
  position: relative;
  min-width: 0;
  padding: 2.6rem 1rem 1rem;
}

.positive-zone {
  background: linear-gradient(90deg, rgba(245, 141, 61, 0.07), transparent);
}

.negative-zone {
  background: linear-gradient(-90deg, rgba(45, 212, 215, 0.07), transparent);
}

.zone-label {
  position: absolute;
  top: 0.7rem;
  left: 1rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.negative-zone .zone-label { right: 1rem; left: auto; }

.selected-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(6.5rem, 1fr));
  gap: 0.65rem;
  align-content: center;
  min-height: 9.2rem;
}

.selected-list .ion-card {
  min-height: 5.35rem;
  cursor: pointer;
}

.selected-list .ion-symbol { font-size: 1.3rem; }
.selected-list .ion-name { display: none; }

.selected-list .ion-card::after {
  position: absolute;
  z-index: 4;
  top: 0.1rem;
  right: 0.05rem;
  display: grid;
  width: 1.35rem;
  height: 1.35rem;
  place-items: center;
  border: 2px solid #071b35;
  border-radius: 50%;
  color: #071b35;
  background: #fff;
  content: "×";
  font-size: 1rem;
  font-weight: 900;
  line-height: 1;
}

.zone-placeholder {
  grid-column: 1 / -1;
  place-self: center;
  color: rgba(158, 177, 201, 0.5);
  font-size: 0.875rem;
  font-weight: 700;
}

.charge-dock {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  gap: 0.7rem;
  min-width: 0;
  padding: 1rem 0.7rem;
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: rgba(5, 22, 43, 0.88);
}

.dock-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.charge-rail {
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
  max-height: 8.8rem;
  overflow: auto;
  scrollbar-width: thin;
}

.charge-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 4.4rem;
  height: 1.1rem;
}

.charge-half {
  position: relative;
  border: 2px solid rgba(255,255,255,0.16);
}

.charge-half.positive {
  border-radius: 99px 0 0 99px;
  background: rgba(245, 141, 61, 0.18);
}

.charge-half.negative {
  border-radius: 0 99px 99px 0;
  background: rgba(45, 212, 215, 0.18);
}

.charge-half.present.positive {
  border-color: var(--orange);
  background: var(--orange);
}

.charge-half.present.negative {
  border-color: var(--cyan);
  background: var(--cyan);
}

.charge-pair.paired .charge-half {
  box-shadow: 0 0 12px rgba(98, 223, 162, 0.24);
}

.charge-pair.paired .charge-half.positive { border-right-color: var(--green); }
.charge-pair.paired .charge-half.negative { border-left-color: var(--green); }

.rail-zero {
  display: grid;
  width: 3.2rem;
  height: 3.2rem;
  place-items: center;
  border: 1px dashed rgba(158,177,201,0.35);
  border-radius: 50%;
  color: rgba(158,177,201,0.7);
  font-weight: 900;
}

.charge-equation {
  padding: 0.38rem 0.62rem;
  border-radius: 0.55rem;
  color: var(--ink);
  background: rgba(255,255,255,0.07);
  font-variant-numeric: tabular-nums;
  font-size: 0.86rem;
  font-weight: 900;
  white-space: nowrap;
}

.charge-equation.balanced { color: var(--green); }
.charge-equation.unbalanced { color: #ffd28c; }

.empty-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.85rem;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 700;
}

.empty-hint[hidden] { display: none; }

.empty-hint svg { width: 1rem; height: 1rem; }

.board-footer {
  justify-content: space-between;
  gap: 1.2rem;
  margin-top: 1.15rem;
}

.feedback {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  color: var(--muted);
}

.feedback p { margin: 0; }

.feedback-icon {
  display: grid;
  width: 1.65rem;
  height: 1.65rem;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(158,177,201,0.4);
  border-radius: 50%;
  font-family: Georgia, serif;
  font-size: 0.9rem;
  font-weight: 800;
}

.feedback.warning { color: #ffd28c; }
.feedback.warning .feedback-icon { border-color: var(--gold); }
.feedback.error { color: var(--danger); }
.feedback.error .feedback-icon { border-color: var(--danger); }

.button-primary {
  min-width: 12rem;
  color: #071b35;
  background: linear-gradient(135deg, #7ef3e6, var(--cyan));
  box-shadow: 0 10px 28px rgba(45, 212, 215, 0.2);
}

.button-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }

.success-card {
  position: relative;
  gap: 1rem;
  margin-top: 0.85rem;
  padding: 1.2rem 1.35rem;
  border-color: rgba(98, 223, 162, 0.4);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(100deg, rgba(98, 223, 162, 0.13), transparent 55%),
    rgba(9, 38, 57, 0.94);
}

.success-card[hidden] { display: none; }

.success-badge {
  display: grid;
  width: 3.2rem;
  height: 3.2rem;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 1rem;
  color: #06291e;
  background: var(--green);
  box-shadow: 0 10px 24px rgba(98, 223, 162, 0.2);
}

.success-badge svg { width: 1.65rem; height: 1.65rem; stroke-width: 3; }

.success-copy { min-width: 0; flex: 1; }

.success-copy h3 {
  margin: 0.15rem 0 0.25rem;
  color: var(--green);
  font-size: clamp(1.7rem, 4vw, 2.4rem);
  letter-spacing: -0.035em;
}

.success-copy h3 sub { font-size: 0.62em; vertical-align: -0.25em; }
.success-copy p:last-child { margin: 0; color: var(--muted); }

.button-next {
  color: #081d39;
  background: var(--green);
}

.button-next:hover { filter: brightness(1.08); }

@media (max-width: 980px) {
  .ion-grid { grid-template-columns: repeat(2, minmax(7rem, 1fr)); }
  .drop-stage { grid-template-columns: minmax(0, 1fr) 8.5rem minmax(0, 1fr); }
  .selected-list { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .app-shell { width: min(100% - 1rem, 42rem); padding-top: 0.6rem; }

  .topbar { align-items: flex-start; gap: 1rem; }
  .progress-wrap { min-width: 7.8rem; font-size: 0.78rem; }

  .challenge-panel {
    align-items: stretch;
    flex-direction: column;
    gap: 1rem;
    padding: 1.1rem;
  }

  .challenge-actions { align-self: stretch; justify-content: space-between; }

  .ion-shelf {
    grid-template-columns: 1fr;
    gap: 0.4rem;
    padding: 0.75rem;
  }

  .shelf-divider { height: 2.2rem; }
  .shelf-divider::before { right: 1rem; left: 1rem; top: auto; bottom: auto; width: auto; height: 1px; }
  .shelf-divider span { width: 2rem; height: 2rem; }
  .shelf-half { padding: 0.55rem; }
  .ion-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.45rem; }
  .ion-card { min-height: 5.4rem; }
  .ion-name { font-size: 0.65rem; }

  .bonding-board { padding: 1rem; }

  .drop-stage {
    grid-template-columns: minmax(0, 1fr) 5.4rem minmax(0, 1fr);
    min-height: 12rem;
  }

  .selected-zone { padding: 2.2rem 0.45rem 0.7rem; }
  .zone-label { left: 0.55rem; font-size: 0.65rem; }
  .negative-zone .zone-label { right: 0.55rem; }
  .selected-list { gap: 0.4rem; min-height: 8rem; }
  .selected-list .ion-card { min-height: 4.6rem; }
  .charge-dock { padding: 0.75rem 0.3rem; }
  .dock-label { font-size: 0; }
  .dock-label::after { content: "Match"; font-size: 0.62rem; }
  .charge-pair { width: 3.2rem; height: 0.86rem; }
  .charge-equation { padding: 0.3rem; font-size: 0.67rem; }

  .board-footer { align-items: stretch; flex-direction: column; }
  .button-primary { width: 100%; }

  .success-card { align-items: flex-start; flex-wrap: wrap; }
  .button-next { width: 100%; }
}

@media (max-width: 460px) {
  .brand-mark { width: 2.8rem; height: 2.8rem; border-radius: 0.85rem; }
  .brand-mark span:first-child { left: 0.48rem; }
  .brand-mark span:last-child { right: 0.48rem; }
  .eyebrow { font-size: 0.66rem; }
  h1 { font-size: 1.2rem; }
  .progress-wrap { min-width: 6.2rem; }

  .button-quiet { padding: 0.65rem 0.8rem; }
  .help-menu summary { padding: 0.65rem 0.8rem; }
  .ion-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
