@font-face {
  font-family: "DM Serif Display";
  src: url("assets/dm-serif.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Work Sans";
  src: url("assets/work-sans.ttf") format("truetype");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --paper: oklch(0.968 0.014 85);
  --paper-2: oklch(0.938 0.022 85);
  --paper-3: oklch(0.9 0.028 85);
  --ink: oklch(0.24 0.045 255);
  --ink-2: oklch(0.42 0.035 255);
  --line: oklch(0.85 0.025 85);
  --accent: oklch(0.5 0.17 35);
  --sun: oklch(0.85 0.15 85);
  --rail: oklch(0.25 0.05 255);
  --rail-2: oklch(0.31 0.05 255);
  --rail-line: oklch(0.42 0.05 255);
  --rail-text: oklch(0.96 0.015 90);
  --rail-muted: oklch(0.8 0.03 250);

  --serif: "DM Serif Display", "Iowan Old Style", Georgia, serif;
  --sans: "Work Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --rail-w: clamp(20rem, 25vw, 24rem);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--ink-2) var(--paper-2); }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  caret-color: var(--accent);
  accent-color: var(--accent);
}
body:has(dialog[open]) { overflow: hidden; }
::selection { background: var(--sun); color: var(--ink); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p, ol, ul, dl, dd, fieldset { margin: 0; padding: 0; }
ol, ul { list-style: none; }
svg { fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.rail :focus-visible { outline-color: var(--sun); }

.skip {
  position: absolute; left: 0.75rem; top: -4rem; z-index: 100;
  background: var(--ink); color: var(--paper); padding: 0.6rem 1rem; border-radius: 6px;
}
.skip:focus { top: 0.75rem; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 100vh; }

.rail {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--rail); color: var(--rail-text);
  padding: 2rem 1.5rem 1.5rem;
  display: flex; flex-direction: column; gap: 1.5rem;
  color-scheme: dark;
  scrollbar-color: var(--rail-line) transparent;
}
.rail ::selection { background: var(--sun); color: var(--ink); }

.brand { display: flex; align-items: center; gap: 0.9rem; }
.mark { width: 3.4rem; height: auto; flex: none; }
.mark-sun { fill: var(--sun); stroke: none; }
.mark-moon { fill: none; stroke: var(--rail-text); stroke-width: 2; }
.brand h1 { font-family: var(--serif); font-weight: 400; font-size: 2rem; line-height: 1.05; letter-spacing: -0.01em; }
.dates { color: var(--rail-muted); font-size: 0.875rem; margin-top: 0.2rem; }

.controls { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label, .days legend { font-size: 0.8125rem; font-weight: 600; color: var(--rail-muted); letter-spacing: 0.01em; padding: 0; }

.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 0.8rem; top: 50%; width: 1.15rem; height: 1.15rem; translate: 0 -50%; color: var(--rail-muted); pointer-events: none; }
.rail input[type="text"], .rail select {
  width: 100%; min-height: 2.9rem; padding: 0.6rem 0.85rem;
  background: var(--rail-2); border: 1px solid var(--rail-line); border-radius: 8px;
  color: var(--rail-text); caret-color: var(--sun);
  transition: border-color 0.15s, background-color 0.15s;
}
.search-wrap input { padding-left: 2.5rem; }
.rail input::placeholder { color: var(--rail-muted); opacity: 1; }
.rail input[type="text"]:hover, .rail select:hover { border-color: var(--rail-muted); }
.rail input[type="text"]:focus-visible, .rail select:focus-visible { outline: 3px solid var(--sun); outline-offset: 1px; border-color: var(--sun); }
.rail select { appearance: none; padding-right: 2.4rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23d5dbe8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.7rem center; background-size: 1.2rem; }

.days { border: 0; min-width: 0; }
.days legend { margin-bottom: 0.35rem; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--rail-2); border: 1px solid var(--rail-line); border-radius: 8px; padding: 3px; gap: 3px; }
.seg label { position: relative; }
.seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg span { display: grid; place-items: center; min-height: 2.5rem; border-radius: 5px; font-size: 0.875rem; font-weight: 500; color: var(--rail-text); transition: background-color 0.15s, color 0.15s; text-align: center; }
.seg input:hover + span { background: var(--rail-line); }
.seg input:checked + span { background: var(--sun); color: var(--ink); font-weight: 650; }
.seg input:focus-visible + span { outline: 3px solid var(--sun); outline-offset: 2px; }

.free { display: flex; align-items: center; gap: 0.65rem; font-size: 0.9375rem; cursor: pointer; min-height: 2.25rem; }
.free input { width: 1.2rem; height: 1.2rem; margin: 0; accent-color: var(--sun); }

.saved-toggle {
  display: flex; align-items: center; gap: 0.7rem; width: 100%; min-height: 3.1rem;
  padding: 0.6rem 0.9rem; border-radius: 8px;
  background: transparent; border: 1.5px solid var(--sun); color: var(--sun);
  font-weight: 600; text-align: left;
  transition: background-color 0.15s, color 0.15s, transform 0.15s var(--ease);
}
.saved-toggle svg { width: 1.3rem; height: 1.3rem; flex: none; }
.saved-label { flex: 1; }
.saved-count { min-width: 1.7rem; padding: 0.1rem 0.5rem; border-radius: 999px; background: var(--sun); color: var(--ink); font-size: 0.8125rem; text-align: center; font-weight: 700; }
.saved-toggle:hover { background: oklch(0.85 0.15 85 / 0.14); }
.saved-toggle:active { transform: scale(0.98); }
.saved-toggle[aria-pressed="true"] { background: var(--sun); color: var(--ink); }
.saved-toggle[aria-pressed="true"] svg path { fill: currentColor; }
.saved-toggle[aria-pressed="true"] .saved-count { background: var(--ink); color: var(--sun); }

.plan { border-top: 1px solid var(--rail-line); padding-top: 1.25rem; display: flex; flex-direction: column; gap: 0.8rem; }
.plan h2 { font-family: var(--serif); font-weight: 400; font-size: 1.35rem; }
.plan-hint { color: var(--rail-muted); font-size: 0.9rem; max-width: 30ch; }
.plan-list { display: flex; flex-direction: column; }
.plan-list li { border-bottom: 1px solid oklch(0.38 0.05 255); }
.plan-item { display: grid; grid-template-columns: 4.6rem 1fr; gap: 0.6rem; width: 100%; padding: 0.55rem 0.25rem; background: none; border: 0; text-align: left; border-radius: 4px; color: var(--rail-text); }
.plan-item:hover { background: var(--rail-2); }
.plan-item .pt { color: var(--sun); font-weight: 600; font-size: 0.875rem; }
.plan-item .pd { display: block; color: var(--rail-muted); font-size: 0.75rem; font-weight: 400; }
.plan-item .pn { font-size: 0.9375rem; line-height: 1.3; }
.plan-total { display: flex; justify-content: space-between; font-size: 0.9rem; color: var(--rail-muted); }
.plan-total strong { color: var(--rail-text); }
.plan-clash { display: flex; gap: 0.5rem; align-items: flex-start; font-size: 0.875rem; background: oklch(0.85 0.15 85 / 0.14); border-radius: 8px; padding: 0.6rem 0.7rem; color: var(--rail-text); }
.plan-clash svg { width: 1.1rem; height: 1.1rem; flex: none; margin-top: 0.1rem; color: var(--sun); }

.fine { margin-top: auto; padding-top: 0.5rem; color: var(--rail-muted); font-size: 0.8125rem; }

/* ---------- main ---------- */
main { padding: 2.5rem clamp(1.5rem, 4vw, 4.5rem) 5rem; min-width: 0; }
.listhead { max-width: 56rem; margin-bottom: 0.5rem; display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.25rem 1.5rem; }
.listhead h2 { font-size: 1rem; font-weight: 600; outline-offset: 4px; }
#count { color: var(--ink-2); font-size: 0.9375rem; }

.day { max-width: 56rem; margin-top: 2.5rem; }
.day:first-child { margin-top: 1rem; }
.day-head { display: flex; align-items: flex-end; gap: 1.1rem; border-top: 3px solid var(--ink); padding-top: 0.6rem; }
.day-num { font-family: var(--serif); font-size: 5.25rem; line-height: 0.85; color: var(--accent); letter-spacing: -0.02em; }
.day-head h3 { font-family: var(--serif); font-weight: 400; font-size: 2.1rem; line-height: 1.05; text-wrap: balance; }
.day-head p { color: var(--ink-2); font-size: 0.9375rem; margin-top: 0.15rem; }
.day-head > div { padding-bottom: 0.2rem; }

.event {
  position: relative;
  display: grid; grid-template-columns: 7.5rem minmax(0, 1fr) auto; gap: 0.25rem 1.5rem;
  padding: 1.35rem 0.75rem; margin-inline: -0.75rem;
  border-bottom: 1px solid var(--line);
  border-radius: 6px;
  transition: background-color 0.15s;
}
.event:hover { background: var(--paper-2); }
.event.is-saved { background: oklch(0.94 0.045 90); }
.event.is-saved:hover { background: oklch(0.915 0.06 90); }

.when { display: flex; flex-direction: column; }
.t-start { font-family: var(--serif); font-size: 2rem; line-height: 1; letter-spacing: -0.01em; }
.t-start small { font-family: var(--sans); font-size: 0.8125rem; font-weight: 600; margin-left: 0.2rem; color: var(--ink-2); }
.t-end { color: var(--ink-2); font-size: 0.8125rem; margin-top: 0.35rem; }

.what { min-width: 0; }
.what h4, .what .title { margin: 0; font: inherit; }
.open {
  all: unset; box-sizing: border-box; cursor: pointer;
  font-family: var(--serif); font-size: 1.5rem; line-height: 1.2; text-wrap: balance;
  color: var(--ink);
}
.open::after { content: ""; position: absolute; inset: 0; border-radius: 6px; }
.open:hover { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; text-decoration-color: var(--accent); }
.open:focus-visible { outline: none; }
.event:has(.open:focus-visible) { outline: 3px solid var(--accent); outline-offset: -3px; }
.sum { margin-top: 0.4rem; color: var(--ink-2); max-width: 62ch; text-wrap: pretty; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.9rem; margin-top: 0.7rem; font-size: 0.875rem; color: var(--ink-2); }
.meta .place { display: inline-flex; align-items: center; gap: 0.3rem; }
.meta svg { width: 1rem; height: 1rem; flex: none; }

.tag {
  --h: 250;
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.12rem 0.6rem 0.12rem 0.5rem; border-radius: 999px;
  background: oklch(0.91 0.06 var(--h)); color: oklch(0.3 0.09 var(--h));
  font-size: 0.8125rem; font-weight: 600;
}
.tag::before { content: ""; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: oklch(0.5 0.16 var(--h)); }
.tag[data-cat="Art"] { --h: 345; }
.tag[data-cat="Film"] { --h: 295; }
.tag[data-cat="Food"] { --h: 55; }
.tag[data-cat="Literature"] { --h: 175; }
.tag[data-cat="Music"] { --h: 255; }
.tag[data-cat="Outdoors"] { --h: 140; }
.tag[data-cat="Walks"] { --h: 85; }

.clash { display: flex; gap: 0.4rem; align-items: flex-start; margin-top: 0.7rem; font-size: 0.875rem; font-weight: 500; color: oklch(0.42 0.13 45); }
.clash svg { width: 1.05rem; height: 1.05rem; flex: none; margin-top: 0.12rem; }

.side { display: flex; align-items: flex-start; gap: 0.85rem; }
.price { font-family: var(--serif); font-size: 1.35rem; line-height: 2.75rem; min-width: 3.2rem; text-align: right; }
.price.free-price { color: var(--accent); }

.bm {
  position: relative; z-index: 1;
  display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border-radius: 50%;
  background: transparent; border: 1.5px solid var(--line); color: var(--ink);
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.2s var(--ease);
}
.bm svg { width: 1.3rem; height: 1.3rem; }
.bm:hover { border-color: var(--ink); background: var(--paper); }
.bm:active { transform: scale(0.92); }
.bm[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--sun); }
.bm[aria-pressed="true"] svg path { fill: currentColor; }

