/* ==========================================================================
   Caffeine Cutoff Calculator
   --------------------------------------------------------------------------
   Hand-written rather than Tailwind utilities, following css/hub.css and
   css/checkout.css: css/app.css is a compiled build, so a new utility class
   does not exist until someone re-runs it — and a feature that only styles
   correctly after a build step is a feature that ships broken.

   Palette is the SleepOriginal system, declared once here as custom properties
   so nothing downstream hardcodes a hex value.
   ========================================================================== */

.caff {
  --caff-ivory:    #FBF6EC;
  --caff-surface:  #FFFDF9;
  --caff-navy:     #071B45;
  --caff-terra:    #C47B55;
  --caff-secondary:#5F6978;
  --caff-sage:     #667051;
  --caff-dusk:     #6F829B;
  --caff-border:   #DED5C9;
  --caff-gold:     #B99A5E;

  --caff-radius: 18px;
  --caff-gap: clamp(1rem, 3vw, 1.75rem);

  background: var(--caff-ivory);
  color: var(--caff-navy);
  padding: clamp(1.5rem, 5vw, 3.5rem) 0 clamp(3rem, 8vw, 5rem);
  /* No horizontal overflow at any width — the chart scales rather than scrolls. */
  overflow-x: hidden;
}

.caff-shell {
  width: min(1120px, 100% - 2rem);
  margin-inline: auto;
}

/* --- Breadcrumb --------------------------------------------------------- */

.caff-crumb ol {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  font-size: .85rem;
  color: var(--caff-secondary);
}
.caff-crumb li + li::before { content: '/'; margin-right: .5rem; color: var(--caff-border); }
.caff-crumb a { color: var(--caff-dusk); text-decoration: none; }
.caff-crumb a:hover { text-decoration: underline; }

/* --- Header ------------------------------------------------------------- */

.caff-head { max-width: 46rem; margin-bottom: clamp(1.5rem, 4vw, 2.5rem); }

.caff-eyebrow {
  margin: 0 0 .75rem;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--caff-gold);
}

.caff-head h1 {
  margin: 0 0 .75rem;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(2rem, 5.5vw, 3rem);
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.caff-standfirst {
  margin: 0 0 1.25rem;
  font-size: clamp(1.02rem, 2.4vw, 1.18rem);
  line-height: 1.6;
  color: var(--caff-secondary);
}

.caff-note {
  margin: 0;
  padding: .85rem 1rem;
  border-left: 3px solid var(--caff-gold);
  background: var(--caff-surface);
  border-radius: 0 10px 10px 0;
  font-size: .9rem;
  line-height: 1.6;
  color: var(--caff-secondary);
}
.caff-note strong { color: var(--caff-navy); }

/* --- Layout ------------------------------------------------------------- */

.caff-grid {
  display: grid;
  gap: var(--caff-gap);
  grid-template-columns: 1fr;
  align-items: start;
}

/* Two columns only where there is genuinely room; the result stays in view
   while the form is edited. */
@media (min-width: 62rem) {
  .caff-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .caff-result { position: sticky; top: 1.5rem; }
}

.caff-panel {
  background: var(--caff-surface);
  border: 1px solid var(--caff-border);
  border-radius: var(--caff-radius);
  padding: clamp(1.15rem, 3.5vw, 1.9rem);
}

/* --- Form --------------------------------------------------------------- */

.caff-field { margin-bottom: 1.25rem; }
.caff-field:last-child { margin-bottom: 0; }

.caff-field > label,
.caff-field > legend {
  display: block;
  margin-bottom: .45rem;
  font-size: .92rem;
  font-weight: 600;
  color: var(--caff-navy);
}

fieldset.caff-field { border: 0; margin-inline: 0; padding: 0; }

.caff-field input[type="time"],
.caff-field input[type="number"],
.caff-field select {
  width: 100%;
  /* 44px minimum target, and 16px text so iOS does not zoom on focus. */
  min-height: 44px;
  padding: .6rem .75rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--caff-navy);
  background: #fff;
  border: 1px solid var(--caff-border);
  border-radius: 10px;
}

