:root {
  color-scheme: light;
  --bg: #eef2ef;
  --ink: #1c2c32;
  --muted: #3e5258;
  --line: #c9d4d0;
  --card: #f7faf8;
  --field: #ffffff;
  --ink-btn: #1e3a4c;
  --ink-press: #152a38;
  --danger: #8a3a3a;
  --food: #f0d3bf;
  --supplements: #ddd6f0;
  --bowel: #d3e3ee;
  --symptoms: #f0d4d8;
  --activity: #d5e6d4;
  --sleep: #d8d6ee;
  --stress: #f1e4b4;
  --font-serif: Literata, "Iowan Old Style", Palatino, serif;
  --font-sans: Karla, "Avenir Next", sans-serif;
  --radius-card: 8px;
  --radius-control: 6px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 10px;
  --space-4: 14px;
  --space-5: 16px;
  --tap: 44px;
  --control: 46px;
  --tile-min: 112px;
  --focus: 2px solid var(--ink-btn);
  --shadow-tile: 0 4px 10px rgba(28, 44, 50, 0.12);
}

* { box-sizing: border-box; }

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: #dfe7e3;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 17px;
  font-weight: 500;
  line-height: 1.4;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

h1,
.date-line,
.section-name,
.daybar h1,
.group h2 {
  font-family: var(--font-serif);
  font-optical-sizing: auto;
}

.sheet {
  width: min(480px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
}

main {
  padding:
    calc(18px + env(safe-area-inset-top))
    16px
    calc(168px + env(safe-area-inset-bottom));
}

h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 680;
  line-height: 1.2;
}

.date-line {
  margin: 0;
  color: var(--ink);
  font-size: 22px;
  font-weight: 680;
  line-height: 1.2;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  align-items: stretch;
}

.section {
  min-width: 0;
  min-height: var(--tile-min);
  border-radius: var(--radius-card);
}

.section.open { min-height: 0; }

.section.open { grid-column: 1 / -1; }

.section-name {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  width: 100%;
  min-height: var(--tile-min);
  padding: var(--space-4) var(--space-4) var(--space-4) var(--space-5);
  border: 0;
  border-radius: var(--radius-card);
  background: transparent;
  text-align: left;
  font-size: 22px;
  font-weight: 680;
  line-height: 1.15;
  user-select: none;
  touch-action: manipulation;
}

.section-name span { min-width: 0; }

.section-name svg {
  width: 26px;
  height: 26px;
  flex: none;
  margin-top: 1px;
}

.section.open .section-name {
  flex-direction: row;
  align-items: center;
  min-height: 56px;
  padding-bottom: 4px;
  border-radius: var(--radius-card) var(--radius-card) 0 0;
}

.section form { padding: 4px 14px 14px; }

@media (prefers-reduced-motion: no-preference) {
  .section.open form {
    animation: open-form 160ms ease;
  }
}

@keyframes open-form {
  from { opacity: 0; }
  to { opacity: 1; }
}

.section label,
.section .label {
  margin: var(--space-3) 0 var(--space-1);
  font-size: 15px;
  font-weight: 500;
}

.section input,
.section select,
.section textarea {
  min-height: var(--control);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-control);
  font-size: 16px;
}

.section textarea { min-height: 84px; }

.section .pair {
  flex-direction: row;
  align-items: stretch;
}

.section .pair input {
  flex: 1;
  width: auto;
  min-width: 0;
}

.section .pair select {
  width: 118px;
  flex: none;
}

.section .note-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  min-height: var(--tap);
  margin-top: var(--space-2);
  border: 1px dashed var(--ink-btn);
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--ink);
  font-weight: 700;
  font-size: 16px;
}

.section .note-toggle .plus {
  font-size: 20px;
  line-height: 1;
}

.section .note-toggle[aria-expanded="true"] {
  background: var(--ink-btn);
  border-style: solid;
  border-color: var(--ink-btn);
  color: white;
}

.section .choices { flex-direction: column; }

.section .choices.wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.section .choices button {
  min-height: var(--tap);
  padding: 6px;
  font-size: 16px;
}

.section .counter button {
  width: 44px;
  height: 44px;
  font-size: 22px;
}

.section .counter strong {
  font-family: Literata, Palatino, serif;
  font-size: 22px;
  font-weight: 680;
}

.section .save {
  width: 100%;
  min-height: var(--tap);
  margin-top: var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: var(--ink-btn);
  color: white;
  font-weight: 700;
  font-size: 17px;
}

.section .save[aria-disabled="true"] {
  background: transparent;
  border-color: var(--ink);
  color: var(--ink);
}

.save-hint {
  margin: var(--space-1) 0 0;
  color: var(--muted);
  font-size: 15px;
}

