:root {
  --paper: #f3ede1;
  --card: #fbf8f1;
  --ink: #1f1a15;
  --muted: #5c5348;
  --line: #d6cbb8;
  --accent: #c2410c;
  --accent-dark: #9a3412;
  --focus: #0b5fff;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
html.lock { overflow: hidden; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: rgba(194, 65, 12, 0.18);
}

button, input, select { font: inherit; color: inherit; touch-action: manipulation; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-family: var(--serif); text-wrap: balance; }

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

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: 12px; top: -60px; z-index: 100;
  background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 6px;
}
.skip:focus { top: 12px; }

.wrap { width: 100%; max-width: 1180px; margin-inline: auto; padding-inline: 24px; }

/* Masthead */
.masthead { border-bottom: 2px solid var(--ink); background: var(--paper); }
.masthead-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--serif); font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; }
.masthead nav { display: flex; gap: 8px; }
.masthead nav a {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px;
  text-decoration: none; font-weight: 600; font-size: 0.95rem; border-radius: 999px;
  transition: background-color 0.15s;
}
.masthead nav a:hover { background: rgba(31, 26, 21, 0.09); }
.count {
  display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 6px;
  border-radius: 999px; background: var(--ink); color: var(--paper); font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

/* Hero */
.hero { padding-block: 48px 28px; }
.kicker { font-size: 0.85rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent-dark); margin-bottom: 12px; }
.hero h1 { font-size: clamp(2.2rem, 5.6vw, 4rem); line-height: 1.04; letter-spacing: -0.02em; max-width: 16ch; }
.lede { margin-top: 18px; max-width: 56ch; font-size: 1.1rem; color: var(--muted); text-wrap: pretty; }

/* Layout */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 40px; align-items: start; padding-bottom: 56px; }

