:root {
  --paper: #F7F8FA;
  --card: #FFFFFF;
  --ink: #1B2340;
  --muted: #5B6480;
  --line: #DDE1EA;
  --faint: #A3AABD;
  --accent: #4B1F7A;
  --on-accent: #FFFFFF;
  --danger: #C62F3A;
  /* phones don't ship Comic Sans, Comic Neue is the webfont stand-in */
  --display: "Comic Sans MS", "Comic Neue", cursive;
  --ui: "Instrument Sans", system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111111;
    --card: #1C1C1C;
    --ink: #EDEDED;
    --muted: #A3A3A3;
    --line: #2E2E2E;
    --faint: #6B6B6B;
    --accent: #6A35A8;
    --danger: #FF6B72;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 var(--ui);
  -webkit-text-size-adjust: 100%;
}

button, input, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- shared bits ---------- */

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.btn-accent {
  background: var(--accent);
  color: var(--on-accent);
  border: 0;
  border-radius: 8px;
  padding: 0 20px;
  min-height: 44px;
  font-weight: 600;
}
.btn-accent:hover { filter: brightness(1.12); }
.btn-accent:disabled { opacity: 0.6; cursor: default; }

.quiet {
  background: none;
  border: 0;
  color: var(--muted);
  min-height: 44px;
  padding: 0 8px;
}
.quiet:hover { color: var(--ink); }

.err { color: var(--danger); margin: 0; min-height: 1.5em; font-size: 0.9rem; }

/* ---------- login ---------- */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login form { width: 100%; max-width: 340px; display: grid; gap: 16px; }
.login h1 { font: 700 2.9rem/1.05 var(--display); margin: 0; }
.login p { margin: 0; color: var(--muted); }

.field { display: grid; gap: 6px; font-size: 0.9rem; font-weight: 600; }
.field input, .field textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-weight: 400;
  font-size: 1rem;
}
.field input:focus, .field textarea:focus { border-color: var(--ink); outline: none; }

/* ---------- app header ---------- */

.top {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 12px 16px;
  padding: 20px 16px 12px;
  padding-top: max(20px, env(safe-area-inset-top));
  max-width: 1200px;
  margin: 0 auto;
}
.top h1 { font: 700 clamp(2.5rem, 7vw, 4.5rem)/1 var(--display); margin: 0; }
.top h1 small { font-weight: 400; color: var(--muted); font-size: 0.52em; margin-left: 4px; }
.top .logout { align-self: start; }

.controls { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.nav { display: flex; }
.nav button {
  min-width: 44px;
  min-height: 40px;
  border: 1.5px solid var(--line);
  background: var(--card);
  padding: 0 12px;
}
.nav button:first-child { border-radius: 8px 0 0 8px; }
.nav button:last-child { border-radius: 0 8px 8px 0; }
.nav button + button { border-left: 0; }

.views { display: flex; background: var(--line); border-radius: 10px; padding: 3px; }
.views button {
  border: 0;
  background: none;
  border-radius: 7px;
  min-height: 34px;
  padding: 0 12px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
}
.views button[aria-pressed="true"] { background: var(--card); color: var(--ink); }

.controls .add { margin-left: auto; }

main.cal-wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px 120px; }

@media (max-width: 700px) {
  .views .v-week { display: none; }
  /* thumb-reach add button */
  .controls .add {
    position: fixed;
    z-index: 5;
    right: 16px;
    bottom: max(16px, env(safe-area-inset-bottom));
    min-height: 56px;
    padding: 0 26px;
    border-radius: 999px;
    font-size: 1.05rem;
    box-shadow: 0 6px 20px rgb(27 35 64 / 0.25);
  }
}

/* ---------- FullCalendar skin ---------- */

.fc {
  --fc-border-color: var(--line);
  --fc-page-bg-color: var(--paper);
  --fc-neutral-bg-color: var(--card);
  --fc-today-bg-color: transparent;
  --fc-event-bg-color: var(--ink);
  --fc-event-border-color: var(--ink);
  --fc-event-text-color: var(--paper);
  --fc-list-event-hover-bg-color: var(--card);
  --fc-highlight-color: rgb(106 53 168 / 0.18);
  --fc-now-indicator-color: #D93D42;
  font-family: var(--ui);
}
.fc a { color: inherit; text-decoration: none; }
.fc .fc-scrollgrid { border-radius: 10px; overflow: hidden; }
.fc .fc-daygrid-day, .fc .fc-timegrid-col, .fc .fc-daygrid-day.fc-day-today, .fc .fc-timegrid-col.fc-day-today { background: var(--card); }
.fc .fc-day-other .fc-daygrid-day-top { opacity: 1; }
.fc .fc-day-other .fc-daygrid-day-number { color: var(--faint); }
.fc .fc-col-header-cell-cushion { font-size: 0.8rem; font-weight: 600; color: var(--muted); padding: 8px 4px; }
.fc .fc-daygrid-day-frame { min-height: 104px; }
.fc .fc-daygrid-day-number { font-weight: 600; font-size: 0.85rem; padding: 4px 8px; margin: 4px; }
.fc .fc-day-today .fc-daygrid-day-number,
.fc .fc-day-today .fc-col-header-cell-cushion {
  background: var(--accent);
  color: var(--on-accent);
  border-radius: 999px;
}
.fc .fc-daygrid-event, .fc .fc-timegrid-event { border-radius: 5px; padding: 2px 5px; font-size: 0.8rem; cursor: pointer; }
.fc .fc-daygrid-more-link { font-size: 0.8rem; font-weight: 600; color: var(--muted); }

