/* A desk calendar: cream stock, ruled lines, a pink margin rule down the left
   like a pad of paper, the month printed big in calendar red, Sundays in red,
   and a red line across the page where today is. */

:root {
  --paper: #fbf7ee;
  --paper-edge: #f3ecdc;
  --ink: #24211c;
  --ink-soft: #6f675b;
  --ink-faint: #a89f90;
  --rule: #e6dcc8;
  --rule-strong: #cbbfa6;
  --margin: #e8aaa2;
  --red: #c0392b;
  --event-ink: #2f4f7f;
  --highlight: #fbe59a;
  --shadow: 0 1px 0 rgba(60, 40, 10, .04), 0 12px 32px rgba(60, 40, 10, .14);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: "Avenir Next", "Helvetica Neue", "Segoe UI", system-ui, sans-serif;

  --date-col: 68px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1c1a17;
    --paper-edge: #24211d;
    --ink: #ece6da;
    --ink-soft: #b3aa9a;
    --ink-faint: #7b7366;
    --rule: #332f29;
    --rule-strong: #4a443b;
    --margin: #6e3a33;
    --red: #ef6a5b;
    --event-ink: #9db8e0;
    --highlight: rgba(240, 200, 80, .2);
    --shadow: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #1c1a17;
  --paper-edge: #24211d;
  --ink: #ece6da;
  --ink-soft: #b3aa9a;
  --ink-faint: #7b7366;
  --rule: #332f29;
  --rule-strong: #4a443b;
  --margin: #6e3a33;
  --red: #ef6a5b;
  --event-ink: #9db8e0;
  --highlight: rgba(240, 200, 80, .2);
  --shadow: 0 12px 32px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

[hidden] { display: none !important; }

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right))
           calc(32px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

/* ---------------------------------------------------------------- header -- */

.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 28px 0 18px;
  border-bottom: 3px double var(--rule-strong);
}

.title {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -.01em;
  line-height: 1.05;
}

.today-line {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 16px;
  font-style: italic;
  min-height: 1.35em;
}

.today-line strong { color: var(--red); font-style: normal; font-weight: 600; }

.top-actions { display: flex; align-items: center; gap: 6px; flex: none; }

.text-button {
  border: 0;
  background: none;
  padding: 8px 10px;
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  cursor: pointer;
}

.text-button:hover { color: var(--ink); background: var(--paper-edge); }
.text-button[aria-pressed="true"] { color: var(--red); }
.text-button--danger { color: var(--red); }

.add-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: var(--red);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
}

.add-button svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; fill: none; }

.signin {
  margin: 16px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  background: var(--paper-edge);
  font-size: 16px;
}

.signin a { color: var(--red); font-weight: 600; }

/* ---------------------------------------------------------------- months -- */

.month { margin-top: 8px; }

.month-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 22px 0 6px;
  background: var(--paper);
  border-bottom: 2px solid var(--ink);
}

.month-name {
  margin: 0;
  color: var(--red);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: .01em;
}

.month-year {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .14em;
  color: var(--ink-faint);
  font-variant-numeric: lining-nums;
}

.rows { list-style: none; margin: 0; padding: 0; }

.row {
  position: relative;
  display: grid;
  grid-template-columns: var(--date-col) 1fr auto;
  align-items: center;
  min-height: 56px;
  border-bottom: 1px solid var(--rule);
}

.row-date {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--margin);
  padding: 6px 0;
}

.row-num {
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: lining-nums tabular-nums;
}

.row-dow {
  margin-top: 3px;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.row--sunday .row-num,
.row--sunday .row-dow { color: var(--red); }

/* Several dates on one day share the number: only the first prints it. */
.row--same-day .row-num,
.row--same-day .row-dow { visibility: hidden; }

.row-what {
  min-width: 0;
  padding: 8px 8px 8px 16px;
}

.row-name {
  display: block;
  font-size: 19px;
  overflow-wrap: anywhere;
}

.row--event .row-name { color: var(--event-ink); font-style: italic; }

.row-note {
  display: block;
  margin-top: 1px;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink-faint);
}

.row--past .row-num,
.row--past .row-dow,
.row--past .row-name { opacity: .45; }

/* Today: a stroke of highlighter across the row. */
.row--today { background: var(--highlight); }
.row--today .row-name { font-weight: 700; font-size: 21px; }
.row--today .row-num,
.row--today .row-dow { color: var(--red); }

.today-tag {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 6px 0;
  border: 1.5px solid var(--red);
  border-radius: 3px;
  color: var(--red);
  font-family: var(--sans);
  font-size: 10px;
  font-style: normal;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  vertical-align: 3px;
}

