/* Push-ups — "Navy Poster".
   Two grounds: the navy field (Today, target not met) and the paper sheet
   (Today once met, and History). Everything flips between them. */

@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 400 900;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url('./fonts/archivo-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 400 900;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url('./fonts/archivo-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --navy: #090446;
  --navy-2: #2a2766;
  --navy-line: #3a3775;
  --navy-muted: #c9c7dc;
  --paper: #f3f2f2;
  --ink: #201e1d;
  --muted: #444141;
  --muted-2: #605d5d;
  --line: rgb(32 30 29 / 0.4);
  --line-soft: #c9c7dc;
  --bar-unmet: #9b9797;
  --bar-empty: #d7d3d3;
  --danger: #ff9783;
  --radius: 0;
  --tap: 48px;
  --rule-w: 2px;

  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);

  /* The navy field. Unchanged in dark mode — it already is dark. */
  --field-bg: var(--navy);
  --field-fg: var(--paper);
  --field-line: var(--navy-line);
  --field-muted: var(--navy-muted);
  --field-track: var(--navy-2);
  --field-press: var(--navy-2);

  /* The paper sheet. */
  --sheet-bg: var(--paper);
  --sheet-fg: var(--navy);
  --sheet-text: var(--ink);
  --sheet-line: var(--line);
  --sheet-line-soft: var(--line-soft);
  --sheet-muted: var(--muted);
  --sheet-muted-2: var(--muted-2);
  --sheet-press: var(--navy-muted);
  --sheet-block-bg: var(--navy);
  --sheet-block-fg: var(--paper);
  --sheet-block-press: var(--navy-2);
  --sheet-bar-unmet: var(--bar-unmet);
  --sheet-bar-empty: var(--bar-empty);
  --sheet-danger: #c0392b;

  color-scheme: light dark;
}

/* Dark mode is not part of the design. This darkens the paper sheet and keeps
   the navy field as-is; inverted blocks switch to a paper fill so they stay
   legible. See DESIGN-NOTES.md — worth confirming with the designer. */
@media (prefers-color-scheme: dark) {
  :root {
    --sheet-bg: #0e0c26;
    --sheet-fg: var(--paper);
    --sheet-text: var(--paper);
    --sheet-line: rgb(243 242 242 / 0.35);
    --sheet-line-soft: var(--navy-line);
    --sheet-muted: var(--navy-muted);
    --sheet-muted-2: #9d9ab8;
    --sheet-press: #1b1840;
    --sheet-block-bg: var(--paper);
    --sheet-block-fg: #0e0c26;
    --sheet-block-press: var(--navy-muted);
    --sheet-bar-unmet: #6f6c90;
    --sheet-bar-empty: #2a2766;
    --sheet-danger: var(--danger);
  }
}

* { box-sizing: border-box; }

/* Author rules outrank the UA's [hidden] rule, so make hiding non-negotiable. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

/* ---------- the two grounds ---------- */

body {
  --ground: var(--field-bg);
  --on-ground: var(--field-fg);
  --ink-strong: var(--field-fg);
  --rule: var(--field-line);
  --dim: var(--field-muted);
  --press: var(--field-press);
  --block-bg: var(--field-fg);
  --block-fg: var(--field-bg);
  --block-press: var(--navy-muted);
  --delete: var(--field-muted);

  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--ground);
  color: var(--on-ground);
  font-family: Archivo, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  transition: background-color 160ms ease, color 160ms ease;
}

/* Target met, or looking at History: flip to the paper sheet. */
body.is-done,
body[data-view="history"] {
  --ground: var(--sheet-bg);
  --on-ground: var(--sheet-fg);
  --ink-strong: var(--sheet-fg);
  --rule: var(--sheet-line-soft);
  --dim: var(--sheet-muted);
  --press: var(--sheet-press);
  --block-bg: var(--sheet-block-bg);
  --block-fg: var(--sheet-block-fg);
  --block-press: var(--sheet-block-press);
  --delete: var(--sheet-muted-2);
}

body[data-view="history"] {
  --on-ground: var(--sheet-text);
  --rule: var(--sheet-line);
  --delete: var(--sheet-danger);
}

button, input, label { font: inherit; }
button { touch-action: manipulation; color: inherit; }

