/* ---- tokens ------------------------------------------------------------------------------------ */

:root {
  --bg: #f6f5f9;
  --surface: #ffffff;
  --surface-2: #efedf4;
  --surface-alt: #faf9fc;
  --text: #1b1726;
  --muted: #625c70;
  --border: #e2dfe9;
  --accent: #6d28d9;
  --accent-hover: #5b21b6;
  --accent-soft: #ede8fd;
  --accent-contrast: #ffffff;
  --danger: #c93b3b;
  --ok: #1f8a5b;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(30 15 60 / 0.05);
  --shadow-lg: 0 8px 24px rgb(30 15 60 / 0.12);
  /* the map: postcodes in the accent, the brush's paint over them in teal (painted-areas.md), so the layers read apart */
  --sea: #dde8f0;
  --land: #f1f0f4;
  --land-hover: #e5e2ec;
  --land-border: #b4aec0;
  --paint: #8b5cf6;
  --paint-fill: color-mix(in srgb, var(--paint) 42%, var(--land));
  --paint-border: #6d28d9;
  --brush: #0d9488;
  --brush-edge: #0f766e;
  --brush-opacity: 0.38;
  /* the calendar: hour lines, and the veil over time that has passed */
  --grid-hour: #e6e3ec;
  --past-veil: rgb(228 226 236 / 0.6);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #110f16;
    --surface: #19161f;
    --surface-2: #241f2c;
    --surface-alt: #1d1a24;
    --text: #ece9f2;
    --muted: #a39cb1;
    --border: #2d2836;
    --accent: #a78bfa;
    --accent-hover: #c4b5fd;
    --accent-soft: #2c2048;
    --accent-contrast: #170d2e;
    --danger: #ff6b6b;
    --ok: #4cc38a;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 8px 24px rgb(0 0 0 / 0.45);
    --sea: #10161c;
    --land: #221e29;
    --land-hover: #2e2937;
    --land-border: #4b4558;
    --paint: #a78bfa;
    --paint-fill: color-mix(in srgb, var(--paint) 42%, var(--land));
    --paint-border: #c4b5fd;
    --brush: #2dd4bf;
    --brush-edge: #99f6e4;
    --brush-opacity: 0.45;
    --grid-hour: #2b2733;
    --past-veil: rgb(12 10 16 / 0.55);
  }
}

