:root {
  --bg-start: #fff7fb;
  --bg-end: #f3f8ff;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #f472b6;
  --primary-dark: #ec4899;
  --line: #fbcfe8;
  --shadow: 0 8px 28px rgba(244, 114, 182, 0.1);
  --page-padding: clamp(8px, 1.5vw, 16px);
  --page-top: max(12px, env(safe-area-inset-top));
  --header-height: var(--page-top);
  --gallery-min: clamp(calc(112px * 0.8), calc(16vw * 0.8), calc(240px * 0.8));
  --title-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

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

html {
  width: 100%;
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-start) 0%, var(--bg-end) 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

.page-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  width: 100%;
  max-width: 100vw;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.page-main {
  flex: 1;
  width: 100%;
  max-width: 100%;
  padding: var(--page-top) var(--page-padding) calc(var(--page-padding) + env(safe-area-inset-bottom));
}

.page-main:has(.time-rail) {
  padding-right: calc(var(--page-padding) + 97px);
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2vw, 24px);
  width: 100%;
  max-width: 100%;
}

.timeline-sentinel {
  width: 100%;
  height: 1px;
  pointer-events: none;
}

.timeline-load-wrap {
  display: none;
  justify-content: center;
  margin: 16px 0 8px;
}

.timeline-load-wrap.is-loading {
  display: flex;
}

.timeline-load-status {
  margin: 0;
  font-size: 14px;
  color: #9ca3af;
}

.timeline-end {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin: 28px 0 36px;
  padding: 0 24px;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: #6b7280;
}

.timeline-end::before,
.timeline-end::after {
  content: "";
  flex: 1;
  max-width: 120px;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    #d1d5db 50%,
    transparent 100%
  );
}

.timeline-item {
  width: 100%;
  position: relative;
  scroll-margin-top: calc(var(--page-top) + 12px);
}

.timeline-item[id^="month-"] {
  scroll-margin-top: calc(var(--page-top) + 12px);
}

.timeline-card {
  width: 100%;
  max-width: 100%;
  background: var(--card);
  border-radius: 14px;
  padding: clamp(14px, 2vw, 22px);
  box-shadow: var(--shadow);
  border: 1px solid #fce7f3;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: clamp(12px, 2vw, 20px);
  padding: 6px 0;
  margin-bottom: clamp(20px, 3.5vw, 32px);
  min-width: 0;
}

.card-leading {
  flex: 1;
  min-width: 0;
}

.card-title {
  margin: 0;
  color: #666;
  font-family: var(--title-font);
  font-size: clamp(1.2rem, 3vw, 1.55rem);
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: -0.02em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-insight {
  margin: 6px 0 0;
  color: #666;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.card-insight-viewport {
  position: relative;
  display: block;
  overflow: hidden;
  transition: height 0.48s ease-out;
}

.card-insight-measurer {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  visibility: hidden;
  pointer-events: none;
  height: auto;
  overflow: visible;
}

.card-insight-inner {
  display: block;
  max-width: 100%;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.48s ease-out, transform 0.48s ease-out;
}

.card-insight-text {
  display: inline;
  white-space: pre-wrap;
  word-break: break-word;
}

.card-insight-viewport.is-animating .card-insight-inner {
  opacity: 0.52;
  transform: translateY(-4px);
}

.card-insight-viewport.is-animating.is-expanding .card-insight-inner {
  opacity: 1;
  transform: translateY(0);
}

.card-insight-viewport.is-animating.is-collapsing .card-insight-inner {
  opacity: 0.62;
  transform: translateY(2px);
}

.card-insight-toggle {
  display: inline;
  margin: 0 0 0 2px;
  white-space: nowrap;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 12px;
  line-height: inherit;
  color: var(--primary-dark);
  cursor: pointer;
  vertical-align: baseline;
  -webkit-font-smoothing: antialiased;
  transition: color 0.2s ease-out, opacity 0.35s ease-out;
}

.card-insight-viewport.is-animating .card-insight-toggle {
  opacity: 0.85;
}

.card-insight-toggle:disabled {
  opacity: 0.55;
  cursor: wait;
}

.card-insight-toggle:hover:not(:disabled) {
  color: #be185d;
  text-decoration: underline;
}

@media (prefers-reduced-motion: reduce) {
  .card-insight-viewport,
  .card-insight-inner,
  .card-insight-toggle {
    transition: none;
  }
}

.card-meta {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.2vw, 12px);
  margin-left: auto;
  padding-top: 2px;
}

