:root {
  --ink: #1b1033;
  --canary: #ffd93d;
  --paper: #fffcf2;
  --wash: #fff4c4;
  --flag: #c4123f;
  --free: #0b6b6a;
  --rule: 3px;
  --display: Futura, "Futura PT", "Century Gothic", "Avenir Next", "Trebuchet MS", sans-serif;
  --text: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  --rail: 380px;
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--text);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 4px solid var(--flag);
  outline-offset: 2px;
}
.rail :focus-visible { outline-color: var(--ink); }
.detail :focus-visible { outline-color: var(--ink); }
.day-head :focus-visible { outline-color: var(--canary); }

.skip {
  position: absolute;
  left: 8px;
  top: -60px;
  z-index: 50;
  background: var(--ink);
  color: var(--canary);
  padding: 10px 14px;
  font-weight: 700;
}
.skip:focus { top: 8px; }

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

/* ---------- Rail ---------- */

.rail {
  background: var(--canary);
  border-right: var(--rule) solid var(--ink);
  padding: 32px 28px 32px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.wordmark {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: 112px;
  line-height: 0.82;
  letter-spacing: -0.055em;
  margin-left: -6px;
}

.lede {
  margin: 18px 0 0;
  font-size: 19px;
  line-height: 1.35;
  font-weight: 600;
  max-width: 24ch;
}

.controls { display: grid; gap: 16px; }

.field { display: grid; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }

.field label, .field legend {
  font-weight: 700;
  font-size: 15px;
  padding: 0;
}

input[type="search"], select {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  background: var(--paper);
  border: var(--rule) solid var(--ink);
  border-radius: 0;
  appearance: none;
  -webkit-appearance: none;
}
input[type="search"]::placeholder { color: #5c5273; opacity: 1; }

select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 22px) 52%, calc(100% - 16px) 52%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: 40px;
}

.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: var(--rule) solid var(--ink); background: var(--paper); }
.seg-btn {
  height: 42px;
  border: 0;
  border-right: var(--rule) solid var(--ink);
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}
.seg-btn:last-child { border-right: 0; }
.seg-btn[aria-pressed="true"] { background: var(--ink); color: var(--canary); }
.seg-btn:focus-visible { outline-offset: -6px; }

