/* Swim speed calculator: the form (index.html) and the results (tables.html).
   Loaded after css/apalala.css; uses its v6 variables. The last block is the print
   sheet: "Export as PDF" prints the results page, and the browser saves it as a PDF. */

/* ----- Form ----- */
.swim-intro {
  max-width: 46rem;
  margin: 1rem 0 1.5rem;
}

.swim-intro h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(1.8rem, 3.6vw, 2.5rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.swim-intro p {
  margin: 0;
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--color-gray-600);
}

.swim-how {
  margin: 0 0 1.5rem;
  max-width: 46rem;
  color: var(--color-gray-600);
}

.swim-how summary {
  width: fit-content;
  font-family: var(--font-title);
  font-weight: 600;
  color: var(--color-teal-800);
  cursor: pointer;
}

.swim-how p {
  margin: 0.75rem 0 0;
}

/* Three cards side by side, one under the other on a phone. Inside a card every field is a
   label above its control: the v5 label/control grid needs 470px, a card has about 300. */
.swim-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(19rem, 100%), 1fr));
  gap: 1rem;
  align-items: start;
}

.swim-form > fieldset,
.swim-form > fieldset:first-of-type {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-column: auto;
  gap: 1rem;
  align-content: start;
  box-sizing: border-box;
  width: auto;
  min-width: 0;
  margin: 0;
  padding: 1rem 1.25rem 1.25rem;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-card);
  background: var(--color-white);
  box-shadow: var(--shadow-card);
}

.swim-form > fieldset > legend:first-child {
  padding: 0 0.4rem;
  font-size: 1.0625rem;
  font-weight: 600;
}

.swim-form .field {
  display: grid;
  grid-column: auto;
  gap: 0.35rem;
  align-content: start;
  min-width: 0;
  margin: 0;
}

.swim-form .field--wide,
.swim-form fieldset > .swim-hint {
  grid-column: 1 / -1;
}

.swim-form .field > label,
.swim-form .field-label {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--color-teal-950);
}

.swim-form .field-check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  width: fit-content;
  cursor: pointer;
}

.swim-form .field .control {
  display: flex;
  flex-wrap: wrap;
  grid-column: auto;
  align-items: center;
  gap: 0.4rem 0.5rem;
  width: auto;
  margin: 0;
}

.swim-form input[type="text"],
.swim-form input[type="number"] {
  box-sizing: border-box;
  height: 2.5rem;
  margin: 0;
  padding: 0 0.6rem;
  border-width: 1px;
  font-variant-numeric: tabular-nums;
}

.swim-form input[type="text"] {
  grid-column: 1 / -1;
  width: 100%;
  max-width: none;
}

.swim-form input[type="number"] {
  width: 4.75rem;
}

.swim-form input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.swim-form input[type="checkbox"],
.swim-form input[type="radio"] {
  flex: none;
  margin: 0;
  accent-color: var(--color-teal-800);
}

.swim-form .unit {
  margin-inline-end: 0.35rem;
  color: var(--color-gray-600);
}

.swim-form .field .choice {
  gap: 0.4rem 1.5rem;
}

.swim-form .choice label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2rem;
  font-weight: 400;
  cursor: pointer;
}

.swim-form .swim-hint {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--color-gray-600);
}

.swim-submit {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.swim-submit input[type="submit"] {
  grid-column: auto;
  width: auto;
  max-width: none;
  min-height: 2.75rem;
  margin: 0;
  padding: 0 2rem;
  font-family: var(--font-title);
  font-size: 1.0625rem !important;
}

/* ----- Results ----- */
.swim-results {
  padding-block: 1.25rem 1rem;
}

.res-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem 2rem;
  margin-bottom: 1.5rem;
}

.res-head h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.7rem, 3.4vw, 2.4rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.res-sub {
  margin: 0;
  color: var(--color-gray-600);
}

.res-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.res-actions .btn {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding-inline: 1.4rem;
  font-family: var(--font-title);
  font-size: 1rem;
  line-height: 1.2;
  text-decoration: none;
}

.res-block {
  margin-top: 1.25rem;
  padding: 1.25rem 1.5rem 1.5rem;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-card);
  background: var(--color-white);
  box-shadow: var(--shadow-card);
}

.res-block > h2 {
  position: static;
  margin: 0 0 0.75rem;
  font-size: 1.25rem;
}

.res-note {
  max-width: 62rem;
  margin: 0 0 1rem;
  color: var(--color-gray-600);
}

.res-note.small {
  margin: 1rem 0 0;
  font-size: 0.875rem;
}

.res-adjust {
  margin: 0.75rem 0 0;
  font-size: 0.875rem;
  color: var(--color-orange-dark);
  white-space: pre-line;
}

/* Key figures */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 0.75rem;
  margin: 0;
}

.kpi {
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  background: var(--color-paper);
}

