:root {
  color-scheme: light;
  --background: #f9f9f9;
  --surface: #ffffff;
  --surface-low: #f3f3f3;
  --surface-mid: #eeeeee;
  --surface-high: #e8e8e8;
  --surface-variant: #e2e2e2;
  --surface-bright: #ffffff;
  --text: #1a1c1c;
  --text-muted: #5a413f;
  --outline: #8e706e;
  --outline-variant: #e2bebb;
  --primary: #8f0516;
  --primary-strong: #b1252a;
  --secondary: #795900;
  --secondary-soft: #d4af37;
  --tertiary: #45599c;
  --selected-bg: #f0f4ff;
  --vegetarian: #2e7d32;
  --haircut: #8e706e;
  --shadow-soft: 0 12px 28px rgba(26, 28, 28, 0.08);
  --radius-sm: 2px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;
  --calendar-gap: 2px;
  --calendar-cell-width: 112px;
  --calendar-cell-height: 68px;
  --calendar-panel-width: 100%;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--background);
  color: var(--text);
  font-family: "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

button {
  font: inherit;
}

.material-symbols-outlined {
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  font-size: 20px;
  line-height: 1;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--outline-variant);
}

.topbar__inner,
.page {
  width: min(1200px, calc(100% - 48px));
  margin: 0 auto;
}

.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand__mark {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(143, 5, 22, 0.18);
}

.brand__text h1,
.brand__text p,
.hero-months__en,
.hero-months__zh,
.detail-card h3,
.detail-panel__header h2 {
  margin: 0;
}

.brand__text h1 {
  font-family: "Hanken Grotesk", "Noto Sans SC", sans-serif;
  font-size: 1.26rem;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.brand__text p {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

.export-button {
  min-height: 32px;
  padding: 0 14px;
  border: 1px solid var(--outline-variant);
  border-radius: 999px;
  background: var(--surface-bright);
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.page {
  flex: 1;
  padding: 10px 0 16px;
}

.hero-card {
  width: min(100%, var(--calendar-panel-width));
  margin: 0 auto;
  padding-bottom: 6px;
}

.hero-card__main {
  display: block;
}

.hero-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.hero-nav {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 0 1 auto;
  margin-right: 12px;
}

.hero-nav[data-scale="compact"] {
  gap: 10px;
}

.hero-nav[data-scale="tight"] {
  gap: 8px;
}

.icon-button {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--outline-variant);
  border-radius: 999px;
  background: var(--surface-bright);
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.icon-button:hover {
  background: var(--surface-low);
  color: var(--primary);
  border-color: var(--primary);
}

.hero-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.hero-title-compact {
  display: none;
  color: var(--primary);
  font-family: "Hanken Grotesk", "Noto Sans SC", sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  white-space: nowrap;
}

.hero-nav[data-scale="compact"] .hero-title {
  gap: 8px;
}

.hero-nav[data-scale="tight"] .hero-title {
  gap: 6px;
}

.hero-year {
  font-family: "Hanken Grotesk", sans-serif;
  font-size: clamp(2.6rem, 7vw, 4rem);
  line-height: 0.84;
  font-weight: 800;
  letter-spacing: -0.05em;
}

.hero-nav[data-scale="compact"] .hero-year {
  font-size: clamp(2.2rem, 5.6vw, 3.2rem);
}

.hero-nav[data-scale="tight"] .hero-year {
  font-size: clamp(1.72rem, 4.6vw, 2.5rem);
}

.hero-months {
  padding-left: 10px;
  border-left: 2px solid var(--primary);
}

.hero-nav[data-scale="compact"] .hero-months {
  padding-left: 8px;
}

.hero-nav[data-scale="tight"] .hero-months {
  padding-left: 6px;
}

.hero-months__en {
  display: block;
  color: var(--text-muted);
  font-family: "Hanken Grotesk", sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.28em;
}

.hero-nav[data-scale="compact"] .hero-months__en {
  font-size: 0.64rem;
  letter-spacing: 0.2em;
}

.hero-nav[data-scale="tight"] .hero-months__en {
  font-size: 0.56rem;
  letter-spacing: 0.14em;
}

.hero-months__zh {
  display: block;
  margin-top: 2px;
  color: var(--primary);
  font-family: "Hanken Grotesk", "Noto Sans SC", sans-serif;
  font-size: clamp(1.22rem, 2.8vw, 1.72rem);
  font-weight: 700;
  line-height: 1.02;
}

.hero-nav[data-scale="compact"] .hero-months__zh {
  font-size: clamp(1rem, 2.2vw, 1.36rem);
}

.hero-nav[data-scale="tight"] .hero-months__zh {
  font-size: clamp(0.86rem, 1.8vw, 1.08rem);
}

.hero-nav__actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hero-nav[data-scale="tight"] .icon-button {
  width: 30px;
  height: 30px;
}

.dual-card {
  display: flex;
  align-items: stretch;
  min-width: 280px;
  margin-left: auto;
  padding: 8px 10px;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-lg);
  background: var(--surface-low);
  box-shadow: var(--shadow-soft);
  flex: 0 1 420px;
}

.dual-card__section {
  flex: 1;
  min-width: 0;
}

.dual-card__label,
.detail-panel__eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-family: "Hanken Grotesk", sans-serif;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.dual-card__label-compact {
  display: none;
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
}

.dual-card__lines p {
  margin: 0 0 1px;
  font-size: 0.7rem;
  font-weight: 500;
  white-space: nowrap;
}

.hero-topline[data-density="compact"] .dual-card__label {
  display: none;
}

.hero-topline[data-density="compact"] .dual-card__label-compact {
  display: block;
}

.hero-topline[data-density="compact"] .dual-card {
  padding: 6px 8px;
  border: 0;
  box-shadow: none;
  background: transparent;
}

.hero-topline[data-density="compact"] .dual-card__divider {
  display: none;
}

.hero-topline[data-density="compact"] .dual-card__lines p {
  font-size: 0.62rem;
}

.hero-topline[data-density="plain"] .hero-year,
.hero-topline[data-density="plain"] .hero-months {
  display: none;
}

.hero-topline[data-density="plain"] .hero-title-compact {
  display: block;
}

.hero-topline[data-density="plain"] .dual-card__label {
  display: none;
}

.hero-topline[data-density="plain"] .dual-card__label-compact {
  display: block;
}

.hero-topline[data-density="plain"] .dual-card {
  padding: 6px 8px;
  border: 0;
  box-shadow: none;
  background: transparent;
}

.hero-topline[data-density="plain"] .dual-card__divider {
  display: none;
}

.hero-topline[data-density="plain"] .dual-card__lines p {
  font-size: 0.58rem;
}

.dual-card__divider {
  width: 1px;
  margin: 0 8px;
  background: var(--outline-variant);
}

.calendar-panel {
  overflow: visible;
  padding-bottom: 12px;
  width: min(100%, var(--calendar-panel-width));
  margin: 0 auto;
}

.weekday-grid,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, var(--calendar-cell-width));
  gap: var(--calendar-gap);
}

