/* Layout follows the Figma frames (Hero, Scroll): 1440 wide, 10px margins,
   8 equal columns. Month name sits in columns 1–3; day / activity / type /
   time / distance take one column each (4–8). Rows are 20px apart.

   Hero   – name and title on top, year + totals in the middle, the twelve
            month bars stacked at the bottom of the first screen.
   Scroll – open a month and scroll: year + totals pin to the top, the month
            bar pins under them (--pin), the next month peeks at the bottom,
            and each following month bar slides up over the pinned one. */

:root {
  --margin: 10px;
  --row: 20px;
  --bar: 28px;   /* one month bar: divider + name */
  /* name + title block: 253px as drawn (900px-tall window), less in a shorter
     window so the twelve month bars still end at the bottom of the first screen */
  --mast: clamp(48px, calc(100dvh - 640px), 253px);
  --pin: 270px;  /* where the open month's bar sticks; also the pinned header's height */
}

* { box-sizing: border-box; }

html { background: #000; }

body {
  margin: 0;
  padding: 0 var(--margin);
  background: #000;
  color: #fff;
  font: 14px/var(--row) "Times New Roman", Times, Tinos, serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, dl, dt, dd, p { margin: 0; font: inherit; }

a { color: inherit; text-decoration: none; }
a:hover, a:focus-visible { text-decoration: underline; text-underline-offset: 2px; }

.grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  align-content: start;
}

.page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: 6px;
}

/* Name + title */
.masthead { height: var(--mast); padding-top: 7px; line-height: 16px; }
.name { grid-column: 1 / span 3; }
.title { grid-column: 4 / span 5; }

/* Year switcher + yearly totals */
.summary {
  position: sticky;
  top: 0;
  z-index: 10;
  flex: none;
  height: var(--pin);
  padding-top: 8px;
  background: #000;
}
.years { grid-column: 1 / span 3; display: flex; align-items: flex-start; gap: 16px; }
.years > * { opacity: 0.2; }
.years > [aria-current] { opacity: 1; }
.years > button {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.years > button:not([aria-current]):hover,
.years > button:not([aria-current]):focus-visible { opacity: 0.6; outline: none; }
.totals {
  grid-column: 4 / span 5;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

/* Pushes the twelve closed month bars to the bottom of the first screen.
   A fixed height (not flex) so nothing shifts when a month opens.
   342px = twelve bars 336 + bottom padding 6. */
.spacer {
  flex: none;
  height: max(var(--bar), calc(100vh - var(--mast) - var(--pin) - 342px));
  height: max(var(--bar), calc(100dvh - var(--mast) - var(--pin) - 342px));
}

/* Month bar: a divider with the month name under it. Bars and their days are
   siblings, so every bar can stick at --pin; a later bar paints over an
   earlier one. */
.month,
.peek {
  display: block;
  width: 100%;
  height: var(--bar);
  margin: 0;
  padding: 1px 0 0;
  border: 0;
  border-top: 1px solid #fff;
  background: #000;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.month { position: sticky; top: var(--pin); }
.month:focus-visible, .peek:focus-visible { outline: 1px dotted #fff; outline-offset: -3px; }

/* Day rows start on the same line as the month name, in columns 4–8.
   position: relative lifts them above the bar they overlap. */
.days {
  position: relative;
  margin: calc(2px - var(--bar)) 0 0 37.5%;
}
.days[hidden] { display: none; }
.day {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.day > * {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 1ch;
}
/* Space between the last row and the next month's divider: 2px here plus the
   row's own 2px, the same 4px there is between two rows. */
.days-end { height: 2px; }

/* The next month, peeking at the bottom of the window while this month is on
   screen. It ends up exactly under the real bar that follows (negative
   margin), so the hand-over is seamless. */
.peek {
  position: sticky;
  bottom: 6px;
  width: 160%;       /* .days is 62.5% wide; this spans the full 100% */
  margin-left: -60%;
  margin-bottom: calc(var(--bar) * -1);
}
.peek::after { /* keeps the strip under the pinned bar black */
  content: "";
  position: absolute;
  inset: 100% 0 auto;
  height: 6px;
  background: #000;
}

/* Activity photo for the hovered day, in black and white. Every photo is
   centred on the same point, taken from the Figma placement: 19.7% across the
   content width and 37.4% down the window, up to 56% of the window's height.
   It sits over the month divider, above everything else. */
.photo {
  --content: calc(100vw - var(--margin) * 2);
  position: fixed;
  z-index: 20;
  left: calc(var(--margin) + var(--content) * 0.197);
  top: 37.4vh;
  transform: translate(-50%, -50%);
  width: auto;
  height: auto;
  max-width: calc(var(--content) * 0.33);
  max-height: 56vh;
  filter: grayscale(1);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s;
}
.photo.is-visible { opacity: 1; visibility: visible; }
@media (hover: none), (max-width: 1099px) { .photo { display: none; } }

/* Narrow windows (phones, tablets, small laptop windows): the same page with
   less air. Name and title stay side by side, the five totals sit in one row
   under the years, and year + totals still pin to the top with the open
   month's bar under them. The day rows no longer fit beside the month name,
   so they go under it at full width, on two lines: day, sports, time and
   distance, then the session types. */
@media (max-width: 1099px) {
  :root { --mast: 104px; --pin: 96px; }
  .years, .totals { grid-column: 1 / -1; }
  .totals { margin-top: var(--row); }
  .month { z-index: 5; } /* rows now pass under the bar, not beside its name */
  .days { margin: 0; padding-top: 2px; }
  .day {
    grid-template-columns: 28px minmax(0, 1fr) 68px 50px;
    padding-bottom: 6px;
  }
  .day > :nth-child(3) { grid-row: 2; grid-column: 2 / -1; opacity: 0.5; }
  .day > :last-child { padding-right: 0; }
  .peek { width: 100%; margin-left: 0; }
}
