/* Sensation S: one sheet, one key. Daylight only, square corners only. */

:root {
  --gut: 40px;
  --lw: 2.75rem;   /* month label column */
  --ah: 1.5rem;    /* day number row */
  --hair: color-mix(in srgb, var(--ink-soft) 55%, var(--bg));
  --rule: var(--ink-soft);
}

* { box-sizing: border-box; }

html, body { background: var(--bg); }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}

.sheet {
  /* The chart sets the width: as wide as the screen allows, no wider than 40px a square,
     and short enough that the key and the note stay above the fold on a laptop. */
  width: min(100% - 2 * var(--gut), 31 * 40px + 2 * var(--lw) + 4px,
             max(660px, (100vh - 350px) * 31 / 12 + 2 * var(--lw) + 4px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

/* Header strip */
.strip {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border: 2px solid var(--ink);
}
.strip > * {
  margin: 0;
  padding: 9px 12px;
  font-size: 12px;
  font-weight: var(--fw-medium);
  letter-spacing: .06em;
  line-height: 1.2;
}
.strip .title { font-size: 15px; font-weight: var(--fw-bold); }
.strip .year {
  align-self: stretch;
  display: flex;
  align-items: center;
  padding: 0 28px;
  border-left: .75px solid var(--ink);
  border-right: .75px solid var(--ink);
}
.strip .form { text-align: right; }

/* Chart: one DOM, two orientations. Each square carries --m and --d. */
.chart {
  display: grid;
  grid-template-columns: var(--lw) minmax(0, 1fr) var(--lw);
  grid-template-areas: ". da ." "ma plot mb" ". db ." ". lg .";
  margin-top: 14px;
  font-size: 11px;
  letter-spacing: .06em;
  line-height: 1;
}
.da { grid-area: da; }
.db { grid-area: db; }
.ma { grid-area: ma; }
.mb { grid-area: mb; }
.plot { grid-area: plot; }
.legend { grid-area: lg; }

.days {
  display: grid;
  grid-template-columns: repeat(31, minmax(0, 1fr));
  height: var(--ah);
  padding: 0 2px;
  color: var(--ink-soft);
}
.days span { display: flex; align-items: center; justify-content: center; }
.da span { align-items: flex-end; padding-bottom: 5px; }
.db span { align-items: flex-start; padding-top: 5px; }

.months {
  display: grid;
  grid-template-rows: repeat(12, minmax(0, 1fr));
  padding: 2px 0;
  color: var(--ink);
  font-weight: var(--fw-medium);
}
.months span { display: flex; align-items: center; }
.ma span { justify-content: flex-end; padding-right: 8px; }
.mb span { justify-content: flex-start; padding-left: 8px; }

.plot {
  --cols: 31;
  container-type: inline-size;
  display: grid;
  grid-template-columns: repeat(31, minmax(0, 1fr));
  position: relative;
  border: 2px solid transparent;
}

/* The 2px outer rule is drawn over the squares as one stepped outline of the real days. */
.frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}
.frame polygon {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2px;
  stroke-linejoin: miter;
  vector-effect: non-scaling-stroke;
}
.frame.tall { display: none; }

/* Each real square draws the rule after its day (--ad) and the rule after its month (--am),
   except where the outer rule runs. A missing day draws nothing. Squares stretch to their
   track, so every rule in a row lands on the same pixel. */
.sq {
  --ad: .75px;
  --am: .75px;
  --adc: var(--hair);
  grid-column: var(--d);
  grid-row: var(--m);
  align-self: stretch;
  justify-self: stretch;
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  border-style: solid;
  border-color: var(--hair);
  border-right-color: var(--adc);
  border-width: 0 var(--ad) var(--am) 0;
  color: var(--ink);
  letter-spacing: 0;
}
.sq.f5 { --ad: 1.25px; --adc: var(--rule); }
.sq.dl { --ad: 0px; }
.sq.ml { --am: 0px; }
.sq.off { border-width: 0; }

.sq b {
  font-weight: var(--fw-bold);
  font-size: calc(100cqw / var(--cols) * .56);
  line-height: 1;
}
.sq .t { display: none; }

.sq.today {
  outline: 2px solid var(--c-brick);
  outline-offset: -1px;
  z-index: 2;
}
.sq.today::before,
.sq.holding::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform .12s linear;
}
.sq.holding::before {
  transform: scaleX(1);
  transition: transform var(--hold, 800ms) linear;
}

.legend {
  margin: 0;
  padding: 2px 2px 0;
  color: var(--ink-soft);
  letter-spacing: .06em;
}

/* The key */
.keyrow {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  margin-top: 18px;
}
.key {
  appearance: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: inherit;
  font: inherit;
  display: grid;
  justify-items: center;
  gap: 6px;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.cap {
  position: relative;
  display: grid;
  place-items: center;
  width: 3.5rem;
  height: 3.5rem;
  border: 2px solid var(--ink);
  background: var(--bg);
  font-size: 1.6rem;
  font-weight: var(--fw-bold);
  line-height: 1;
}
.fill {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--bg);
  clip-path: inset(0 100% 0 0);
  transition: clip-path .12s linear;
}
.key.holding .fill {
  clip-path: inset(0 0 0 0);
  transition: clip-path var(--hold, 800ms) linear;
}
.caption {
  position: relative;
  font-size: 11px;
  font-weight: var(--fw-medium);
  letter-spacing: .06em;
  line-height: 1.2;
}
.key:focus-visible { outline: none; }
.key:focus-visible .cap { outline: 2px solid var(--ink); outline-offset: 3px; }
.key[aria-disabled="true"] { cursor: default; }
.key[aria-disabled="true"] .cap { border-color: var(--ink-soft); color: var(--ink-soft); }
.key.past { opacity: .4; }

.instr {
  margin: 0;
  padding-top: 15px;
  max-width: 52em;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}
.plain {
  appearance: none;
  margin: 0;
  padding: 6px 12px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  line-height: 1.3;
  cursor: pointer;
}
.plain:hover { background: color-mix(in srgb, var(--ink) 7%, var(--bg)); }
.plain:active { background: color-mix(in srgb, var(--ink) 14%, var(--bg)); }
.plain:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.note {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--ink-soft);
}
.msg {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--error);
}