.weekday-grid {
  margin-bottom: 2px;
}

.weekday-cell {
  padding: 5px 0;
  text-align: center;
  background: var(--primary);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
}

.weekday-cell--weekend {
  background: #ffc641;
  color: #715300;
}

.calendar-wrapper {
  overflow: visible;
  padding-top: 2px;
}

.calendar-wrapper--scrollable {
  overflow: auto;
  padding-bottom: 6px;
}

.calendar-cell {
  position: relative;
  height: var(--calendar-cell-height);
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 5px;
  border: 1px solid var(--outline-variant);
  background: var(--surface-bright);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background-color 120ms ease, box-shadow 120ms ease;
}

.calendar-cell:hover {
  background: var(--surface);
  box-shadow: 0 4px 10px rgba(26, 28, 28, 0.06);
  z-index: 2;
}

.calendar-cell--inactive {
  background: var(--surface-low);
  color: var(--text-muted);
  opacity: 0.68;
}

.calendar-cell--today {
  border-color: var(--secondary-soft);
  background: #fff1e3;
}

.calendar-cell--selected {
  border-color: var(--primary-strong);
  background: rgba(255, 255, 255, 0.98);
  z-index: 3;
}

.calendar-cell--first {
  border-bottom: 3px solid var(--primary);
}

.calendar-cell--assembly {
  border-bottom: 3px solid var(--secondary-soft);
}

.calendar-cell--assembly .calendar-meta {
  color: var(--primary);
}

.calendar-cell__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.calendar-day {
  font-size: 0.96rem;
  font-weight: 700;
  line-height: 1;
}

.calendar-day--today {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.18em;
  padding: 0 0.24em;
  border-radius: 4px;
  background: #b1252a;
  color: #fff;
  line-height: 1.05;
}

