:root {
  --bg: #f4f8f4;
  --surface: #ffffff;
  --text: #17301f;
  --muted: #5d7364;
  --border: #dbe6dd;
  --brand: #2f7d4f;
  --brand-text: #ffffff;

  --normal: #2f7d4f;
  --normal-bg: #e3f3e8;
  --attention: #9a6700;
  --attention-bg: #fff4d6;
  --urgent: #c2410c;
  --urgent-bg: #ffe7d9;
  --today: #b91c1c;
  --today-bg: #fde2e2;
  --past: #57534e;
  --past-bg: #ece9e6;

  --radius: 14px;
  --tabbar-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1712;
    --surface: #18241c;
    --text: #e4efe7;
    --muted: #9db3a4;
    --border: #2a3a2f;
    --brand: #4fb07a;
    --brand-text: #08130c;

    --normal: #6fd197;
    --normal-bg: #1d3526;
    --attention: #f2c14e;
    --attention-bg: #3a3017;
    --urgent: #ff9a62;
    --urgent-bg: #3e2418;
    --today: #ff7b7b;
    --today-bg: #421d1d;
    --past: #c4bdb6;
    --past-bg: #2c2a28;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

a { color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--brand);
  color: var(--brand-text);
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
}
.brand {
  font-weight: 700;
  font-size: 1.2rem;
  text-decoration: none;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  outline: none;
}

h1 { font-size: 1.5rem; margin: 4px 0 12px; }
h2 { font-size: 1.05rem; margin: 24px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 1.05rem;
}

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 6px solid var(--status, var(--border));
  border-radius: var(--radius);
  padding: 12px 14px;
  text-decoration: none;
}
.item-emoji { font-size: 1.6rem; }
.item-main { flex: 1; min-width: 0; }
.item-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { color: var(--muted); font-size: .85rem; }

.pill {
  flex-shrink: 0;
  font-size: .85rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--status);
  background: var(--status-bg);
}

.s-normal    { --status: var(--normal);    --status-bg: var(--normal-bg); }
.s-attention { --status: var(--attention); --status-bg: var(--attention-bg); }
.s-urgent    { --status: var(--urgent);    --status-bg: var(--urgent-bg); }
.s-today     { --status: var(--today);     --status-bg: var(--today-bg); }
.s-past      { --status: var(--past);      --status-bg: var(--past-bg); }

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 12px 16px;
  border-radius: 12px;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--brand); color: var(--brand-text); border-color: var(--brand); }
.btn-danger { color: var(--today); }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.btn-row .btn { flex: 1; }

.cta { margin-top: 24px; }

.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.chip {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .9rem;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--brand); color: var(--brand-text); border-color: var(--brand); }

form { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > label, .field > legend { font-weight: 600; }
fieldset { border: 0; margin: 0; padding: 0; }
input[type="text"], input[type="date"], select {
  font: inherit;
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.hint { color: var(--muted); font-size: .85rem; }

.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.choices input { accent-color: var(--brand); }
.choices label:has(input:checked) { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }

.quick { display: flex; gap: 8px; flex-wrap: wrap; }
.quick .chip { font-size: .85rem; }

.checks { display: grid; gap: 8px; }
.checks label { display: flex; align-items: center; gap: 10px; }
.checks input { width: 20px; height: 20px; accent-color: var(--brand); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 12px;
}

.detail-head { display: flex; align-items: center; gap: 12px; }
.detail-head .item-emoji { font-size: 2.4rem; }
.countdown {
  margin-top: 12px;
  text-align: center;
  border-radius: var(--radius);
  padding: 16px;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: .02em;
  color: var(--status);
  background: var(--status-bg);
}
.facts { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.note { color: var(--muted); font-size: .9rem; margin: 12px 0 0; }

.banner {
  max-width: 560px;
  margin: 12px auto 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--attention-bg);
  color: var(--text);
  border: 1px solid var(--border);
  width: calc(100% - 32px);
}
.banner ul { margin: 0; padding-left: 18px; }
.banner button { margin-top: 8px; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: .75rem;
  text-decoration: none;
  color: var(--muted);
}
.tabbar a span { font-size: 1.25rem; line-height: 1; }
.tabbar a[aria-current="page"] { color: var(--brand); font-weight: 700; }
.tab-add span {
  background: var(--brand);
  color: var(--brand-text);
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.btn-stack { display: grid; gap: 8px; }
.btn-stack + .card { margin-top: 16px; }
label.btn { cursor: pointer; }

.tips { margin: 8px 0 0; padding-left: 20px; }
.tips li + li { margin-top: 4px; }

.scan-note { margin: 0 0 16px; }
.scan-date { font-size: 1.4rem; font-weight: 800; margin: 2px 0 4px; }

.scan-photo {
  display: block;
  width: 100%;
  max-height: 40vh;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}
progress {
  width: 100%;
  height: 10px;
  margin-top: 10px;
  accent-color: var(--brand);
}

.ocr-text { margin-top: 16px; color: var(--muted); }
.ocr-text summary { cursor: pointer; }
.ocr-text pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: .8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

/* Live camera with aiming box */
.viewfinder {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
}
.viewfinder video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.aim {
  position: absolute;
  z-index: 1;
  left: 8%;
  right: 8%;
  top: 35%;
  height: 30%;
  border: 3px solid #ffd54f; /* visible on white and dark packs */
  border-radius: 10px;
  /* darken everything outside the box */
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
}
.aim-hint {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  bottom: 8px;
  margin: 0;
  text-align: center;
  color: #fff;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .8);
}
.cam-row { display: flex; gap: 8px; margin-top: 12px; }
.cam-row .btn-primary { flex: 1; font-size: 1.05rem; }
.cam-row [aria-pressed="true"] { background: var(--attention-bg); border-color: var(--attention); }

/* Mark the date on a photo */
.crop {
  position: relative;
  touch-action: none;
  user-select: none;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
}
.crop img { display: block; width: 100%; height: auto; pointer-events: none; }
.crop-box {
  position: absolute;
  border: 3px solid #fff;
  border-radius: 8px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
}

.scan-thumb {
  display: block;
  width: 100%;
  max-height: 120px;
  object-fit: contain;
  margin-top: 8px;
  border-radius: 8px;
  background: #000;
}
