:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #637083;
  --line: #dce3ee;
  --accent: #215cff;
  --accent-soft: #e8eeff;
  --good: #0f7a4f;
  --warn: #ad5f00;
  --shadow: 0 20px 60px rgba(23, 32, 51, 0.10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #e9efff, var(--bg) 45%);
  color: var(--text);
}

.app {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0;
}

.hero {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px;
  align-items: stretch;
  margin-bottom: 24px;
}

.eyebrow {
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 10px;
  font-size: 0.8rem;
}

h1, h2 { margin: 0; }

h1 {
  font-size: clamp(2rem, 5vw, 4.6rem);
  line-height: 0.95;
  letter-spacing: -0.06em;
  max-width: 850px;
}

h2 {
  font-size: 1.25rem;
  margin-bottom: 18px;
}

.intro {
  max-width: 780px;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.6;
}

.summary-card, .panel {
  background: rgba(255,255,255,0.82);
  border: 1px solid rgba(255,255,255,0.8);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  border-radius: 28px;
}

.summary-card {
  padding: 26px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 180px;
}

.summary-card span, .summary-card small, article span {
  color: var(--muted);
}

.summary-card strong {
  font-size: 3rem;
  margin: 6px 0;
}

.grid {
  display: grid;
  grid-template-columns: 410px 1fr;
  gap: 24px;
  align-items: start;
}

.panel { padding: 24px; }

.controls {
  position: sticky;
  top: 20px;
}

label {
  display: block;
  font-weight: 700;
  font-size: 0.92rem;
  margin: 14px 0 7px;
}

input, select, button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 13px;
  font: inherit;
  color: var(--text);
  background: #fff;
}

input:focus, select:focus {
  outline: 3px solid var(--accent-soft);
  border-color: var(--accent);
}

.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.check {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 9px;
  align-items: center;
  font-weight: 600;
  color: var(--muted);
  margin-top: 16px;
}

.check input { width: 18px; height: 18px; }

button {
  border: 0;
  background: var(--accent);
  color: white;
  font-weight: 800;
  cursor: pointer;
  margin-top: 16px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

article {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 20px;
  padding: 16px;
  min-height: 112px;
}

article strong {
  display: block;
  font-size: 1.25rem;
  margin-top: 10px;
  letter-spacing: -0.03em;
}

.chart-wrap {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 22px;
  padding: 12px;
  overflow: hidden;
}

canvas { display: block; max-width: 100%; }

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

.table-wrap {
  overflow: auto;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  min-width: 980px;
}

th, td {
  text-align: right;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

th:first-child, td:first-child,
th:nth-child(3), td:nth-child(3) { text-align: left; }

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

.rules {
  margin-top: 24px;
  color: var(--muted);
  line-height: 1.6;
}

.rules h2 { color: var(--text); }

@media (max-width: 980px) {
  .hero, .grid { grid-template-columns: 1fr; }
  .controls { position: static; }
  .cards { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 620px) {
  .two, .cards { grid-template-columns: 1fr; }
  .app { width: min(100% - 20px, 1180px); padding: 18px 0; }
  .panel, .summary-card { border-radius: 20px; padding: 18px; }
}

.hint {
  margin: 0 0 0.75rem;
  color: #637083;
  font-size: 0.92rem;
  line-height: 1.45;
}

.field-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.95rem;
}

.field-label label {
  margin: 0;
}

.tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

.info-button {
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  line-height: 1;
  font-weight: 800;
  display: inline-grid;
  place-items: center;
  padding: 0;
  cursor: help;
}

/* ensure the info-button aligns vertically with surrounding text */
.info-button { vertical-align: middle; }

/* Chart hover tooltip */
.chart-tooltip {
  position: absolute;
  z-index: 2147483647;
  background: #172033;
  color: #fff;
  padding: 10px 12px;
  border-radius: 8px;
  box-shadow: 0 12px 36px rgba(23,32,51,0.32);
  font-size: 0.9rem;
  pointer-events: none;
  min-width: 160px;
}
.chart-tooltip .title { font-weight: 800; margin-bottom: 6px; }
.chart-tooltip .line { display: flex; justify-content: space-between; gap: 12px; color: #bcd0ff; }
.chart-tooltip .muted { color: #9aa6b8; font-weight: 600; }

.info-button:focus-visible {
  outline: 3px solid rgba(33, 92, 255, 0.25);
  outline-offset: 2px;
}

.tooltip-content {
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%) translateY(4px);
  width: min(340px, calc(100vw - 40px));
  background: #172033;
  color: #fff;
  border-radius: 14px;
  padding: 0.85rem 0.95rem;
  box-shadow: 0 16px 42px rgba(23, 32, 51, 0.28);
  font-size: 0.86rem;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.tooltip-content::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: #172033;
}

.tooltip-content a {
  display: inline-block;
  color: #bcd0ff;
  font-weight: 700;
  margin-top: 0.45rem;
}

.tooltip:hover .tooltip-content,
.tooltip:focus-within .tooltip-content {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

/* When the JS tooltip portal is active, hide inline tooltip elements
   to avoid duplicate visible boxes and layout issues. */
.js-tooltip-portal .tooltip-content {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Portal-based tooltip (appended to <body>) */
.tooltip-portal {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2147483647;
  pointer-events: auto;
}

.tooltip-portal .tooltip-portal-content {
  position: absolute;
  left: 0;
  top: 0;
  width: min(340px, calc(100vw - 40px));
  background: #172033;
  color: #fff;
  border-radius: 14px;
  padding: 0.85rem 0.95rem;
  box-shadow: 0 16px 42px rgba(23,32,51,0.28);
  font-size: 0.86rem;
  line-height: 1.45;
  pointer-events: auto;
  transform: none !important;
  opacity: 1 !important;
}

.tooltip-portal .tooltip-portal-content::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: #172033;
}

.tooltip-portal a {
  color: #bcd0ff;
  font-weight: 700;
}

.tooltip-portal a:focus {
  outline: 3px solid rgba(188, 208, 255, 0.55);
  outline-offset: 3px;
}

/* When JS tooltip portal is active, hide the native inline tooltips to avoid duplicates */
.js-tooltip-portal .tooltip .tooltip-content {
  display: none !important;
}

.check {
  align-items: flex-start;
}

.check .tooltip {
  margin-top: 0.05rem;
}

.source-note {
  color: var(--muted);
  margin: 1rem 0 0;
  line-height: 1.55;
}

@media (max-width: 620px) {
  .tooltip-content {
    left: auto;
    right: -0.5rem;
    transform: translateY(4px);
  }

  .tooltip:hover .tooltip-content,
  .tooltip:focus-within .tooltip-content {
    transform: translateY(0);
  }

  .tooltip-content::after {
    left: auto;
    right: 0.75rem;
    transform: none;
  }
}

.check {
  grid-template-columns: 20px minmax(0, 1fr) auto;
}
