/* ---------- Playground (/playground/): inputs, summary tiles, SVG chart and yearly table.
   Loaded only by that page, after site.css, whose tokens it uses. */

.playground {
  --field-line: #8C8579; /* input borders, 3.6:1 on white */
  --error: #B42318; /* 6.6:1 on white */
  --kept: #BCDCCF; /* chart colours shared with the landing chart */
  --grid: #EDE9E2;
  padding-block: var(--s-8) var(--s-12);
}
.playground [hidden] { display: none !important; }

/* ---------- head */

.pg-head { max-width: 46rem; }
.pg-head__title {
  font-size: clamp(2rem, 1.4rem + 2vw, 2.75rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
}
.pg-head__lead {
  margin-top: 12px;
  color: var(--muted);
  font-size: var(--fs-lead);
  line-height: 1.5;
}
.pg-head__note {
  margin-top: var(--s-3);
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  font-size: 0.9375rem;
  line-height: 1.5;
}

.pg-layout {
  display: grid;
  grid-template-columns: minmax(0, 24rem) minmax(0, 1fr);
  gap: var(--s-4) clamp(24px, 3.5vw, 48px);
  align-items: start;
  margin-top: var(--s-6);
}

/* ---------- inputs */

.pg-form {
  display: grid;
  gap: var(--s-3);
  padding: clamp(20px, 2.4vw, 28px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.pg-group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.pg-group + .pg-group {
  padding-top: var(--s-3);
  border-top: 1px solid var(--line);
}
/* Floated so the legend sits inside the group, not on its top border. */
.pg-group__title {
  float: left;
  width: 100%;
  margin-bottom: 14px;
  padding: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.pg-group__title + * { clear: both; }

/* Fields sit in two columns; each field spans three rows (label, control, notes) of a
   shared subgrid, so controls in one row line up even when a label wraps. */
.pg-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
}
.pg-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
@supports (grid-template-rows: subgrid) {
  .pg-field {
    display: grid;
    grid-row: span 3;
    grid-template-rows: subgrid;
  }
}
.pg-field--wide { grid-column: 1 / -1; }
.pg-field__label {
  align-self: end;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.3;
}
.pg-field__notes { padding-bottom: 12px; }
.pg-field__hint {
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.4;
}
.pg-field__error {
  margin-top: 4px;
  color: var(--error);
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.4;
}
.pg-field__error:empty { display: none; }

.pg-input { position: relative; }
.pg-input input,
.pg-select {
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 9px 12px;
  border: 1px solid var(--field-line);
  border-radius: 10px;
  background-color: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.pg-input input { padding-right: var(--unit-space, 12px); }
.pg-input--usdc { --unit-space: 58px; }
.pg-input--pct { --unit-space: 32px; }
.pg-input--x { --unit-space: 30px; }
.pg-input--years { --unit-space: 56px; }
.pg-input__unit {
  position: absolute;
  top: 50%;
  right: 12px;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1;
  transform: translateY(-50%);
  pointer-events: none;
}
.pg-select {
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23101418' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
  cursor: pointer;
  appearance: none;
}
.pg-input input:hover:not(:disabled),
.pg-select:hover { border-color: var(--ink); }
.pg-input input:focus-visible,
.pg-select:focus-visible {
  border-color: var(--accent);
  border-radius: 10px;
  outline-offset: 1px;
}
.pg-form input[aria-invalid="true"],
.pg-form select[aria-invalid="true"] {
  border-color: var(--error);
  box-shadow: inset 0 0 0 1px var(--error);
}
.pg-input input:disabled {
  border-color: var(--line-strong);
  background-color: var(--placeholder);
  color: var(--muted);
  cursor: not-allowed;
}

.pg-switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
}
.pg-switch__label {
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.3;
  cursor: pointer;
}
.pg-switch__input {
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  margin: 0;
  border-radius: 999px;
  background: #7D776C;
  cursor: pointer;
  transition: background-color 0.2s var(--ease);
  appearance: none;
}
.pg-switch__input::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(16 20 24 / 0.3);
  transition: transform 0.2s var(--ease);
}
.pg-switch__input:checked { background: var(--accent); }
.pg-switch__input:checked::before { transform: translateX(18px); }
.pg-switch__input:focus-visible { border-radius: 999px; }
.pg-switch__hint { margin: 8px 0 var(--s-2); }

@media (forced-colors: active) {
  .pg-switch__input { border: 1px solid CanvasText; }
  .pg-switch__input::before { background: CanvasText; }
  .pg-switch__input:checked { background: Highlight; }
}

/* ---------- results */

.pg-results { min-width: 0; }
.pg-results__body {
  display: grid;
  gap: var(--s-3);
  transition: opacity 0.2s var(--ease);
}
.pg-results__body.is-stale { opacity: 0.45; }
.no-js .pg-results__body { display: none; }
.pg-notice {
  margin-bottom: var(--s-2);
  padding: 12px 16px;
  border: 1px solid #EFC3BD;
  border-radius: var(--radius);
  background: #FDF3F1;
  font-size: 0.9375rem;
}

.pg-summary {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--line);
}
.pg-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 18px 20px 20px;
  background: var(--surface);
}
.pg-tile :where(dd) { margin: 0; }
.pg-tile--hero {
  grid-row: span 2;
  gap: 6px;
  padding: 24px;
}
.pg-tile__label {
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.35;
}
.pg-tile__value {
  font-size: clamp(1.375rem, 1.15rem + 0.6vw, 1.75rem);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.pg-tile--hero .pg-tile__value {
  font-size: clamp(2.25rem, 1.7rem + 1.6vw, 3rem);
  letter-spacing: -0.04em;
  line-height: 1.05;
}
.pg-tile__unit {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0;
}
.pg-tile__sub {
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.4;
}
.pg-tile__cap {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding-top: var(--s-2);
}
.pg-meter {
  display: block;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--accent-soft);
}
.pg-meter__fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.3s var(--ease);
}

