:root {
  color-scheme: light;
  --bg: #f7f9fc;
  --bg-panel: #ffffff;
  --bg-subtle: #eef5f6;
  --text: #172033;
  --heading: #0c1222;
  --muted: #5f6b7a;
  --muted-strong: #354052;
  --border: #d9e1ea;
  --border-strong: #b9c6d6;
  --primary: #126c7a;
  --primary-dark: #0b4f5b;
  --primary-soft: #e2f5f7;
  --accent: #d94f45;
  --accent-soft: #fff0ee;
  --success: #167a45;
  --warning: #b7791f;
  --danger: #c73535;
  --track: #e8eef5;
  --shadow: 0 18px 44px rgba(23, 32, 51, 0.11);
  --shadow-soft: 0 10px 28px rgba(23, 32, 51, 0.08);
  --radius: 8px;
  --radius-sm: 6px;
  --container: 1120px;
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(rgba(18, 108, 122, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(18, 108, 122, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, #fbfdff 0%, var(--bg) 42%, #edf4f2 100%);
  background-size: 32px 32px, 32px 32px, auto;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
}

body::before {
  position: fixed;
  z-index: -1;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(18, 108, 122, 0.1), transparent 32%),
    linear-gradient(315deg, rgba(217, 79, 69, 0.08), transparent 28%);
  content: "";
  pointer-events: none;
}

button,
input {
  font: inherit;
}

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

a {
  color: var(--primary);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

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

p,
ul {
  margin-bottom: 1rem;
}

ul {
  padding-left: 1.2rem;
}

li + li {
  margin-top: 0.35rem;
}

::selection {
  color: #ffffff;
  background: var(--primary);
}

.page-shell {
  width: min(100% - 48px, var(--container));
  margin: 0 auto;
}

.tool-section {
  padding: 24px 0 72px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 8px 0 48px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--heading);
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: 0;
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--primary-dark);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--primary), var(--primary-dark));
  box-shadow: var(--shadow-soft);
}

.brand-emoji {
  font-size: 0;
  line-height: 1;
}

.brand-emoji::before {
  color: #ffffff;
  content: "A+";
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 950;
  line-height: 1;
}

.site-tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.tool-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.82fr) minmax(420px, 1fr);
  align-items: start;
  gap: 44px;
}

.hero {
  position: sticky;
  top: 28px;
  padding-top: 18px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  margin: 0 0 18px;
  border: 1px solid rgba(18, 108, 122, 0.22);
  border-radius: 999px;
  padding: 4px 12px;
  color: var(--primary-dark);
  background: rgba(226, 245, 247, 0.86);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  max-width: 9ch;
  margin-bottom: 18px;
  color: var(--heading);
  font-size: 4.35rem;
  font-weight: 900;
  line-height: 0.98;
  letter-spacing: 0;
}

.hero-copy {
  max-width: 31rem;
  margin-bottom: 0;
  color: var(--muted-strong);
  font-size: 1.2rem;
  line-height: 1.55;
}

.hero::after {
  display: block;
  width: min(100%, 360px);
  height: 10px;
  margin-top: 34px;
  border-radius: 999px;
  background:
    linear-gradient(90deg, var(--primary) 0 58%, transparent 58% 62%, var(--accent) 62% 78%, transparent 78% 82%, #f4b740 82% 100%);
  content: "";
}

.tool-panel {
  display: grid;
  gap: 20px;
}

.calculator-card,
.result-card,
.explanation-card,
.faq-grid,
.share-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.calculator-card,
.result-card {
  padding: 26px;
}

.card-heading {
  margin-bottom: 20px;
}

.card-heading h2,
.explanation-card h2,
.section-heading h2 {
  margin-bottom: 8px;
  color: var(--heading);
  font-size: 1.55rem;
  font-weight: 850;
  line-height: 1.2;
  letter-spacing: 0;
}

.card-heading p,
.explanation-card p,
.faq-item p,
.site-footer {
  color: var(--muted);
}

.card-heading p {
  margin-bottom: 0;
  font-size: 0.96rem;
}

.grade-form {
  display: grid;
  gap: 14px;
}

.form-message {
  display: none;
  border: 1px solid rgba(199, 53, 53, 0.28);
  border-left: 4px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  color: #982222;
  background: #fff5f4;
  font-size: 0.92rem;
  font-weight: 750;
}

.form-message.is-visible {
  display: block;
}

.field-group {
  display: grid;
  gap: 7px;
}

label {
  color: var(--heading);
  font-size: 0.93rem;
  font-weight: 800;
  line-height: 1.35;
}

.percent-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 52px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fbfdff;
  transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

.percent-input:focus-within {
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(18, 108, 122, 0.14);
}

.field-group.has-error .percent-input {
  border-color: var(--danger);
  background: #fffafa;
}

.field-group.has-error .percent-input:focus-within {
  box-shadow: 0 0 0 4px rgba(199, 53, 53, 0.13);
}

input {
  width: 100%;
  min-width: 0;
  min-height: 50px;
  border: 0;
  border-radius: var(--radius);
  padding: 13px 8px 13px 14px;
  color: var(--heading);
  background: transparent;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  outline: none;
}

input::placeholder {
  color: #8a97a8;
  font-weight: 600;
}

.percent-input span {
  min-width: 42px;
  padding-right: 14px;
  color: var(--muted);
  font-size: 0.96rem;
  font-weight: 850;
  text-align: right;
}

.field-error {
  min-height: 19px;
  margin-bottom: 0;
  color: var(--danger);
  font-size: 0.86rem;
  font-weight: 700;
}

.calculate-button,
.share-button,
.share-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 850;
  letter-spacing: 0;
  transition: transform 160ms ease, box-shadow 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.calculate-button {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--primary-dark);
  padding: 12px 18px;
  color: #ffffff;
  background: linear-gradient(180deg, var(--primary), var(--primary-dark));
  box-shadow: 0 14px 28px rgba(18, 108, 122, 0.24);
  font-size: 1rem;
}

