:root {
  color-scheme: dark;
  --bg: #0b1020;
  --surface: #131a30;
  --surface-2: #1b2547;
  --border: #263056;
  --text: #e6e9f5;
  --muted: #8a93b2;
  --col: #22d3ee;       /* highlighted cycle column */
  --row: #4ade80;       /* bedtime inside the highlight window */
  --cross: #facc15;     /* where the two meet */
  --now: #fbbf24;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0 auto;
  max-inline-size: 44rem;
  min-block-size: 100dvh;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
    max(1.5rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  background: radial-gradient(120% 60% at 50% -10%, #1a2550 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.4;
}

.top { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-block-end: 1rem; }
h1 { margin: 0; font-size: 1.4rem; letter-spacing: .01em; }
#clock { color: var(--muted); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); font-size: .875rem; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: .25rem; padding: .25rem; margin-block-end: 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.tabs button { min-block-size: 2.75rem; border: 0; border-radius: calc(var(--radius) - 4px);
  background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text); box-shadow: 0 0 0 1px var(--border); }
:focus-visible { outline: 2px solid var(--col); outline-offset: 2px; }

/* Bedtime table: sticky column and row headers keep their context while scrolling (responsive-table guide). */
.table-wrapper { overflow: auto; max-block-size: calc(100dvh - 13rem); min-block-size: 12rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { inline-size: 100%; border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; }
caption { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); }
th, td { padding: .5rem .35rem; text-align: center; white-space: nowrap; }
thead th { position: sticky; inset-block-start: 0; z-index: 2; background: var(--surface-2); font-weight: 700; border-block-end: 1px solid var(--border); }
thead th small { display: block; color: var(--muted); font-size: .75rem; font-weight: 400; }
th:first-child { position: sticky; inset-inline-start: 0; text-align: start; padding-inline-start: .75rem; }
thead th:first-child { z-index: 3; }
tbody th { z-index: 1; background: var(--surface); font-weight: 600; }
tbody tr + tr > * { border-block-start: 1px solid rgb(255 255 255 / .04); }

.day { margin-inline-start: .1em; font-size: .65em; vertical-align: super; color: var(--muted); }
td.later { color: var(--muted); }
thead th.col { color: var(--col); }
td.col { color: var(--col); font-weight: 700; background: rgb(34 211 238 / .08); }
tr.win > * { background: rgb(74 222 128 / .1); }
tr.win > th { color: var(--row); }
tr.win > td.col, td.cross { background: var(--cross); color: #14110a; font-weight: 800; }
tr.win > td.col .day, td.cross .day { color: #5c4a00; }
tbody th.now { color: var(--now); }

.wake-input { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .75rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); font-weight: 600; }
input, select { min-block-size: 2.75rem; padding: .4rem .6rem; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; font: inherit; font-size: 1rem; /* 16px stops iOS zoom-on-focus */ }
input[type="time"] { font-variant-numeric: tabular-nums; }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.cards li { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .75rem;
  padding: .8rem 1rem; background: var(--surface); border: 1px solid var(--border); border-inline-start: 4px solid var(--border);
  border-radius: var(--radius); }
.cards li.hl { border-inline-start-color: var(--col); }
.cards .bed { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.cards .meta { color: var(--muted); }
.cards .in { font-variant-numeric: tabular-nums; color: var(--now); }
.cards li.empty { display: block; color: var(--muted); border-inline-start-color: var(--now); }

.settings { margin-block-start: 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .25rem 1rem 1rem; }
.settings summary { min-block-size: 2.75rem; display: flex; align-items: center; font-weight: 600; cursor: pointer; }
#settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: .75rem; margin-block-end: .75rem; }
#settings label { display: grid; gap: .25rem; color: var(--muted); font-size: .875rem; }
#settings label.check { grid-auto-flow: column; justify-content: start; align-items: center; gap: .6rem; color: var(--text); }
#settings input[type="checkbox"] { inline-size: 1.4rem; block-size: 1.4rem; min-block-size: 0; accent-color: var(--col); }

/* On a phone the highlighted x5 column must be visible without sideways scrolling, so compress the table. */
.table-wrapper { container-type: inline-size; }
@container (width < 32rem) {
  table { font-size: .875rem; }
  th, td { padding-inline: .2rem; }
  th:first-child { padding-inline-start: .5rem; }
  thead th small { font-size: .65rem; }
  /* The dimmed colour already says "next day"; screen readers still hear the +N. */
  .day { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); }
}
@container (width < 22rem) {
  table { font-size: .8125rem; }
  th:first-child { padding-inline-start: .35rem; }
}

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