:focus-visible {
  outline: 2px solid var(--on-ground);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- app bar ---------- */

.appbar {
  --bar-bg: var(--ground);
  --bar-fg: var(--on-ground);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(6px + var(--safe-t)) calc(8px + var(--safe-r)) 6px calc(16px + var(--safe-l));
  background: var(--bar-bg);
  color: var(--bar-fg);
  transition: inherit;
}

/* The bar keeps the navy field behind History, where the body is paper. */
body[data-view="history"] .appbar {
  --bar-bg: var(--field-bg);
  --bar-fg: var(--field-fg);
  --press: var(--field-press);
}

.app-title {
  margin: 0;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* One 2px frame around the pair, no gap, no radius. The 6px block margins
   keep the tap area at 48px while the visible block stays 36px. */
.tabs {
  display: flex;
  margin: 6px 0 6px auto;
  box-shadow: inset 0 0 0 2px var(--bar-fg);
}

.tab {
  position: relative;
  display: flex;
  align-items: center;
  height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--bar-fg);
  font-size: 14px;
  font-weight: 800;
}

.tab[aria-selected="true"] {
  background: var(--bar-fg);
  color: var(--bar-bg);
}

/* The block stays 36px tall; the tap area reaches 48px. */
.tab::after {
  content: '';
  position: absolute;
  inset: -6px 0;
}

.icon-btn {
  display: grid;
  place-items: center;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
}

.icon-btn:active { background: var(--press); }
.icon-btn svg { display: block; }

/* ---------- layout ---------- */

.main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px calc(16px + var(--safe-r)) 24px calc(16px + var(--safe-l));
}

body[data-view="history"] .main { padding-top: 20px; }

.panel { border: 0; background: none; padding: 0; }

.panel-title {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-strong);
}

/* ---------- today ---------- */

.summary { margin: 0; }

.big-number {
  /* 300px unless the digits would overflow the column. */
  margin: 0 0 0 -6px;
  font-size: min(300px, calc((100vw - 32px) / (0.42 * var(--digits, 2))));
  font-weight: 900;
  font-stretch: 62%;
  line-height: 0.8;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.big-label {
  margin: 8px 0 0;
  font-size: 30px;
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -0.01em;
  text-transform: uppercase;
}

.progress {
  height: 16px;
  margin-top: 20px;
  background: var(--field-track);
  border-radius: 0;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--field-fg);
  transition: width 220ms ease;
}

/* Met: the whole track reads as one solid block. */
body.is-done .progress { background: var(--sheet-fg); }
body.is-done .progress-fill { background: var(--sheet-fg); }

.progress-row {
  display: flex;
  justify-content: space-between;
  margin: 8px 0 0;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- entries ---------- */

.entry-list {
  list-style: none;
  margin: 24px 0 0;
  padding: 0;
  border-top: var(--rule-w) solid var(--ink-strong);
}

.entry-list:empty { display: none; }

.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--tap);
  border-bottom: var(--rule-w) solid var(--rule);
}

.entry-amount {
  min-width: 3ch;
  font-size: 20px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.entry-time {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: var(--dim);
}

.entry-delete { color: var(--delete); }
.entry-delete:active { background: var(--press); }

.empty {
  margin: 12px 0 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--dim);
}

.text-btn {
  display: flex;
  align-items: center;
  height: var(--tap);
  padding: 0 12px 0 0;
  border: 0;
  background: none;
  color: inherit;
  font-size: 15px;
  font-weight: 800;
}

/* ---------- quick add ---------- */

.quick-add {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
  background: var(--ground);
  transition: inherit;
}

body[data-view="history"] .quick-add { display: none; }

.quick-label {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  height: 32px;
  padding: 0 16px;
  border-top: var(--rule-w) solid var(--ink-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.quick-btn {
  display: flex;
  align-items: center;
  gap: 1px;
  height: 60px;
  padding: 0 0 0 12px;
  border: 0;
  border-radius: 0;
  background: var(--block-bg);
  color: var(--block-fg);
  font-size: 26px;
  font-weight: 900;
  font-stretch: 80%;
  font-variant-numeric: tabular-nums;
  text-align: left;
}

.quick-btn .plus { font-weight: 500; }

.quick-btn:active { background: var(--block-press); }

.quick-btn-custom {
  background: var(--ground);
  color: var(--on-ground);
  box-shadow: inset 0 0 0 2px var(--on-ground);
  font-size: 15px;
  font-weight: 800;
  font-stretch: 100%;
}

.quick-btn-custom:active { background: var(--press); }

.quick-add :focus-visible { outline-offset: -4px; }
.quick-btn:focus-visible { outline-color: var(--block-fg); }
.quick-btn-custom:focus-visible { outline-color: var(--on-ground); }

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

.chart {
  position: relative;
  height: 72px;
  margin-top: 12px;
  border-bottom: var(--rule-w) solid var(--ink-strong);
}

.chart-svg {
  display: block;
  width: 100%;
  height: 72px;
}

.chart-bar { fill: var(--sheet-fg); }
.chart-bar:not(.is-met) { fill: var(--sheet-bar-unmet); }
.chart-bar.is-empty { fill: var(--sheet-bar-empty); }

.chart-target {
  stroke: var(--sheet-text);
  stroke-width: 2;
  stroke-dasharray: 4 4;
  fill: none;
}

.chart-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--sheet-muted-2);
}

.history-list {
  margin-top: 24px;
  border-top: var(--rule-w) solid var(--ink-strong);
}