.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 26px;
  padding-top: 12px;
  border-top: .75px solid var(--hair);
  font-size: 12px;
}
.wm { display: block; height: 20px; width: auto; }
.others { margin: 0; color: var(--ink-soft); }
.others a { color: var(--ink); text-underline-offset: 2px; }
.colophon { display: none; }

.noscript {
  margin: 18px 0 0;
  font-size: 15px;
}

/* Phone: the chart turns on its side and the key becomes the bottom bar. */
@media screen and (max-width: 719.98px) {
  :root { --gut: 16px; --lw: 1.5rem; --bar: 70px; }
  body { padding-bottom: calc(var(--bar) + 6px + env(safe-area-inset-bottom)); }
  body:has(.msg:not(:empty)) { padding-bottom: calc(var(--bar) + 60px + env(safe-area-inset-bottom)); }

  .sheet { padding-top: 16px; }
  .strip > * { padding: 8px 8px; font-size: 11px; }
  .strip .title { font-size: 13px; }
  .strip .year { padding: 0 10px; }

  .chart { grid-template-areas: ". ma ." "da plot db" ". mb ." ". lg ."; }
  .plot { --cols: 12; grid-template-columns: repeat(12, minmax(0, 1fr)); }
  .sq {
    grid-column: var(--m);
    grid-row: var(--d);
    border-color: var(--hair);
    border-bottom-color: var(--adc);
    border-width: 0 var(--am) var(--ad) 0;
  }
  .sq.off { border-width: 0; }
  .frame.wide { display: none; }
  .frame.tall { display: block; }

  .days {
    grid-template-columns: none;
    grid-template-rows: repeat(31, minmax(0, 1fr));
    height: auto;
    padding: 2px 0;
  }
  .da span { align-items: center; justify-content: flex-end; padding: 0 5px 0 0; }
  .db span { align-items: center; justify-content: flex-start; padding: 0 0 0 5px; }
  .months {
    grid-template-rows: none;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    height: var(--ah);
    padding: 0 2px;
    font-size: 10px;
    letter-spacing: .03em;
  }
  .months span { justify-content: center; padding: 0; }
  .ma span { align-items: flex-end; padding-bottom: 5px; }
  .mb span { align-items: flex-start; padding-top: 5px; }
  .legend { padding-top: 4px; }

  .keyrow { display: block; margin-top: 16px; }
  .instr { padding-top: 0; }
  .key {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 14px;
    height: calc(var(--bar) + env(safe-area-inset-bottom));
    padding: 0 16px env(safe-area-inset-bottom);
    background: var(--bg);
    border-top: 2px solid var(--ink);
  }
  .key::before {
    content: "";
    position: absolute;
    inset: 0;
    background: color-mix(in srgb, var(--ink) 12%, transparent);
    transform: scaleX(0);
    transform-origin: 0 50%;
    transition: transform .12s linear;
  }
  .key.holding::before {
    transform: scaleX(1);
    transition: transform var(--hold, 800ms) linear;
  }
  .cap { width: 3rem; height: 3rem; font-size: 1.4rem; }
  .caption { font-size: 15px; }
  .key.past { opacity: 1; }
  .key.past .cap, .key.past .caption { opacity: .4; }

  /* A refusal or an unreadable record is said where the thumb is, on the bar's top edge. */
  .msg:not(:empty) {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--bar) + env(safe-area-inset-bottom));
    z-index: 5;
    margin: 0;
    padding: 8px 16px;
    background: var(--bg);
    border-top: .75px solid var(--hair);
  }

  .foot { flex-wrap: wrap; }
}

/* The wall sheet: ink on white, wide, nothing but the chart and its paperwork. */
@page { size: landscape; margin: 10mm; }

@media print {
  :root { --bg: #fff; --ink: #000; --ink-soft: #444; }
  html, body { background: #fff; }
  .sheet { width: auto; margin: 0; padding: 0; }
  .keyrow, .actions, .note, .msg, .others, .noscript { display: none; }
  .sq.today { outline: none; }
  .sq.today::before, .sq.holding::before { content: none; }
  .sq b { font-size: calc(100cqw / var(--cols) * .46); }
  .sq.s { gap: .4mm; }
  .sq .t {
    display: block;
    font-style: normal;
    font-size: 5pt;
    line-height: 1;
    font-variant-numeric: tabular-nums;
  }
  .foot {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 0;
    border: 0;
  }
  .wm { height: 14px; }
  .colophon { display: block; margin: 0; font-size: 9pt; color: var(--ink); }
}
