/*
 * Tally.
 *
 * Light is the default because the usual moment is a bright kitchen at half
 * eight. Dark follows the phone's own setting rather than a toggle in here.
 *
 * Outcomes are never distinguished by colour. In the calendar they differ by
 * shape, so nothing reads as a red day or a green day. This is a shared record
 * of an agreed plan, and it may be read over a shoulder.
 */

@font-face {
  font-family: 'Instrument Sans';
  src: url('fonts/instrument-sans.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
}

@font-face {
  font-family: 'JetBrains Mono';
  src: url('fonts/jetbrains-mono.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-sunk: #f2f2f0;
  --border: #e4e4e1;
  --border-strong: #d3d3cf;
  --ink: #101215;
  --muted: #6b727d;
  --faint: #9096a0;
  --accent: #12312a;
  --accent-ink: #f2f7f4;
  --accent-line: #1b5e4a;
  --shadow: 0 1px 2px rgb(16 18 21 / 0.05);

  --sans: 'Instrument Sans', ui-sans-serif, system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --gap: 9px;
  --radius: 12px;
  --tap: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0c0e;
    --surface: #15171b;
    --surface-sunk: #101216;
    --border: #24272e;
    --border-strong: #2f333c;
    --ink: #edeff2;
    --muted: #8a919e;
    --faint: #6b717c;
    --accent: #e4b363;
    --accent-ink: #16130c;
    --accent-line: #e4b363;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.sprite {
  display: none;
}

[hidden] {
  display: none !important;
}

/* ------------------------------------------------------------------ */
/* Shell                                                               */
/* ------------------------------------------------------------------ */

.shell {
  display: grid;
  grid-template-areas: 'masthead' 'tabs' 'main';
  gap: 0;
  max-width: 30rem;
  margin: 0 auto;
  padding: 22px 18px calc(40px + env(safe-area-inset-bottom));
}

.masthead {
  grid-area: masthead;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.wordmark {
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stamp {
  font-family: var(--mono);
  font-size: 0.6875rem;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-transform: uppercase;
}

.tabs {
  grid-area: tabs;
  display: flex;
  gap: 2px;
  margin-top: 20px;
  padding: 3px;
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.tab {
  flex: 1;
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}

.tab[aria-current='page'] {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.main {
  grid-area: main;
  margin-top: 22px;
}

.loading {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.8125rem;
}

/* ------------------------------------------------------------------ */
/* Stage heading                                                       */
/* ------------------------------------------------------------------ */

.stage__rung {
  font-family: var(--mono);
  font-size: 0.6875rem;
  letter-spacing: 0.14em;
  color: var(--accent-line);
}

.stage__name {
  font-size: 2.125rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.05;
  margin-top: 6px;
}

.stage__allows {
  color: var(--muted);
  font-size: 0.875rem;
  margin-top: 6px;
}

.progress {
  display: flex;
  gap: 5px;
  margin-top: 20px;
}

.progress i {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
}

.progress i.on {
  background: var(--accent-line);
}

.progress__meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 0.6875rem;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-transform: uppercase;
}

.rule {
  height: 1px;
  background: var(--border);
  margin: 26px 0 0;
}

.label {
  display: block;
  font-family: var(--mono);
  font-size: 0.625rem;
  letter-spacing: 0.16em;
  color: var(--faint);
  text-transform: uppercase;
  margin: 18px 0 12px;
}

/* ------------------------------------------------------------------ */
/* Outcome buttons                                                     */
/* ------------------------------------------------------------------ */

.outcomes {
  display: grid;
  gap: var(--gap);
}

.outcome {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  min-height: var(--tap);
  padding: 13px 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.08s ease;
}

.outcome:hover {
  border-color: var(--border-strong);
}

.outcome:active {
  transform: scale(0.995);
}

.outcome--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.outcome--primary .outcome__hint {
  color: color-mix(in srgb, var(--accent-ink) 62%, transparent);
}

.outcome[aria-expanded='true'] {
  border-color: var(--accent-line);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.outcome__icon {
  flex: none;
  width: 21px;
  height: 21px;
}

.outcome__label {
  display: block;
  font-size: 0.96875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.outcome__hint {
  display: block;
  font-size: 0.78125rem;
  color: var(--muted);
  margin-top: 1px;
}

.outcome__key {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.6875rem;
  color: var(--faint);
}

/* The extra answer a late or authorised day needs before it can be sent. */

.followup {
  margin-top: -1px;
  padding: 14px 15px 15px;
  background: var(--surface-sunk);
  border: 1px solid var(--accent-line);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
}

.followup label {
  display: block;
  font-size: 0.84375rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.field {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}

.choices {
  display: flex;
  gap: 7px;
  margin-bottom: 12px;
}

.choice {
  flex: 1;
  min-height: 44px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  color: var(--ink);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}

.choice[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.button {
  width: 100%;
  min-height: 48px;
  margin-top: 12px;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 9px;
  color: var(--accent-ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.button--quiet {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--muted);
}

.button[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ------------------------------------------------------------------ */
/* Panels and notices                                                  */
/* ------------------------------------------------------------------ */

.panel {
  padding: 17px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel h2 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.panel p {
  color: var(--muted);
  font-size: 0.875rem;
  margin-top: 4px;
}

.panel + .panel,
.panel + .outcomes,
.outcomes + .panel {
  margin-top: 14px;
}

.notice {
  padding: 14px 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-line);
  border-radius: 9px;
  color: var(--muted);
  font-size: 0.875rem;
}

.notice + * {
  margin-top: 14px;
}

/* ------------------------------------------------------------------ */
/* Status figures                                                      */
/* ------------------------------------------------------------------ */

.figures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  margin-top: 14px;
}

.figure {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.figure__value {
  font-family: var(--mono);
  font-size: 2.75rem;
  font-weight: 700;
  letter-spacing: -0.05em;
  line-height: 0.9;
}

.figure__label {
  font-family: var(--mono);
  font-size: 0.625rem;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
  margin-top: 10px;
}

.ladder {
  list-style: none;
  margin-top: var(--gap);
  display: grid;
  gap: 6px;
}

.ladder li {
  display: flex;
  gap: 13px;
  align-items: baseline;
  padding: 12px 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.ladder li[aria-current='true'] {
  border-color: var(--accent-line);
}

.ladder__rung {
  flex: none;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--faint);
}

.ladder li[aria-current='true'] .ladder__rung {
  color: var(--accent-line);
}

.ladder__name {
  font-size: 0.9375rem;
  font-weight: 600;
}

.ladder__allows {
  display: block;
  font-size: 0.8125rem;
  color: var(--muted);
}

.downtime {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: var(--gap);
  padding: 14px 15px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.84375rem;
}

.downtime svg {
  flex: none;
  width: 20px;
  height: 20px;
  color: var(--faint);
}

/* ------------------------------------------------------------------ */
/* Calendar                                                            */
/* ------------------------------------------------------------------ */

.month {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.month__name {
  font-family: var(--mono);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.month__step {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--ink);
  cursor: pointer;
}

.month__step[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
}

.month__step svg {
  width: 18px;
  height: 18px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-top: 14px;
}

.grid__head {
  font-family: var(--mono);
  font-size: 0.625rem;
  letter-spacing: 0.08em;
  color: var(--faint);
  text-align: center;
  padding-bottom: 6px;
  text-transform: uppercase;
}

.day {
  aspect-ratio: 1;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 2px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.8125rem;
  cursor: default;
}

.day--school {
  background: var(--surface);
  border-color: var(--border);
  color: var(--ink);
  cursor: pointer;
}

.day--school:hover {
  border-color: var(--border-strong);
}

.day--today {
  border-color: var(--accent-line);
  border-width: 2px;
}

.day--blank {
  visibility: hidden;
}

/*
 * Outcome marks differ by SHAPE, never by colour, so the month never reads as
 * a scorecard of good and bad days.
 */
.mark {
  width: 10px;
  height: 10px;
  flex: none;
}

.mark--first_bus {
  background: var(--ink);
  border-radius: 50%;
}

.mark--late {
  border: 2px solid var(--ink);
  border-radius: 50%;
}

.mark--missed {
  background: var(--ink);
}

.mark--authorised {
  border: 2px solid var(--ink);
  transform: rotate(45deg);
}

.mark--none {
  width: 8px;
  height: 2px;
  background: var(--border-strong);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.legend span {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 0.625rem;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-transform: uppercase;
}

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */

/* Tablet: more room, larger display type, calendar cells breathe. */
@media (min-width: 40rem) {
  .shell {
    max-width: 38rem;
    padding: 32px 28px 56px;
  }

  .stage__name {
    font-size: 2.625rem;
  }

  .figure__value {
    font-size: 3.25rem;
  }

  .day {
    min-height: 58px;
    font-size: 0.875rem;
  }

  .grid {
    gap: 6px;
  }
}

/*
 * Desktop: the stage stops being a thing you scroll past and becomes a column
 * that stays put, with the active view beside it. The tabs turn into a list,
 * because a segmented control stretched across a wide screen is absurd.
 */
@media (min-width: 64rem) {
  .shell {
    grid-template-areas:
      'masthead masthead'
      'tabs     main';
    grid-template-columns: 15rem 1fr;
    column-gap: 40px;
    max-width: 64rem;
    padding: 40px 40px 72px;
  }

  .tabs {
    flex-direction: column;
    gap: 2px;
    align-self: start;
    position: sticky;
    top: 40px;
    margin-top: 30px;
    padding: 4px;
  }

  .tab {
    text-align: left;
    padding: 0 12px;
    min-height: 42px;
  }

  .main {
    margin-top: 30px;
  }

  .outcomes {
    grid-template-columns: 1fr 1fr;
  }

  /* A follow up belongs to the button above it, so it must not be split
     across columns. */
  .outcomes > div:has(.followup) {
    grid-column: 1 / -1;
  }

  .day {
    min-height: 66px;
  }
}

/* ------------------------------------------------------------------ */
/* Shared                                                              */
/* ------------------------------------------------------------------ */

.icon {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:focus-visible {
  outline: 2px solid var(--accent-line);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* ------------------------------------------------------------------ */
/* Log forms                                                           */
/* ------------------------------------------------------------------ */

.field-row + .field-row,
.field-row + .choices {
  margin-top: 12px;
}

.field-row label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 7px;
}

.field-row .choices {
  margin-bottom: 0;
}

.entries {
  list-style: none;
  display: grid;
  gap: 6px;
}

.entries li {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.entry__icon {
  flex: none;
  width: 19px;
  height: 19px;
  color: var(--muted);
}

.entry__title {
  display: block;
  font-size: 0.9375rem;
  font-weight: 600;
}

.entry__detail {
  display: block;
  font-size: 0.8125rem;
  color: var(--muted);
}

.entry__when {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.6875rem;
  color: var(--faint);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ */
/* Term strip and month tally                                          */
/* ------------------------------------------------------------------ */

.term {
  margin-top: 18px;
}

.term__head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--mono);
  font-size: 0.625rem;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}

/* One tick per school day in the term. Logged or not, never which outcome. */
.term__strip {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  height: 22px;
  padding-bottom: 5px;
}

.tick {
  flex: 1;
  height: 9px;
  min-width: 2px;
  border-radius: 1px;
  background: var(--border);
}

.tick--logged {
  height: 17px;
  background: var(--muted);
}

.tick--shown {
  background: var(--accent-line);
  box-shadow: 0 5px 0 -3px var(--accent-line);
}

.tally {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 14px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.tally__item {
  display: flex;
  align-items: center;
  gap: 9px;
}

.tally__n {
  font-family: var(--mono);
  font-size: 1.125rem;
  font-weight: 700;
  min-width: 1.2em;
}

.tally__t {
  font-size: 0.75rem;
  color: var(--muted);
}

@media (min-width: 40rem) {
  .tally {
    grid-template-columns: repeat(4, 1fr);
  }
}

.panel__lead {
  color: var(--muted);
  font-size: 0.8125rem;
  margin-bottom: 14px;
}

.choices--compact .choice {
  min-width: 44px;
}