/* ---------- empty / error ---------- */
.empty { max-width: 56rem; margin-top: 3rem; padding: 3rem 1rem; text-align: center; border: 1.5px dashed var(--ink-2); border-radius: 12px; }
.empty[hidden], .load-error[hidden] { display: none; }
.empty svg { width: 3.5rem; height: 3.5rem; color: var(--ink-2); stroke-width: 1.5; }
.empty h3 { font-family: var(--serif); font-weight: 400; font-size: 2rem; margin-top: 0.5rem; }
.empty p { color: var(--ink-2); margin: 0.5rem auto 1.5rem; max-width: 40ch; text-wrap: balance; }
.btn {
  min-height: 2.9rem; padding: 0.6rem 1.4rem; border-radius: 8px; border: 0;
  background: var(--ink); color: var(--paper); font-weight: 600;
  transition: background-color 0.15s, transform 0.15s var(--ease);
}
.btn:hover { background: oklch(0.32 0.05 255); }
.btn:active { transform: scale(0.97); }
.load-error { margin-top: 2rem; padding: 1rem 1.25rem; border-radius: 8px; background: oklch(0.93 0.05 30); color: oklch(0.32 0.1 30); max-width: 56rem; }
.linklike { background: none; border: 0; padding: 0; text-decoration: underline; font-weight: 600; }