/* Toolbar */
.toolbar {
  display: grid; grid-template-columns: minmax(0, 1fr) 200px auto; gap: 12px; align-items: end;
  padding: 16px; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
.field { display: grid; gap: 4px; min-width: 0; }
.field label { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.field input, .field select {
  width: 100%; min-height: 46px; padding: 0 12px; border: 1.5px solid #8c7f6c; border-radius: 8px;
  background-color: #fff; color: var(--ink);
}
.field input::placeholder { color: #6d6458; }
.toggle {
  display: inline-flex; align-items: center; gap: 8px; min-height: 46px; padding: 0 16px;
  border: 1.5px solid var(--ink); border-radius: 8px; background: transparent; font-weight: 600; cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.toggle:hover { background: rgba(31, 26, 21, 0.08); }
.toggle[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.toggle[aria-pressed="true"] svg path { fill: currentColor; }

.result-count { margin: 18px 2px 6px; font-size: 0.9rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Day groups */
.day { margin-top: 22px; }
.day-head {
  display: flex; align-items: baseline; gap: 12px; padding-bottom: 8px; border-bottom: 2px solid var(--ink);
  font-size: 1.5rem; letter-spacing: -0.01em;
}
.day-head small { font-family: var(--sans); font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.day-list { list-style: none; margin: 0; padding: 0; }

/* Item */
.item {
  position: relative; display: grid; grid-template-columns: 104px minmax(0, 1fr) auto; gap: 16px;
  padding: 18px 8px 18px 0; border-bottom: 1px solid var(--line);
  transition: background-color 0.15s;
}
.item:hover { background: rgba(251, 248, 241, 0.9); }
.item[hidden] { display: none; }
.when { padding-left: 14px; border-left: 5px solid var(--cat, var(--ink)); font-variant-numeric: tabular-nums; }
.when strong { display: block; font-size: 1.05rem; line-height: 1.3; }
.when span { font-size: 0.85rem; color: var(--muted); }
.item-main { min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; margin-bottom: 4px; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.chips i { width: 9px; height: 9px; border-radius: 50%; background: var(--cat); display: inline-block; }
.item h4 { margin: 0; font-family: var(--serif); font-size: 1.3rem; line-height: 1.2; letter-spacing: -0.01em; }
.open {
  all: unset; cursor: pointer; display: inline; text-wrap: balance;
}
.open::after { content: ""; position: absolute; inset: 0; }
.open:hover { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.open:focus-visible { outline: none; }
.open:focus-visible::after { outline: 3px solid var(--focus); outline-offset: -3px; border-radius: 4px; }
.place { margin-top: 4px; color: var(--muted); font-size: 0.95rem; }
.summary { margin-top: 8px; max-width: 62ch; text-wrap: pretty; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.tag { padding: 2px 10px; border: 1px solid #8c7f6c; border-radius: 999px; font-size: 0.85rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.tag.free { background: #e2edd2; border-color: #4d6b22; color: #2b4010; }

.quick {
  position: relative; z-index: 2; display: grid; place-items: center; width: 44px; height: 44px;
  border: 1.5px solid #8c7f6c; border-radius: 50%; background: #fff; cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.quick:hover { border-color: var(--ink); background: #f0e8d8; }
.quick[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.quick[aria-pressed="true"] svg path { fill: currentColor; }

/* Empty */
.empty { margin-top: 24px; padding: 32px 24px; text-align: center; border: 2px dashed #8c7f6c; border-radius: 12px; background: var(--card); }
.empty[hidden] { display: none; }
.empty h3 { font-size: 1.5rem; }
.empty p { margin: 8px auto 18px; max-width: 40ch; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 20px;
  border: 1.5px solid var(--ink); border-radius: 8px; background: var(--ink); color: var(--paper); font-weight: 700; cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.btn:hover { background: #3a3228; }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: rgba(31, 26, 21, 0.08); }

/* Shortlist */
.shortlist {
  position: sticky; top: 16px; padding: 22px; background: var(--ink); color: var(--paper); border-radius: 14px;
  scroll-margin-top: 16px;
}
.shortlist h2 { font-size: 1.6rem; letter-spacing: -0.01em; }
.shortlist h2:focus { outline: none; }
.shortlist h2:focus-visible { outline: 3px solid #9cc0ff; outline-offset: 4px; }
.shortlist :focus-visible { outline-color: #9cc0ff; }
.sl-note { margin-top: 10px; color: #dcd3c2; text-wrap: pretty; }
.sl-summary { margin: 8px 0 14px; color: #dcd3c2; font-variant-numeric: tabular-nums; }
.sl-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 0; }
.sl-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 12px 0; border-top: 1px solid rgba(243, 237, 225, 0.25); }
.sl-time { display: block; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: #f0b998; font-variant-numeric: tabular-nums; }
.sl-open {
  all: unset; cursor: pointer; font-family: var(--serif); font-size: 1.1rem; line-height: 1.25; text-wrap: balance;
}
.sl-open:hover { text-decoration: underline; text-underline-offset: 3px; }
.sl-open:focus-visible { outline: 3px solid #9cc0ff; outline-offset: 2px; border-radius: 3px; }
.sl-remove {
  min-height: 44px; padding: 0 12px; border: 1px solid rgba(243, 237, 225, 0.5); border-radius: 8px;
  background: transparent; color: var(--paper); cursor: pointer; font-size: 0.9rem; font-weight: 600;
  transition: background-color 0.15s;
}
.sl-remove:hover { background: rgba(243, 237, 225, 0.16); }
.conflicts { margin-top: 14px; padding: 12px 14px; border-radius: 8px; background: #f6d9c3; color: #4a1a05; font-size: 0.92rem; }
.conflicts strong { display: block; margin-bottom: 4px; }
.conflicts ul { margin: 0; padding-left: 18px; }

.footer { padding-block: 24px 40px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.9rem; }

/* Detail dialog */
.detail {
  width: min(680px, calc(100vw - 48px)); max-height: calc(100dvh - 48px); margin: auto; padding: 0;
  border: 2px solid var(--ink); border-radius: 14px; background: var(--card); color: var(--ink);
  overscroll-behavior: contain; overflow: auto;
}
.detail::backdrop { background: rgba(31, 26, 21, 0.6); }
.detail-inner { padding: 28px 32px 32px; }
.detail-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.close {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px;
  border: 1.5px solid var(--ink); border-radius: 8px; background: transparent; cursor: pointer; font-weight: 600;
  transition: background-color 0.15s;
}
.close:hover { background: rgba(31, 26, 21, 0.1); }
.detail h2 { font-size: clamp(1.7rem, 4.5vw, 2.4rem); line-height: 1.1; letter-spacing: -0.015em; overflow-wrap: anywhere; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 24px; margin: 22px 0; padding: 18px 0; border-block: 1px solid var(--line); }
.facts div { min-width: 0; }
.facts dt { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.detail-body { white-space: pre-line; max-width: 60ch; text-wrap: pretty; font-size: 1.05rem; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 26px; }
.save { min-width: 220px; }
.save[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.save[aria-pressed="true"]:hover { background: var(--accent-dark); }
.save svg path { fill: none; }
.save[aria-pressed="true"] svg path { fill: currentColor; }

@media (prefers-reduced-motion: no-preference) {
  .detail[open] { animation: rise 0.22s ease-out; }
  .detail[open]::backdrop { animation: fade 0.22s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
  @keyframes fade { from { opacity: 0; } to { opacity: 1; } }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition-duration: 0.01ms !important; }
}

/* Tablet & mobile */
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 32px; }
  .shortlist { position: static; }
}

@media (max-width: 640px) {
  .wrap { padding-inline: 16px; }
  .hero { padding-block: 32px 20px; }
  .lede { font-size: 1rem; }
  .toolbar { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding: 12px; }
  .field-search { grid-column: 1 / -1; }
  .toggle { justify-content: center; }
  .item { grid-template-columns: minmax(0, 1fr) auto; padding-right: 0; gap: 10px 12px; }
  .when { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; padding-left: 10px; }
  .item h4 { font-size: 1.2rem; }
  .masthead nav a { padding: 0 8px; }
  .detail {
    width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; border: 0; border-radius: 0;
  }
  .detail-inner { padding: 16px 16px calc(28px + env(safe-area-inset-bottom)); }
  .facts { grid-template-columns: 1fr 1fr; }
  .save { width: 100%; }
}
