:root {
  --bg: #f4f3ef;
  --ink: #1b1b1a;
  --muted: #6d6b66;
  --line: rgba(0, 0, 0, 0.09);
  --open: #ffffff;
  --closed: #e3e1da;
  --free: #1d8a4e;
  --free-ink: #ffffff;
  --now: #e0352b;
  --warn: #a14a00;
  --hour: 44px;
  --head: 2.25rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131312;
    --ink: #eeece6;
    --muted: #98958d;
    --line: rgba(255, 255, 255, 0.1);
    --open: #24231f;
    --closed: #181816;
    --free: #2c9d5e;
    --free-ink: #ffffff;
    --now: #ff5a4f;
    --warn: #ffab5c;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0 auto;
  max-width: 68rem;
  padding: 1rem max(1rem, env(safe-area-inset-right)) 2rem max(1rem, env(safe-area-inset-left));
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
}

p {
  margin: 0;
}

.head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
}

.where,
.status,
footer {
  color: var(--muted);
  font-size: 0.85rem;
}

.status {
  margin-top: 0.4rem;
}

.status.warn {
  color: var(--warn);
  font-weight: 600;
}

.weeknav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}

.range {
  min-width: 6.5rem;
  text-align: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.weeknav button {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
}

.weeknav button:hover {
  background: var(--line);
}

/* Day tabs: phones only. */
.tabs {
  display: none;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.25rem;
  margin-top: 0.75rem;
}

.tabs button {
  display: grid;
  gap: 0.1rem;
  padding: 0.4rem 0;
  border-radius: 0.6rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.tabs button b {
  font-size: 1.05rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.tabs button.today b {
  color: var(--now);
}

.tabs button[aria-selected="true"] {
  background: var(--ink);
  color: var(--bg);
}

.tabs button[aria-selected="true"] b {
  color: var(--bg);
}

.tabs button.none {
  opacity: 0.55;
}

/* Calendar. --a0/--a1 are the first and last minute on the axis; every
   positioned element sets --s/--e (start and end minute). */
.cal {
  display: grid;
  grid-template-columns: 2.6rem 1fr;
  margin-top: 0.9rem;
}

.axis,
.track {
  position: relative;
  height: calc((var(--a1) - var(--a0)) * var(--hour) / 60);
}

.axis {
  margin-top: var(--head);
}

.axis span {
  position: absolute;
  top: calc((var(--s) - var(--a0)) * var(--hour) / 60);
  right: 0.5rem;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cols {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 3px;
}

.col h2 {
  height: var(--head);
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: var(--head);
  text-align: center;
  color: var(--muted);
}

.col.today h2 {
  color: var(--now);
}

.col.past .track {
  opacity: 0.45;
}

.track {
  overflow: hidden;
  border-radius: 0.5rem;
  background: var(--closed);
}

.track > * {
  position: absolute;
  left: 0;
  right: 0;
  top: calc((var(--s) - var(--a0)) * var(--hour) / 60);
  height: calc((var(--e) - var(--s)) * var(--hour) / 60);
}

.open {
  background-color: var(--open);
  /* Hour lines, measured from the top of the open block. */
  background-image: linear-gradient(var(--line) 1px, transparent 1px);
  background-size: 100% var(--hour);
  background-position: 0 calc((var(--a0) - var(--s)) * var(--hour) / 60);
}

.unknown {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.72rem;
  background: var(--closed)
    repeating-linear-gradient(135deg, transparent 0 6px, var(--line) 6px 8px);
}

.free {
  left: 2px;
  right: 2px;
  margin-top: 1px;
  height: calc((var(--e) - var(--s)) * var(--hour) / 60 - 2px);
  padding: 0.2rem 0.4rem;
  overflow: hidden;
  border-radius: 0.4rem;
  background: var(--free);
  color: var(--free-ink);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
}

.free small {
  display: block;
  font-weight: 400;
  opacity: 0.85;
}

.now {
  height: 2px;
  margin-top: -1px;
  background: var(--now);
  z-index: 2;
  pointer-events: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  margin: 1rem 0 0.5rem;
  padding: 0;
  list-style: none;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.k {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 0.2rem;
  border: 1px solid var(--line);
}

.k.free {
  background: var(--free);
}

.k.busy {
  background: var(--open);
}

.k.closed {
  background: var(--closed);
}

.k.unknown {
  background: var(--closed) repeating-linear-gradient(135deg, transparent 0 3px, var(--line) 3px 5px);
}

/* Phones: one day at a time, picked with the tabs. */
@media (max-width: 640px) {
  :root {
    --hour: 52px;
    --head: 0.5rem;
  }

  .tabs {
    display: grid;
  }

  .cols {
    display: block;
  }

  .col:not(.sel),
  .col h2 {
    display: none;
  }

  .axis {
    margin-top: 0;
  }

  .cal {
    margin-top: 1.25rem;
  }

  .free {
    padding: 0.35rem 0.6rem;
    font-size: 0.95rem;
  }

  .free small {
    display: inline;
    margin-left: 0.4rem;
  }
}