/* ---------- chart */

.pg-chart {
  margin: 0;
  padding: clamp(16px, 2.4vw, 24px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.pg-chart__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
}
.pg-chart__title { font-weight: 600; }
.pg-chart__unit { color: var(--muted); font-size: var(--fs-small); }
.pg-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 0.8125rem;
}
.pg-legend li {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.pg-key {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}
.pg-key--kept { background: var(--kept); }
.pg-key--paid { background: var(--accent); }
.pg-key--hurdle {
  width: 18px;
  height: 2px;
  border-radius: 0;
  background: repeating-linear-gradient(90deg, var(--ink) 0 5px, transparent 5px 8px);
}
.pg-chart__plot {
  position: relative;
  min-height: 224px;
  margin-top: var(--s-2);
}
.pg-chart__plot:focus-visible { outline-offset: 6px; }
.pg-chart__plot svg { display: block; }
.pg-chart__plot text {
  fill: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.pg-chart__plot .pg-hurdle-label { fill: var(--ink); font-weight: 600; }
.pg-gridline { stroke: var(--grid); }
.pg-baseline { stroke: var(--line-strong); }
.pg-hurdle {
  stroke: var(--ink);
  stroke-width: 1.5;
  stroke-dasharray: 6 5;
}
.pg-kept { fill: var(--kept); }
.pg-paid { fill: var(--accent); }
.pg-band { fill: transparent; }
.pg-band.is-active { fill: rgb(15 110 92 / 0.07); }

.pg-tip {
  position: absolute;
  z-index: 2;
  display: grid;
  grid-template-columns: 12px auto auto;
  align-items: center;
  gap: 3px 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 10px 28px -14px rgb(16 20 24 / 0.35);
  font-size: 0.8125rem;
  line-height: 1.35;
  white-space: nowrap;
  pointer-events: none;
}
.pg-tip__title,
.pg-tip__limit { grid-column: 1 / -1; }
.pg-tip__title { margin-bottom: 3px; font-weight: 600; }
.pg-tip__limit { margin-top: 3px; font-weight: 600; }
.pg-tip__key {
  width: 12px;
  height: 3px;
  border-radius: 2px;
}
.pg-tip__key--paid { background: var(--accent); }
.pg-tip__key--kept { background: var(--kept); }
.pg-tip__value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.pg-tip__label { color: var(--muted); }

/* ---------- yearly table */

.pg-yearly {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.pg-yearly__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  padding: 18px 20px 14px;
}
.pg-yearly__title {
  font-size: 1rem;
  letter-spacing: -0.01em;
}
.pg-yearly__unit { color: var(--muted); font-size: var(--fs-small); }
.pg-table {
  overflow-x: auto;
  overscroll-behavior-x: contain;
}
.pg-table:focus-visible { outline-offset: -2px; border-radius: 0; }
.pg-table table {
  width: 100%;
  min-width: 36rem;
  border-collapse: collapse;
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}
.pg-table th,
.pg-table td {
  padding: 11px 16px;
  text-align: right;
  vertical-align: top;
  white-space: nowrap;
}
.pg-table thead th {
  padding-block: 10px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.3;
  vertical-align: bottom;
  white-space: normal;
}
.pg-table tbody tr + tr > * { border-top: 1px solid var(--line); }
.pg-table tbody th { font-weight: 500; }
.pg-table tfoot > tr > * {
  border-top: 1px solid var(--line-strong);
  font-weight: 600;
}
.pg-table tr > :first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  text-align: left;
}
.pg-table tr > :last-child { text-align: left; }
.pg-table tr.is-limited > * { background: #FDF6E7; }
.pg-due {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}
.pg-badge {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--highlight);
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.6;
}
.pg-badge + .pg-badge { margin-left: 4px; }

.pg-method {
  max-width: 64ch;
  color: var(--muted);
  font-size: var(--fs-small);
  line-height: 1.6;
}
.pg-method__title {
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 0.9375rem;
  letter-spacing: -0.01em;
}
.pg-method code {
  padding: 0.1em 0.35em;
  border-radius: 6px;
  background: var(--placeholder);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.875em;
}

/* ---------- playground, responsive */

@media (max-width: 1099px) {
  .pg-layout { grid-template-columns: minmax(0, 1fr); }
}

@media (min-width: 720px) and (max-width: 1099px) {
  .pg-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: var(--s-5);
    align-items: start;
  }
  .pg-group + .pg-group {
    padding-top: 0;
    border-top: 0;
  }
  .pg-group--consumer {
    grid-column: 1 / -1;
    padding-top: var(--s-3);
    border-top: 1px solid var(--line);
  }
  .pg-group--consumer > :not(legend) { max-width: 26rem; }
}

@media (max-width: 599px) {
  .pg-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pg-tile--hero {
    grid-column: 1 / -1;
    grid-row: auto;
    padding: 20px 16px;
  }
  .pg-tile { padding: 14px 16px 16px; }
  .pg-yearly__head { padding-inline: 16px; }
  .pg-table th,
  .pg-table td { padding-inline: 12px; }
}