.caff-field input:focus-visible,
.caff-field select:focus-visible,
.caff-btn:focus-visible,
.caff-iconbtn:focus-visible,
.caff-addbtn:focus-visible,
.caff-radio input:focus-visible + span {
  outline: 3px solid var(--caff-dusk);
  outline-offset: 2px;
}

.caff-hint {
  margin: .4rem 0 0;
  font-size: .82rem;
  line-height: 1.5;
  color: var(--caff-secondary);
}
.caff-hint--block { margin: 1rem 0 0; }

/* --- Sensitivity radios ------------------------------------------------- */

.caff-radios { display: grid; gap: .5rem; }

.caff-radio {
  display: flex;
  align-items: flex-start;
  gap: .65rem;
  /* The whole row is the target, not just the dot. */
  min-height: 44px;
  padding: .65rem .8rem;
  border: 1px solid var(--caff-border);
  border-radius: 10px;
  cursor: pointer;
  font-size: .93rem;
  line-height: 1.45;
}
.caff-radio input { margin-top: .15rem; width: 18px; height: 18px; accent-color: var(--caff-terra); }
.caff-radio:has(input:checked) {
  border-color: var(--caff-terra);
  /* Not colour alone: the border thickens as well, so the selected state
     survives a monochrome display or colour-blind vision. */
  box-shadow: inset 0 0 0 1px var(--caff-terra);
}

/* --- Entries ------------------------------------------------------------ */

.caff-h2 {
  margin: 1.75rem 0 .85rem;
  font-family: Georgia, serif;
  font-size: 1.15rem;
}

.caff-entry {
  padding: .9rem;
  margin-bottom: .75rem;
  border: 1px solid var(--caff-border);
  border-radius: 12px;
  background: var(--caff-ivory);
}

.caff-entry-grid {
  display: grid;
  gap: .75rem;
  grid-template-columns: 1fr;
}

@media (min-width: 30rem) {
  .caff-entry-grid {
    grid-template-columns: minmax(0, 1fr) 7rem 7.5rem auto;
    align-items: end;
  }
  .caff-entry-grid .caff-field { margin-bottom: 0; }
}

.caff-entry-actions { display: flex; gap: .4rem; }

.caff-iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--caff-border);
  border-radius: 10px;
  background: #fff;
  color: var(--caff-secondary);
  cursor: pointer;
}
.caff-iconbtn:hover { color: var(--caff-navy); border-color: var(--caff-dusk); }
.caff-iconbtn--remove:hover { color: var(--caff-terra); border-color: var(--caff-terra); }
.caff-iconbtn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.caff-addbtn {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: .5rem;
  padding: .7rem 1rem;
  border: 1px dashed var(--caff-border);
  border-radius: 12px;
  background: transparent;
  color: var(--caff-dusk);
  font: inherit;
  font-weight: 600;
  font-size: .93rem;
  cursor: pointer;
}
.caff-addbtn:hover { border-color: var(--caff-dusk); color: var(--caff-navy); }

/* --- Buttons ------------------------------------------------------------ */

.caff-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.25rem; }

.caff-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  min-height: 48px;
  padding: .75rem 1.4rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 700;
  font-size: .96rem;
  text-decoration: none;
  cursor: pointer;
}