.section .card-msg {
  min-height: 1.2em;
  margin: 6px 0 0;
  color: var(--ink-btn);
  font-size: 15px;
  font-weight: 700;
}

.food { background: var(--food); }
.supplements { background: var(--supplements); }
.bowel { background: var(--bowel); }
.symptoms { background: var(--symptoms); }
.activity { background: var(--activity); }
.sleep { background: var(--sleep); }
.stress { background: var(--stress); }

.linkish {
  display: flex;
  align-items: center;
  width: auto;
  min-height: 40px;
  margin: 2px 0 16px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.back {
  min-height: 44px;
  margin: 0 0 6px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 500;
  font-size: 17px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

label, .label {
  display: block;
  margin: var(--space-3) 0 var(--space-1);
  font-weight: 500;
}

.pair, .time-row, .counter {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="time"],
select,
textarea {
  width: 100%;
  min-height: var(--control);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--field);
  font-size: 16px;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

.pair input { flex: 1; min-width: 0; }

.pair select {
  width: 124px;
  flex: none;
  background-color: var(--field);
}

select {
  appearance: none;
  padding-right: 32px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink) 50%),
    linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 16px) calc(50% - 2px), calc(100% - 11px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.choices {
  display: flex;
  gap: 8px;
}

.choices.wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.choices button {
  flex: 1;
  min-height: var(--tap);
  padding: var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--field);
}

.choices button[aria-pressed="true"] {
  background: var(--ink-btn);
  border-color: var(--ink-btn);
  color: white;
}

.counter { align-items: center; }

.counter button {
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--field);
  font-size: 24px;
  line-height: 1;
}

.counter strong {
  min-width: 40px;
  text-align: center;
  font-family: Literata, Palatino, serif;
  font-size: 24px;
  font-weight: 680;
}

.daybar {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  gap: 8px;
  align-items: center;
  margin-bottom: 18px;
}

.daybar h1 {
  font-size: 20px;
  font-weight: 680;
  text-align: center;
}

.daybar button {
  height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--field);
  font-size: 22px;
}

.daybar button:disabled { opacity: 0.35; }

.group { margin: 0 0 18px; }

.group h2 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 680;
}

.entry {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 0 0 8px;
  padding: 12px;
  border-radius: var(--radius-control);
  background: var(--field);
  border: 1px solid var(--line);
}

.entry p { margin: 0; flex: 1; }

.entry small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.edit {
  min-height: var(--tap);
  padding: 8px 4px;
  border: 0;
  background: transparent;
  color: var(--ink-btn);
  font-weight: 700;
  font-size: 15px;
}

.remove {
  min-height: 44px;
  padding: 8px 4px;
  border: 0;
  background: transparent;
  color: var(--danger);
  font-weight: 700;
  font-size: 15px;
}

.empty {
  margin: 24px 0;
  color: var(--muted);
}

.pin { padding-top: 14vh; }

.pin p { color: var(--muted); }

.error {
  min-height: 1.3em;
  margin: 10px 0 0;
  color: var(--danger);
  font-weight: 700;
}

.notice {
  margin: 0 0 8px;
  text-align: center;
  color: var(--ink);
  font-weight: 700;
}

.pdf-link {
  display: block;
  margin-top: 8px;
  text-align: center;
  color: var(--ink);
  font-weight: 700;
}

.dock {
  position: fixed;
  z-index: 2;
  left: 50%;
  bottom: 0;
  width: min(480px, 100%);
  transform: translateX(-50%);
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.dock .history {
  min-height: 40px;
  margin-bottom: var(--space-2);
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
}

.dock button, .dock a.primary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--ink-btn);
  color: white;
  font-weight: 700;
  font-size: 18px;
  text-decoration: none;
}

.dock button:disabled {
  background: #c5cfcc;
  color: #5c6866;
}

.dock button:active, .dock a.primary:active {
  background: var(--ink-press);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.section-name:focus-visible {
  outline: var(--focus);
  outline-offset: 2px;
}

button,
a,
.section {
  touch-action: manipulation;
}

@media (hover: hover) and (pointer: fine) {
  a,
  button:not(:disabled):not([aria-disabled="true"]),
  select,
  .section-name,
  input[type="time"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
  }

  button:disabled,
  button[aria-disabled="true"] {
    cursor: not-allowed;
  }

  .section:not(.open) {
    transition: transform 120ms ease, box-shadow 120ms ease;
  }

  .section:not(.open):hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-tile);
  }

  .section:not(.open):active {
    transform: none;
    box-shadow: none;
  }
}

@media (max-width: 520px) {
  body { background: var(--bg); }
}