.card-time {
  flex-shrink: 0;
  color: var(--muted);
  font-size: clamp(0.75rem, 1.4vw, 0.88rem);
  white-space: nowrap;
}

.card-badge {
  flex-shrink: 0;
  background: #fdf2f8;
  color: #be185d;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.card-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--gallery-min));
  gap: clamp(12px, 2.5vw, 20px);
  width: 100%;
}

.gallery-photo {
  margin: 0;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 10px;
  background: #f3f4f6;
  cursor: pointer;
}

.gallery-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transition: transform 0.35s ease;
}

.gallery-photo:hover img {
  transform: scale(1.12);
}

.time-rail {
  position: fixed;
  top: calc(var(--page-top) + 8px);
  right: clamp(6px, 1vw, 12px);
  bottom: 16px;
  width: 88px;
  z-index: 90;
  pointer-events: none;
}

.time-rail-track {
  --rail-axis-col: 24px;
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: calc(100vh - var(--page-top) - 24px);
  pointer-events: auto;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid #fce7f3;
  box-shadow: 0 8px 24px rgba(244, 114, 182, 0.14);
  backdrop-filter: blur(10px);
  overflow: hidden;
}

.time-rail-track.is-nav-more::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 28px;
  border-radius: 0 0 14px 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.92) 75%);
  pointer-events: none;
}

.time-rail-track::before {
  content: "";
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: calc(var(--rail-axis-col) / 2);
  width: 1px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: linear-gradient(180deg, #fce7f3 0%, #fbcfe8 50%, #fce7f3 100%);
}

.time-rail-scroll {
  flex: 1;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 10px 10px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(244, 114, 182, 0.45) transparent;
}

.time-rail-scroll::-webkit-scrollbar {
  width: 4px;
}

.time-rail-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.time-rail-scroll::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(244, 114, 182, 0.45);
}

.time-nav-sentinel {
  width: 100%;
  height: 1px;
  pointer-events: none;
  flex-shrink: 0;
}

.time-rail-year {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  margin: 10px 0 5px;
  padding: 4px 6px 4px var(--rail-axis-col);
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.2;
  text-align: center;
  color: var(--primary-dark);
}

.time-rail-year:first-child {
  margin-top: 0;
}

.time-rail-item {
  position: relative;
  display: grid;
  grid-template-columns: var(--rail-axis-col) minmax(0, 1fr);
  align-items: center;
  width: 100%;
  margin: 2px 0;
  padding: 7px 6px 7px 0;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.time-rail-item::before {
  content: "";
  grid-column: 1;
  justify-self: center;
  align-self: center;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #fbcfe8;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.time-rail-item:hover {
  color: #be185d;
  background: rgba(253, 242, 248, 0.9);
}

.time-rail-item:hover::before {
  background: var(--primary);
}

.time-rail-item.is-active {
  color: #fff;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), #fb7185);
  box-shadow: 0 4px 14px rgba(244, 114, 182, 0.35);
}

.time-rail-item.is-active::before {
  width: 5px;
  height: 5px;
  background: #fff;
  box-shadow: 0 0 0 1.5px var(--primary);
}

body.lightbox-open {
  overflow: hidden;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}

.lightbox.is-open {
  display: flex;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(4px);
}

.lightbox-dialog {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2vw, 20px);
  width: min(96vw, 1200px);
  padding: clamp(12px, 3vw, 24px);
  pointer-events: none;
}

.lightbox-dialog > * {
  pointer-events: auto;
}

.lightbox-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  max-height: 88vh;
}

.lightbox-image {
  display: block;
  max-width: 100%;
  max-height: calc(88vh - 40px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  background: #111827;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  cursor: zoom-out;
}

.lightbox-counter {
  margin: 12px 0 0;
  color: #f9fafb;
  font-size: 0.95rem;
  text-align: center;
}

.lightbox-nav,
.lightbox-close {
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.lightbox-nav {
  width: clamp(40px, 6vw, 52px);
  height: clamp(40px, 6vw, 52px);
  border-radius: 50%;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  line-height: 1;
  flex-shrink: 0;
}

.lightbox-nav:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.28);
  transform: scale(1.06);
}

.lightbox-nav:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.lightbox-close {
  position: absolute;
  top: clamp(8px, 2vw, 16px);
  right: clamp(8px, 2vw, 16px);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.6rem;
  line-height: 1;
  z-index: 2;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.28);
}

@media (max-width: 640px) {
  .lightbox-dialog {
    flex-direction: column;
    width: 100vw;
    padding: 48px 12px 16px;
  }

  .lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
  }

  .lightbox-prev {
    left: 8px;
  }

  .lightbox-next {
    right: 8px;
  }

  .lightbox-nav:hover:not(:disabled) {
    transform: translateY(-50%) scale(1.06);
  }
}