.caff-btn--primary { background: var(--caff-terra); color: #FFFDF9; }
.caff-btn--primary:hover { background: #b06c48; }

.caff-btn--ghost {
  background: transparent;
  border-color: var(--caff-border);
  color: var(--caff-secondary);
}
.caff-btn--ghost:hover { border-color: var(--caff-dusk); color: var(--caff-navy); }

.caff-price { font-weight: 600; opacity: .9; }

/* --- Result ------------------------------------------------------------- */

.caff-result-label {
  margin: 0 0 .35rem;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--caff-secondary);
}

.caff-window {
  margin: 0 0 .6rem;
  font-family: Georgia, serif;
  font-size: clamp(1.6rem, 4.5vw, 2.15rem);
  line-height: 1.2;
  color: var(--caff-navy);
}

.caff-result-context {
  margin: 0 0 1.25rem;
  font-size: .9rem;
  line-height: 1.6;
  color: var(--caff-secondary);
}

.caff-stats {
  display: grid;
  gap: .75rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0 0 1.25rem;
  padding: 0;
}
.caff-stats > div {
  padding: .75rem .85rem;
  background: var(--caff-ivory);
  border: 1px solid var(--caff-border);
  border-radius: 12px;
}
.caff-stats dt { margin: 0 0 .2rem; font-size: .76rem; letter-spacing: .04em; text-transform: uppercase; color: var(--caff-secondary); }
.caff-stats dd { margin: 0; font-size: 1.12rem; font-weight: 700; }

/* Informational, never alarming: sage rather than red, because the tool
   cannot assess anyone and a warning colour would imply that it had. */
.caff-notice {
  margin: 0 0 1.25rem;
  padding: .9rem 1rem;
  border: 1px solid var(--caff-border);
  border-left: 3px solid var(--caff-sage);
  border-radius: 0 10px 10px 0;
  background: var(--caff-ivory);
  font-size: .88rem;
  line-height: 1.6;
  color: var(--caff-secondary);
}
.caff-notice p { margin: 0; }

.caff-insights { margin: 0 0 1.25rem; padding-left: 1.1rem; }
.caff-insights li { margin-bottom: .5rem; font-size: .9rem; line-height: 1.6; color: var(--caff-secondary); }
.caff-insights li:last-child { margin-bottom: 0; }

/* --- Chart -------------------------------------------------------------- */

.caff-chart-wrap { margin: 0 0 1rem; }
.caff-chart-wrap figcaption {
  margin-bottom: .6rem;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--caff-secondary);
}

.caff-chart { width: 100%; }
.caff-svg { display: block; width: 100%; height: 150px; }

.caff-svg-area  { fill: rgba(196, 123, 85, .12); stroke: none; }
.caff-svg-line  { fill: none; stroke: var(--caff-terra); stroke-width: 2; stroke-linejoin: round; }
.caff-svg-dot   { fill: var(--caff-terra); }
.caff-svg-bed   { stroke: var(--caff-dusk); stroke-width: 1.5; stroke-dasharray: 4 4; }
.caff-svg-label { fill: var(--caff-secondary); font-size: 11px; font-family: inherit; }

@media (prefers-reduced-motion: no-preference) {
  .caff-svg--animate .caff-svg-line {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    animation: caff-draw .7s ease-out forwards;
  }
}
@keyframes caff-draw { to { stroke-dashoffset: 0; } }

/* --- Table -------------------------------------------------------------- */

.caff-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}
.caff-table th, .caff-table td {
  padding: .55rem .5rem;
  text-align: left;
  border-bottom: 1px solid var(--caff-border);
}
.caff-table th { font-size: .76rem; letter-spacing: .04em; text-transform: uppercase; color: var(--caff-secondary); }
.caff-table td:last-child, .caff-table th:last-child { text-align: right; }

.caff-result-actions { margin-top: 1rem; }

/* --- Offer -------------------------------------------------------------- */

.caff-offer { margin-top: var(--caff-gap); }
.caff-offer h2 { margin: 0 0 .6rem; font-family: Georgia, serif; font-size: clamp(1.3rem, 3.5vw, 1.7rem); }
.caff-offer p { margin: 0 0 1.15rem; color: var(--caff-secondary); line-height: 1.65; }
.caff-offer-secondary { margin: 1rem 0 0; font-size: .9rem; }
.caff-offer-secondary a { color: var(--caff-dusk); }

