:root {
  --board: #1F2A44;
  --board-deep: #151D31;
  --paper: #EEF1F7;
  --muted: #9AA6C2;
  --ink: #1F2A44;
  --danger: #A0302A;
  --round: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;
  --text: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { background: var(--board); -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--board);
  color: var(--paper);
  font: 400 16px/1.45 var(--text);
  padding: calc(env(safe-area-inset-top) + 8px) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid #F2E39B; outline-offset: 2px; }
.card :focus-visible, dialog :focus-visible { outline-color: var(--ink); }

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

/* Header */
.top, main, .empty, .hint, .bottom > * { width: 100%; max-width: 560px; margin-inline: auto; }

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0 20px;
}

h1 { margin: 0; font: 800 34px/1.1 var(--round); letter-spacing: -0.01em; }
.sub { margin: 6px 0 0; color: var(--muted); font-size: 15px; }
#progress-line { color: var(--paper); }

.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.08);
  color: var(--paper);
}

/* Install hint */
.hint {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px 12px 12px 16px;
  border-radius: 12px;
  background: rgb(255 255 255 / 0.08);
}
.hint[hidden] { display: none; }
.hint p { margin: 0; flex: 1; font-size: 15px; }
.hint .btn.ghost { flex: none; background: var(--paper); color: var(--ink); }

/* Cards */
main {
  display: grid;
  gap: 14px;
  align-content: start;
  flex: 1;
  padding-bottom: 16px;
}

.card {
  --stock: #BFE3D0;
  background: var(--stock);
  color: var(--ink);
  border-radius: 8px;
  padding: 12px 14px 10px 16px;
  /* the clipped corner of a time-clock card */
  clip-path: polygon(0 0, calc(100% - 24px) 0, 100% 24px, 100% 100%, 0 100%);
}

.card-head {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px 0 0;
  border: 0;
  background: none;
  text-align: left;
}

.emoji { font-size: 24px; line-height: 1; }
.emoji:empty { display: none; }

.name {
  flex: 1;
  min-width: 0;
  font: 700 18px/1.25 var(--round);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.streak { display: flex; align-items: baseline; gap: 4px; }
.streak b { font: 800 28px/1 var(--round); font-variant-numeric: tabular-nums; }
.streak small { font-size: 13px; font-weight: 600; opacity: 0.7; }

.holes {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  align-items: end;
}

.hole {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
  border: 0;
  background: none;
  user-select: none;
  -webkit-user-select: none;
}

.punch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px dashed rgb(31 42 68 / 0.38);
  transition: background-color 0.12s, border-color 0.12s;
}

.is-today .punch { width: 44px; height: 44px; border: 2.5px solid var(--ink); }

.hole[aria-pressed="true"] .punch {
  background: var(--board);
  border-color: transparent;
  box-shadow: inset 0 3px 5px rgb(0 0 0 / 0.55), 0 1px 0 rgb(255 255 255 / 0.45);
}

.day { font-size: 12px; font-weight: 600; opacity: 0.7; }
.is-today .day { opacity: 1; font-weight: 800; }

.just .punch { animation: punch 0.24s cubic-bezier(.3,1.6,.5,1); }
@keyframes punch {
  0% { transform: scale(0.6); }
  100% { transform: scale(1); }
}

/* Empty state */
.empty { padding: 8px 0 24px; }
.empty h2 { margin: 0 0 8px; font: 800 24px/1.2 var(--round); }
.empty p { margin: 0 0 10px; max-width: 42ch; }
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.suggestions button {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  color: var(--ink);
  font: 700 16px var(--round);
}

/* Footer */
.bottom {
  position: sticky;
  bottom: 0;
  padding: 16px 0 calc(env(safe-area-inset-bottom) + 12px);
  background: linear-gradient(to bottom, rgb(31 42 68 / 0), var(--board) 40%);
}

.add {
  display: block;
  height: 54px;
  border: 2px dashed rgb(238 241 247 / 0.45);
  border-radius: 8px;
  background: var(--board-deep);
  color: var(--paper);
  font: 700 17px var(--round);
}

/* Dialogs */
dialog {
  width: min(100vw - 32px, 520px);
  max-height: calc(100dvh - 48px);
  overflow: auto;
  border: 0;
  border-radius: 14px;
  padding: 20px;
  background: var(--paper);
  color: var(--ink);
}
dialog::backdrop { background: rgb(10 14 25 / 0.65); }

dialog h2 { margin: 0 0 16px; font: 800 24px/1.2 var(--round); }
dialog h3 { margin: 20px 0 6px; font: 700 17px var(--round); }
dialog p { margin: 0 0 12px; }
dialog .muted { color: rgb(31 42 68 / 0.6); font-weight: 400; }

.stock-dialog { --stock: #BFE3D0; background: var(--stock); }

.field { display: block; margin-bottom: 16px; font-weight: 600; }
.field input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border: 1.5px solid rgb(31 42 68 / 0.25);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: 400 16px var(--text);
}

.swatches { margin: 0 0 8px; padding: 0; border: 0; }
.swatches legend { padding: 0; margin-bottom: 8px; font-weight: 600; }
.swatch-list { display: flex; gap: 12px; }
.swatch-list input { position: absolute; opacity: 0; pointer-events: none; }
.swatch-list label {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgb(31 42 68 / 0.2);
  cursor: pointer;
}
.swatch-list input:checked + label { border: 3px solid var(--ink); box-shadow: inset 0 0 0 3px var(--paper); }
.swatch-list input:focus-visible + label { outline: 3px solid var(--ink); outline-offset: 2px; }

.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.actions.start { justify-content: flex-start; margin-top: 8px; }

.btn {
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 22px;
  font: 700 16px var(--round);
}
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.ghost { background: rgb(31 42 68 / 0.1); color: var(--ink); }
.btn.danger { display: block; margin: 16px 0 0; padding: 0; background: none; color: var(--danger); }
.btn.danger[hidden] { display: none; }
.btn.small { min-height: 36px; padding: 0 14px; background: var(--ink); color: var(--paper); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 18px; }
.stats dt { font-size: 13px; font-weight: 600; opacity: 0.7; }
.stats dd { margin: 2px 0 0; font: 800 28px/1.1 var(--round); font-variant-numeric: tabular-nums; }

.history {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 1fr);
  grid-auto-columns: 1fr;
  gap: 4px;
}
.history span {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1.5px solid rgb(31 42 68 / 0.28);
}
.history .on { background: var(--board); border-color: transparent; box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.5); }
.history .future { border-color: transparent; }
.history .today { border: 2px solid var(--ink); }
.caption { margin-top: 8px; font-size: 13px; opacity: 0.7; }

.status { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.status dt { font-weight: 600; }
.status dd { margin: 0; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  transform: translateX(-50%);
  width: min(100vw - 32px, 520px);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 12px 16px;
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.35);
  z-index: 10;
}
.toast[hidden] { display: none; }
.toast span { flex: 1; }

@media (prefers-reduced-motion: reduce) {
  .just .punch { animation: none; }
  .punch { transition: none; }
}
