:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --ink: #1d2321;
  --muted: #6b7472;
  --line: #e2e0da;
  --accent: #1f6f5c;
  --food: #d98324;
  --water: #2f80c2;
  --urine: #c9a227;
  --stool: #8a6244;
  --ok: #1f7a4d;
  --warn: #a8641b;
  --err: #b3261e;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16191a;
    --card: #212527;
    --ink: #eceeed;
    --muted: #9aa3a1;
    --line: #343a3c;
    --accent: #46a88d;
  }
}

* { box-sizing: border-box; }

/* .modal sets display:flex, which beats the UA [hidden] rule -- without this,
   toggling .hidden changes nothing and the modal stays on screen. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
body.locked { overflow: hidden; }

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

.header {
  max-width: 560px;
  margin: 0 auto;
  padding: 28px 16px 18px;
  text-align: center;
}
.header h1 { margin: 0; font-size: 30px; letter-spacing: -0.02em; }
.header .sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

/* ------------------------------- tiles --------------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.tile {
  appearance: none;
  border: 1px solid var(--line);
  border-left: 5px solid var(--tile, var(--accent));
  background: var(--card);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 22px 14px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-height: 104px;
  justify-content: center;
  transition: transform .06s ease, box-shadow .15s ease;
}
.tile:active { transform: scale(.97); }
.tile .ico { font-size: 28px; line-height: 1; }

.t-food  { --tile: var(--food); }
.t-water { --tile: var(--water); }
.t-urine { --tile: var(--urine); }
.t-stool { --tile: var(--stool); }

/* ------------------------------ recent --------------------------------- */
.recent { margin-top: 30px; }
.recent-head { display: flex; align-items: baseline; justify-content: space-between; }
.recent-head h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; }

.linkbtn {
  background: none; border: 0; padding: 0;
  color: var(--accent); font-size: 14px; cursor: pointer;
}

.recent-list { list-style: none; margin: 0; padding: 0; }
.recent-list .entry {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--tile, var(--accent));
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.recent-list .ico { font-size: 18px; }
.recent-list .meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.recent-list .meta em { font-style: normal; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-list .when { color: var(--muted); font-size: 13px; white-space: nowrap; }
.recent-list .empty { color: var(--muted); font-size: 14px; padding: 8px 2px; }

/* ------------------------------- modal --------------------------------- */
.backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 10;
}

.modal {
  position: fixed;
  z-index: 11;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 40px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 560px) {
  .modal { bottom: auto; top: 50%; transform: translate(-50%, -50%); border-radius: 18px; }
}

.modal form { display: contents; }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 19px; }
.close {
  background: none; border: 0; color: var(--muted);
  font-size: 30px; line-height: 1; cursor: pointer; padding: 0 4px;
}

.modal-body { padding: 16px 18px; overflow-y: auto; }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--muted); margin-bottom: 5px;
}
.field input, .field select {
  width: 100%;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom-on-focus */
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  min-height: 44px;
}
.field input:focus, .field select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.modal-foot {
  display: flex; gap: 10px;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
}
.btn {
  flex: 1;
  font: inherit; font-weight: 600; font-size: 16px;
  border-radius: 11px; padding: 13px; cursor: pointer;
  min-height: 48px;
}
.btn.primary { background: var(--accent); border: 1px solid var(--accent); color: #fff; }
.btn.primary:disabled { opacity: .6; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }

/* ------------------------------- toast --------------------------------- */
.toast {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translateX(-50%);
  z-index: 20;
  background: var(--ink);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 15px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
  max-width: 90vw;
}
.toast.ok   { background: var(--ok);   color: #fff; }
.toast.warn { background: var(--warn); color: #fff; }
.toast.err  { background: var(--err);  color: #fff; }

/* Installed (home-screen) mode: respect the notch and home indicator. */
@media (display-mode: standalone) {
  .header { padding-top: calc(28px + env(safe-area-inset-top)); }
  main { padding-bottom: calc(48px + env(safe-area-inset-bottom)); }
}
