:root {
  --bg: #e7e1d6;
  --wash: #cfe8d8;
  --card: #f7f3eb;
  --ink: #221e1a;
  --muted: #5e564c;
  --line: #ddd4c6;
  --empty: #d5cdc0;
  --moss: #1f7a45;
  --amber: #9a6410;
  --sky: #1d6f97;
  --rose: #9d3d52;
  --lilac: #654b96;
  --tide: #0f766e;
  --shadow: 0 16px 40px rgba(60, 42, 20, 0.06);
  --cell: 16px;
  --gap: 3px;
  --dow: 14px;
  color-scheme: light;
  font-family: Figtree, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141311;
    --wash: #1c3330;
    --card: #1d1b18;
    --ink: #f4efe6;
    --muted: #c2b6a6;
    --line: #34302a;
    --empty: #34302b;
    --moss: #8ed4a6;
    --amber: #e7c078;
    --sky: #9fd0ea;
    --rose: #f0aeb8;
    --lilac: #d2c0f0;
    --tide: #8fd9d0;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 320px at 0% -10%, var(--wash), transparent 70%),
    var(--bg);
  color: var(--ink);
}

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

button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

::selection {
  background: color-mix(in srgb, var(--moss) 35%, transparent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  left: 12px;
  top: -48px;
  background: var(--ink);
  color: var(--bg);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 5;
}

.skip:focus { top: 12px; }

.wrap {
  max-width: 920px;
  margin: 0 auto;
  padding: 36px 20px 72px;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
}

h1 {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-family: Newsreader, Georgia, serif;
  font-size: 2.6rem;
  font-weight: 560;
  letter-spacing: -0.03em;
  line-height: 1;
}

.mark { color: var(--ink); flex: none; }

.lede {
  margin: 10px 0 0;
  max-width: 42ch;
  color: var(--muted);
  line-height: 1.45;
}

.date {
  margin: 0;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.add {
  display: flex;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 22px 0 8px;
  padding: 12px 0;
  background: var(--bg);
}

.field { flex: 1; display: flex; }

.add input {
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
}

.add input::placeholder { color: var(--muted); opacity: 1; }

.add button,
#fresh,
#confirm-ok {
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
}

.add button:hover,
#fresh:hover,
#confirm-ok:hover {
  background: color-mix(in srgb, var(--ink) 82%, var(--moss));
}

.banner {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin: 8px 0 16px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--amber);
  background: color-mix(in srgb, var(--amber) 16%, var(--card));
}

.banner p { margin: 0; }

.banner[hidden] { display: none; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin: 8px 0 12px;
}

.section-head h2 {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

#summary {
  margin: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.habit {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px 12px;
  margin: 0 0 10px;
  box-shadow: var(--shadow);
}

.habit-top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
}

.toggle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--c);
  background: transparent;
  color: var(--card);
  display: grid;
  place-items: center;
  padding: 0;
}

.toggle svg { width: 22px; height: 22px; }

.toggle[aria-pressed="true"] {
  background: var(--c);
  border-color: var(--c);
}

.habit h3 {
  margin: 0;
  font-family: Newsreader, Georgia, serif;
  font-size: 1.35rem;
  font-weight: 560;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.meta {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}

.remove {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  min-height: 40px;
  padding: 8px 10px;
}

.remove:hover { color: var(--rose); }

.heat {
  overflow-x: auto;
  margin-top: 14px;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.heat-inner { width: max-content; min-width: 100%; }

.months {
  display: flex;
  gap: var(--gap);
  height: 16px;
  margin: 0 0 4px;
  padding-left: calc(var(--dow) + var(--gap));
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.02em;
}

.months span {
  width: var(--cell);
  flex: none;
  overflow: visible;
  white-space: nowrap;
}

.heat-body { display: flex; gap: var(--gap); }

.dow {
  width: var(--dow);
  flex: none;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}

.dow span {
  height: var(--cell);
  line-height: var(--cell);
}

.cols { display: flex; gap: var(--gap); }

.col { display: flex; flex-direction: column; gap: var(--gap); }

.cell {
  width: var(--cell);
  height: var(--cell);
  border-radius: 4px;
  padding: 0;
  border: 0;
  background: var(--empty);
  flex: none;
}

button.cell { cursor: pointer; }

button.cell.on { background: var(--c); }

button.cell.today {
  box-shadow: 0 0 0 1px var(--card), 0 0 0 2px var(--ink);
  position: relative;
  z-index: 1;
}

button.cell:hover { transform: scale(1.12); }

button.cell:focus-visible { outline-offset: 1px; z-index: 1; }

.cell.future { opacity: 0.35; }

.empty {
  padding: 28px 8px 12px;
  color: var(--muted);
}

.empty-title {
  margin: 12px 0 4px;
  color: var(--ink);
  font-family: Newsreader, Georgia, serif;
  font-size: 1.6rem;
}

.empty p { margin: 0; }

.ghost {
  display: grid;
  grid-template-columns: repeat(14, 12px);
  gap: 4px;
  width: max-content;
}

.ghost i {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--empty);
  display: block;
}

.ghost i.on { background: color-mix(in srgb, var(--moss) 70%, var(--empty)); }

.status {
  min-height: 1.4em;
  margin: 8px 0 0;
  color: var(--muted);
}

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  margin-top: 28px;
}

.tools button,
.file {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
}

.file { display: inline-flex; align-items: center; cursor: pointer; }

.file input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.file:focus-within {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.fine {
  flex-basis: 100%;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
  max-width: 62ch;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--ink);
  padding: 20px;
  max-width: min(400px, calc(100vw - 32px));
}

dialog::backdrop { background: rgba(20, 16, 12, 0.5); }

dialog p { margin: 0 0 16px; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

dialog button[value="cancel"] {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
}

.noscript {
  max-width: 920px;
  margin: 0 auto;
  padding: 12px 20px 32px;
}

@media (max-width: 520px) {
  .wrap { padding: 22px 14px 48px; }
  h1 { font-size: 2.15rem; }
  .top { flex-direction: column; align-items: flex-start; gap: 8px; }
  .date { text-align: left; }
  .add { flex-direction: column; }
  .add button { width: 100%; }
  .habit-top { align-items: start; }
  .remove { justify-self: end; }
  .banner { flex-direction: column; align-items: stretch; }
  .section-head { align-items: flex-start; flex-direction: column; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
  button.cell:hover { transform: none; }
}
