/* Minute Jar.
 *
 * The palette, the header bar, the buttons and the help sheet arrive from
 * name-hat, which is the most recently conventional app here; what is new is
 * the headline card, the ring, the week strip and the session list.
 */

/* R8.4. The theme is resolved in app.js and only the result reaches
   `data-theme`, so each palette below is written ONCE: light on :root, dark on
   :root[data-theme="dark"]. An @media (prefers-color-scheme) copy would be the
   dark palette written twice. */
:root {
  color-scheme: light;

  --bg: #f2f3f5;
  --surface: #ffffff;
  --surface-sunken: #f7f8fa;
  --border: #dcdfe4;
  --border-strong: #c3c8d0;
  --text: #1b1f24;
  --text-muted: #616b78;
  --text-faint: #98a1ac;
  --accent: #2f5cff;
  --accent-hover: #2749d6;
  --accent-text: #ffffff;
  --accent-soft: #e8edff;
  --good: #1d7a4c;
  --good-soft: #e6f5ed;
  --danger: #b3261e;
  --danger-soft: #fdeceb;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.04);
  --scrim: rgba(16, 24, 40, 0.45);
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #14171c;
  --surface: #1c2027;
  --surface-sunken: #22272f;
  --border: #2e343d;
  --border-strong: #3d444f;
  --text: #e6e9ee;
  --text-muted: #9aa4b1;
  --text-faint: #6d7783;
  --accent: #6b8cff;
  --accent-hover: #85a0ff;
  --accent-text: #10131a;
  --accent-soft: #23304f;
  --good: #5fd39b;
  --good-soft: #17352a;
  --danger: #f2837c;
  --danger-soft: #3a2220;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --scrim: rgba(0, 0, 0, 0.62);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 620px;
  margin: 0 auto;
}

.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;
}

/* ---------- header ---------- */

/* R8.5. One row from 320 px up: the way back on the left, the tools on the
   right, the jar's name centred in what is left and cut with … rather than
   wrapped. R8.3: the page paints under the status bar, so the bar's own
   controls start below it. */
.app-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 4px;
  padding: max(24px, env(safe-area-inset-top)) 0 16px;
}

.hdr-left {
  display: flex;
  align-items: center;
}

.app-header h1 {
  min-width: 0;
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Too narrow for a letter and the …: not drawn, still read. */
.app-header h1.is-cramped {
  color: transparent;
}

.hdr-actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 2px;
}

#hdr .hdr-btn,
#hdr #hdrHelp,
#hdr #hdrJars,
#hdr #hdrTheme {
  min-width: 44px;
  min-height: 44px;
}

#hdr .hdr-btn {
  padding: 7px 4px;
}

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

button {
  font: inherit;
  cursor: pointer;
  color: var(--text);
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 9px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { background: var(--surface-sunken); }

.btn-primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  min-height: 44px;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
  min-height: 44px;
}

.btn-quiet:hover:not(:disabled) {
  background: var(--surface);
  color: var(--text);
}

.btn-lg {
  padding: 12px 20px;
  font-size: 16px;
  min-height: 52px;
}

.btn-sm {
  min-height: 44px;
  padding: 6px 12px;
  font-size: 13px;
}

.is-danger {
  color: var(--danger);
}

.is-danger:hover:not(:disabled) {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0;
}

#run-controls .btn-primary { flex: 1 1 100%; }

.controls-wrap { flex-wrap: wrap; }

.controls-wrap .btn { flex: 1 1 auto; }

/* ---------- the headline card ---------- */

/* R5.2/R5.3. Three numbers, one big, and the card itself is the control that
   swaps which. Its height is fixed so a number changing every second cannot
   move the screen under a finger. */
.headline {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 132px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
}

.headline.is-running {
  border-color: var(--accent);
}

.ring-wrap {
  flex: none;
  width: 84px;
  height: 84px;
}

.ring {
  width: 84px;
  height: 84px;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: var(--surface-sunken);
  stroke-width: 12;
}

.ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 12;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s ease;
}

.ring-fill.is-met {
  stroke: var(--good);
}