.kpi dt {
  font-size: 0.8125rem;
  color: var(--color-gray-600);
}

.kpi dd {
  margin: 0.15rem 0 0;
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 1.375rem;
  line-height: 1.2;
  color: var(--color-teal-950);
  font-variant-numeric: tabular-nums;
}

.kpi dd small {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 0.8125rem;
  color: var(--color-gray-600);
}

/* Where you stand: one bell curve per result */
.bells {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(18.5rem, 100%), 1fr));
  gap: 1rem;
}

.bell {
  padding: 1rem 1rem 0.9rem;
  border: 1px solid var(--color-line);
  border-radius: 12px;
  break-inside: avoid;
}

.res-block .bell h3 {
  position: static;
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-teal-800);
}

.bell-value {
  margin: 0.15rem 0 0;
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 1.75rem;
  line-height: 1.15;
  color: var(--color-teal-950);
  font-variant-numeric: tabular-nums;
}

.bell-level {
  margin: 0.1rem 0 0.4rem;
  font-size: 0.875rem;
  color: var(--color-gray-600);
}

.bell-level b {
  color: var(--color-teal-800);
}

.bell svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.bell-curve { fill: none; stroke: var(--color-ming); stroke-width: 2; }
.bell-area { fill: var(--color-ming); opacity: 0.16; }
.bell-base { stroke: var(--color-edge); stroke-width: 1; }
.bell-mark { stroke-width: 1.5; stroke-dasharray: 3 3; }
.bell-dot { stroke: var(--color-white); stroke-width: 1.5; }
.g-pub { stroke: var(--color-gray-medium); fill: var(--color-gray-medium); }
.g-avg { stroke: var(--color-ming); fill: var(--color-ming); }
.g-elite { stroke: var(--color-orange); fill: var(--color-orange); }
.bell-you { stroke: var(--color-teal-950); stroke-width: 2.5; }
.bell-you-dot { fill: var(--color-teal-950); stroke: var(--color-white); stroke-width: 2; }
.bell-you-label {
  fill: var(--color-teal-950);
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 12px;
}

.bell-legend {
  display: grid;
  gap: 0.2rem;
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.8125rem;
  color: var(--color-gray-600);
}

.bell-legend li {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  margin: 0;
}

.bell-legend i {
  flex: none;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
}

.bell-legend .g-pub i { background: var(--color-gray-medium); }
.bell-legend .g-avg i { background: var(--color-ming); }
.bell-legend .g-elite i { background: var(--color-orange); }

.bell-legend b {
  margin-inline-start: auto;
  color: var(--color-teal-950);
  font-variant-numeric: tabular-nums;
}

.bell--empty .bell-value {
  font-size: 1rem;
  font-family: var(--font-body);
  font-weight: 400;
  color: var(--color-gray-600);
}

.res-sources {
  margin: 1rem 0 0;
  font-size: 0.8125rem;
  color: var(--color-gray-600);
}

.res-sources a {
  white-space: nowrap;
}

/* Pace tables */
.table-scroll {
  overflow-x: auto;
  margin-top: 0.75rem;
}

.table-scroll table {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.res-block h3 {
  position: static;
  margin: 1.25rem 0 0;
  font-size: 1rem;
}

.res-chart {
  max-width: 46rem;
}

/* ----- Phone ----- */
@media (max-width: 640px) {
  .res-block {
    padding: 1rem 1rem 1.25rem;
  }

  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
  }

  .kpi dd {
    font-size: 1.25rem;
  }

  .res-actions,
  .res-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
  }
}

/* ----- Print: this is the PDF ----- */
@media print {
  @page {
    size: A4;
    margin: 14mm 12mm;
  }

  html,
  body {
    background: #fff !important;
  }

  body > header,
  .breadcrumb,
  body > footer,
  .no-print {
    display: none !important;
  }

  main.swim-results {
    width: auto;
    margin: 0;
    padding: 0;
  }

  .res-block {
    margin-top: 5mm;
    padding: 4mm 5mm 5mm;
    box-shadow: none;
    break-inside: auto;
  }

  .kpi,
  .bell-area,
  .bell-legend i,
  thead,
  thead th,
  thead td,
  th {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .bells {
    grid-template-columns: repeat(3, 1fr);
    gap: 3mm;
  }

  .bell {
    padding: 3mm;
  }

  .bell-value {
    font-size: 15pt;
  }

  .kpis {
    grid-template-columns: repeat(5, 1fr);
    gap: 2mm;
  }

  .kpi dd {
    font-size: 13pt;
  }

  .res-block h3,
  .res-block > h2 {
    break-after: avoid;
  }

  .table-scroll {
    overflow: visible;
    break-inside: avoid;
  }

  .table-scroll table {
    width: 100%;
    font-size: 8.5pt;
  }

  .res-chart {
    break-inside: avoid;
  }

  a {
    color: inherit;
    text-decoration: none;
  }
}