.saved-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 52px;
  padding: 0 14px;
  border: var(--rule) solid var(--ink);
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}
.saved-count {
  min-width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  background: var(--ink);
  color: var(--canary);
  font-family: var(--display);
  font-weight: 800;
  font-size: 17px;
}
.saved-toggle[aria-pressed="true"] { background: var(--flag); border-color: var(--flag); color: #fff; box-shadow: 0 0 0 var(--rule) var(--ink) inset; }
.saved-toggle[aria-pressed="true"] .saved-count { background: #fff; color: var(--flag); }
.saved-toggle:hover:not([aria-pressed="true"]), .seg-btn:hover:not([aria-pressed="true"]) { background: var(--wash); }

/* ---------- Stage / list ---------- */

.stage { min-width: 0; outline: none; }

.status {
  margin: 0;
  padding: 14px 40px;
  font-weight: 600;
  font-size: 15px;
  border-bottom: 1px solid var(--ink);
}

.day-head {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin: 0;
  padding: 12px 40px;
  background: var(--ink);
  color: var(--canary);
  font-family: var(--display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.01em;
}
.day-head .n { font-family: var(--text); font-weight: 600; font-size: 15px; }

.list { max-width: 1040px; }

.item {
  position: relative;
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr) auto;
  border-bottom: var(--rule) solid var(--ink);
  background: var(--paper);
}
.item:hover { background: var(--wash); }
.item.is-saved { box-shadow: inset 10px 0 0 var(--flag); }

.when {
  padding: 22px 16px 22px 40px;
  border-right: 1px solid var(--ink);
  font-family: var(--display);
  line-height: 1;
}
.item.is-saved .when { padding-left: 40px; }
.when .start { font-size: 40px; font-weight: 800; letter-spacing: -0.04em; white-space: nowrap; }
.when .start small { font-size: 16px; font-weight: 700; letter-spacing: 0; margin-left: 2px; }
.when .until { display: block; margin-top: 8px; font-family: var(--text); font-size: 14px; font-weight: 600; }

.what { padding: 20px 24px 22px; min-width: 0; }

.tags { display: flex; flex-wrap: wrap; gap: 6px 8px; margin-bottom: 8px; align-items: center; }
.tag {
  font-size: 14px;
  font-weight: 700;
  padding: 1px 9px;
  border: 2px solid var(--ink);
  line-height: 1.5;
}
.tag.saved { background: var(--flag); border-color: var(--flag); color: #fff; }
.where { font-size: 15px; font-weight: 500; }

.item h2 { margin: 0; font-family: var(--display); font-weight: 700; font-size: 27px; line-height: 1.12; letter-spacing: -0.015em; }

.open-item {
  all: unset;
  cursor: pointer;
}
.open-item::after { content: ""; position: absolute; inset: 0; }
.open-item:focus-visible { outline: 4px solid var(--flag); outline-offset: -4px; }
.item:has(.open-item:focus-visible) { outline: 4px solid var(--flag); outline-offset: -4px; }
.open-item:focus-visible { outline: none; }
.item:hover .open-item { text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 4px; }

.summary { margin: 8px 0 0; max-width: 56ch; font-size: 16px; }

.cost {
  padding: 22px 40px 22px 8px;
  font-family: var(--display);
  font-weight: 800;
  font-size: 26px;
  letter-spacing: -0.02em;
  text-align: right;
}
.cost.free { color: var(--free); }

/* ---------- Empty ---------- */

.empty { padding: 56px 40px; max-width: 620px; }
.empty[hidden] { display: none; }
.empty h2 { margin: 0 0 8px; font-family: var(--display); font-size: 40px; line-height: 1.05; letter-spacing: -0.03em; }
.empty p { margin: 0 0 24px; max-width: 44ch; }

.btn {
  height: 50px;
  padding: 0 22px;
  border: var(--rule) solid var(--ink);
  background: var(--ink);
  color: var(--canary);
  font-weight: 700;
  cursor: pointer;
  border-radius: 0;
}
.btn:hover { background: #33224f; }

/* ---------- Detail ---------- */

.detail {
  position: fixed;
  inset: 0 0 0 auto;
  margin: 0;
  width: min(580px, 100%);
  max-width: none;
  height: 100%;
  max-height: none;
  padding: 0;
  border: 0;
  border-left: var(--rule) solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  overflow-y: auto;
}
.detail:not([open]) { display: none; }
.detail::backdrop { background: rgba(27, 16, 51, 0.55); }
.detail[open] { animation: slide 0.22s ease-out; }
.detail[open]::backdrop { animation: fade 0.22s ease-out; }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.detail-inner { padding: 0 36px 40px; }

.detail-bar {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: flex-end;
  padding: 16px 0;
  background: var(--paper);
  z-index: 2;
}
.close {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  padding: 0 16px;
  border: var(--rule) solid var(--ink);
  background: var(--canary);
  font-weight: 700;
  cursor: pointer;
}
.close:hover { background: #ffe680; }

.detail-time {
  font-family: var(--display);
  font-weight: 800;
  font-size: 88px;
  line-height: 0.9;
  letter-spacing: -0.06em;
  margin-top: 8px;
}
.detail-time small { font-size: 28px; letter-spacing: -0.02em; margin-left: 4px; }
.detail-cat { margin: 16px 0 6px; font-weight: 700; color: var(--flag); }
.detail-title { margin: 0 0 20px; font-family: var(--display); font-weight: 800; font-size: 40px; line-height: 1.05; letter-spacing: -0.03em; }

.detail-body p { margin: 0 0 14px; max-width: 52ch; }
.detail-body p:first-child { font-size: 19px; line-height: 1.45; }
.detail-body p:not(:first-child) { padding: 12px 14px; background: var(--wash); border-left: 6px solid var(--ink); }

.facts { display: grid; grid-template-columns: 110px 1fr; margin: 24px 0 28px; border-top: var(--rule) solid var(--ink); }
.facts dt, .facts dd { margin: 0; padding: 10px 0; border-bottom: 1px solid var(--ink); }
.facts dt { font-weight: 700; }

.save { width: 100%; height: 56px; font-size: 18px; }
.save[aria-pressed="true"] { background: var(--flag); border-color: var(--flag); color: #fff; }
.save[aria-pressed="true"]:hover { background: #a30f35; }

/* ---------- Mobile ---------- */

@media (max-width: 900px) {
  .shell { display: block; }
  .rail {
    position: static;
    height: auto;
    overflow: visible;
    border-right: 0;
    border-bottom: var(--rule) solid var(--ink);
    padding: 22px 16px 20px;
    gap: 18px;
  }
  .wordmark { font-size: 72px; }
  .lede { font-size: 17px; margin-top: 12px; max-width: 32ch; }
  .controls { grid-template-columns: 1fr 1fr; gap: 12px; }
  .controls .field:first-child, .saved-toggle { grid-column: 1 / -1; }
  .controls .days { grid-column: 1 / -1; }
  .status { padding: 12px 16px; }
  .day-head { padding: 10px 16px; font-size: 20px; }
  .item { grid-template-columns: 92px minmax(0, 1fr); }
  .item.is-saved { box-shadow: inset 8px 0 0 var(--flag); }
  .when { padding: 16px 8px 16px 16px; }
  .when .start { font-size: 28px; }
  .when .start small { font-size: 13px; }
  .when .until { font-size: 12px; margin-top: 6px; }
  .what { padding: 16px 16px 16px 14px; }
  .item h2 { font-size: 22px; }
  .cost { grid-column: 2; padding: 0 16px 16px 14px; text-align: left; font-size: 20px; margin-top: -4px; }
  .empty { padding: 36px 16px; }
  .empty h2 { font-size: 32px; }
  .detail { width: 100%; border-left: 0; }
  .detail-inner { padding: 0 18px 32px; }
  .detail-time { font-size: 68px; }
  .detail-title { font-size: 32px; }
}

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

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .detail[open], .detail[open]::backdrop { animation: none; }
}
