:root {
  color-scheme: light;
  --ink: #1c1b19;
  --muted: #68635c;
  --line: #ded8cf;
  --paper: #fbfaf7;
  --panel: #ffffff;
  --accent: #c83f37;
  --accent-2: #1f7a76;
  --date: #f1eee8;
  --weekend: #fff1e8;
  --today: #fff8c7;
  --shadow: 0 12px 32px rgba(29, 27, 23, 0.12);
}

html,
body {
  height: 100%;
}

* {
  box-sizing: border-box;
}

body {
  -webkit-text-size-adjust: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--paper);
  font-family:
    Inter, "Noto Sans HK", "Noto Sans TC", "PingFang HK", "Microsoft JhengHei",
    sans-serif;
}

a {
  color: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 58px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 250, 247, 0.94);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  place-items: center;
  border: 2px solid var(--ink);
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: clamp(1.05rem, 1.8vw, 1.36rem);
  letter-spacing: 0;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.actions a,
.dialog-body a {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
  font: inherit;
  cursor: pointer;
}

.actions a {
  padding: 6px 10px;
  font-size: 0.82rem;
}

main {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  padding: 12px 16px 20px;
}

.site-footer {
  flex: 0 0 auto;
  padding: 4px 12px 6px;
  color: var(--muted);
  text-align: center;
  font-size: 0.66rem;
  line-height: 1.2;
}

.site-footer a {
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.data-notice,
.source-note {
  margin: 0 0 8px;
  font-size: 0.74rem;
  line-height: 1.35;
}

.data-notice {
  border: 1px solid rgba(200, 63, 55, 0.35);
  padding: 7px 9px;
  background: #fff4ef;
  color: #9b2f29;
  font-weight: 700;
}

.source-note {
  color: var(--muted);
}

.controls {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(320px, 1.2fr);
  align-items: end;
  gap: 10px;
  margin-bottom: 10px;
}

.search-box,
.district-box {
  display: flex;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.search-box,
.district-box {
  flex-direction: column;
}

.search-box input {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0 12px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}

.district-box {
  min-width: 260px;
}

.district-chips {
  display: flex;
  min-height: 34px;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  border: 1px solid var(--line);
  padding: 3px;
  background: var(--panel);
}

.district-chips button {
  flex: 0 0 auto;
  min-height: 26px;
  border: 1px solid transparent;
  padding: 0 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
}

.district-chips button.active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  margin-bottom: 10px;
  color: var(--muted);
}

.summary strong {
  color: var(--ink);
  font-size: 1.08rem;
}

.schedule-shell {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.timeline {
  min-width: 100%;
}

.timeline-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: var(--venue-width) 1fr;
  min-height: 34px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.corner,
.venue-cell {
  position: sticky;
  left: 0;
  z-index: 4;
  width: var(--venue-width);
  border-right: 1px solid var(--line);
  background: #f8f5ef;
}

.corner {
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 700;
}

.date-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--col-width);
}

.date-cell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 34px;
  border-right: 1px solid var(--line);
  background: var(--date);
  font-size: 0.66rem;
}

.date-cell.weekend {
  background: var(--weekend);
}

.date-cell.today {
  background: var(--today);
  font-weight: 800;
}

.date-cell small {
  margin-top: 2px;
  color: var(--muted);
}

.timeline-row,
.group-row {
  display: grid;
  grid-template-columns: var(--venue-width) 1fr;
  border-bottom: 1px solid var(--line);
}

.timeline-row {
  min-height: 34px;
}

.group-row {
  min-height: 24px;
}

.venue-cell,
.group-cell {
  display: flex;
  align-items: center;
  overflow: hidden;
  color: var(--ink);
  line-height: 1.18;
}

.venue-cell {
  gap: 6px;
  justify-content: space-between;
  padding: 4px 7px 4px 10px;
  font-size: 0.72rem;
}