.empty-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100%;
  min-height: calc(100dvh - var(--page-top) - 32px);
  padding: 40px var(--page-padding);
  background: rgba(255, 255, 255, 0.65);
  border-radius: 14px;
}

.empty-icon {
  font-size: clamp(2.5rem, 8vw, 4rem);
  margin-bottom: 12px;
}

.empty-box h2 {
  margin: 0 0 8px;
}

.empty-box p {
  margin: 0;
  color: var(--muted);
}

.page-main:has(.access-gate) {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - var(--page-top));
}

.access-gate {
  width: 100%;
  max-width: 400px;
}

.access-gate-card {
  padding: clamp(28px, 5vw, 36px);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #fce7f3;
  box-shadow: 0 12px 32px rgba(244, 114, 182, 0.16);
  text-align: center;
}

.access-gate-icon {
  font-size: 2rem;
  margin-bottom: 8px;
}

.access-gate-title {
  margin: 0 0 8px;
  font-size: clamp(1.25rem, 3vw, 1.5rem);
  font-weight: 800;
}

.access-gate-desc {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.access-gate-flashes {
  margin-bottom: 16px;
}

.access-gate-flash {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
}

.access-gate-flash-error {
  background: #fef2f2;
  color: #b91c1c;
}

.access-gate-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.access-gate-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  font: inherit;
  font-size: 1rem;
  background: #fff;
  text-align: center;
}

.access-gate-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(244, 114, 182, 0.18);
}

.access-gate-btn {
  margin-top: 6px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), #fb7185);
  color: #fff;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.access-gate-btn:hover {
  filter: brightness(1.03);
}

@media (max-width: 640px) {
  .page-main:has(.time-rail) {
    padding-right: calc(var(--page-padding) + 70px);
  }

  .time-rail {
    width: 64px;
    right: 4px;
    top: calc(var(--page-top) + 8px);
    bottom: 10px;
  }

  .time-rail-track {
    --rail-axis-col: 20px;
  }

  .time-rail-item {
    font-size: 0.72rem;
    padding: 6px 4px 6px 0;
  }

  .time-rail-year {
    font-size: 0.82rem;
    padding-right: 4px;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .empty-box {
    min-height: auto;
  }
}

.admin-entry-fab {
  position: fixed;
  right: max(18px, env(safe-area-inset-right, 0px) + 14px);
  bottom: max(22px, env(safe-area-inset-bottom, 0px) + 18px);
  z-index: 96;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ec4899, #db2777);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 22px rgba(236, 72, 153, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.admin-entry-fab:hover {
  color: #fff;
  box-shadow: 0 10px 26px rgba(236, 72, 153, 0.42);
  transform: translateY(-1px);
}

body:has(.time-rail) .admin-entry-fab {
  right: calc(clamp(6px, 1vw, 12px) + 88px + 28px);
}

body:has(.time-rail) .back-to-top {
  bottom: max(72px, env(safe-area-inset-bottom, 0px) + 68px);
}

.back-to-top {
  position: fixed;
  right: max(18px, env(safe-area-inset-right, 0px) + 14px);
  bottom: max(22px, env(safe-area-inset-bottom, 0px) + 18px);
  z-index: 95;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid #fce7f3;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: #be185d;
  box-shadow: 0 6px 20px rgba(244, 114, 182, 0.22);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(0.92);
  transition:
    opacity 0.4s ease,
    visibility 0.4s ease,
    transform 0.4s ease,
    box-shadow 0.2s ease;
  pointer-events: none;
  backdrop-filter: blur(8px);
  -webkit-tap-highlight-color: transparent;
}

body:has(.time-rail) .back-to-top {
  right: calc(clamp(6px, 1vw, 12px) + 88px + 28px);
}

.back-to-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.back-to-top:hover {
  box-shadow: 0 8px 24px rgba(244, 114, 182, 0.3);
}

.back-to-top:active {
  transform: translateY(0) scale(0.96);
}

.back-to-top-icon {
  display: block;
}

@media (max-width: 640px) {
  body:has(.time-rail) .admin-entry-fab {
    right: calc(4px + 64px + 24px);
  }

  body:has(.time-rail) .back-to-top {
    right: calc(4px + 64px + 24px);
  }

  .back-to-top {
    width: 42px;
    height: 42px;
  }

  .admin-entry-fab {
    min-width: 48px;
    height: 36px;
    font-size: 0.82rem;
  }
}
