:root {
  color-scheme: light dark;
  --bg: #fafaf7;
  --fg: #1c1c1a;
  --muted: #5c5c57;
  --border: #c9c9c2;
  --surface: #ffffff;
  --accent: #0b5cad;
  --accent-fg: #ffffff;
  --done: #1d6b3a;
  --done-bg: #d8f0e0;
  --missed-bg: #f6dcd8;
  --error: #a3260f;
  --l1: #e3f0e6;
  --l2: #bfe0c8;
  --l3: #8fcaa0;
  --l4: #5bb077;
  --card: rgba(255, 255, 255, 0.72);
  --glow: rgba(11, 92, 173, 0.16);
  --aurora-a: rgba(91, 176, 119, 0.28);
  --aurora-b: rgba(11, 92, 173, 0.22);
  --shadow: 0 1px 2px rgba(20, 30, 20, 0.06), 0 8px 24px rgba(20, 30, 20, 0.06);
  --radius: 1rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412;
    --fg: #ece6e6;
    --muted: #a8a8a0;
    --border: #44443f;
    --surface: #1e1e1b;
    --accent: #7ab8f5;
    --accent-fg: #0b1d30;
    --done: #8fd8a7;
    --done-bg: #1f3a2a;
    --missed-bg: #4a2420;
    --error: #ff9c86;
    --l1: #1f3326;
    --l2: #285038;
    --l3: #34704c;
    --l4: #43905f;
    --card: rgba(30, 30, 27, 0.72);
    --glow: rgba(122, 184, 245, 0.18);
    --aurora-a: rgba(67, 144, 95, 0.30);
    --aurora-b: rgba(122, 184, 245, 0.18);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(60rem 30rem at 10% -10%, var(--aurora-a), transparent 60%),
    radial-gradient(50rem 28rem at 100% 0%, var(--aurora-b), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--fg);
  font: 1rem/1.5 system-ui, sans-serif;
}

main {
  max-width: 40rem;
  margin: 0 auto;
  padding: 0.75rem;
  overflow-wrap: anywhere;
}

h1 {
  font-size: 1.75rem;
  letter-spacing: -0.02em;
  margin: 1.25rem 0 0.5rem;
  background: linear-gradient(90deg, var(--fg), var(--accent), var(--done), var(--fg));
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shine 12s linear infinite;
}
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.5rem; }

a { color: var(--accent); }

a, button, input, summary { min-height: 44px; }

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

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

nav {
  position: sticky;
  top: 0.5rem;
  z-index: 1;
  padding: 0.25rem 0.5rem;
  background: var(--card);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  align-items: center;
}

nav a, p a[rel] {
  text-decoration: none;
  font-weight: 500;
  padding: 0 0.4rem;
  border-radius: 0.5rem;
  display: inline-flex;
  align-items: center;
  min-width: 44px;
}

nav form { margin-left: auto; }

button, input:not([type="checkbox"]) {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.5rem 0.9rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.2s ease;
}

button:active { transform: scale(0.97); }
button:hover { box-shadow: var(--shadow); }

input:not([type="checkbox"]) { width: 100%; }

button { cursor: pointer; }

form button[type="submit"]:not(.check) {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

nav form button { background: var(--surface); color: var(--fg); border-color: var(--border); }

label { display: block; margin-top: 0.5rem; }

fieldset { border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); margin: 0.75rem 0; }

fieldset label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  margin: 0 0.5rem 0 0;
}

input[type="checkbox"] { width: 1.5rem; height: 1.5rem; min-height: 0; }

[role="alert"] { color: var(--error); font-weight: 600; }

/* Day page: one wide tappable row per habit. */
.habits { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }

.habits form { margin: 0; }

.check {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 60px;
  text-align: left;
  position: relative;
  overflow: hidden;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-weight: 500;
}

/* Spotlight that follows the pointer (set by app.js). */
.check::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(14rem circle at var(--mx, 50%) var(--my, 50%), var(--glow), transparent 70%);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.check:hover::before { opacity: 1; }

.check .box {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 2px solid var(--border);
  border-radius: 0.75rem;
  font-size: 1.5rem;
  line-height: 1;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.check[aria-pressed="true"] .box { background: var(--done); color: var(--surface); }
.check[aria-pressed="true"] .box.pop { animation: pop 0.35s ease; }

.check[aria-pressed="true"] { background: var(--done-bg); border-color: var(--done); }
.check[aria-pressed="true"] .box { border-color: var(--done); }
.check[aria-busy="true"] { opacity: 0.6; }

.readonly {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 56px;
}

.readonly .box {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 2px solid var(--border);
  border-radius: 0.75rem;
}

.status { color: var(--error); min-height: 1.5rem; }

/* Statistics tables scroll inside their own box, never the page. */
.scroll { overflow-x: auto; }

table { border-collapse: separate; border-spacing: 3px; width: 100%; }
caption { text-align: left; font-weight: 600; padding: 0.5rem 0; }
th, td { border: 0; border-radius: 0.5rem; padding: 0.4rem; text-align: center; }
thead th, tfoot th, tfoot td { color: var(--muted); font-weight: 600; }
tbody td { background: var(--card); }
th[scope="row"] { text-align: left; }

td.done { background: var(--done-bg); color: var(--done); font-weight: 600; }
td.missed { background: var(--missed-bg); }
td.future, td.na { color: var(--muted); }

.calendar td { padding: 0; }
.calendar td a, .calendar td > span:not(.sr) {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  text-decoration: none;
  color: inherit;
}
.calendar small { font-size: 0.7rem; color: var(--muted); }
.calendar td { transition: transform 0.15s ease; }
.calendar td:hover { transform: scale(1.06); }
.lvl-1 { background: var(--l1); }
.lvl-2 { background: var(--l2); }
.lvl-3 { background: var(--l3); }
.lvl-4 { background: var(--l4); }

@keyframes shine { to { background-position: -300% 0; } }

@keyframes pop {
  0% { transform: scale(0.6); }
  60% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.habits li { animation: rise 0.35s ease backwards; }
.habits li:nth-child(2) { animation-delay: 0.04s; }
.habits li:nth-child(3) { animation-delay: 0.08s; }
.habits li:nth-child(4) { animation-delay: 0.12s; }
.habits li:nth-child(n+5) { animation-delay: 0.16s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  h1 { background-position: 0 0; }
}