.child-row .venue-cell {
  padding-left: 24px;
  background:
    linear-gradient(to right, #d0c7ba 0 3px, transparent 3px),
    #fbfaf7;
}

.standalone-row .venue-cell {
  background: #fffdf9;
  font-weight: 650;
}

.venue-cell span {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.district-tag {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  min-height: 16px;
  border: 1px solid var(--line);
  padding: 0 4px;
  background: #fff;
  color: var(--muted);
  font-size: 0.58rem;
  line-height: 1;
}

.group-cell {
  position: sticky;
  left: 0;
  z-index: 5;
  width: var(--venue-width);
  gap: 6px;
  border-right: 1px solid var(--line);
  padding: 0 10px;
  background: #24211e;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
}

.group-cell small {
  display: inline-grid;
  min-width: 18px;
  height: 18px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.45);
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.66rem;
}

.track,
.group-track {
  position: relative;
}

.track {
  min-height: 34px;
  background-image:
    linear-gradient(to right, rgba(222, 216, 207, 0.78) 1px, transparent 1px),
    linear-gradient(
      to right,
      rgba(200, 63, 55, 0.06) 0,
      rgba(200, 63, 55, 0.06) calc(var(--col-width) * 2),
      transparent calc(var(--col-width) * 2),
      transparent calc(var(--col-width) * 7)
    );
  background-size: var(--col-width) 100%, calc(var(--col-width) * 7) 100%;
  background-position: 0 0, calc(var(--weekend-offset) * var(--col-width)) 0;
}

.group-track {
  min-height: 24px;
  background:
    linear-gradient(to right, rgba(36, 33, 30, 0.12) 1px, transparent 1px),
    #f0ece5;
  background-size: var(--col-width) 100%, auto;
}

.event-bar {
  position: absolute;
  top: var(--bar-top, 4px);
  height: var(--bar-height, 24px);
  min-height: 0;
  border: 0;
  padding: 3px 5px;
  background: var(--accent-2);
  color: #fff;
  text-align: left;
  font: inherit;
  font-size: 0.6rem;
  line-height: 1.08;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(32, 31, 28, 0.18);
}

.event-bar.split-bar {
  padding: 1px 4px;
  font-size: 0.52rem;
  line-height: 1;
  box-shadow: 0 3px 10px rgba(32, 31, 28, 0.16);
}

.event-bar:hover,
.event-bar:focus-visible {
  outline: 2px solid #1c1b19;
  outline-offset: 2px;
}

.event-bar span {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.event-bar.split-bar span {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.empty {
  padding: 26px;
  color: var(--muted);
}

dialog {
  width: min(720px, calc(100vw - 32px));
  border: 0;
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(16, 14, 12, 0.48);
}

.dialog-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  font-size: 1.5rem;
  cursor: pointer;
}

dialog img {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  background: #24211e;
}

.image-loader {
  display: grid;
  min-height: 260px;
  place-items: center;
  background: #24211e;
}

.image-loader[hidden] {
  display: none;
}

.image-loader::after {
  width: 30px;
  height: 30px;
  border: 3px solid rgba(255, 255, 255, 0.28);
  border-top-color: #fff;
  border-radius: 50%;
  content: "";
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.dialog-body {
  padding: 22px;
}

.dialog-kicker {
  margin: 0 0 8px;
  color: var(--accent);
  font-weight: 700;
}

.dialog-body h2 {
  margin: 0 0 18px;
  font-size: 1.45rem;
  line-height: 1.28;
}

dl {
  display: grid;
  gap: 10px;
  margin: 0 0 20px;
}

dl div {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
}

#dialogDate {
  white-space: pre-line;
}

.dialog-body a {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  padding: 0 14px;
  background: var(--ink);
  color: #fff;
}

@media (max-width: 760px) {
  .topbar {
    align-items: center;
    gap: 8px;
    min-height: 48px;
    padding: 8px 10px;
  }

  .brand {
    flex: 1 1 auto;
    gap: 8px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
    border-width: 1px;
    font-size: 0.78rem;
  }

  h1 {
    font-size: 1rem;
    line-height: 1.1;
  }

  .brand p {
    display: -webkit-box;
    overflow: hidden;
    margin-top: 2px;
    font-size: 0.64rem;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
  }

  .actions {
    flex: 0 0 auto;
    gap: 4px;
  }

  .actions a {
    padding: 5px 7px;
    font-size: 0.68rem;
  }

  main {
    padding: 8px;
  }

  .data-notice,
  .source-note {
    margin-bottom: 6px;
    font-size: 0.64rem;
  }

  .controls {
    grid-template-columns: 1fr;
    gap: 6px;
    margin-bottom: 6px;
  }

  .search-box,
  .district-box {
    gap: 4px;
    font-size: 0.68rem;
  }

  .search-box input {
    min-height: 32px;
    padding: 0 9px;
    font-size: 0.78rem;
  }

  .district-box {
    min-width: 0;
  }

  .district-chips {
    min-height: 32px;
    padding: 2px;
  }

  .district-chips button {
    min-height: 24px;
    padding: 0 7px;
    font-size: 0.66rem;
  }

  .summary {
    gap: 6px 12px;
    margin-bottom: 6px;
    font-size: 0.74rem;
  }

  .summary strong {
    font-size: 0.98rem;
  }

  .schedule-shell {
    min-height: 0;
    box-shadow: none;
  }

  .timeline-header {
    min-height: 30px;
  }

  .corner {
    padding: 0 6px;
    font-size: 0.66rem;
  }

  .date-cell {
    min-height: 30px;
    font-size: 0.56rem;
  }

  .date-cell small {
    margin-top: 1px;
  }

  .timeline-row {
    min-height: 32px;
  }

  .group-row,
  .group-track {
    min-height: 22px;
  }

  .venue-cell {
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 2px;
    padding: 3px 5px;
    font-size: 0.62rem;
  }

  .child-row .venue-cell {
    padding-left: 14px;
    background:
      linear-gradient(to right, #d0c7ba 0 2px, transparent 2px),
      #fbfaf7;
  }

  .venue-cell span {
    -webkit-line-clamp: 1;
  }

  .district-tag {
    max-width: 100%;
    min-height: 13px;
    padding: 0 3px;
    overflow: hidden;
    font-size: 0.5rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .group-cell {
    padding: 0 6px;
    font-size: 0.64rem;
  }

  .group-cell small {
    min-width: 15px;
    height: 15px;
    font-size: 0.58rem;
  }

  .track {
    min-height: 32px;
  }

  .event-bar {
    padding: 3px 4px;
    font-size: 0.52rem;
    line-height: 1;
    box-shadow: 0 4px 10px rgba(32, 31, 28, 0.16);
  }

  .event-bar span {
    -webkit-line-clamp: 2;
  }

  dialog {
    width: min(100vw - 16px, 720px);
    max-height: calc(100dvh - 16px);
  }

  dialog img {
    max-height: 34dvh;
  }

  .image-loader {
    min-height: 34dvh;
  }

  .dialog-body {
    padding: 16px;
  }

  .dialog-body h2 {
    margin-bottom: 14px;
    font-size: 1.12rem;
  }

  dl {
    gap: 8px;
    font-size: 0.88rem;
  }

  dl div {
    grid-template-columns: 48px 1fr;
    gap: 8px;
  }

  .dialog-body a {
    min-height: 36px;
    padding: 0 12px;
    font-size: 0.9rem;
  }
}

@media (max-width: 420px) {
  .actions a {
    padding: 4px 5px;
    font-size: 0.62rem;
  }

  h1 {
    font-size: 0.92rem;
  }

  .brand p {
    max-width: 180px;
  }
}

@media (max-height: 520px) and (max-width: 950px) {
  .topbar {
    gap: 8px;
    min-height: 42px;
    padding: 5px 8px;
  }

  .brand {
    gap: 8px;
    min-width: 260px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
    border-width: 1px;
    font-size: 0.76rem;
  }

  h1 {
    font-size: 0.98rem;
    line-height: 1.08;
  }

  .brand p {
    margin-top: 1px;
    font-size: 0.62rem;
    white-space: nowrap;
  }

  .actions {
    gap: 4px;
  }

  .actions a {
    min-height: 30px;
    padding: 4px 7px;
    font-size: 0.68rem;
  }

  main {
    padding: 5px 8px 8px;
  }

  .controls {
    grid-template-columns: minmax(180px, 0.9fr) minmax(260px, 1.1fr);
    gap: 6px;
    margin-bottom: 4px;
  }

  .search-box,
  .district-box {
    gap: 0;
  }

  .search-box > span,
  .district-box > span {
    display: none;
  }

  .search-box input {
    min-height: 29px;
    padding: 0 8px;
    font-size: 0.72rem;
  }

  .district-box {
    min-width: 0;
  }

  .district-chips {
    min-height: 29px;
    padding: 2px;
  }

  .district-chips button {
    min-height: 23px;
    padding: 0 7px;
    font-size: 0.64rem;
  }

  .summary {
    gap: 6px 12px;
    margin-bottom: 4px;
    font-size: 0.72rem;
  }

  .summary strong {
    font-size: 0.96rem;
  }

  .schedule-shell {
    box-shadow: none;
  }

  .timeline-header {
    min-height: 28px;
  }

  .corner {
    padding: 0 5px;
    font-size: 0.63rem;
  }

  .date-cell {
    min-height: 28px;
    font-size: 0.54rem;
  }

  .date-cell small {
    margin-top: 0;
  }

  .timeline-row {
    min-height: 30px;
  }

  .track {
    min-height: 30px;
  }

  .group-row,
  .group-track {
    min-height: 20px;
  }

  .venue-cell {
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 1px;
    padding: 2px 4px;
    font-size: 0.58rem;
  }

  .child-row .venue-cell {
    padding-left: 12px;
    background:
      linear-gradient(to right, #d0c7ba 0 2px, transparent 2px),
      #fbfaf7;
  }

  .venue-cell span {
    -webkit-line-clamp: 1;
  }

  .district-tag {
    max-width: 100%;
    min-height: 12px;
    padding: 0 3px;
    overflow: hidden;
    font-size: 0.48rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .group-cell {
    padding: 0 5px;
    font-size: 0.6rem;
  }

  .group-cell small {
    min-width: 14px;
    height: 14px;
    font-size: 0.54rem;
  }

  .event-bar {
    padding: 2px 4px;
    font-size: 0.5rem;
    line-height: 1;
    box-shadow: 0 3px 8px rgba(32, 31, 28, 0.15);
  }

  .event-bar.split-bar {
    padding: 1px 3px;
    font-size: 0.48rem;
  }
}