.headline-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Every line in this card is one line. A label that wraps pushes into the
   number below it — at 320 px "LEFT OF THE GOAL" wrapped and overlapped an
   "8 min" that had itself wrapped — and a card whose height depends on its
   text is a card that moves the screen every time a number changes. */
.headline-label {
  height: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 11px;
  font-weight: 650;
  line-height: 16px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.headline-big {
  min-height: 40px;
  white-space: nowrap;
  font-size: 34px;
  font-weight: 700;
  line-height: 40px;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.headline-exact {
  height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12.5px;
  line-height: 18px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.headline-rest {
  flex: none;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: right;
}

.headline-small {
  white-space: nowrap;
}

/* A narrow phone gives the card 252 px to divide: the ring gives up the room
   rather than the numbers. */
@media (max-width: 360px) {
  .headline {
    gap: 10px;
    padding: 14px 12px;
  }

  .ring-wrap,
  .ring {
    width: 64px;
    height: 64px;
  }

  .headline-big { font-size: 30px; }
}

.headline-small {
  display: block;
  min-height: 32px;
  font-size: 12.5px;
  line-height: 16px;
  color: var(--text-muted);
}

.headline-small b {
  display: block;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ---------- the stretch left running ---------- */

.runaway {
  margin: 0 0 14px;
  padding: 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-sunken);
}

.runaway-text {
  margin: 0 0 10px;
  font-size: 14px;
}

.runaway-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ---------- the day ---------- */

.round-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  margin: 0 0 10px;
  padding: 0 2px;
}

.stats {
  display: flex;
  gap: 14px;
  min-height: 18px;
  margin: 0;
  font-size: 12.5px;
  line-height: 18px;
  color: var(--text-muted);
}

.stats b {
  font-weight: 600;
  color: var(--text);
}

/* ---------- lists ---------- */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.row-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: left;
  box-shadow: var(--shadow);
}

.row-main:hover:not(:disabled) { border-color: var(--border-strong); }

.row-name {
  flex: 1;
  min-width: 0;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.row-note {
  flex: none;
  font-size: 12.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.row-side {
  flex: none;
  min-width: 46px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.row-side:hover:not(:disabled) {
  border-color: var(--border-strong);
  color: var(--text);
}

.tag {
  flex: none;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--surface-sunken);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.name-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
}

/* ---------- the week ---------- */

.week-heading {
  margin: 20px 2px 8px;
  font-size: 12.5px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* Seven fixed columns that shrink rather than wrap: a strip that drops a day
   onto a second row at 320 px is a strip nobody reads as a week. */
.week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.day {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  padding: 6px 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 11px;
  color: var(--text-muted);
}

.day b {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.day.is-today {
  border-color: var(--border-strong);
}

.day.is-shown {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Met is a tick as well as a colour: no state carried by colour alone. */
.day.is-met b {
  color: var(--good);
}

/* ---------- forms, notes, hints ---------- */

.add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.add-form input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.note {
  min-height: 18px;
  margin: 0 2px 10px;
  font-size: 12.5px;
  line-height: 18px;
  color: var(--text-muted);
}

.note.is-error { color: var(--danger); }

.empty {
  margin: 0;
  padding: 26px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  text-align: center;
  font-size: 13.5px;
  color: var(--text-muted);
}

.hint {
  margin: 20px 2px 0;
  font-size: 12px;
  color: var(--text-faint);
}

.hint kbd {
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  font: inherit;
  font-size: 11px;
}

/* ---------- edit ---------- */

.settings {
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

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

.setting + .setting { margin-top: 10px; }

.setting-label {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 600;
}

.setting-select {
  flex: 0 0 auto;
  min-height: 44px;
  min-width: 124px;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.setting-hint {
  margin: 10px 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.settings .btn { width: 100%; }

/* ---------- help sheet ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--scrim);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheetCard {
  width: 100%;
  max-width: 460px;
  max-height: 86dvh;
  overflow-y: auto;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
}

.sheetCard h2 {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 650;
}

.sheetCard p {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--text-muted);
}

.sheetCard p b { color: var(--text); }

.sheetCard .hint { margin: 0 0 16px; }

.sheetCard .btn { width: 100%; }

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .ring-fill { transition: none; }
}