.vegetarian-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--vegetarian);
  font-size: 15px;
  font-variation-settings: "FILL" 0, "wght" 300, "GRAD" 0, "opsz" 20;
}

.calendar-meta {
  display: grid;
  gap: 1px;
  color: var(--text-muted);
  font-size: 0.53rem;
  line-height: 1.18;
}

.calendar-cell--first .calendar-meta {
  color: var(--primary);
}

.calendar-memorials {
  display: grid;
  gap: 1px;
  min-height: 12px;
  margin-top: 1px;
  font-size: 0.52rem;
  line-height: 1.14;
  overflow: hidden;
}

.calendar-memorials__item--tibetan,
.calendar-memorials__item--han {
  color: var(--primary);
}

.calendar-memorials__item--assembly {
  color: #8f6a00;
  font-weight: 700;
}

.calendar-memorials__item {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-memorials--collapsed {
  min-height: 0;
  margin-top: 0;
}

.calendar-icons {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  min-height: 12px;
}

.calendar-icons__group {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 16px;
}

.calendar-icons__group--top-right {
  justify-content: flex-end;
  margin-left: auto;
}

.calendar-icons__group--bottom-left {
  justify-content: flex-start;
}

.calendar-icons__group--bottom-right {
  justify-content: flex-end;
  margin-left: auto;
}

.festival-badge {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: #fff;
  font-size: 0.56rem;
  font-weight: 700;
  line-height: 1;
}

.festival-dot {
  width: 7px;
  height: 7px;
  display: inline-flex;
  border-radius: 999px;
}

.festival-badge--zen {
  background: #43a047;
}

.festival-badge--white {
  background: #b45309;
}

.festival-badge--medicine {
  background: #2c4183;
}

.festival-badge--thousand {
  background: #d4af37;
}

.festival-badge--patrol {
  background: #7e57c2;
}

.festival-badge--sages {
  background: #8f0516;
}

.festival-badge--amitabha {
  background: #c62828;
}

.festival-badge--avalokite {
  background: #00acc1;
}

.festival-badge--earth {
  background: #827717;
}

.festival-badge--sun {
  background: #ef6c00;
}

.festival-badge--dragon {
  background: #00897b;
}

.festival-badge--light {
  background: #5e35b1;
}

.festival-badge--protector {
  background: #6d4c41;
}

.festival-badge--shakyamuni {
  background: #c62828;
}

.haircut-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--haircut);
  font-size: 15px;
  line-height: 1;
}

.haircut-icon--legend {
  font-size: 16px;
}

.calendar-type-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #d4af37;
  font-size: 15px;
  font-variation-settings: "FILL" 0, "wght" 300, "GRAD" 0, "opsz" 20;
}

.calendar-cell--mode-icon .calendar-meta,
.calendar-cell--mode-dot .calendar-meta,
.calendar-cell--scroll-lock .calendar-meta {
  font-size: 0.5rem;
  line-height: 1.12;
}

.calendar-cell--mode-icon .calendar-day,
.calendar-cell--mode-dot .calendar-day,
.calendar-cell--scroll-lock .calendar-day {
  font-size: 0.9rem;
}

.legend-panel {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--outline-variant);
  margin-top: 10px;
}

.legend-group {
  display: grid;
  gap: 4px;
}

.legend-group__title {
  margin: 0;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.legend-icons,
.legend-states {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
}

#legend-festivals {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  font-size: 0.74rem;
}

.legend-state {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 4px;
  border: 1px solid var(--outline-variant);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.legend-state--today {
  border-color: #d4af37;
  background: #fff1e3;
  color: var(--primary);
}

.legend-state--first {
  border-bottom: 3px solid var(--primary);
}

.legend-state--assembly {
  border-bottom: 3px solid var(--secondary-soft);
  color: #8f6a00;
}

.legend-state--selected {
  border-color: var(--primary-strong);
  color: var(--primary-strong);
}

.legend-note {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
  padding-top: 6px;
  border-top: 1px solid var(--outline-variant);
}

.legend-note--compact {
  border-top: 0;
  padding-top: 0;
}

.legend-separator {
  width: 1px;
  height: 12px;
  background: var(--outline-variant);
}

.detail-modal[hidden] {
  display: none;
}

.detail-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
}

.detail-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 28, 28, 0.52);
  backdrop-filter: blur(4px);
}