/* ---- base -------------------------------------------------------------------------------------- */

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

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0; letter-spacing: -0.015em; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; display: flex; align-items: center; gap: 0.5rem; }
p { margin: 0; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.error { color: var(--danger); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- shell ------------------------------------------------------------------------------------- */

/* dvh where supported: on phones 100vh also counts the room behind the browser's toolbars. */
.shell { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.55rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 760;
  font-size: 1.1rem;
  letter-spacing: -0.03em;
}

/* The two event cards and the spark; the same drawing as the favicon. */
.brand-mark {
  width: 24px;
  height: 24px;
  background: url("/favicon.svg") center / contain no-repeat;
}

.brand--big { font-size: 1.7rem; }
.brand--big .brand-mark { transform: scale(1.35); margin-right: 0.3rem; }

.topnav { display: flex; gap: 0.2rem; flex-wrap: wrap; }

.topnav a {
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 560;
}

/* Hover styles only where there's a real hover: on touch screens they'd stick after a tap. */
@media (hover: hover) {
  .topnav a:hover { background: var(--surface-2); color: var(--text); }
}
.topnav a.active { background: var(--accent-soft); color: var(--accent); }
/* The nav's icons are for the phone tab bar (see "phones" at the end). */
.nav-icon { display: none; }

.topbar-end { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.topbar-email { color: var(--muted); font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
/* The account's address, a link to Settings (specs/settings.md); on phones just its icon. */
.topbar-settings { display: inline-flex; align-items: center; min-width: 0; padding: 0.4rem 0.6rem; border-radius: 8px; text-decoration: none; color: var(--muted); }
@media (hover: hover) {
  .topbar-settings:hover { background: var(--surface-2); }
  .topbar-settings:hover .topbar-email { color: var(--text); }
}
.topbar-settings.active { background: var(--accent-soft); color: var(--accent); }
.topbar-settings.active .topbar-email { color: var(--accent); }

/* Settings: the account, adult events' switch, then Google Maps' two options, each a whole clickable row. */
.settings-email { margin: 0; overflow-wrap: anywhere; }
.settings-options { display: flex; flex-direction: column; gap: 0.5rem; margin: 0; padding: 0; border: 0; min-width: 0; }
.settings-option { display: flex; align-items: flex-start; gap: 0.6rem; padding: 0.7rem 0.85rem; border: 1px solid var(--border); border-radius: 9px; cursor: pointer; }
.settings-option input { margin: 0.2rem 0 0; accent-color: var(--accent); }
.settings-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.settings-option-text { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.settings h2, .settings-maps p { margin: 0; }

.page { flex: 1; padding: 1.75rem 1.25rem 3rem; }
/* A phone turned sideways gets this layout, and index.html's viewport-fit=cover lets the page reach under its notch:
   keep clear of it. (The insets are 0 everywhere else.) */
.topbar, .page {
  padding-left: max(1.25rem, env(safe-area-inset-left));
  padding-right: max(1.25rem, env(safe-area-inset-right));
}

.narrow { max-width: 760px; margin: 0 auto; width: 100%; }
.stack { display: flex; flex-direction: column; gap: 0.9rem; }
.stack-lg { display: flex; flex-direction: column; gap: 1.25rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  min-width: 0;
}

.empty { display: flex; flex-direction: column; gap: 0.6rem; }
.empty-title { font-weight: 650; font-size: 1.05rem; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-actions { display: flex; gap: 0.5rem; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  padding: 0.5rem 0.9rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.btn:disabled { opacity: 0.55; cursor: default; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn--danger { color: var(--danger); }
@media (hover: hover) {
  .btn:hover { background: var(--surface-2); }
  .btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
  .btn--ghost:hover { color: var(--text); }
  .btn--danger:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
}
.btn--small { padding: 0.3rem 0.65rem; font-size: 0.85rem; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); color: var(--accent); }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn + .btn { margin-left: -1px; }
.btn-group .btn:first-child { border-radius: 9px 0 0 9px; }
.btn-group .btn:last-child { border-radius: 0 9px 9px 0; }

.btn--refresh svg { width: 15px; height: 15px; }
.btn--spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn--spinning svg { animation: none; } }

input[type="text"], input[type="email"], input[type="number"], input[type="date"], input[type="time"], input[type="search"], select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0.55rem 0.75rem;
  min-width: 0;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

.field { display: flex; flex-direction: column; gap: 0.35rem; min-width: 0; }
.field > span { font-weight: 600; font-size: 0.9rem; }
/* The field around a select with long options. WebKit (every iPhone browser) lays a select's options out as wide as the
   longest one and lets that spill out of the select, invisibly but widening the page, so a phone zooms out to fit.
   Clipping its field stops it; the padding, cancelled by the margin, keeps the focus ring inside the clip. */
.field--select { overflow: hidden; padding: 4px; margin: -4px; }

/* A switch (Settings' adult events, a filter's): a checkbox with role="switch", drawn as a track and its knob, with
   its label and a line about it beside it, all one click target. It flips at once, as anything the user does. */
.toggle { display: flex; align-items: flex-start; gap: 0.75rem; cursor: pointer; }
.toggle input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  position: relative;
  width: 2.6rem;
  height: 1.5rem;
  margin: 0;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid color-mix(in srgb, var(--muted) 45%, var(--border));
  cursor: pointer;
}
.toggle input::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(1.5rem - 6px);
  height: calc(1.5rem - 6px);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.3);
}
.toggle input:checked { background: var(--accent); border-color: var(--accent); }
.toggle input:checked::before { transform: translateX(1.1rem); }
.toggle input:focus { box-shadow: 0 0 0 3px var(--accent-soft); }
.toggle-text { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }

.title-input {
  flex: 1;
  min-width: 0;
  font-size: 1.1rem !important;
  font-weight: 680 !important; /* over the text fields' `font: inherit` */
  border-color: transparent !important;
  background: transparent !important;
  padding: 0.25rem 0.5rem !important;
  margin-left: -0.5rem;
}
@media (hover: hover) { .title-input:hover { border-color: var(--border) !important; } }
.title-input:focus { border-color: var(--accent) !important; background: var(--surface) !important; }

.hint { font-size: 0.85rem; color: var(--muted); }
.hint b { color: var(--text); font-weight: 650; }
/* Wording that depends on the device's main pointer (a touch screen's is coarse). */
.for-touch { display: none; }
@media (pointer: coarse) {
  .for-touch { display: inline; }
  .for-mouse { display: none; }
}

/* ---- loading & saving --------------------------------------------------------------------------
   Nothing looks empty while it loads, and nothing looks done while it's still being saved. Loading and busy
   states start instantly (they answer the user); leaving them is eased from JS (js/motion.js). */

.loading { display: flex; align-items: center; gap: 0.6rem; margin: 0; color: var(--muted); font-weight: 550; }
@keyframes pulse { 50% { opacity: 0.35; } }
.loading::before, .btn[aria-busy="true"]::after, .save-status--saving::before, .week-corner::after {
  content: "";
  flex: none;
  width: 1em;
  height: 1em;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}
.loading--page { min-height: 100vh; min-height: 100dvh; justify-content: center; }

.btn[aria-busy="true"] { cursor: progress; }
.btn[aria-busy="true"]:disabled { opacity: 0.8; }
.btn--refresh[aria-busy="true"]::after { content: none; }
input[aria-busy="true"], select[aria-busy="true"], fieldset[aria-busy="true"], .chip-x[aria-busy="true"] { opacity: 0.5; cursor: progress; }
/* Sections being reloaded: dimmed, and not clickable until fresh. */
.card[aria-busy="true"], .stack-lg[aria-busy="true"] { opacity: 0.6; pointer-events: none; }

/* ---- chips ------------------------------------------------------------------------------------- */

.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.12rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 560;
  line-height: 1.5;
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--surface));
}
.chip a { color: inherit; text-decoration: none; }
@media (hover: hover) { .chip a:hover { text-decoration: underline; } }

.chip-x {
  border: 0;
  background: none;
  color: inherit;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.1rem;
  margin-right: -0.2rem;
  opacity: 0.55;
  cursor: pointer;
}
@media (hover: hover) { .chip-x:hover { opacity: 1; } }

/* Read by screen readers, not shown. */
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* ---- filters ----------------------------------------------------------------------------------- */

/* The whole card opens the editor (FLT-9): the name's link is stretched over the card, and its focus ring is the
   card's. The × (FLT-11) sits above the link, in the corner the name keeps clear of. */