.day { background: none; border: 0; border-radius: 0; }

.day-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 52px;
  padding: 0;
  border-bottom: var(--rule-w) solid var(--rule);
  cursor: pointer;
  list-style: none;
}

.day-summary::-webkit-details-marker { display: none; }

.day-label { flex: 1; font-size: 16px; font-weight: 800; }

.day-score {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--sheet-muted);
}

.day-flag {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  box-shadow: inset 0 0 0 2px currentColor;
  color: var(--sheet-text);
}

.day-flag .dash {
  width: 10px;
  height: 2.5px;
  background: currentColor;
}

.day.is-met > .day-summary .day-flag {
  background: var(--sheet-block-bg);
  box-shadow: none;
  color: var(--sheet-block-fg);
}

/* An expanded day becomes a navy block. */
.day[open] {
  background: var(--field-bg);
  color: var(--field-fg);
  --rule: var(--navy-line);
  --dim: var(--navy-muted);
  --press: var(--navy-2);
}

.day[open] > .day-summary {
  padding: 0 12px;
  border-bottom: 0;
}

.day[open] > .day-summary .day-score { color: inherit; }

.day[open] > .day-summary .day-flag {
  background: none;
  box-shadow: inset 0 0 0 2px currentColor;
  color: var(--field-fg);
}

.day-body {
  padding: 0 0 4px 12px;
  border-top: var(--rule-w) solid var(--field-fg);
}

.day-body .entry-list {
  margin: 0;
  border-top: 0;
}

.day-body .entry {
  border-bottom: 1px solid var(--navy-line);
}

.day-body .entry-amount { font-size: 18px; }

.day-body .entry-edit {
  height: var(--tap);
  padding: 0 12px;
  border: 0;
  background: none;
  color: var(--navy-muted);
  font-size: 14px;
  font-weight: 700;
}

.day-body .entry-delete {
  width: 44px;
  min-width: 44px;
  color: var(--danger);
}

.day-body .empty { color: var(--navy-muted); }

.day-body .text-btn {
  padding-left: 0;
  color: var(--field-fg);
}

/* ---------- toast ---------- */

.toast-host {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-b) + 162px);
  display: flex;
  justify-content: center;
  padding: 0 16px;
  pointer-events: none;
  z-index: 20;
}

body[data-view="history"] .toast-host { bottom: calc(var(--safe-b) + 16px); }

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 420px;
  padding: 8px 8px 8px 16px;
  background: var(--navy);
  color: var(--paper);
  box-shadow: inset 0 0 0 2px var(--paper);
  pointer-events: auto;
  animation: toast-in 140ms ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.toast-text {
  flex: 1;
  font-size: 15px;
  font-weight: 700;
}

.toast-action {
  height: 40px;
  padding: 0 16px;
  border: 0;
  background: var(--paper);
  color: var(--navy);
  font-size: 15px;
  font-weight: 800;
}

/* ---------- settings dialog ---------- */

.dialog {
  width: min(480px, 100vw);
  max-width: 100vw;
  max-height: 88dvh;
  overflow-y: auto;
  margin: auto auto 0;
  padding: 16px calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  border: 0;
  border-top: var(--rule-w) solid var(--sheet-fg);
  border-radius: 0;
  background: var(--sheet-bg);
  color: var(--sheet-text);
}

.dialog::backdrop { background: rgb(9 4 70 / 0.6); }

.dialog :focus-visible { outline-color: var(--sheet-text); }

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.dialog-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  color: var(--sheet-fg);
}

.dialog .icon-btn { color: var(--sheet-text); }
.dialog .icon-btn:active { background: var(--sheet-press); }

.dialog-subhead {
  margin: 24px 0 8px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sheet-fg);
}

.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-row label { flex: 1; font-weight: 700; }

#target-input {
  width: 5.5rem;
  min-height: var(--tap);
  padding: 0 10px;
  border: 2px solid var(--sheet-text);
  border-radius: 0;
  background: transparent;
  color: var(--sheet-text);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.btn {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 16px;
  border: 2px solid var(--sheet-text);
  border-radius: 0;
  background: transparent;
  color: var(--sheet-text);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

.btn:active { background: var(--sheet-press); }

.btn-primary {
  border-color: var(--sheet-block-bg);
  background: var(--sheet-block-bg);
  color: var(--sheet-block-fg);
}

.btn-primary:active { background: var(--navy-2); border-color: var(--navy-2); color: var(--paper); }

.btn-block { width: 100%; margin-top: 8px; }

.dialog-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.file-btn { justify-content: center; }

.hint {
  margin: 8px 0 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--sheet-muted);
}

.version { margin-top: 16px; font-size: 12px; letter-spacing: 0.04em; }

@media (prefers-reduced-motion: reduce) {
  body, .appbar, .quick-add { transition: none; }
  .progress-fill { transition: none; }
  .toast { animation: none; }
}
