:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef5f3;
  --ink: #17212b;
  --muted: #657487;
  --line: #d9e1ea;
  --primary: #116d6e;
  --primary-dark: #0b4f53;
  --accent: #eb8a3d;
  --good: #16834a;
  --bad: #c74737;
  --warn: #b86a00;
  --shadow: 0 18px 45px rgba(25, 40, 60, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(17, 109, 110, 0.1), transparent 360px),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 0.72rem 0.92rem;
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
}

button.primary,
.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 1.5rem;
  align-items: end;
  padding: clamp(1.25rem, 4vw, 3rem);
  max-width: 1280px;
  margin: 0 auto;
}

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

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

h1 {
  margin-bottom: 0.85rem;
  font-size: clamp(2rem, 4vw, 4.2rem);
  line-height: 1.02;
  letter-spacing: 0;
  max-width: 900px;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand-icon {
  width: clamp(58px, 7vw, 84px);
  height: clamp(58px, 7vw, 84px);
  flex: 0 0 auto;
  filter: drop-shadow(0 10px 20px rgba(6, 19, 31, 0.18));
}

.brand-title h1 {
  margin-bottom: 0;
}

h2 {
  font-size: clamp(1.45rem, 2.2vw, 2.25rem);
  margin-bottom: 0;
}

h3 {
  margin-bottom: 0.8rem;
  font-size: 1.05rem;
}

.intro {
  margin-top: 1rem;
  max-width: 760px;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.55;
}

.progress-card,
.task-panel,
.side-panel,
.study-tools > section {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.progress-card {
  padding: 1rem;
}

.progress-card span,
.progress-card small {
  display: block;
  color: var(--muted);
}

.progress-card strong {
  display: block;
  margin: 0.35rem 0;
  font-size: 1.25rem;
}

.main-tabs {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 0.55rem;
  overflow-x: auto;
  width: min(1280px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 0.75rem 0;
  background: rgba(245, 247, 251, 0.92);
  backdrop-filter: blur(14px);
  border-block: 1px solid var(--line);
}

.tab {
  white-space: nowrap;
  font-weight: 700;
}

.tab.active {
  color: white;
  background: var(--ink);
  border-color: var(--ink);
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 3rem);
}

.site-footer {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 3rem 2.5rem;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: right;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  margin-bottom: 1rem;
}

.hint,
.large-note {
  max-width: 560px;
  color: var(--primary-dark);
  background: var(--surface-2);
  border-left: 5px solid var(--primary);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  margin: 0;
  line-height: 1.45;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, 0.8fr);
  gap: 1rem;
  align-items: start;
}

.two-columns {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
}

.task-panel,
.side-panel,
.study-tools > section {
  padding: clamp(1rem, 2vw, 1.35rem);
}

.task-text {
  color: #253441;
  font-size: 1.12rem;
  line-height: 1.55;
}

.model-note {
  width: fit-content;
  max-width: 760px;
  margin: -0.35rem 0 0.75rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid #c8e4df;
  border-radius: 8px;
  color: var(--primary-dark);
  background: #f2faf8;
  font-size: 0.9rem;
  line-height: 1.4;
}

.equation-editor,
.equation-display {
  display: flex;
  align-items: stretch;
  gap: 0.7rem;
  flex-wrap: wrap;
  margin: 1rem 0;
}

.equation-side {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  align-items: stretch;
}

.plus {
  display: grid;
  place-items: center;
  align-self: center;
  min-width: 1.2rem;
  color: var(--primary-dark);
  font-size: 1.45rem;
  font-weight: 900;
}

.arrow {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 900;
  min-width: 2.5rem;
  font-size: 1.6rem;
}

.compound-card {
  min-width: 146px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 0.55rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.coefficient-control {
  display: grid;
  grid-template-columns: 34px 44px 34px;
  align-items: center;
  gap: 0.25rem;
}

.coefficient-control button {
  padding: 0;
  height: 34px;
  font-weight: 900;
}

.coefficient-control output {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 900;
}

.molecule {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.18rem;
  flex-wrap: wrap;
}

.molecule-placed {
  position: relative;
  width: 100%;
  min-height: 118px;
}

.atom {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #101820;
  font-size: 0.75rem;
  font-weight: 900;
  border: 2px solid rgba(0, 0, 0, 0.14);
  box-shadow: inset 0 -5px 8px rgba(0, 0, 0, 0.1);
}

.atom-placed {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 2;
}

.atom-core {
  width: 38px;
  height: 38px;
}

.atom-large {
  width: 36px;
  height: 36px;
}

.bond {
  width: 14px;
  height: 3px;
  border-radius: 999px;
  background: #7a8794;
}

.bond-placed {
  position: absolute;
  transform-origin: left center;
  z-index: 1;
}

.bond-placed.double {
  height: 4px;
  box-shadow: 0 6px 0 0 #b7bec7;
}

.bond-placed.ionic {
  background: repeating-linear-gradient(
    90deg,
    #7a8794 0,
    #7a8794 7px,
    transparent 7px,
    transparent 12px
  );
}

.molecule-chain .atom,
.molecule-trigonal .atom,
.molecule-propane .atom,
.molecule-methane .atom,
.molecule-ammonia .atom,
.molecule-linear .atom,
.molecule-chlorate .atom {
  box-shadow:
    inset 0 -6px 10px rgba(0, 0, 0, 0.12),
    0 4px 8px rgba(0, 0, 0, 0.08);
}

.formula {
  text-align: center;
  font-weight: 900;
  font-size: 1.08rem;
}

sub {
  display: inline-block;
  transform: translateY(0.34em);
  font-size: 0.65em;
  line-height: 1;
  vertical-align: baseline !important;
}

.chem-sub {
  display: inline-block;
  transform: translateY(0.36em);
  font-size: 0.65em;
  line-height: 1;
}

.button-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.feedback {
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  min-height: 3rem;
  line-height: 1.45;
}

.feedback.good {
  background: #e8f7ee;
  border-color: #a7d9bc;
  color: #105f35;
}

.feedback.bad {
  background: #fff0ed;
  border-color: #efb3a8;
  color: #933020;
}

.feedback.warn,
.feedback.neutral {
  background: #fff7e8;
  border-color: #f0d09b;
  color: #704100;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 0.7rem 0.55rem;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--muted);
  font-size: 0.82rem;
}

tr.ok td:last-child {
  color: var(--good);
  font-weight: 800;
}

tr.missing td:last-child {
  color: var(--bad);
  font-weight: 800;
}

.given-list {
  display: grid;
  gap: 0.7rem;
  margin: 1rem 0;
}

.given-list div {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 0.7rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.65rem;
}

dt {
  color: var(--muted);
  font-weight: 800;
}

dd {
  margin: 0;
}

.answer-line {
  display: grid;
  grid-template-columns: auto minmax(120px, 220px) auto;
  align-items: center;
  gap: 0.65rem;
  font-weight: 800;
}

.answer-line input,
#calcDisplay {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem 0.85rem;
  background: white;
}

.study-tools {
  display: grid;
  gap: 1rem;
}

.tool-title {
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
  align-items: baseline;
}

.tool-title span {
  color: var(--muted);
  font-size: 0.85rem;
}

.periodic-table {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
  transform-origin: top right;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.periodic-table:hover,
.periodic-table:focus {
  transform: scale(1.08);
  z-index: 2;
}

.element-tile {
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem;
  background: #f8fbfd;
}

.element-tile strong {
  display: block;
  font-size: 1.05rem;
}

.element-tile span,
.element-tile small {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
}

.calculator {
  margin-top: 0.6rem;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}

.calculator button {
  min-height: 42px;
  padding: 0.45rem;
  font-weight: 800;
}

.solution-box {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 8px;
  border: 1px dashed var(--primary);
  background: #effafa;
  line-height: 1.55;
}

.hidden {
  display: none;
}

.badge {
  display: inline-flex;
  width: fit-content;
  margin-bottom: 0.7rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  color: white;
  background: var(--primary-dark);
  font-size: 0.82rem;
  font-weight: 900;
}

.formula-focus {
  display: inline-flex;
  margin: 0.2rem 0 1rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  font-size: 1.5rem;
  font-weight: 900;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-weight: 800;
}

.formula-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  margin-top: 1rem;
}

.formula-grid span {
  display: grid;
  place-items: center;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  font-weight: 900;
}

.basic-tools {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.tool-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  font-weight: 800;
  background: #fbfdff;
}

.tool-toggle::after {
  content: "+";
  font-size: 1.2rem;
  color: var(--primary-dark);
}

.tool-toggle[aria-expanded="true"]::after {
  content: "−";
}

.tool-panel {
  padding: 0.25rem 0 0.2rem;
}

.tool-panel.collapsed {
  display: none;
}

.compact-periodic-table {
  margin-top: 0.85rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
  transform: none;
}

.compact-periodic-table:hover,
.compact-periodic-table:focus {
  transform: none;
}

.compact-periodic-table .element-tile {
  min-height: 60px;
  padding: 0.38rem;
}

.compact-periodic-table .element-tile strong {
  font-size: 0.95rem;
}

.compact-periodic-table .element-tile span,
.compact-periodic-table .element-tile small {
  font-size: 0.68rem;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1rem;
}

.learning-card {
  min-height: 160px;
  padding: 1.2rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.learning-card strong {
  display: block;
  margin-bottom: 0.65rem;
  color: var(--primary-dark);
}

@media (max-width: 900px) {
  .app-header,
  .workspace,
  .two-columns {
    grid-template-columns: 1fr;
  }

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

  .brand-title {
    align-items: flex-start;
  }

  .periodic-table {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .compact-periodic-table {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .app-header,
  main {
    padding-inline: 1rem;
  }

  .main-tabs {
    width: calc(100% - 2rem);
  }

  .site-footer {
    padding-inline: 1rem;
  }

  .brand-title {
    gap: 0.8rem;
  }

  .answer-line,
  .given-list div {
    grid-template-columns: 1fr;
  }

  .periodic-table {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .compact-periodic-table {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .compound-card {
    width: 100%;
  }
}