.ev { display: flex; align-items: center; gap: 6px; min-width: 0; }
.ev-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ev-title b { font-weight: 600; opacity: 0.75; margin-right: 3px; }
.dots { display: inline-flex; flex-shrink: 0; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); border: 1px solid var(--fc-event-text-color); margin-left: -3px; }
.fc-timegrid-event .ev { flex-wrap: wrap; }

/* agenda (list) view: this is the phone default, so it gets the most care */
.fc .fc-list { border: 0; }
.fc .fc-list-table td { border-color: var(--line); }
.fc .fc-list-day-cushion { background: var(--paper); padding: 20px 4px 6px; text-align: left; }
.fc .fc-list-day-text, .fc .fc-list-day-side-text { font: 700 1.2rem/1.1 var(--display); }
.fc .fc-list-day-side-text { color: var(--muted); font-weight: 500; }
.fc .fc-day-today .fc-list-day-text { display: inline-block; background: var(--accent); color: var(--on-accent); border-radius: 999px; padding: 4px 12px; }
.fc .fc-list-event { background: var(--card); cursor: pointer; }
.fc .fc-list-event td { padding: 14px 10px; }
.fc .fc-list-event-time { color: var(--muted); font-size: 0.9rem; width: 1%; }
.fc .fc-list-event-graphic { display: none; }
.fc .fc-list-event-title .ev { align-items: flex-start; }
.fc .fc-list-event-title .ev-title { white-space: normal; font-weight: 600; }
.fc .fc-list-event .dots i { width: 14px; height: 14px; border-color: #000; }
/* the "No plans yet" row under today */
.fc .is-placeholder .fc-list-event-time { font-size: 0; padding-right: 0; }
.fc .is-placeholder .ev-title { color: var(--muted); font-weight: 400; font-size: 0.9rem; }
.ev-loc { display: block; font-weight: 400; color: var(--muted); font-size: 0.9rem; }
.fc .fc-list-empty { background: var(--card); border-radius: 10px; min-height: 180px; }
.fc .fc-list-empty-cushion { color: var(--muted); }

@media (max-width: 700px) {
  .fc .fc-daygrid-day-frame { min-height: 72px; }
  .fc .fc-daygrid-day-number { font-size: 0.75rem; padding: 2px 5px; margin: 2px; }
  .fc .fc-daygrid-event { font-size: 0.7rem; padding: 1px 3px; }
  .fc .fc-daygrid-event .dots { display: none; }
}

/* ---------- plan sheet ---------- */

dialog.sheet {
  border: 1px solid var(--line);
  overflow-x: hidden;
  padding: 0;
  width: min(520px, 100% - 32px);
  max-height: min(92dvh, 820px);
  border-radius: 16px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.3);
}
dialog.sheet::backdrop { background: rgb(18 22 42 / 0.45); }
.sheet-body { padding: 20px 20px 16px; display: grid; gap: 16px; }

.sheet .title-input {
  border: 0;
  border-bottom: 2px solid var(--line);
  background: none;
  width: 100%;
  font: 700 1.75rem/1.2 var(--display);
  padding: 4px 0 8px;
  border-radius: 0;
}
.sheet .title-input:focus { outline: none; border-color: var(--ink); }
.sheet .title-input::placeholder { color: var(--muted); opacity: 0.6; }

.when { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
/* datetime inputs have a big intrinsic width that blows out the grid otherwise */
.when input { min-width: 0; }
.allday { display: flex; align-items: center; gap: 10px; min-height: 32px; font-size: 0.95rem; }
.allday input { width: 20px; height: 20px; accent-color: var(--accent); }

.notes-head { display: flex; justify-content: space-between; align-items: baseline; }
.linkish { background: none; border: 0; padding: 4px 0; color: var(--muted); font-size: 0.85rem; font-weight: 600; text-decoration: underline; }
.notes-view {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-weight: 400;
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--paper);
}
.notes-view a { color: var(--accent); font-weight: 600; text-underline-offset: 3px; }
.hint { color: var(--muted); font-weight: 400; font-size: 0.8rem; }
[hidden] { display: none !important; }

fieldset.going { border: 0; padding: 0; margin: 0; }
fieldset.going legend { font-size: 0.9rem; font-weight: 600; margin-bottom: 8px; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px 0 10px;
  border-radius: 999px;
  border: 2px solid var(--c);
  background: none;
  font-weight: 600;
  font-size: 0.95rem;
}
/* the dot squishes into a checkmark: same box, borders become the tick's two strokes */
.chip::before {
  content: "";
  box-sizing: border-box;
  width: 12px;
  height: 12px;
  margin: 0;
  border-radius: 50%;
  background: var(--c);
  border: 0 solid var(--on);
  transition: width 200ms, height 200ms, margin 200ms, border-radius 200ms, border-width 200ms, background-color 200ms, transform 200ms;
}
.chip[aria-pressed="true"] { background: var(--c); color: var(--on); }
.chip[aria-pressed="true"]::before {
  width: 6px;
  height: 11px;
  margin: -2px 3px 0; /* keeps the label from shifting when the box narrows */
  border-radius: 0;
  background: transparent;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}
@media (prefers-reduced-motion: reduce) {
  .chip::before { transition: none; }
}

.sheet-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  position: sticky;
  bottom: 0;
  background: var(--card);
}
.sheet-actions .btn-accent { margin-left: auto; }
.delete { color: var(--danger); }

@media (max-width: 700px) {
  /* bottom sheet on phones */
  dialog.sheet {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-radius: 16px 16px 0 0;
    max-height: 92dvh;
  }
  .when { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: no-preference) {
  dialog.sheet[open] { animation: rise 180ms ease-out; }
  @keyframes rise { from { transform: translateY(24px); opacity: 0; } }
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(88px, calc(env(safe-area-inset-bottom) + 88px));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.95rem;
  z-index: 10;
  max-width: calc(100% - 32px);
}
.toast:empty { display: none; }
