/*
 * Palette values are verified, not eyeballed. Every pairing below was run through the
 * WCAG formula; ratios are recorded beside each one so a change has to re-earn them.
 *
 * Cool and fresh on purpose. An earlier version was warm and muted, which collapsed into
 * sepia: beige, brown and rust read as dated and, worse, as sad. The brief only ever
 * asked for "nothing alarming at a glance", and this app exists to tell someone they are
 * not alone on a bad afternoon. It should not look like a filing cabinet.
 *
 * Light and dark are not mirror images. Light elevates the button with a dark fill on a
 * pale ground (11.80:1, clearing the 3:1 component bar on its own). The mirror of that in
 * dark mode tops out near 1.16:1, so dark carries elevation on a border instead (4.82:1).
 */

:root {
  --ground:        #F3F5F4;
  --text:          #15201D;  /* 15.27:1 on ground */
  --text-soft:     #4A5A56;  /*  6.64:1 on ground, also the input border */
  --face:          #24352F;  /* 11.80:1 on ground, so no border needed */
  --face-edge:     transparent;
  --face-label:    #F1F6F4;  /* 11.83:1 on face */
  --accent:        #0E7C68;  /*  4.68:1 on ground: text weight, so 4.5 applies */

  /*
   * Chart series. Colour follows importance rather than making two equal categories:
   * people is the number that matters and wears the accent hue, repeat presses are the
   * mashing on top and stay neutral. That also buys hue separation instead of fighting
   * for lightness separation, which two steps of one hue could not win here.
   */
  --series-people: #00957B;  /*  3.43:1 on ground: graphic weight, so 3:1 applies */
  --series-repeat: #565F5C;  /*  6.02:1 on ground; ΔE 15.8 from series-people */

  --lift: 0 6px 16px rgba(21, 32, 29, 0.16);
  --lift-pressed: 0 2px 5px rgba(21, 32, 29, 0.20);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground:      #101614;
    --text:        #E6EDEA;  /* 15.40:1 on ground */
    --text-soft:   #9FB0AB;  /*  8.08:1 on ground */
    --face:        #1B2522;
    --face-edge:   #75877F;  /*  4.82:1 on ground: this is what makes the button visible */
    --face-label:  #E6EDEA;  /* 13.24:1 on face */
    --accent:      #4FD1B8;  /*  9.72:1 on ground */
    --series-people: #4FD1B8;
    --series-repeat: #77857F;  /* 4.75:1 on ground; ΔE 20.6 from series-people */
    --lift: 0 6px 18px rgba(0, 0, 0, 0.5);
    --lift-pressed: 0 2px 6px rgba(0, 0, 0, 0.55);
  }
}

:root[data-theme="dark"] {
  --ground:      #101614;
  --text:        #E6EDEA;
  --text-soft:   #9FB0AB;
  --face:        #1B2522;
  --face-edge:   #75877F;
  --face-label:  #E6EDEA;
  --accent:      #4FD1B8;
  --series-people: #4FD1B8;
  --series-repeat: #77857F;
  --lift: 0 6px 18px rgba(0, 0, 0, 0.5);
  --lift-pressed: 0 2px 6px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--ground);
  color: var(--text);
  /*
   * System stack on purpose. This page has to answer a thumb in under 100ms from a phone
   * home screen, and a webfont is a render-blocking request standing in front of that.
   */
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Visible in both themes, and never removed without replacement. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  padding-top: max(1rem, env(safe-area-inset-top));
}

.wordmark {
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  color: var(--text-soft);
}