.filter-card { position: relative; display: flex; flex-direction: column; gap: 0.3rem; }
.filter-card h2 { margin: 0 2.5rem 0 0; }
.filter-name { color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.filter-name::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.filter-name:focus-visible { outline: none; }
.filter-name:focus-visible::after { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (hover: hover) {
  .filter-card:has(.filter-name:hover) { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); box-shadow: var(--shadow-lg); }
  .filter-card:has(.filter-name:hover) .filter-name { color: var(--accent); }
}
.filter-summary { overflow-wrap: anywhere; }
.filter-delete {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  z-index: 1;
  min-width: 2.2rem;
  height: 2.2rem;
  padding: 0 0.45rem;
  font-size: 1.4rem;
  font-weight: 500;
  line-height: 1;
}
.filter-delete[aria-busy="true"]::after { width: 0.6em; height: 0.6em; }
@media (hover: hover) { .filter-delete:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); } }

/* the editor */
.editor-wrap { max-width: 1100px; margin: 0 auto; width: 100%; display: flex; flex-direction: column; gap: 0.75rem; }
.back-link { align-self: flex-start; text-decoration: none; font-weight: 600; font-size: 0.9rem; }
.editor-head { display: flex; align-items: center; gap: 1rem; }
.editor-head .title-input { font-size: 1.5rem !important; letter-spacing: -0.015em; }
.save-status { display: inline-flex; align-items: center; gap: 0.45rem; flex: none; font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.save-status--saved { color: var(--ok); }
.save-status--error { color: var(--danger); }
.editor-matches { display: flex; flex-wrap: wrap; gap: 0.25rem 0.9rem; align-items: baseline; }
.editor-count { font-weight: 650; }
.editor h2 { margin: 0; }
.editor-subhead { margin: 0.4rem 0 0; font-size: 0.95rem; }

/* Times of day (FLT-5): a row per window, "Starts  from [18:00] to [23:00]". */
.windows { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.6rem 1rem; align-items: center; }
.window { display: contents; }
.window-label { font-weight: 600; }
.window-fields { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.5rem; }
.window-word, .window-dash { color: var(--muted); }
.window-dash { display: none; }
.time-input { min-width: 7.5rem; min-height: 2.6rem; }
.window-note { grid-column: 2; margin-top: -0.3rem; }

/* Weekdays and days of the month (FLT-6): a switch each, pressed is on. */
.days { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.days .day { min-width: 3.2rem; }
.monthdays { display: grid; grid-template-columns: repeat(7, minmax(0, 2.9rem)); gap: 0.35rem; }
.monthdays .day { min-width: 0; padding-inline: 0; font-variant-numeric: tabular-nums; }
.monthdays-actions { display: flex; gap: 0.4rem; }

/* Sources (FLT-7): All or a choice, then a tick box per source. */
.source-list { padding-left: 0.2rem; }
.source { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.6rem; cursor: pointer; }
.source input { align-self: center; margin: 0; width: 1rem; height: 1rem; accent-color: var(--accent); }
.source-name { font-weight: 600; }
.source-link { text-decoration: none; }
@media (hover: hover) { .source-link:hover { text-decoration: underline; } }

.selection-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.selection-count { font-weight: 650; }
/* Paint over sea alone matches nothing (AREA-11): said plainly, since it's rarely meant. */
.selection-sea { font-weight: 600; color: var(--danger); }

/* ---- an event (Matches, and the calendar's popup) and Matches ----------------------------------- */

.matches { max-width: 760px; margin: 0 auto; width: 100%; }
.matches-left { font-weight: 600; color: var(--muted); }
.match-slot[aria-busy="true"] { opacity: 0.6; pointer-events: none; }

.event { display: flex; flex-direction: column; gap: 1rem; }
.event-head { display: flex; flex-direction: column; gap: 0.3rem; }
.event-title { display: block; margin: 0; font-size: 1.35rem; line-height: 1.25; letter-spacing: -0.015em; overflow-wrap: anywhere; }
.event-when { font-weight: 600; }
.event-tags { margin-top: 0.3rem; }
.event-img { display: block; width: 100%; max-height: 320px; object-fit: cover; border-radius: 9px; background: var(--surface-2); }
.event-facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.35rem 1rem; margin: 0; }
.event-fact { display: contents; }
.event-fact dt { color: var(--muted); font-weight: 600; font-size: 0.9rem; line-height: 1.6; }
.event-fact dd { margin: 0; overflow-wrap: anywhere; }
.event-description-wrap { display: flex; flex-direction: column; align-items: flex-start; gap: 0.2rem; }
.event-description { display: flex; flex-direction: column; gap: 0.6rem; overflow-wrap: anywhere; white-space: pre-line; }
/* The first few lines, fading out, until Read more (MATCH-2). */
.event-description--folded { max-height: 7.6em; overflow: hidden; }
.event-description--folded:not(.event-description--fits) { mask-image: linear-gradient(to bottom, black 50%, transparent); -webkit-mask-image: linear-gradient(to bottom, black 50%, transparent); }
.event-more { padding-inline: 0; color: var(--accent); }
.event-links { display: flex; flex-wrap: wrap; gap: 0.5rem; }
/* Google's embedded map of where it is (MATCH-3); the background shows until it has drawn. */
.event-map { display: block; width: 100%; height: 300px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); }
/* Until Google's cookies are accepted, a box of the map's size stands in for it (MATCH-9): one button, its whole
   area clickable. */
.map-consent {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  cursor: pointer;
}
@media (hover: hover) { .map-consent:hover { border-color: var(--accent); background: var(--accent-soft); } }
.match-filters { display: flex; flex-direction: column; gap: 0.35rem; }
.match-filters h3 { margin: 0; font-size: 0.9rem; }
.match-filters ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.match-filters li { display: flex; flex-wrap: wrap; gap: 0.1rem 0.75rem; align-items: baseline; overflow-wrap: anywhere; min-width: 0; }