/* ---------- detail dialog ---------- */
dialog.detail {
  border: 0; padding: 0; margin: 0;
  inset: 0 0 0 auto;
  width: min(36rem, 100%); max-width: none;
  height: 100dvh; max-height: none;
  background: var(--paper); color: var(--ink);
  box-shadow: -16px 0 48px oklch(0.2 0.05 255 / 0.28);
  overflow: hidden;
}
dialog.detail::backdrop { background: oklch(0.2 0.05 255 / 0.55); }
dialog.detail[open] { animation: slide-in 0.4s var(--ease); }
dialog.detail[open]::backdrop { animation: fade-in 0.3s ease-out; }
@keyframes slide-in { from { opacity: 0; transform: translateX(2.5rem); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.d-inner { display: flex; flex-direction: column; height: 100%; }
.d-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.5rem; border-bottom: 1px solid var(--line); }
.d-close {
  display: inline-flex; align-items: center; gap: 0.5rem; min-height: 2.75rem; padding: 0.4rem 1rem 0.4rem 0.8rem;
  background: transparent; border: 1.5px solid var(--ink); border-radius: 999px; font-weight: 600;
  transition: background-color 0.15s, color 0.15s;
}
.d-close svg { width: 1.2rem; height: 1.2rem; }
.d-close:hover { background: var(--ink); color: var(--paper); }
.d-scroll { flex: 1; overflow-y: auto; padding: 1.75rem 1.5rem 2rem; scrollbar-color: var(--ink-2) transparent; overscroll-behavior: contain; }
.d-scroll h2 { font-family: var(--serif); font-weight: 400; font-size: clamp(2rem, 6vw, 2.9rem); line-height: 1.05; letter-spacing: -0.01em; text-wrap: balance; }
.d-lede { margin-top: 0.75rem; color: var(--accent); font-weight: 600; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem 1.5rem; margin-top: 1.75rem; padding: 1.25rem 0; border-block: 1px solid var(--line); }
.facts dt { font-size: 0.8125rem; font-weight: 600; color: var(--ink-2); }
.facts dd { font-size: 1.0625rem; margin-top: 0.1rem; }
.facts dd small { display: block; color: var(--ink-2); font-size: 0.875rem; }
.d-scroll h3 { font-family: var(--serif); font-weight: 400; font-size: 1.4rem; margin-top: 1.75rem; }
.d-body { margin-top: 0.5rem; white-space: pre-line; max-width: 62ch; font-size: 1.0625rem; line-height: 1.6; text-wrap: pretty; }
.d-foot { padding: 1rem 1.5rem calc(1rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--paper); }
.d-save {
  display: flex; align-items: center; justify-content: center; gap: 0.7rem; width: 100%; min-height: 3.4rem;
  border-radius: 10px; border: 2px solid var(--ink); background: var(--ink); color: var(--paper); font-weight: 650; font-size: 1.0625rem;
  transition: background-color 0.15s, color 0.15s, transform 0.15s var(--ease);
}
.d-save svg { width: 1.35rem; height: 1.35rem; }
.d-save:hover { background: oklch(0.32 0.05 255); }
.d-save:active { transform: scale(0.98); }
.d-save[aria-pressed="true"] { background: var(--sun); color: var(--ink); border-color: var(--ink); }
.d-save[aria-pressed="true"]:hover { background: oklch(0.88 0.14 85); }
.d-save[aria-pressed="true"] svg path { fill: currentColor; }

/* ---------- tablet & mobile ---------- */
@media (max-width: 960px) {
  .shell { display: block; }
  .rail { position: static; height: auto; overflow: visible; padding: 1.25rem 1rem 1.25rem; gap: 1rem; }
  .mark { width: 2.8rem; }
  .brand h1 { font-size: 1.7rem; }
  .controls { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem 0.9rem; }
  .field:first-child, .days { grid-column: 1 / -1; }
  .days { order: 2; }
  .field:nth-child(2) { order: 3; }
  .free { order: 4; align-self: end; min-height: 2.9rem; }
  .plan, .fine { display: none; }
  main { padding: 1.5rem 1rem 7rem; }

  .saved-toggle {
    position: fixed; z-index: 20; left: 50%; bottom: calc(0.9rem + env(safe-area-inset-bottom)); translate: -50% 0;
    width: auto; min-width: 12.5rem; max-width: calc(100% - 2rem);
    background: var(--rail); box-shadow: 0 8px 24px oklch(0.2 0.05 255 / 0.4), 0 2px 6px oklch(0.2 0.05 255 / 0.3);
  }
  .saved-toggle:hover { background: var(--rail); }
  .saved-toggle[aria-pressed="true"] { background: var(--sun); }
  .saved-toggle:focus-visible { outline-color: var(--sun); outline-offset: 3px; }
}

@media (max-width: 640px) {
  .day { margin-top: 2rem; }
  .day-num { font-size: 4rem; }
  .day-head h3 { font-size: 1.7rem; }
  .event {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "when side" "what what";
    gap: 0.6rem 0.75rem; padding: 1.1rem 0.75rem;
  }
  .when { grid-area: when; flex-direction: row; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
  .t-start { font-size: 1.6rem; }
  .t-end { margin-top: 0; }
  .what { grid-area: what; }
  .side { grid-area: side; align-items: center; }
  .price { line-height: 1; min-width: 0; }
  .open { font-size: 1.35rem; }

  dialog.detail { width: 100%; box-shadow: none; }
  dialog.detail[open] { animation-name: rise-in; }
  @keyframes rise-in { from { opacity: 0; transform: translateY(2rem); } to { opacity: 1; transform: none; } }
  .d-top, .d-scroll, .d-foot { padding-inline: 1.1rem; }
  .facts { gap: 1rem; }
}

@media (max-width: 380px) {
  .controls { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