.calculate-button:hover {
  background: linear-gradient(180deg, #157b8b, #0a4650);
  box-shadow: 0 18px 34px rgba(18, 108, 122, 0.28);
  transform: translateY(-1px);
}

.calculate-button:active,
.share-button:active,
.share-action:active,
.share-close:active {
  transform: translateY(0);
}

.calculate-button:focus-visible,
.share-button:focus-visible,
.share-action:focus-visible,
.share-close:focus-visible,
.footer-links a:focus-visible,
.brand:focus-visible {
  outline: 3px solid rgba(18, 108, 122, 0.22);
  outline-offset: 3px;
}

.result-card {
  position: relative;
  border-top: 5px solid var(--tier-color, var(--primary));
  opacity: 0;
  transform: translateY(12px);
}

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

.result-card.is-visible {
  animation: result-enter 360ms ease-out forwards;
}

.result-label {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.result-number {
  margin-bottom: 10px;
  color: var(--tier-color, var(--primary));
  font-size: 3.9rem;
  font-weight: 950;
  line-height: 0.95;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.result-subtitle {
  max-width: 38rem;
  margin-bottom: 6px;
  color: var(--heading);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.55;
}

.result-feedback {
  margin-bottom: 0;
  color: var(--tier-color, var(--primary));
  font-size: 0.98rem;
  font-weight: 850;
}

.result-visual {
  display: grid;
  gap: 16px;
  margin-top: 24px;
  border-top: 1px solid var(--border);
  padding-top: 24px;
}

.result-bar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px 14px;
}

.bar-label {
  color: var(--muted-strong);
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.3;
}

.bar-value {
  color: var(--heading);
  font-size: 0.86rem;
  font-weight: 900;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.bar-track {
  position: relative;
  grid-column: 1 / -1;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--track);
}

.bar-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  transition: width 760ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.bar-fill-current {
  background: linear-gradient(90deg, #19a0a9, var(--primary));
}

.bar-fill-needed {
  position: relative;
  background: var(--bar-needed-color, var(--primary));
}

.bar-fill-needed::after {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0));
  content: "";
}

.bar-fill-target {
  min-width: 2px;
  border-right: 3px dashed var(--accent);
  border-radius: 0;
  background: transparent;
}

.result-bar-row.is-complete .bar-label,
.result-bar-row.is-overflow .bar-label {
  color: var(--bar-needed-color, var(--primary));
}

.result-bar-row.is-complete .bar-track::after {
  position: absolute;
  top: 50%;
  left: 10px;
  color: var(--success);
  content: "✓";
  font-size: 0.86rem;
  font-weight: 900;
  line-height: 1;
  transform: translateY(-50%);
}

.result-bar-row.is-overflow .bar-track::after {
  position: absolute;
  top: 50%;
  right: 0;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 2px solid #ffffff;
  border-radius: 50%;
  color: #ffffff;
  background: var(--danger);
  content: "+";
  font-size: 0.82rem;
  font-weight: 900;
  line-height: 1;
  transform: translateY(-50%);
}

.share-button {
  min-height: 44px;
  margin-top: 24px;
  border: 1px solid rgba(18, 108, 122, 0.25);
  padding: 10px 14px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 0.93rem;
}

.share-button:hover {
  border-color: rgba(18, 108, 122, 0.42);
  background: #d4eef1;
  transform: translateY(-1px);
}

.content-section {
  padding: 72px 0;
}

.explanation-section {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.54));
}

.explanation-card {
  padding: 34px;
}

.explanation-card p:last-child,
.example-box p:last-child,
.faq-item p:last-child {
  margin-bottom: 0;
}

.example-box {
  margin-top: 24px;
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
  background: #f4fbfc;
}

.example-box + .example-box {
  border-left-color: var(--accent);
  background: #fff8f4;
}

.example-box h3 {
  margin-bottom: 8px;
  color: var(--heading);
  font-size: 1.08rem;
  font-weight: 850;
  line-height: 1.3;
}