.quiet {
  appearance: none;
  background: none;
  border: none;
  padding: 0.5rem;
  margin: -0.5rem;
  min-height: 44px;      /* tap target, R-03 */
  color: var(--text-soft);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.quiet:hover { color: var(--text); }

.screen {
  flex: 1;
  width: 100%;
  max-width: 34rem;
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.screen[hidden] { display: none; }

/* ---------------------------------------------------------------- the phrase gate -- */

.gate {
  width: 100%;
  margin-top: 3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.gate-title {
  font-size: 1.375rem;
  font-weight: 600;
  margin: 0;
}

.gate-note {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.95rem;
}

.field { display: flex; flex-direction: column; gap: 0.4rem; }
.field-label { font-size: 0.85rem; color: var(--text-soft); }

.field input,
.field select {
  font: inherit;
  padding: 0.75rem;
  min-height: 44px;
  color: var(--text);
  background: var(--ground);
  border: 1px solid var(--text-soft);   /* 6.15:1 and 6.84:1: clears the 3:1 boundary bar */
  border-radius: 6px;
  width: 100%;
}

/* Native control, so the arrow and the open list follow the viewer's platform. */
.field select { appearance: none; background-image: none; }

.solid {
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 0.75rem 1.25rem;
  color: var(--face-label);
  background: var(--face);
  border: 1px solid var(--face-edge);
  border-radius: 6px;
  cursor: pointer;
}
.solid:disabled { opacity: 0.6; cursor: default; }

/* Never colour alone: every notice carries its meaning in the words. */
.notice {
  margin: 0;
  color: var(--text);
  font-size: 0.95rem;
  border-left: 3px solid var(--accent);
  padding-left: 0.75rem;
}

/* ------------------------------------------------------------------- the counter -- */

.today {
  margin-top: 2.5rem;
  text-align: center;
}

.count {
  margin: 0;
  font-size: clamp(3.5rem, 18vw, 5rem);
  line-height: 1;
  font-weight: 600;
  /* Proportional digits change width as they roll, so the number visibly jitters. */
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.count[data-state="loading"],
.count[data-state="quiet"] { font-size: clamp(1.1rem, 5vw, 1.35rem); font-weight: 500; }

.count-label {
  margin: 0.35rem 0 0;
  color: var(--text-soft);
  font-size: 0.95rem;
}

/*
 * The identity motif: one weighted press. It is the only element on the page with
 * elevation and the only thing that animates.
 */
.sigh {
  appearance: none;
  margin: 2.25rem 0 0;
  width: min(62vw, 15rem);
  aspect-ratio: 1;
  max-width: 100%;
  border-radius: 50%;
  border: 1px solid var(--face-edge);
  background: var(--face);
  color: var(--face-label);
  box-shadow: var(--lift);
  cursor: pointer;
  position: relative;
  transition: transform 260ms cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 180ms ease-out;
}

.sigh-label {
  font-size: 1.25rem;
  font-weight: 500;
  letter-spacing: 0.06em;
}

.sigh:disabled { opacity: 0.55; cursor: default; }

/* Bound to pointerdown in app.js, never to the network round trip. */
.sigh[data-pressed="true"] {
  transform: scale(0.96);
  box-shadow: var(--lift-pressed);
  transition-duration: 60ms;
}

/* The ring is the "it went somewhere" signal. One pulse per press, never a loop. */
.sigh::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  pointer-events: none;
}
.sigh[data-ripple="true"]::after {
  animation: ring 560ms ease-out;
}

@keyframes ring {
  from { opacity: 0.75; transform: scale(1); }
  to   { opacity: 0;    transform: scale(1.22); }
}

.rank {
  margin: 1.5rem 0 0;
  min-height: 1.5rem;
  text-align: center;
  font-size: 1.05rem;
  color: var(--accent);   /* the one deliberate accent, at the one moment it matters */
}

/* ------------------------------------------------------------------- the history -- */

.history { width: 100%; margin-top: 3rem; }

.history-title {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-soft);
}

.legend {
  display: flex;
  gap: 1rem;
  margin: 0 0 0.6rem;
  font-size: 0.8rem;
  color: var(--text-soft);   /* labels wear text tokens, never the series colour */
}
.legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.legend i {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 2px;
  flex: none;
}
.legend .swatch-people { background: var(--series-people); }
.legend .swatch-repeat { background: var(--series-repeat); }

.bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 4rem;
  width: 100%;
  padding-bottom: 5px;   /* room for the today marker below the baseline */
  overflow: hidden;      /* bars only: no text is clipped here */
}

.day {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  /*
   * The 2px surface gap is what lets a two-step ramp work here. Touching fills would
   * have to clear 3:1 against each other, which two steps of one muted hue cannot do
   * while also clearing 3:1 against the ground. Separated, each only borders the ground.
   */
  gap: 2px;
}
.day[data-weekend="true"] { opacity: 0.55; }

.seg { border-radius: 1px; min-height: 2px; }
.seg-people { background: var(--series-people); }
.seg-repeat { background: var(--series-repeat); }

/*
 * A day with nothing on it. It gets a neutral baseline tick rather than the people
 * colour, which the minimum-height guard was otherwise painting it: a 2px sliver of
 * accent on a day nobody pressed reads as "one person", not as "none". Reusing a text
 * token keeps the accent meaning exactly one thing, and adds no colour to verify.
 */
.seg-none { background: var(--text-soft); opacity: 0.3; }

/* Today is marked by position, not by colour, since both colours now carry meaning. */
.day[data-today="true"]::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -5px;
  height: 2px;
  background: var(--text-soft);
}

.history-note {
  margin: 0.6rem 0 0;
  font-size: 0.85rem;
  color: var(--text-soft);
}

.foot {
  width: 100%;
  margin-top: 2.5rem;
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-soft);
}

/*
 * Motion is the product here, so reduced motion is not "no feedback". The press still
 * registers; it just stops springing and pulsing.
 */
@media (prefers-reduced-motion: reduce) {
  .sigh { transition: opacity 80ms linear; }
  .sigh[data-pressed="true"] { transform: none; opacity: 0.7; }
  .sigh[data-ripple="true"]::after { animation: none; }
}

/* ---------------------------------------------------------------- the charter ----- */

/* Link colour reuses the verified text tokens rather than introducing a new blue. */
a { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
a.wordmark { color: var(--text-soft); text-decoration: none; }
a.wordmark:hover { color: var(--text); }

.prose {
  width: 100%;
  margin-top: 1rem;
  font-size: 1rem;
}
.prose h1 { font-size: 1.375rem; margin: 0 0 1rem; }
.prose h2 { font-size: 1rem; margin: 2rem 0 0.5rem; color: var(--text-soft); }
.prose p { margin: 0 0 0.85rem; }
.prose ul, .prose ol { margin: 0 0 0.85rem; padding-left: 1.25rem; }
.prose li { margin-bottom: 0.5rem; }
.back { margin-top: 2rem; }
.foot-links { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }

/* ------------------------------------------------------------- the accent picker -- */

.tint {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 44px;   /* tap target, R-03 */
  cursor: pointer;
  color: var(--text-soft);
}
.tint:hover { color: var(--text); }

/*
 * A native colour input, so the picker is the one the viewer already knows. Only the hue
 * of their choice is kept: theme.js works out a lightness that meets the contrast target
 * for each role, so no pick can make the interface unreadable.
 */
.tint input[type="color"] {
  appearance: none;
  width: 1.1rem;
  height: 1.1rem;
  padding: 0;
  border: 1px solid var(--text-soft);   /* 6.64:1 and 8.08:1, clears the 3:1 boundary bar */
  border-radius: 50%;
  background: none;
  cursor: pointer;
}
.tint input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.tint input[type="color"]::-webkit-color-swatch { border: none; border-radius: 50%; }
.tint input[type="color"]::-moz-color-swatch { border: none; border-radius: 50%; }