/* Calendar invite on the left, No and Yes on the right; on phones the answers come first, full width. */
.match-actions { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 0.75rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.invite { display: flex; flex-direction: column; align-items: flex-start; gap: 0.35rem; min-width: 0; }
.invite-note { overflow-wrap: anywhere; }
.answers { display: flex; gap: 0.5rem; }
.answers .btn { min-width: 7.5rem; }
.answer-no { color: var(--danger); }

/* ---- the calendar (specs/calendar.md) ---------------------------------------------------------
   It fills the screen below the top bar: its views scroll, not the page. Answers look the same everywhere (CAL-4):
   yes is filled in the accent, no is faded and struck through, the rest plain. */

.shell:has(.calendar) { height: 100vh; height: 100dvh; }
.page:has(.calendar) { display: flex; flex-direction: column; min-height: 0; padding-bottom: 1rem; }
.calendar { flex: 1; min-height: 0; width: 100%; max-width: 1400px; margin: 0 auto; display: flex; flex-direction: column; gap: 0.75rem; }

.cal-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; flex-wrap: wrap; }
.cal-title { font-size: 1.5rem; font-variant-numeric: tabular-nums; min-height: 1.2em; }
/* The shown week's number after its dates. */
.cal-weekno {
  display: inline-block;
  margin-left: 0.55rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0;
  vertical-align: 0.2em;
  white-space: nowrap;
}
.cal-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.cal-bar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem 1rem; }
.cal-legend { display: flex; gap: 0.4rem; font-size: 0.78rem; }
.legend { padding: 0.05rem 0.45rem; border-radius: 4px; background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.legend--yes { background: var(--accent); color: var(--accent-contrast); }
.legend--no { opacity: 0.5; text-decoration: line-through; background: var(--surface-2); }

.cal-host {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* month: --month-lines is how many lines of events a day holds (month-view.js reads it) */
.month-scroll { --month-row: 7.25rem; --month-lines: 4; flex: 1; min-height: 0; overflow-y: auto; overflow-anchor: none; }
.month-weekdays {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.month-weekdays div { padding: 0.45rem 0.6rem; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.month-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); height: var(--month-row); }
.month-day {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 4px;
  background: var(--surface);
  border-right: 1px solid var(--grid-hour);
  border-bottom: 1px solid var(--grid-hour);
  overflow: hidden;
  cursor: pointer;
}
.month-day:last-child { border-right: 0; }
.month-day--alt { background: var(--surface-alt); }
@media (hover: hover) { .month-day:hover { background-color: color-mix(in srgb, var(--accent) 5%, var(--surface)); } }
/* A day whose events are still being fetched: greyed out, gently pulsing. The overlay is always there, invisible
   when idle, so month-view.js can fade it out when the events are drawn (CAL-8). */
.month-day::before { content: ""; position: absolute; inset: 0; z-index: 1; background: color-mix(in srgb, var(--muted) 18%, transparent); opacity: 0; pointer-events: none; }
.month-day--loading::before { opacity: 1; animation: pulse 1.2s ease-in-out infinite; }
.month-daynum {
  align-self: flex-start;
  flex: none;
  padding: 0 0.4rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 620;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  white-space: nowrap;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}
/* The past, dulled (CAL-1): a veil as a background-image, so the months' alternating backgrounds still show. */
.month-day--past { background-image: linear-gradient(var(--past-veil), var(--past-veil)); }
.month-day--past .month-daynum { color: var(--muted); font-weight: 520; }
.month-day--past .month-events { opacity: 0.6; }
.month-day--today .month-daynum { background: var(--accent); color: var(--accent-contrast); }
.month-events { display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.month-event {
  display: block;
  width: 100%;
  padding: 1px 5px;
  font: inherit;
  font-size: 0.75rem;
  line-height: 1.35;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
}
.month-event-time { font-weight: 650; font-variant-numeric: tabular-nums; }
.month-event--yes { background: var(--accent); color: var(--accent-contrast); }
.month-event--no { opacity: 0.55; text-decoration: line-through; background: transparent; border-color: var(--border); }
@media (hover: hover) { .month-event:hover { border-color: var(--accent); } }
.month-more { padding: 0 5px; font-size: 0.72rem; font-weight: 650; color: var(--muted); white-space: nowrap; }

/* week */
.week-scroll { --gutter: 56px; --hour: 48px; flex: 1; min-height: 0; overflow-y: auto; }
.week-head {
  position: sticky;
  top: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: var(--gutter) repeat(7, minmax(0, 1fr));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.week-dayhead { display: flex; align-items: baseline; gap: 0.4rem; padding: 0.45rem 0.6rem; border-left: 1px solid var(--grid-hour); }
.week-dow { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.week-date { font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.week-dayhead--today .week-date { padding: 0 0.45rem; border-radius: 999px; background: var(--accent); color: var(--accent-contrast); }
.week-dayhead--past .week-dow { opacity: 0.75; }
.week-dayhead--past .week-date { color: var(--muted); font-weight: 600; }
.week-body { display: grid; grid-template-columns: var(--gutter) minmax(0, 1fr); }
.week-gutter { position: relative; }
.week-hour { position: absolute; right: 8px; transform: translateY(-50%); font-size: 0.72rem; line-height: 1; color: var(--muted); font-variant-numeric: tabular-nums; }
.week-days {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  background-image: linear-gradient(to bottom, var(--grid-hour) 1px, transparent 1px);
  background-size: 100% var(--hour);
}
/* The day's lanes exactly fill its column: lane width × lane count = day width (CAL-5). */
.week-col { position: relative; border-left: 1px solid var(--grid-hour); --lane-w: calc(100% / var(--lanes, 1)); }
.week-col--today { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.week-layer { position: absolute; inset: 0; }
/* The part of a day that has passed (week-view.js sets its height), veiled, events included. */
.week-past { position: absolute; top: 0; left: 0; right: 0; z-index: 1; background: var(--past-veil); pointer-events: none; }
/* A transparent border keeps neighbouring blocks apart without changing the lanes' sizes. */
.week-event {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  overflow: hidden;
  padding: 2px 5px;
  font: inherit;
  font-size: 0.75rem;
  line-height: 1.25;
  text-align: left;
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  background-clip: padding-box;
  border: 1px solid transparent;
  border-radius: 6px;
  box-shadow: inset 3px 0 0 color-mix(in srgb, var(--accent) 55%, transparent);
  cursor: pointer;
}
.week-event-time { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Wrapped between words only: in a narrow lane a long word is clipped rather than broken letter by letter. A block
   too narrow for any text (several side by side on a phone) is just its colour; it still opens the event. */
.week-event-title { max-width: 100%; overflow-wrap: normal; }
.week-event { container-type: inline-size; }
@container (max-width: 34px) { .week-event-time, .week-event-title { display: none; } }
.week-event--yes { background-color: var(--accent); color: var(--accent-contrast); box-shadow: none; }
.week-event--no { opacity: 0.55; text-decoration: line-through; background-color: var(--surface-2); box-shadow: inset 3px 0 0 var(--border); }
@media (hover: hover) { .week-event:hover { filter: brightness(0.95); } }
/* An end the source didn't give: an hour, fading out (CAL-5). Past midnight, square ends where it carries on. */
.week-event--open-end { mask-image: linear-gradient(to bottom, black 45%, transparent); -webkit-mask-image: linear-gradient(to bottom, black 45%, transparent); }
.week-event--continued { border-top-left-radius: 0; border-top-right-radius: 0; }
.week-event--continues { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
/* A week whose events are still being fetched: every day greyed out, and a spinner in the header's corner. Both
   overlays are always there, invisible when idle, so week-view.js can fade them out when the events arrive. */
.week-col::after { content: ""; position: absolute; inset: 0; z-index: 2; background: color-mix(in srgb, var(--muted) 16%, transparent); opacity: 0; pointer-events: none; }
.week-days--loading .week-col::after { opacity: 1; animation: pulse 1.2s ease-in-out infinite; }
.week-corner { display: flex; align-items: center; justify-content: center; color: var(--muted); }
/* Paused while hidden, so an idle page isn't animating anything. */
.week-corner::after { opacity: 0; animation-play-state: paused; }
.week-corner.week-loading::after { opacity: 1; animation-play-state: running; }
.week-now { position: absolute; z-index: 4; width: calc(100% / 7); height: 2px; margin-top: -1px; background: var(--danger); pointer-events: none; }
.week-now::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
@media (prefers-reduced-motion: reduce) {
  .month-day--loading::before, .week-days--loading .week-col::after { animation: none; }
}

/* The event popup (CAL-6): the event as Matches shows it, scrolling inside the dialog, and the answers lit as in
   the calendar. */
.event-dialog { width: min(680px, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); }
.event-dialog .dialog-body { padding: 0.75rem 1.5rem 1.5rem; }
.event-popup-head { position: sticky; top: 0; z-index: 2; margin-bottom: -1.5rem; pointer-events: none; }
.event-popup-head .dialog-close { pointer-events: auto; background: var(--surface); }
.event-popup .event-title { padding-right: 2.5rem; }
.event-popup .answer-yes[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.event-popup .answer-no[aria-pressed="true"] { opacity: 0.6; text-decoration: line-through; background: var(--surface-2); color: var(--muted); }
/* "Add “clay croquis” to a filter?" (CAL-7) */
.add-tag { padding: 1rem; border-radius: 10px; background: var(--accent-soft); }
.add-tag h3 { margin: 0; font-size: 1rem; }
.add-tag-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ---- tagging (specs/tagging.md), for admins ----------------------------------------------------- */

.tagging { max-width: 900px; margin: 0 auto; width: 100%; }
.tagging-counts { font-weight: 600; color: var(--muted); }
.tag-status { align-self: flex-start; padding: 0.05rem 0.55rem; border-radius: 999px; font-size: 0.78rem; font-weight: 650; background: var(--surface-2); color: var(--muted); }
.tag-status--waiting { background: var(--accent-soft); color: var(--accent); }
.tag-event .event-facts code, .rule-pattern-text { font-size: 0.85em; padding: 0.05rem 0.3rem; border-radius: 4px; background: var(--surface-2); overflow-wrap: anywhere; }
.tagging-tags h2 { margin: 0; }
.tagging-tags-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.tagging-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.tagging-nav, .tagging-do { display: flex; gap: 0.5rem; }
.tagging-done { min-width: 7rem; }
/* The tree's add, rename and delete (TREE-7): only while editing it. */
.tag-actions { display: none; margin-left: auto; padding-left: 0.5rem; gap: 0.1rem; }
.tagging-picker--editing .tag-actions { display: inline-flex; }
.tag-action { min-width: 1.9rem; height: 1.9rem; padding: 0 0.35rem; font-size: 1rem; font-weight: 600; }
@media (hover: hover) { .tag-delete:hover { color: var(--danger); } }
.rule-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0.75rem; }
.rule-pattern-field { grid-column: 1 / -1; }
.rule-actions { display: flex; gap: 0.5rem; }
.rules summary { cursor: pointer; list-style-position: outside; }
.rules summary h2 { display: inline; margin: 0; }
.rules[open] summary { margin-bottom: 0.5rem; }
.rules-body { display: flex; flex-direction: column; gap: 1rem; margin-top: 0.75rem; }
.rules-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.rules-source h3 { margin: 0 0 0.35rem; font-size: 0.95rem; }
.rules-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.rule { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.5rem; padding: 0.35rem 0.5rem; border-radius: 8px; background: var(--surface-alt); min-width: 0; }
.rule-kind { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.rule-arrow { color: var(--muted); }
.rule-adult { font-size: 0.75rem; font-weight: 650; color: var(--danger); }
.rule-delete { margin-left: auto; min-width: 2rem; height: 2rem; padding: 0 0.4rem; font-size: 1.2rem; line-height: 1; }
@media (hover: hover) { .rule-delete:hover { color: var(--danger); } }

/* ---- the tag picker (specs/tags.md, TREE-5 and TREE-6) -----------------------------------------
   The tree scrolls in a box of its own, so a long one doesn't push the rest of the editor away. */

.tag-picker { display: flex; flex-direction: column; gap: 0.6rem; min-width: 0; }
.tag-search { width: 100%; max-width: 26rem; }
.tag-tree-box { max-height: min(28rem, 60vh); overflow: auto; overscroll-behavior: contain; padding: 0.35rem; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-alt); }
.tag-tree, .tag-children { list-style: none; margin: 0; padding: 0; }
.tag-children { padding-left: 1.25rem; }
.tag-row { display: flex; align-items: center; min-height: 2rem; }
.tag-toggle, .tag-toggle-space { flex: none; width: 1.7rem; height: 1.7rem; }
.tag-toggle { display: grid; place-items: center; padding: 0; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; }
.tag-toggle svg { width: 14px; height: 14px; }
.tag-toggle[aria-expanded="true"] svg { transform: rotate(90deg); }
@media (hover: hover) { .tag-toggle:hover { background: var(--surface-2); color: var(--text); } }
.tag-label { display: inline-flex; align-items: baseline; flex-wrap: wrap; gap: 0 0.45rem; min-width: 0; padding: 0.2rem 0.45rem; border-radius: 6px; cursor: pointer; }
.tag-label input { flex: none; align-self: center; width: 1rem; height: 1rem; margin: 0; accent-color: var(--accent); cursor: inherit; }
@media (hover: hover) { .tag-node:not(.tag-node--covered) > .tag-row .tag-label:hover { background: var(--surface-2); } }
.tag-name { overflow-wrap: anywhere; }
.tag-node--picked > .tag-row .tag-name { font-weight: 650; }
/* Taken in by a picked tag above: shown ticked, dimmed, and not to be ticked on its own. */
.tag-node--covered > .tag-row .tag-label { color: var(--muted); cursor: default; }
.tag-node--covered > .tag-row input { opacity: 0.6; }
.tag-long { color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.tag-tree mark { padding: 0 1px; border-radius: 3px; color: inherit; background: color-mix(in srgb, var(--accent) 28%, transparent); }

/* ---- login and report -------------------------------------------------------------------------- */

.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.75rem;
  padding: 2rem 1rem;
  background: radial-gradient(60rem 30rem at 50% -10%, var(--accent-soft), transparent 70%);
}

.login-card { width: 100%; max-width: 410px; padding: 2rem; box-shadow: var(--shadow-lg); }
.login-card h1 { font-size: 1.45rem; }
.login-card .btn--primary { padding: 0.65rem 1rem; }
.sent-icon { font-size: 2.6rem; line-height: 1; color: var(--accent); }

.report-card { max-width: 520px; }
.choices, .checks { display: flex; flex-direction: column; gap: 0.6rem; margin: 0; padding: 0; border: none; min-width: 0; }
.choices legend, .checks legend { font-weight: 600; font-size: 0.9rem; padding: 0; margin-bottom: 0.35rem; }
.choice { display: flex; gap: 0.65rem; align-items: flex-start; padding: 0.75rem 0.85rem; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
@media (hover: hover) { .choice:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); } }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin: 0.2rem 0 0; accent-color: var(--accent); }
.choice-text { display: flex; flex-direction: column; gap: 0.2rem; }
.choice-warning { color: var(--danger); font-weight: 550; }

/* ---- guide ------------------------------------------------------------------------------------- */

.guide { max-width: 760px; margin: 0.5rem auto 0; display: flex; flex-direction: column; gap: 1.5rem; }
.guide-head { display: flex; flex-direction: column; gap: 0.35rem; }
.guide-lead { color: var(--muted); font-size: 1.05rem; }
.guide-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1rem; }
.guide-step { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 1.1rem; }
.guide-icon { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); }
.guide-icon svg { width: 24px; height: 24px; }
.guide-body { display: flex; flex-direction: column; align-items: flex-start; gap: 0.65rem; }
.guide-body h2 { margin: 0; }
.guide-kicker { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.guide-gestures b { font-weight: 650; }
.guide-progress { font-weight: 600; color: var(--accent); }
.guide-link::after { content: "→"; }
.guide-foot { font-size: 0.9rem; }

/* ---- the postcode map (specs/postcode-map.md, specs/painted-areas.md) --------------------------- */

.map-panel { display: flex; flex-direction: column; gap: 0.6rem; }
.map-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; }
/* Erase, when on, is red: it's the one that removes things. */
.btn.tool-erase[aria-pressed="true"] {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
}
/* Brush sizes (AREA-3): a dot as big as the brush, more or less. */
.map-brushes .btn { padding-inline: 0.7rem; }
.brush-dot { display: block; border-radius: 50%; background: currentColor; }
.brush-thin .brush-dot { width: 5px; height: 5px; }
.brush-medium .brush-dot { width: 9px; height: 9px; }
.brush-thick .brush-dot { width: 15px; height: 15px; }
.map-undo:disabled { opacity: 0.45; }
.map-find { display: flex; gap: 0.4rem; flex: 1; min-width: min(100%, 16rem); max-width: 26rem; }
.map-find-input { flex: 1; }

.map {
  position: relative;
  height: min(70vh, 720px);
  min-height: 320px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--sea);
  cursor: crosshair;
  /* Every finger on the map is the map's own (postcode-map.js): no page scroll, zoom, text selection or callout. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.map:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.map--grab, .map--panning { cursor: grab; }
.map--panning { cursor: grabbing; }
.map-svg { display: block; width: 100%; height: 100%; }

.pc { fill: var(--land); stroke: var(--land-border); stroke-width: 0.8; stroke-linejoin: round; vector-effect: non-scaling-stroke; fill-rule: evenodd; }
.pc--hover { fill: var(--land-hover); stroke: var(--text); stroke-width: 1.6; }
.pc--on { fill: var(--paint-fill); stroke: var(--paint-border); }
.pc--on.pc--hover { fill: color-mix(in srgb, var(--paint) 72%, var(--land)); stroke: var(--text); }
.map--erase .pc--hover { stroke: var(--danger); }

/* The paint: translucent as one layer (a stroke over paint doesn't darken it), with a crisp outline. A stroke under
   way is drawn as a line as wide as the brush; an erasing one is cut out through a mask. */
.paint { pointer-events: none; }
.paint-fill { opacity: var(--brush-opacity); }
.paint-shape { fill: var(--brush); fill-rule: evenodd; }
.paint-live { fill: none; stroke: var(--brush); stroke-linecap: round; stroke-linejoin: round; }
.paint-edge { fill: none; stroke: var(--brush-edge); stroke-width: 1.4; stroke-linejoin: round; vector-effect: non-scaling-stroke; fill-rule: evenodd; }
.erase-live { fill: none; stroke: black; stroke-linecap: round; stroke-linejoin: round; }
.map-brush {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  border: 2px solid var(--brush-edge);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgb(255 255 255 / 0.6);
  pointer-events: none;
}
.map-brush--erase { border-color: var(--danger); border-style: dashed; }

.map-inset { fill: none; stroke: var(--land-border); stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
.map-labels { pointer-events: none; }
.pc-label, .map-inset-label { fill: var(--muted); font-family: system-ui, sans-serif; font-weight: 650; text-anchor: middle; dominant-baseline: middle; }
.pc-label--on { fill: var(--text); }
.map-inset-label { text-anchor: start; }

.map-tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.82rem;
  line-height: 1.35;
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
}
.map-tip--pinned { transform: translateX(-50%); }
.map-tip-on { opacity: 0.75; font-size: 0.78rem; }

.map-zoom { position: absolute; right: 0.6rem; top: 0.6rem; z-index: 4; display: flex; flex-direction: column; gap: 0.3rem; }
.map-zoom-btn { width: 2.2rem; height: 2.2rem; padding: 0; font-size: 1.1rem; box-shadow: var(--shadow); }
.map-credit { font-size: 0.75rem; color: var(--muted); }

/* ---- dialogs ----------------------------------------------------------------------------------- */

/* A modal <dialog> (Feedback, specs/feedback.md). Its form fills it, so a click on the dialog itself is on the
   backdrop. */
.dialog {
  width: min(520px, calc(100vw - 2rem));
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.dialog::backdrop { background: rgb(25 12 50 / 0.35); }
@media (prefers-color-scheme: dark) {
  .dialog::backdrop { background: rgb(0 0 0 / 0.6); }
}
.dialog-body { padding: 1.5rem; }
.dialog-body h2 { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }
/* A heading with an × in the corner that closes the dialog (the map's cookie dialog, MATCH-9). */
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; }
.dialog-close {
  flex: none;
  min-width: 2.2rem;
  height: 2.2rem;
  margin: -0.45rem -0.65rem 0 0;
  padding: 0 0.45rem;
  font-size: 1.4rem;
  font-weight: 500;
  line-height: 1;
}
@media (pointer: coarse) { .dialog-close { min-width: 2.6rem; height: 2.6rem; } }
.map-consent-dialog h3 { margin: 0 0 0.25rem; font-size: 1rem; }
.map-consent-dialog p { margin: 0; }

/* ---- toasts ------------------------------------------------------------------------------------ */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  max-width: min(90vw, 520px);
  padding: 0.6rem 1rem;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-weight: 560;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.2s ease-out;
  transition: opacity 0.3s, transform 0.3s;
}
.toast--error { background: var(--danger); color: #fff; }
.toast--leaving { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---- phones -------------------------------------------------------------------------------------
   One breakpoint, by width. The nav becomes a tab bar at the bottom and the top bar keeps the brand, Feedback and
   Settings. How things react to touch doesn't depend on this; that follows the pointer (hover/pointer queries), so a
   touchscreen laptop gets the wide layout and a narrow desktop window this one. */

@media (max-width: 720px) {
  :root { --tabbar-h: 58px; }

  /* Room for the tab bar, which is fixed over the bottom of the page, and an iPhone's home indicator
     (safe-area-inset-bottom, with viewport-fit=cover; 0 elsewhere). */
  .shell { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

  .topbar { gap: 0.75rem; padding: 0.4rem 0.75rem; }
  .topbar-email { display: none; }
  .topbar-end .btn { padding: 0.4rem 0.6rem; }
  .topbar-feedback .nav-icon, .topbar-settings .nav-icon { width: 20px; height: 20px; }
  /* Log out is on Settings: the settings icon takes its place (SHELL-3). */
  .topbar-logout { display: none; }

  .topnav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr); /* one equal column per page, however many there are */
    gap: 0.15rem;
    padding: 0.3rem 0.3rem calc(0.3rem + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
  .topnav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.1rem;
    padding: 0 0.1rem;
    border-radius: 10px;
    font-size: 0.72rem;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
  }
  .nav-icon { display: block; width: 22px; height: 22px; }
  .nav-icon svg { display: block; width: 100%; height: 100%; }

  .toasts { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 0.75rem); }

  h1 { font-size: 1.4rem; }
  .page { padding: 1rem 0.75rem 2rem; }
  .card { padding: 1rem; }
  .login-card { padding: 1.5rem 1.25rem; }
  .btn-label { display: none; }

  .guide-step { column-gap: 0.8rem; }
  .guide-icon { width: 38px; height: 38px; border-radius: 10px; }
  .guide-icon svg { width: 20px; height: 20px; }

  .calendar { gap: 0.5rem; }
  .page:has(.calendar) { padding-bottom: 0.5rem; }
  .cal-title { font-size: 1.15rem; }
  .cal-weekno { margin-left: 0.35rem; font-size: 0.72rem; }
  .cal-actions { gap: 0.3rem; }
  .cal-actions .btn { padding: 0.45rem 0.55rem; }
  .cal-legend { display: none; }
  /* A phone's day is too narrow for titles: each event is its start time, and the week view has the rest. */
  .month-scroll { --month-row: 5.5rem; --month-lines: 3; }
  .month-weekdays div { padding: 0.4rem 0.3rem; letter-spacing: 0.03em; }
  .month-day { padding: 3px 2px; }
  .month-daynum { padding: 0 0.3rem; font-size: 0.8rem; }
  .month-event { padding: 0 3px; font-size: 0.68rem; text-overflow: clip; }
  .month-event-title { display: none; }
  .month-more { padding: 0 3px; font-size: 0.66rem; }
  .week-scroll { --gutter: 40px; }
  .week-dayhead { flex-direction: column; align-items: center; gap: 0; padding: 0.3rem 0; }
  .week-dow { font-size: 0.62rem; letter-spacing: 0.04em; }
  .week-date { font-size: 1rem; }
  .week-dayhead--today .week-date { padding: 0 0.35rem; }
  .week-hour { right: 5px; font-size: 0.66rem; }
  .week-event { padding: 1px 2px; font-size: 0.62rem; }
  .event-dialog .dialog-body { padding: 0.5rem 1rem 1rem; }
  .event-map { height: 240px; }
  .event-facts { grid-template-columns: minmax(0, 1fr); gap: 0.1rem; }
  .event-fact + .event-fact dt { margin-top: 0.35rem; }
  .match-actions { flex-direction: column-reverse; align-items: stretch; }
  .answers .btn { flex: 1; min-width: 0; }
  .filter-delete { top: 0.4rem; right: 0.4rem; }
  .editor-head .title-input { font-size: 1.25rem !important; }
  .windows { grid-template-columns: minmax(0, 1fr); gap: 0.3rem; }
  .window-label { margin-top: 0.35rem; }
  .window-note { grid-column: 1; margin-top: 0; }
  .window-fields { flex-wrap: nowrap; }
  .window-word { display: none; }
  .window-dash { display: inline; }
  .time-input { flex: 1; min-width: 0; padding-inline: 0.5rem; }
  .days .day { min-width: 0; flex: 1; padding-inline: 0; }
  .monthdays { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .map-toolbar { column-gap: 0.5rem; }
  .map-undo { min-width: 2.6rem; }
  /* The map takes most of the screen, but leaves room above and below to scroll the page past it (MAP-16). */
  .map { height: 62vh; height: 62dvh; min-height: 260px; }
  .map-find { max-width: none; }
}

/* Touch screens: text fields at 16px (iOS zooms into smaller ones when they get focus), and bigger targets for
   the small controls. The × keeps its place in the chip: its negative margins cancel the extra padding. */
@media (pointer: coarse) {
  input[type="text"], input[type="email"], input[type="number"], input[type="date"], input[type="time"], input[type="search"], select, textarea { font-size: 16px; }
  .chip-x { padding: 0.3rem 0.4rem; margin: -0.3rem -0.5rem -0.3rem -0.1rem; }
  .tag-row { min-height: 2.5rem; }
  .tag-toggle, .tag-toggle-space { width: 2.2rem; height: 2.2rem; }
  .tag-label input { width: 1.2rem; height: 1.2rem; }
  .map-zoom-btn { width: 2.6rem; height: 2.6rem; }
  .filter-delete { min-width: 2.6rem; height: 2.6rem; }
  .days .day { min-height: 2.5rem; }
  .source input { width: 1.2rem; height: 1.2rem; }
}