.formula-line {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--primary-dark);
  background: #ffffff;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.faq-section {
  padding-top: 48px;
}

.section-heading {
  margin-bottom: 22px;
}

.section-heading h2 {
  margin-bottom: 0;
  font-size: 2rem;
}

.faq-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
}

.faq-item {
  min-height: 190px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 22px;
  background: rgba(255, 255, 255, 0.92);
}

.faq-item:nth-child(2n) {
  border-right: 0;
}

.faq-item:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.faq-item:first-child {
  background: linear-gradient(180deg, var(--primary-soft), #ffffff);
}

.faq-item h3 {
  margin-bottom: 8px;
  color: var(--heading);
  font-size: 1rem;
  font-weight: 850;
  line-height: 1.35;
}

.faq-item p {
  font-size: 0.93rem;
  line-height: 1.62;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.76);
}

.footer-shell {
  display: grid;
  grid-template-columns: 1.1fr auto 1fr;
  align-items: center;
  gap: 28px;
  padding-top: 32px;
  padding-bottom: 32px;
}

.site-footer p {
  margin-bottom: 0;
  font-size: 0.92rem;
}

.copyright {
  color: var(--heading);
  font-weight: 850;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
}

.footer-links a {
  color: var(--primary-dark);
  font-size: 0.92rem;
  font-weight: 800;
  text-decoration: none;
}

.footer-links a:hover {
  text-decoration: underline;
}

.footer-note {
  justify-self: end;
  max-width: 24rem;
  text-align: right;
}

.share-modal {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  animation: modal-backdrop-in 180ms ease-out;
}

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

.share-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 18, 34, 0.55);
  backdrop-filter: blur(9px);
}

.share-panel {
  position: relative;
  z-index: 1;
  width: min(100%, 760px);
  max-height: min(92vh, 760px);
  overflow: auto;
  padding: 24px;
  animation: modal-panel-in 180ms ease-out;
}

.share-panel h3 {
  margin: 0 48px 18px 0;
  color: var(--heading);
  font-size: 1.25rem;
  font-weight: 850;
  line-height: 1.25;
}

.share-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted-strong);
  background: #ffffff;
  cursor: pointer;
  font-size: 1.45rem;
  font-weight: 500;
  line-height: 1;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.share-close:hover {
  border-color: var(--border-strong);
  background: var(--primary-soft);
  transform: translateY(-1px);
}

#share-canvas {
  display: block;
  width: 100%;
  max-width: 700px;
  height: auto;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  box-shadow: var(--shadow-soft);
}

.share-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.share-action {
  min-height: 44px;
  border: 1px solid var(--primary-dark);
  padding: 10px 14px;
  color: #ffffff;
  background: var(--primary);
  font-size: 0.93rem;
}

.share-action + .share-action {
  border-color: rgba(18, 108, 122, 0.25);
  color: var(--primary-dark);
  background: var(--primary-soft);
}

.share-action:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.share-action + .share-action:hover {
  background: #d4eef1;
}

.share-status {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--muted-strong);
  font-size: 0.86rem;
  font-weight: 700;
}

@keyframes result-enter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes modal-backdrop-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes modal-panel-in {
  from {
    opacity: 0;
    transform: scale(0.98) translateY(8px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@media (max-width: 980px) {
  .tool-layout {
    grid-template-columns: 1fr;
  }

  .hero {
    position: static;
    max-width: 700px;
    padding-top: 0;
  }

  h1 {
    max-width: 11ch;
    font-size: 3.7rem;
  }

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

  .faq-item,
  .faq-item:nth-child(2n),
  .faq-item:nth-last-child(-n + 2) {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .faq-item:last-child {
    border-bottom: 0;
  }

  .footer-shell {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .footer-note {
    justify-self: center;
    text-align: center;
  }
}

@media (max-width: 700px) {
  .page-shell {
    width: min(100% - 32px, var(--container));
  }

  .tool-section {
    padding-top: 16px;
    padding-bottom: 48px;
  }

  .content-section {
    padding: 48px 0;
  }

  .site-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 42px;
  }

  .tool-layout {
    gap: 28px;
  }

  h1 {
    font-size: 3rem;
  }

  .hero-copy {
    font-size: 1.08rem;
  }

  .calculator-card,
  .result-card,
  .explanation-card,
  .share-panel {
    padding: 22px;
  }

  .result-number {
    font-size: 3rem;
  }

  .section-heading h2 {
    font-size: 1.6rem;
  }

  .faq-item {
    min-height: 0;
    padding: 20px;
  }

  .share-actions {
    display: grid;
  }
}

@media (max-width: 420px) {
  .brand {
    font-size: 0.92rem;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  h1 {
    font-size: 2.55rem;
  }

  .calculator-card,
  .result-card,
  .explanation-card,
  .share-panel {
    padding: 18px;
  }

  .result-number {
    font-size: 2.45rem;
  }

  .result-bar-row {
    gap: 6px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