.detail-modal__dialog {
  position: relative;
  z-index: 1;
  width: min(760px, calc(100% - 32px));
  max-height: calc(100vh - 40px);
  margin: 20px auto;
  overflow: auto;
  padding: 24px;
  border: 1px solid var(--outline-variant);
  border-radius: 16px;
  background: var(--surface-bright);
  box-shadow: 0 22px 60px rgba(26, 28, 28, 0.18);
}

.detail-modal__close {
  position: sticky;
  top: 0;
  float: right;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--outline-variant);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text-muted);
  cursor: pointer;
}

.detail-panel__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-right: 48px;
  clear: both;
}

.detail-panel__header h2 {
  font-family: "Hanken Grotesk", "Noto Sans SC", sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.1;
}

.detail-panel__weekday {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.detail-panel__content {
  display: grid;
  gap: 12px;
}

.detail-card {
  padding: 14px 16px;
  border: 1px solid var(--outline-variant);
  border-radius: 14px;
  background: linear-gradient(180deg, #fffdf9 0%, #ffffff 100%);
}

.detail-card h3 {
  margin-bottom: 12px;
  color: var(--primary);
  font-size: 0.98rem;
  letter-spacing: 0.04em;
}

.detail-meta {
  display: grid;
  gap: 10px;
  margin: 0;
}

.detail-meta--calendar {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.detail-meta dt {
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 0.74rem;
}

.detail-meta dd {
  margin: 0;
  font-size: 0.96rem;
  line-height: 1.5;
}

.detail-inline-list,
.detail-list,
.detail-group__list {
  margin: 0;
  padding-left: 18px;
}

.detail-inline-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.detail-list {
  display: grid;
  gap: 8px;
  color: var(--text-muted);
}

.detail-card--practice {
  background: linear-gradient(180deg, #fff6eb 0%, #fffdf9 100%);
  border-color: #f0d0a2;
}

.detail-practice__title,
.detail-practice__description {
  margin: 0;
}

.detail-practice__title {
  color: var(--text);
  font-size: 0.96rem;
  font-weight: 700;
  line-height: 1.5;
}

.detail-practice__description {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.7;
}

.detail-groups {
  display: grid;
  gap: 12px;
}

.detail-groups--stacked {
  gap: 10px;
}

.detail-group {
  padding: 10px 12px;
  border-radius: 10px;
  background: #faf7f4;
}

.detail-group h4 {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
}

.detail-group__list {
  display: grid;
  gap: 6px;
  color: var(--text-muted);
}

.export-modal__dialog {
  width: min(560px, calc(100% - 32px));
}

.export-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.export-field {
  display: grid;
  gap: 6px;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.export-field input {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--outline-variant);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.export-hint,
.export-preview {
  margin: 10px 0 0;
  color: var(--text-muted);
  font-size: 0.84rem;
  line-height: 1.7;
}

.export-actions {
  display: flex;
  justify-content: flex-end;
}

.export-submit-button {
  min-width: 132px;
  min-height: 40px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
}

.export-submit-button[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

@media (max-width: 1080px) {
  .dual-card {
    min-width: 220px;
    flex-basis: 360px;
  }
}

@media (max-width: 820px) {
  .topbar__inner,
  .page {
    width: min(100% - 20px, 100%);
  }

  .topbar__inner {
    display: grid;
  }

  .topbar__inner {
    justify-content: stretch;
  }

  .hero-nav {
    gap: 12px;
  }

  .hero-year {
    font-size: clamp(2.8rem, 14vw, 4rem);
  }

  .dual-card {
    padding: 8px 10px;
  }
}

@media (max-width: 640px) {
  .brand__text h1 {
    font-size: 1.22rem;
    letter-spacing: 0.14em;
  }

  .export-button {
    width: 100%;
  }

  .weekday-cell {
    font-size: 0.68rem;
  }

  .calendar-cell {
    height: var(--calendar-cell-height);
    min-height: 0;
    padding: 4px;
  }

  .calendar-day {
    font-size: 0.88rem;
  }

  .calendar-meta,
  .calendar-memorials {
    font-size: 0.48rem;
  }

  .detail-modal__dialog {
    width: min(100% - 16px, 100%);
    max-height: calc(100vh - 16px);
    margin: 8px auto;
    padding: 18px 14px;
  }

  .detail-panel__header {
    padding-right: 40px;
  }

  .detail-panel__header h2 {
    font-size: 1.28rem;
  }

  .detail-meta--calendar {
    grid-template-columns: 1fr;
  }

  .export-form {
    grid-template-columns: 1fr;
  }

  #legend-festivals {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