/* The line through the page where today falls between two dates. A thin
   band of its own rather than laid over a row edge, so it never sits on top of
   a date number. */
.now {
  position: relative;
  height: 14px;
  list-style: none;
  border-bottom: 1px solid var(--rule);
}

.now::before {
  content: "";
  position: absolute;
  left: calc(var(--date-col) - 5px);
  right: 0;
  top: 6px;
  height: 2px;
  background: var(--red);
}

.now::after {
  content: "";
  position: absolute;
  left: calc(var(--date-col) - 5px);
  top: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
}

.now-date {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--date-col);
  border-right: 1px solid var(--margin);
}

.empty-month {
  padding: 8px 0 8px calc(var(--date-col) + 16px);
  border-bottom: 1px solid var(--rule);
  color: var(--ink-faint);
  font-style: italic;
  font-size: 15px;
  position: relative;
}

.empty-month::before {
  content: "";
  position: absolute;
  left: var(--date-col);
  top: 0;
  bottom: 0;
  border-left: 1px solid var(--margin);
}

/* ---------------------------------------------------------- row controls -- */

.row-button {
  width: 44px;
  height: 44px;
  margin-right: 2px;
  border: 0;
  background: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--ink-faint);
}

.row-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The early reminder: barely there when off, quietly filled in when on. */
.bell { opacity: .45; }
.bell:hover { opacity: .9; }
.bell[aria-pressed="true"] { opacity: 1; color: var(--ink-soft); }
.bell[aria-pressed="true"] svg { fill: currentColor; }

.delete { color: var(--red); }

.editing .row-what { cursor: pointer; }
.editing .row-what:hover .row-name { text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 4px; }
.editing .row-name::after {
  content: "Edit";
  margin-left: 8px;
  font-family: var(--sans);
  font-size: 10px;
  font-style: normal;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ---------------------------------------------------------------- footer -- */

.foot {
  margin-top: 28px;
  text-align: center;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink-faint);
  line-height: 1.7;
}

.foot a, .foot button.link {
  color: var(--ink-soft);
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.foot form { display: inline; }

/* ----------------------------------------------------------------- sheet -- */

.sheet {
  width: min(460px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.sheet::backdrop { background: rgba(30, 20, 10, .35); }

.sheet-form { padding: 20px 20px 16px; }

.sheet-title {
  margin: 0 0 14px;
  padding-bottom: 8px;
  font-size: 22px;
  color: var(--red);
  border-bottom: 2px solid var(--ink);
}

.field { display: block; border: 0; margin: 0 0 14px; padding: 0; min-width: 0; }

.field-label {
  display: block;
  margin-bottom: 6px;
  padding: 0;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.input {
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  background: var(--paper-edge);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
}

.input:focus { outline: 2px solid var(--red); outline-offset: -1px; }

.input--short { width: auto; flex: none; }

.when-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.when-in { color: var(--ink-soft); font-style: italic; }

.hint { margin: 6px 0 0; font-size: 14px; color: var(--ink-soft); font-style: italic; min-height: 1em; }
.hint:empty { display: none; }

.segmented {
  display: flex;
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  overflow: hidden;
}

.segmented label { flex: 1; position: relative; }

.segmented input { position: absolute; opacity: 0; pointer-events: none; }

.segmented span {
  display: block;
  padding: 8px 6px;
  text-align: center;
  font-family: var(--sans);
  font-size: 14px;
  cursor: pointer;
  color: var(--ink-soft);
}

.segmented label + label span { border-left: 1px solid var(--rule-strong); }
.segmented input:checked + span { background: var(--ink); color: var(--paper); }
.segmented input:focus-visible + span { outline: 2px solid var(--red); outline-offset: -2px; }

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 8px;
  font-size: 16px;
  cursor: pointer;
}

.check input { width: 18px; height: 18px; accent-color: var(--red); }

.form-error { margin: 0; min-height: 0; color: var(--red); font-family: var(--sans); font-size: 13px; }
.form-error:empty { display: none; }

.sheet-actions { display: flex; align-items: center; gap: 6px; margin-top: 14px; }
.spacer { flex: 1; }

.solid-button {
  border: 0;
  border-radius: 6px;
  padding: 9px 18px;
  background: var(--red);
  color: #fff;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  cursor: pointer;
}

/* ----------------------------------------------------------------- toast -- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 32px);
  padding: 6px 6px 6px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 14px;
  box-shadow: var(--shadow);
}

.toast .text-button { color: var(--highlight); }
:root[data-theme="dark"] .toast .text-button { color: var(--red); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .toast .text-button { color: var(--red); }
}

@media (max-width: 380px) {
  :root { --date-col: 56px; }
  .title { font-size: 28px; }
  .row-num { font-size: 23px; }
}
