:root {
  --navy: #0b1b33;
  --paper: #ffffff;
  --ink: #0b1b33;
  --page: #f4f7fc;
  --amber: #f0b429;
  --green: #d9f2df;
  --go: #1a5c1e;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  touch-action: manipulation;
}

body { display: flex; flex-direction: column; }

/* Slow pulse between two calm colours: one cycle takes four seconds. */
body.alarm { animation: pulse 4s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { background-color: var(--page); }
  50% { background-color: var(--amber); }
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 16px;
}

.panel { background: var(--paper); color: var(--ink); border-radius: 24px; }

/* Header with reminders: weekday, date and time in one dark bar. */
.clockbox {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 10px 68px 10px 12px;
  border-radius: 0 0 24px 24px;
  background: var(--navy);
  color: var(--paper);
  font-size: max(48px, 4.4vw);
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.dates { display: contents; }
.datebox, .timebox { display: flex; align-items: center; gap: 12px; padding-left: 20px; border-left: 3px solid #8d9ab5; }
.clock { font-size: 1.15em; line-height: 1.15; font-variant-numeric: tabular-nums; }
#year { display: none; }

/* Without reminders: a large clock on a light page. */
main:not(.busy) { padding: 16px; }
main:not(.busy) .clockbox { flex: 1; flex-direction: column; gap: 8px; padding: 8px; background: none; color: var(--ink); line-height: 1.2; }
main:not(.busy) .timebox { order: -1; padding: 0; border: 0; }
main:not(.busy) .datebox { padding: 0; border: 0; font-weight: 400; font-size: max(48px, 9vh); }
main:not(.busy) .weekday { font-size: max(48px, 9vh); }
main:not(.busy) .icon { display: none; }
main:not(.busy) .clock { font-size: min(46vh, 28vw); line-height: 1.05; }
main:not(.busy) #year { display: inline; white-space: pre; }

.guide { margin: 0; padding: 0 16px; text-align: center; font-size: max(48px, min(5.5vh, 3.4vw)); font-weight: 700; line-height: 1.2; }
main:not(.busy) .guide { display: none; }

/* Reminder cards. The whole card is the touch target. */
.tiles { flex: 1; min-height: 0; display: grid; gap: 16px; padding: 0 16px; grid-template-columns: 1fr; grid-auto-rows: 1fr; }
main:not(.busy) .tiles { display: none; }
.tiles.two, .tiles.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tiles.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.tile {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  padding: 12px;
  border: 3px solid #a9bad6;
  border-radius: 28px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 6px 16px rgba(11, 27, 51, 0.16);
  font: inherit;
  font-size: 48px;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
}

.face {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 8px;
  border-radius: 18px;
  background: var(--panel);
}

.face .pic { width: auto; height: 100%; max-height: min(30vh, 210px); aspect-ratio: 1; }
.text { min-width: 0; display: flex; flex-direction: column; text-align: left; }
.label { display: flex; flex-direction: column; overflow-wrap: anywhere; hyphens: auto; }
.kind { font-size: max(48px, 6vh); }
.name { font-size: max(52px, 8vh); }

.go {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 120px;
  border-radius: 20px;
  background: var(--go);
  color: var(--paper);
  font-size: max(48px, 6.5vh);
}

.tiles.two .face { gap: 16px; }
.tiles.two .face .pic { max-height: min(22vh, 140px); }

/* Three cards: the picture sits above the name. */
.tiles.three .face { flex-direction: column; gap: 8px; }
.tiles.three .face .pic { flex: 0 1 max(150px, 28vh); min-height: 0; width: 100%; height: auto; max-height: none; aspect-ratio: auto; }
.tiles.three .text { text-align: center; max-width: 100%; }
.tiles.three .kind, .tiles.three .name { font-size: max(48px, min(6.5vh, 3.9vw)); }
.tiles.three .go { gap: 8px; min-height: max(120px, 14vh); font-size: max(48px, min(6vh, 3.6vw)); }
.tiles.three .state { font-size: max(48px, min(5vh, 3vw)); }
.tiles.three .done .action { min-height: max(120px, 14vh); font-size: max(48px, min(6vh, 3.6vw)); }
.tiles.three .done .face .pic { flex-basis: max(90px, 18vh); }

/* Narrow screens: give the words the room that margins and the check mark take. */
@media (max-width: 1150px) {
  .tiles.three { gap: 6px; padding: 0 6px; }
  .tiles.three .tile { gap: 6px; padding: 2px; }
  .tiles.three .face { padding: 4px 0; }
  .tiles.three .go .icon { display: none; }
  .tiles.three .done .action { padding: 0; }
}

/* Four cards: two rows with small pictures and a lower button bar. */
.tiles.four { gap: 12px; padding: 0 12px; }
.tiles.four .tile { gap: 8px; padding: 6px; line-height: 1.1; }
.tiles.four .face { gap: 12px; padding: 2px 8px; }
.tiles.four .face .pic { max-height: max(80px, 14vh); }
.tiles.four .kind, .tiles.four .name { font-size: max(48px, min(6vh, 3.2vw)); }
.tiles.four .go { min-height: max(64px, 9vh); font-size: max(48px, min(6vh, 3.2vw)); }

.tile.done .face { background: var(--green); }
.state { font-size: 48px; font-weight: 400; }
.tiles.four .done .face .pic, .tiles.four .done .state { display: none; }
.tiles.four .done .text { text-align: center; max-width: 100%; }
.tiles.four .done .label { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tiles.four .done .label::before { content: "✔ "; }

button {
  font: inherit;
  cursor: pointer;
}

button:disabled { color: inherit; opacity: 1; cursor: default; }
.action:disabled, .tile:disabled { color: var(--ink); }
.action.primary:disabled { color: var(--paper); }

.action {
  min-height: 120px;
  min-width: 240px;
  padding: 16px 40px;
  border: 6px solid var(--ink);
  border-radius: 24px;
  background: var(--paper);
  color: var(--ink);
  font-size: 52px;
  font-weight: 700;
}

.tile.done .action { min-width: 0; padding: 8px; font-size: 48px; border-width: 4px; }
.action.primary { background: var(--go); color: var(--paper); border-color: var(--go); }

.hints { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.hints:empty { display: none; }
.hint { background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 16px; padding: 0 24px; font-size: 48px; line-height: 1.2; }

.gear {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: #b8c4dc;
  font-size: 32px;
}

main:not(.busy) .gear { color: #52607a; }

/* Less room: three or four cards, or the camera banner above. */
main.many { gap: 12px; padding-bottom: 12px; }
main.many .clockbox { padding-top: 4px; padding-bottom: 4px; }

body.filming .guide { display: none; }
body.filming main.many .hints { display: none; }

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(11, 27, 51, 0.92);
  z-index: 5;
}

/* The camera banner stays above every dialog. */
body.filming .overlay { top: 150px; }

.dialog {
  width: 100%;
  max-width: 1100px;
  max-height: 100%;
  overflow: auto;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  text-align: center;
  font-size: 48px;
}

.dialog h1 { margin: 0; font-size: 56px; }
.dialog h1.dose { display: flex; align-items: center; justify-content: center; gap: 24px; }
.dialog h1.dose .pic { font-size: 110px; }
.dialog p { margin: 0; overflow-wrap: anywhere; }
.dialog .buttons { display: flex; gap: 48px; justify-content: center; flex-wrap: wrap; }

.dialog.compact { gap: 16px; padding: 20px 32px; line-height: 1.2; }
.dialog.compact h1 { font-size: 48px; }
.dialog.compact .buttons { gap: 24px; }
.dialog input {
  font: inherit;
  font-size: 56px;
  min-width: 0;
  padding: 8px 16px;
  border: 4px solid var(--ink);
  border-radius: 16px;
  text-align: center;
  text-transform: uppercase;
  user-select: text;
}

.error { color: #7a1f00; font-weight: 700; }

.camera {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin: 12px 16px 0;
  padding: 12px 24px;
  min-height: 130px;
  border-radius: 24px;
  background: var(--amber);
  color: var(--ink);
  font-size: 48px;
  font-weight: 700;
  border: 6px solid var(--ink);
  position: relative;
  z-index: 10;
}

body.filming main:not(.busy) .clock { font-size: min(20vh, 14vw); }

@media (prefers-reduced-motion: reduce) {
  body.alarm { animation-duration: 8s; }
}
