:root {
  color-scheme: light dark;
  /* The family's palette -- the documents app's, the stuff app's, the
     journal's and the books app's: one family of apps on one domain. */
  --bg: #f7f7fa;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #8a8a93;
  --faint: #b6b6c0;
  /* Indigo. The one saturated colour, spent on what is worth the eye: the
     progress, and the buttons that add to it. */
  --accent: #4c3fd6;
  --on-accent: #ffffff;
  --miss: #b8412f;
  --good: #248a3d;
  --hairline: rgba(0, 0, 0, 0.1);
  --card-shadow: 0 1px 2px rgba(20, 20, 40, 0.06), 0 10px 30px -18px rgba(20, 20, 40, 0.4);
  --tag-bg: rgba(0, 0, 0, 0.05);
  --press: rgba(0, 0, 0, 0.04);
  --track: rgba(76, 63, 214, 0.12);

  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #93939c;
    --faint: #55555e;
    --accent: #7c6ffb;
    --on-accent: #ffffff;
    --miss: #ff7c66;
    --good: #30d158;
    --hairline: rgba(255, 255, 255, 0.12);
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 12px 32px -18px rgba(0, 0, 0, 0.8);
    --tag-bg: rgba(255, 255, 255, 0.08);
    --press: rgba(255, 255, 255, 0.06);
    --track: rgba(124, 111, 251, 0.2);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* One readable column, whatever the window. */
.page {
  max-width: 640px;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top, 0px), 12px) 16px
           max(env(safe-area-inset-bottom, 0px), 24px);
}

.head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 4px 14px;
}

.head-text {
  flex: 1;
  min-width: 0;
}

.title {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sub {
  min-height: 20px;
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.head-buttons {
  flex: none;
  align-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
}

.view-swap {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--tag-bg);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}

.view-swap svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.view-swap:active {
  background: var(--press);
}

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

/* The journal's section label. */
.list-head {
  display: flex;
  justify-content: space-between;
  margin: 22px 4px 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.list-count {
  font-weight: 500;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  color: var(--faint);
}

.card {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  overflow: hidden;
}

.empty {
  margin: 14px 4px;
  color: var(--muted);
  font-size: 15px;
}

/* --------------------------------------------------------------------------
   The day's progress
   -------------------------------------------------------------------------- */

.progress {
  padding: 18px 18px 16px;
}

.progress-numbers {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.progress-total {
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.progress-total .unit {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--muted);
}

.goal-plain {
  font-size: 15px;
  color: var(--muted);
}

.bar {
  height: 12px;
  margin-top: 16px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.35s ease;
}

.bar.is-met .bar-fill {
  background: var(--good);
}

.progress-line {
  margin: 10px 0 0;
  font-size: 15px;
  color: var(--muted);
}

.progress-line.is-met {
  color: var(--good);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   The containers
   -------------------------------------------------------------------------- */

/* Four across on a phone: one tap, no scrolling, nothing to aim for. */
.containers {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 108px;
  padding: 14px 6px 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--card-shadow);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease;
}

.container:active {
  transform: scale(0.96);
  background: color-mix(in srgb, var(--accent) 8%, var(--card));
}

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

.container:disabled {
  cursor: default;
}

.container svg {
  width: 34px;
  height: 34px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.container-name {
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  line-height: 1.15;
}

.container-oz {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Rows: the day's log, and the history's days
   -------------------------------------------------------------------------- */

.card > li {
  position: relative;
}

/* A hairline that starts where the text does, as in the phone's own lists. */
.card > li + li::before {
  content: "";
  position: absolute;
  top: 0;
  left: 76px;
  right: 0;
  height: 1px;
  background: var(--hairline);
  pointer-events: none;
}

.row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 56px;
  padding: 10px 16px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

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

@media (hover: hover) {
  .row:hover {
    background: var(--press);
  }
}

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

/* The time or the date, in a column of its own on the left. */
.when {
  flex: none;
  width: 46px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}

.when-big {
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.day-num {
  font-size: 20px;
}

.when-under {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.row-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.row-title {
  font-size: 16px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.row-amount {
  flex: none;
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.row-amount .unit {
  font-weight: 500;
  color: var(--muted);
}

.row-meta {
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.row-meta.is-met {
  color: var(--good);
}

.mini-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}

.mini-bar > div {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

.mini-bar.is-met > div {
  background: var(--good);
}

.chevron {
  flex: none;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--faint);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.more-wrap {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

/* --------------------------------------------------------------------------
   Pills, sheets and the toast
   -------------------------------------------------------------------------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px 7px 14px;
  border: none;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 13%, var(--card));
  color: var(--accent);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

.pill svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pill:active {
  background: color-mix(in srgb, var(--accent) 22%, var(--card));
}

.pill:disabled {
  opacity: 0.5;
  cursor: default;
}

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

/* A dialog rather than a page of its own: each is a small errand. */
.sheet {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  box-shadow: 0 24px 60px -12px rgba(20, 20, 40, 0.45);
}

.sheet::backdrop {
  background: rgba(20, 20, 40, 0.4);
}

.sheet-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
}

.sheet-title {
  margin: 0;
  font-size: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 14px;
  color: var(--muted);
}

.field input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  /* 16px or iOS zooms the page in when the field takes focus. */
  font-size: 16px;
}

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

/* The unit inside the field's right edge. */
.oz-input {
  position: relative;
  display: block;
}

.oz-input input {
  padding-right: 40px;
}

.oz-input span {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 16px;
  pointer-events: none;
}

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

.sheet-note {
  margin: 0;
  font-size: 14px;
  color: var(--miss);
}

.sheet-buttons {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.sheet-gap {
  flex: 1;
}

.sheet-buttons button {
  white-space: nowrap;
  padding: 9px 18px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.sheet-buttons .primary {
  background: var(--accent);
  color: var(--on-accent);
}

.sheet-buttons .secondary {
  background: var(--tag-bg);
  color: var(--text);
}

.sheet-buttons .danger {
  padding-left: 4px;
  padding-right: 4px;
  background: none;
  color: var(--miss);
}

.sheet-buttons button:disabled {
  opacity: 0.55;
  cursor: default;
}

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

/* Over the bottom of the page, clear of the home indicator. */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(env(safe-area-inset-bottom, 0px), 16px);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 14px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 11px 12px 11px 16px;
  border-radius: 999px;
  background: #2c2c2e;
  color: #fff;
  font-size: 15px;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  transform: translateX(-50%);
}

.toast.is-error {
  background: var(--miss);
}

.toast-undo {
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: #b5adff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.foot {
  padding: 28px 4px 8px;
}

.account-line {
  font-size: 13px;
  color: var(--faint);
  text-align: center;
}

.account-line form {
  display: inline;
}

.text-link {
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