/* --- Prose -------------------------------------------------------------- */

.caff-prose { max-width: 46rem; margin-top: var(--caff-gap); }
.caff-prose h2 { margin: 0 0 .85rem; font-family: Georgia, serif; font-size: clamp(1.3rem, 3.5vw, 1.7rem); }
.caff-prose p  { margin: 0 0 1rem; line-height: 1.7; color: var(--caff-secondary); }
.caff-prose h3 { margin: 1.25rem 0 .5rem; font-size: 1rem; }
.caff-prose ul { margin: 0 0 1rem; padding-left: 1.15rem; }
.caff-prose li { margin-bottom: .5rem; line-height: 1.65; color: var(--caff-secondary); }
.caff-prose a  { color: var(--caff-dusk); }

.caff-details {
  margin-bottom: .6rem;
  padding: .85rem 1rem;
  border: 1px solid var(--caff-border);
  border-radius: 12px;
  background: var(--caff-surface);
}
.caff-details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--caff-navy);
  /* Comfortable target without losing the disclosure triangle. */
  min-height: 32px;
  padding: .25rem 0;
}
.caff-details summary:focus-visible { outline: 3px solid var(--caff-dusk); outline-offset: 3px; }
.caff-details[open] summary { margin-bottom: .6rem; }
.caff-details > :last-child { margin-bottom: 0; }

/* --- Tools index -------------------------------------------------------- */

.tools-grid {
  display: grid;
  gap: var(--caff-gap);
  grid-template-columns: 1fr;
  list-style: none;
  margin: 0 0 var(--caff-gap);
  padding: 0;
}

@media (min-width: 40rem)  { .tools-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 64rem)  { .tools-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.tools-card {
  display: flex;
  flex-direction: column;
  padding: clamp(1.15rem, 3vw, 1.6rem);
  background: var(--caff-surface);
  border: 1px solid var(--caff-border);
  border-radius: var(--caff-radius);
  transition: border-color .2s ease, transform .2s ease;
}

@media (prefers-reduced-motion: no-preference) {
  .tools-card:hover { transform: translateY(-2px); }
}
.tools-card:hover { border-color: var(--caff-dusk); }

/* The kind of thing it is, where a price badge used to sit. */
.tools-kind {
  margin: 0 0 .6rem;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--caff-gold);
}

.tools-card-title {
  margin: 0 0 .5rem;
  font-family: Georgia, serif;
  font-size: 1.2rem;
  line-height: 1.3;
}

.tools-card-title a {
  color: var(--caff-navy);
  text-decoration: none;
}
.tools-card-title a:hover { color: var(--caff-terra); }

/* The whole card is clickable, but the link stays a real link — so it is
   reachable by keyboard, appears in a screen reader's link list, and can be
   opened in a new tab. A stretched pseudo-element does the rest. */
.tools-card-title a::after {
  content: '';
  position: absolute;
  inset: 0;
}
.tools-card { position: relative; }

.tools-card-title a:focus-visible {
  outline: 3px solid var(--caff-dusk);
  outline-offset: 3px;
  border-radius: 4px;
}

.tools-card-summary {
  margin: 0 0 1.25rem;
  font-size: .92rem;
  line-height: 1.6;
  color: var(--caff-secondary);
}

.tools-card-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem;
  margin: auto 0 0;
  font-size: .84rem;
}

/* What it asks of you — the thing someone actually weighs before starting. */
.tools-meta { color: var(--caff-secondary); }

.tools-action {
  font-weight: 700;
  color: var(--caff-terra);
}

/* --- Utilities ---------------------------------------------------------- */

.caff-visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* At 320px the stats stack rather than squeezing to an unreadable width. */
@media (max-width: 22.5rem) {
  .caff-stats { grid-template-columns: 1fr; }
  .caff-shell { width: calc(100% - 1.5rem); }
}
