* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #687386;
  --line: #e3e8f0;
  --accent: #4f46e5;
  --accent-dark: #3730a3;
  --accent-soft: #eef2ff;
  --surface: #f8faff;
  --danger: #c62828;
}

html {
  background: #fff;
}

body {
  margin: 0;
  padding: 20px;
  background: #fff;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.5;
}

.widget {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: clamp(20px, 5vw, 36px);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 12px 40px rgba(31, 48, 86, 0.07);
}

.eyebrow {
  margin-bottom: 9px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .13em;
}

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

h1 {
  max-width: 560px;
  margin-bottom: 10px;
  font-size: clamp(25px, 5vw, 34px);
  line-height: 1.16;
  letter-spacing: -.035em;
}

.intro {
  margin-bottom: 28px;
  color: var(--muted);
  font-size: 15px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 700;
}

.input-row {
  display: flex;
  gap: 10px;
}

input {
  display: block;
  min-width: 0;
  width: 100%;
  height: 50px;
  padding: 0 15px;
  border: 1px solid #cfd6e3;
  border-radius: 12px;
  outline: none;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 17px;
  transition: border-color .15s, box-shadow .15s;
}

input::placeholder {
  color: #a0a8b7;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}

button {
  flex-shrink: 0;
  min-height: 50px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 750;
  cursor: pointer;
  transition: background .15s, transform .15s;
}

button:hover {
  background: var(--accent-dark);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible {
  outline: 3px solid rgba(79, 70, 229, .28);
  outline-offset: 2px;
}

.field-notes {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 25px;
  padding-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.error {
  color: var(--danger);
  text-align: right;
}

.results {
  margin-top: 22px;
  padding-top: 25px;
  border-top: 1px solid var(--line);
}

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

h2 {
  margin-bottom: 0;
  font-size: 17px;
  letter-spacing: -.015em;
}

.section-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 21px;
  font-weight: 700;
}

.ladder {
  width: fit-content;
  min-width: 200px;
  max-width: 100%;
  margin: 0 auto 25px;
  padding: 15px 24px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.ladder-row {
  display: grid;
  grid-template-columns: minmax(55px, 1fr) 22px 22px;
  align-items: center;
  min-height: 31px;
}

.ladder-number {
  padding-right: 10px;
  text-align: right;
}

.ladder-divider {
  height: 100%;
  border-left: 1px solid #9ca8ba;
}

.ladder-factor {
  padding-left: 7px;
  color: var(--accent);
  font-weight: 800;
}

.ladder-row:last-child .ladder-divider {
  border-left-color: transparent;
}

.answer-card {
  padding: 20px;
  border: 1px solid #dfe4ff;
  border-radius: 16px;
  background: linear-gradient(145deg, #fbfbff, #f6f7ff);
}

.equation {
  margin: 0 0 10px;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: clamp(15px, 3.6vw, 18px);
  font-weight: 650;
  line-height: 1.8;
}

.equation--powers {
  margin-bottom: 17px;
  color: var(--accent-dark);
}

.equation sup {
  position: relative;
  top: -.1em;
  font-size: .7em;
  line-height: 0;
}

.copy-button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid #d7dcf5;
  background: #fff;
  color: var(--accent-dark);
  font-size: 13px;
}

.copy-button:hover {
  background: var(--accent-soft);
}

.copy-status {
  display: inline-block;
  margin-left: 9px;
  color: #28794b;
  font-size: 12px;
}

.widget__footer {
  margin-top: 22px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

[hidden] {
  display: none !important;
}

@media (max-width: 520px) {
  body {
    padding: 10px;
  }

  .widget {
    padding: 22px 17px;
    border-radius: 18px;
  }

  .input-row {
    flex-direction: column;
  }

  .input-row button {
    width: 100%;
  }

  .field-notes {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .error {
    text-align: left;
  }

  .answer-card {
    padding: 16px;
  }

  .ladder {
    padding: 12px 18px;
  }
}
