:root {
  color-scheme: light;
  font-family:
    Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system,
    sans-serif;
  color: #182338;
  background: #f4f7fb;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 0;
  min-height: 100%;
  margin: 0;
  overflow-x: clip;
}

body {
  background:
    radial-gradient(circle at 10% 5%, rgb(104 151 255 / 13%), transparent 28rem),
    radial-gradient(circle at 90% 24%, rgb(99 199 177 / 12%), transparent 26rem),
    #f4f7fb;
}

button,
input {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.like-terms-shell {
  width: min(100%, 1500px);
  min-width: 0;
  margin: 0 auto;
  padding:
    max(1rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1.5rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
}

.like-terms-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  min-width: 0;
  margin: 0.9rem 0 1.2rem;
}

.like-terms-header > div {
  min-width: 0;
}

.eyebrow,
.subtitle,
.local-note,
.state-question,
.state-formula,
.count-caption,
.separation-note,
.comparison-label,
.comparison-formula,
.insight-text {
  margin: 0;
}

.eyebrow {
  color: #3d5c92;
  font-size: clamp(0.78rem, 1.4vw, 0.98rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  max-width: 26ch;
  margin: 0.35rem 0 0.32rem;
  font-size: clamp(1.75rem, 3.5vw, 3.45rem);
  line-height: 1.04;
  letter-spacing: -0.04em;
  overflow-wrap: anywhere;
}

.subtitle {
  color: #3d5c92;
  font-size: clamp(1rem, 1.8vw, 1.3rem);
  font-weight: 750;
}

.local-note {
  flex: 0 0 auto;
  padding: 0.55rem 0.8rem;
  border: 1px solid #c9d8ed;
  border-radius: 999px;
  color: #47607e;
  background: rgb(255 255 255 / 72%);
  font-size: 0.86rem;
  font-weight: 700;
  white-space: nowrap;
}

.local-note span {
  color: #2c9c79;
}

.like-terms-board {
  --merge-shift: 0px;
  --merge-gap: 1;
  display: grid;
  min-width: 0;
  min-height: clamp(26rem, 54vh, 42rem);
  place-items: center;
  padding: clamp(1rem, 3vw, 2.5rem);
  overflow: hidden;
  border: 1px solid #d8e2f0;
  border-radius: clamp(1.25rem, 3vw, 2.2rem);
  background:
    linear-gradient(rgb(255 255 255 / 88%), rgb(255 255 255 / 88%)),
    linear-gradient(135deg, #eaf1ff, #ebfaf5);
  box-shadow: 0 1.2rem 3rem rgb(55 79 116 / 11%);
}

.state-panel {
  width: min(100%, 1220px);
  min-width: 0;
  text-align: center;
}

.irritation-panel {
  display: grid;
  gap: clamp(1.5rem, 4vw, 3rem);
  place-items: center;
}

.irritation-formulas {
  display: grid;
  gap: 0.65rem;
}

.irritation-formulas p,
.state-formula {
  color: #182338;
  font-size: clamp(2rem, 6vw, 5.3rem);
  font-weight: 820;
  letter-spacing: -0.045em;
  line-height: 1;
}

.irritation-formulas p {
  margin: 0;
}

.irritation-formulas p:last-child {
  color: #4d5b70;
}

.state-question {
  max-width: 42ch;
  color: #3e4f68;
  font-size: clamp(1.08rem, 2.2vw, 1.55rem);
  font-weight: 680;
  line-height: 1.35;
}

.state-formula {
  margin-bottom: clamp(2rem, 5vw, 4rem);
}

.result-formula {
  color: #295f92;
}

.group-equation,
.explore-summands {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(0.7rem, 3vw, 2.4rem);
  min-width: 0;
}

.term-group,
.explore-group {
  display: grid;
  min-width: 0;
  gap: 0.65rem;
  justify-items: center;
}

.group-label {
  color: #52647d;
  font-size: clamp(0.82rem, 1.5vw, 1.02rem);
  font-weight: 780;
}

.block-row,
.mixed-block-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(0.3rem, 0.8vw, 0.65rem);
  min-width: 0;
  max-width: 100%;
}

.algebra-block {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border: 2px solid;
  box-shadow:
    inset 0 0 0 1px rgb(255 255 255 / 35%),
    0 0.35rem 0.8rem rgb(53 73 104 / 13%);
  font-size: clamp(1.05rem, 2.7vw, 1.9rem);
  font-weight: 850;
  line-height: 1;
  user-select: none;
}

.x-block {
  inline-size: clamp(2.6rem, 10vw, 5.5rem);
  block-size: clamp(2.1rem, 6vw, 4rem);
  border-color: #346db1;
  border-radius: clamp(0.55rem, 1.4vw, 0.95rem);
  color: #173f71;
  background: linear-gradient(150deg, #dbeaff, #bcd6fb);
}

.unit-block {
  inline-size: clamp(2.15rem, 6vw, 3.7rem);
  aspect-ratio: 1;
  border-color: #2e8d73;
  border-radius: clamp(0.5rem, 1.2vw, 0.8rem);
  color: #165643;
  background: linear-gradient(150deg, #d8f5eb, #afe2d2);
}

.math-symbol,
.equals-symbol {
  flex: 0 0 auto;
  color: #6a7890;
  font-size: clamp(1.8rem, 4vw, 3rem);
  font-weight: 600;
}

.groups-panel .second-group {
  transform: translateX(0);
}

.groups-panel.is-merging .second-group {
  transform: translateX(var(--merge-shift));
  will-change: transform;
}

.groups-panel.is-merging .merge-plus {
  opacity: var(--merge-gap);
}

.combined-panel,
.counterexample-panel,
.explore-panel {
  display: grid;
  place-items: center;
}

.combined-row {
  margin: 0 auto;
}

.count-caption,
.separation-note {
  margin-top: 1.25rem;
  color: #52647d;
  font-size: clamp(0.95rem, 1.8vw, 1.2rem);
  font-weight: 730;
}

.counterexample-panel .unit-side {
  animation: keep-kinds-apart 1.15s cubic-bezier(0.65, 0, 0.35, 1) both;
}

.separation-note {
  padding: 0.52rem 0.82rem;
  border: 1px solid #cbd8e9;
  border-radius: 999px;
  background: #f8fbff;
}

@keyframes keep-kinds-apart {
  0%,
  100% {
    transform: translateX(0);
  }
  58% {
    transform: translateX(-1rem);
  }
}

.comparison-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(0.9rem, 2.5vw, 1.7rem);
  min-width: 0;
}

.comparison-card {
  display: grid;
  min-width: 0;
  min-height: 20rem;
  align-content: center;
  justify-items: center;
  gap: clamp(1rem, 2.4vw, 1.7rem);
  padding: clamp(1rem, 2.5vw, 2rem);
  border: 2px solid;
  border-radius: 1.35rem;
  background: #fff;
}

.like-card {
  border-color: #a9c9ee;
  background: #f4f8ff;
}

.unlike-card {
  border-color: #bcded5;
  background: #f4fbf8;
}

.comparison-label {
  color: #5c6d84;
  font-size: 0.84rem;
  font-weight: 820;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.comparison-formula {
  font-size: clamp(1.45rem, 3.2vw, 2.5rem);
  font-weight: 820;
  letter-spacing: -0.035em;
}

.mixed-block-row {
  gap: clamp(0.65rem, 2vw, 1.25rem);
}

.kind-divider {
  width: 2px;
  height: clamp(2.8rem, 7vw, 4.5rem);
  border-radius: 99px;
  background: #c8d3e2;
}

.explore-panel .state-formula {
  margin-bottom: clamp(1.25rem, 3vw, 2.2rem);
  font-size: clamp(1.7rem, 4.6vw, 3.8rem);
}

.explore-summands {
  margin-bottom: 1.1rem;
}

.explore-result {
  display: grid;
  gap: 0.6rem;
  min-width: 0;
  justify-items: center;
}

.result-block-row {
  min-height: clamp(2.4rem, 6.5vw, 4rem);
}

.range-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
  width: min(100%, 48rem);
  margin-top: clamp(1.1rem, 3vw, 2rem);
}

.range-control {
  display: grid;
  min-width: 0;
  gap: 0.45rem;
  padding: 0.85rem 1rem;
  border: 1px solid #cad8ea;
  border-radius: 1rem;
  color: #40536f;
  background: rgb(255 255 255 / 84%);
  font-size: 0.9rem;
  font-weight: 720;
  text-align: left;
}

.range-control strong {
  color: #235992;
  font-size: 1.12rem;
}

.range-control input[type="range"] {
  width: 100%;
  min-height: 2.75rem;
  margin: 0;
  accent-color: #2f6fad;
  cursor: pointer;
  touch-action: pan-y;
}

.range-control input[type="range"]:focus-visible {
  outline: 4px solid rgb(57 116 181 / 28%);
  outline-offset: 3px;
}

.range-scale {
  display: flex;
  justify-content: space-between;
  color: #738198;
  font-size: 0.78rem;
}

.conclusion-card {
  width: min(100%, 58rem);
  margin-top: 1.1rem;
  padding: clamp(0.9rem, 2.2vw, 1.5rem);
  border: 2px solid #8eb7e5;
  border-radius: 1.25rem;
  background: linear-gradient(135deg, #edf5ff, #effbf7);
}

.conclusion-card h2 {
  margin: 0;
  color: #1e4d80;
  font-size: clamp(1.25rem, 3vw, 2.15rem);
  line-height: 1.15;
}

.conclusion-card p {
  margin: 0.45rem 0 0;
  color: #405a77;
  font-size: clamp(0.95rem, 1.8vw, 1.18rem);
  font-weight: 680;
}

.like-terms-insight {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-width: 0;
  margin-top: 1rem;
  padding: 1rem clamp(1rem, 2.3vw, 1.5rem);
  border: 1px solid #d8e2ef;
  border-radius: 1.25rem;
  background: rgb(255 255 255 / 88%);
  box-shadow: 0 0.7rem 1.8rem rgb(55 79 116 / 8%);
}

.insight-text {
  min-width: 0;
  color: #2d4565;
  font-size: clamp(1rem, 1.8vw, 1.25rem);
  font-weight: 760;
  line-height: 1.3;
}

.like-terms-controls {
  display: flex;
  flex: 0 0 auto;
  gap: 0.65rem;
}

.primary-button,
.reset-button {
  min-height: 3rem;
  padding: 0.72rem 1.15rem;
  border: 2px solid transparent;
  border-radius: 0.9rem;
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  color: #fff;
  background: #2f6fad;
  box-shadow: 0 0.45rem 1rem rgb(47 111 173 / 24%);
}

.reset-button {
  border-color: #c3d1e3;
  color: #40536f;
  background: #f8fafc;
}

.primary-button:focus-visible,
.reset-button:focus-visible {
  outline: 4px solid rgb(57 116 181 / 28%);
  outline-offset: 3px;
}

button:disabled,
input:disabled {
  cursor: wait;
  opacity: 0.58;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 760px) {
  .like-terms-header,
  .like-terms-insight {
    align-items: stretch;
    flex-direction: column;
  }

  .local-note {
    align-self: flex-start;
  }

  .like-terms-board {
    min-height: 30rem;
  }

  .comparison-grid,
  .range-grid {
    grid-template-columns: 1fr;
  }

  .comparison-card {
    min-height: 14rem;
  }

  .like-terms-controls {
    width: 100%;
  }

  .primary-button,
  .reset-button {
    flex: 1 1 0;
  }
}

@media (max-width: 820px) {
  .explore-summands {
    align-items: center;
    flex-direction: column;
  }

  .explore-summands > .math-symbol {
    line-height: 0.75;
  }
}

@media (max-width: 420px) {
  .like-terms-shell {
    padding-right: max(0.65rem, env(safe-area-inset-right));
    padding-left: max(0.65rem, env(safe-area-inset-left));
  }

  .like-terms-board {
    min-height: 27rem;
    padding: 0.8rem;
    border-radius: 1.1rem;
  }

  .x-block {
    inline-size: 2rem;
    block-size: 1.6rem;
  }

  .unit-block {
    inline-size: 1.55rem;
    block-size: 1.55rem;
  }

  .block-row {
    gap: 0.3rem;
  }

  .group-equation,
  .explore-summands {
    gap: 0.55rem;
  }

  .explore-summands {
    align-items: center;
    flex-direction: column;
  }

  .explore-summands > .math-symbol {
    line-height: 0.75;
  }

  .range-control {
    padding: 0.68rem 0.8rem;
  }
}

@media (max-width: 340px) {
  h1 {
    font-size: 1.48rem;
  }

  .like-terms-header {
    gap: 0.75rem;
  }

  .local-note {
    padding: 0.45rem 0.65rem;
    font-size: 0.75rem;
  }

  .x-block {
    inline-size: 1.75rem;
    block-size: 1.45rem;
    border-width: 1px;
    font-size: 0.96rem;
  }

  .unit-block {
    inline-size: 1.4rem;
    block-size: 1.4rem;
    border-width: 1px;
    font-size: 0.84rem;
  }

  .block-row {
    gap: 0.2rem;
  }

  .group-equation {
    gap: 0.35rem;
  }

  .like-terms-controls {
    flex-direction: column;
  }
}

@media (orientation: portrait) {
  .like-terms-board {
    min-height: min(57rem, 61vh);
  }
}

@media (orientation: landscape) and (max-height: 820px) {
  .like-terms-header {
    margin-top: 0.45rem;
    margin-bottom: 0.7rem;
  }

  .like-terms-board {
    min-height: 22rem;
    padding-block: 0.9rem;
  }

  .state-formula {
    margin-bottom: 1.35rem;
  }

  .comparison-card {
    min-height: 15rem;
  }
}

@media (min-width: 1500px) {
  .like-terms-shell {
    width: min(94vw, 1720px);
  }

  .like-terms-board {
    min-height: 43rem;
  }

  .state-question,
  .insight-text {
    font-size: 1.45rem;
  }
}

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