:root {
  color-scheme: light dark;
  --ink: #161a24;
  --bg: #fbfaf7;
  --card: #ffffff;
  --line: #e4e2dc;
  --muted: #5d6470;
  --accent: #33427a;
  --accent-ink: #ffffff;
  --moon: #c99a2e;
  --warn: #fff3d1;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e8e9ee; --bg: #10131c; --card: #171b27; --line: #2a3042;
    --muted: #9aa1b2; --accent: #9fb0ff; --accent-ink: #10131c; --moon: #f2d98c; --warn: #3a3220;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main { max-width: 760px; margin: 0 auto; padding: 32px 20px 48px; }
h1 { font-size: clamp(28px, 5vw, 42px); line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 14px; }
h2 { font-size: 21px; margin: 32px 0 10px; }
h3 { font-size: 17px; margin: 0 0 8px; }
a { color: var(--accent); }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.lede { font-size: 19px; color: var(--muted); }
[hidden] { display: none !important; }

.site-header, .site-footer { max-width: 760px; margin: 0 auto; padding: 16px 20px; }
.site-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.site-header nav { display: flex; gap: 16px; }
.site-header a { text-decoration: none; }
.brand { font-weight: 700; font-size: 19px; color: var(--ink) !important; }
.site-footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }

.button, button {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 9px 16px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
.button.primary, button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.button { display: inline-block; text-decoration: none; }
button:disabled { opacity: 0.55; cursor: default; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin: 14px 0; }
.notice { background: var(--warn); border-radius: 10px; padding: 12px 14px; margin: 14px 0; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

label { display: block; font-weight: 600; margin: 12px 0 4px; }
label.check { font-weight: 400; display: flex; gap: 10px; align-items: flex-start; margin: 8px 0; }
input[type=text], input[type=email], input[type=password], input[type=time], input[type=date], textarea {
  font: inherit; width: 100%; padding: 9px 11px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
input[type=time], input[type=date] { width: auto; }
input[type=checkbox] { width: 18px; height: 18px; margin-top: 4px; accent-color: var(--accent); }
textarea { min-height: 96px; resize: vertical; }
form .actions { margin-top: 16px; }

.rating { display: flex; gap: 8px; flex-wrap: wrap; }
.rating button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; }

.features { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin: 20px 0; }
.features .card { margin: 0; }
.hero { padding: 24px 0 8px; }
.hero .moon { color: var(--moon); }

.diary-sheet th small { display: block; font-weight: 400; font-size: 12px; }
.diary-sheet td { height: 44px; border: 1px solid var(--line); }
.diary-sheet th { border: 1px solid var(--line); }
.diary-sheet .tick { width: 40px; text-align: center; }
.diary-sheet .wide { width: 22%; }
.routine-key { margin: 0 0 12px; padding-left: 22px; }
.print-only { display: none; }

/* The sleep diary template prints as one landscape sheet: just the table and
   its key, in black on white, without the site around it. */
@media print {
  @page { size: landscape; margin: 10mm; }
  :root { --ink: #000; --bg: #fff; --card: #fff; --line: #000; --muted: #333; }
  body { font-size: 11pt; line-height: 1.35; }
  .site-header, .site-footer, .no-print, .button, button { display: none !important; }
  .print-only { display: block; }
  main { max-width: none; padding: 0; }
  h1 { font-size: 18pt; margin: 0 0 6px; }
  .table-wrap { overflow: visible; }
  .diary-sheet { font-size: 10pt; page-break-inside: avoid; }
  .diary-sheet td { height: 13mm; }
  .diary-sheet th, .diary-sheet td { padding: 3px 4px; }
  .routine-key { columns: 2; margin-bottom: 6px; }
  .sheet p { margin: 0 0 6px; }
}
