/* ==========================================================================
   Material Design 3 (MD3) Design Tokens & Components
   ========================================================================== */

:root {
  /* MD3 Light Color Scheme */
  --md-sys-color-primary: #5b49b6;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #e6deff;
  --md-sys-color-on-primary-container: #190064;

  --md-sys-color-secondary: #5f5b71;
  --md-sys-color-on-secondary: #ffffff;
  --md-sys-color-secondary-container: #e5dff9;
  --md-sys-color-on-secondary-container: #1b192c;

  --md-sys-color-tertiary: #8d4363;
  --md-sys-color-on-tertiary: #ffffff;
  --md-sys-color-tertiary-container: #ffd8e6;
  --md-sys-color-on-tertiary-container: #3a001e;

  --md-sys-color-error: #ba1a1a;
  --md-sys-color-on-error: #ffffff;
  --md-sys-color-error-container: #ffdad6;
  --md-sys-color-on-error-container: #410002;

  --md-sys-color-surface: #fdf8ff;
  --md-sys-color-surface-container-lowest: #ffffff;
  --md-sys-color-surface-container-low: #f7f2fa;
  --md-sys-color-surface-container: #f1ecf4;
  --md-sys-color-surface-container-high: #ebe6ef;
  --md-sys-color-surface-container-highest: #e5e0e9;

  --md-sys-color-on-surface: #1c1b20;
  --md-sys-color-on-surface-variant: #48454e;
  --md-sys-color-outline: #79757f;
  --md-sys-color-outline-variant: #cac4cf;

  /* MD3 Elevation Shadows */
  --md-sys-elevation-1: 0 1px 2px rgba(0, 0, 0, 0.08), 0 1px 3px 1px rgba(0, 0, 0, 0.05);
  --md-sys-elevation-2: 0 1px 2px rgba(0, 0, 0, 0.1), 0 2px 6px 2px rgba(0, 0, 0, 0.06);
  --md-sys-elevation-3: 0 4px 8px 3px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.12);

  /* MD3 Shape Scale */
  --md-sys-shape-corner-xs: 4px;
  --md-sys-shape-corner-sm: 8px;
  --md-sys-shape-corner-md: 12px;
  --md-sys-shape-corner-lg: 16px;
  --md-sys-shape-corner-xl: 28px;
  --md-sys-shape-corner-full: 9999px;

  /* Motion */
  --md-sys-motion-standard: cubic-bezier(0.2, 0, 0, 1);
}

[data-theme="dark"] {
  --md-sys-color-primary: #cbbeff;
  --md-sys-color-on-primary: #2d1286;
  --md-sys-color-primary-container: #432f9d;
  --md-sys-color-on-primary-container: #e6deff;

  --md-sys-color-secondary: #c9c3dc;
  --md-sys-color-on-secondary: #312e41;
  --md-sys-color-secondary-container: #474459;
  --md-sys-color-on-secondary-container: #e5dff9;

  --md-sys-color-tertiary: #ffb0cf;
  --md-sys-color-on-tertiary: #561434;
  --md-sys-color-tertiary-container: #712b4b;
  --md-sys-color-on-tertiary-container: #ffd8e6;

  --md-sys-color-error: #ffb4ab;
  --md-sys-color-on-error: #690005;
  --md-sys-color-error-container: #93000a;
  --md-sys-color-on-error-container: #ffdad6;

  --md-sys-color-surface: #141218;
  --md-sys-color-surface-container-lowest: #0f0d13;
  --md-sys-color-surface-container-low: #1c1b20;
  --md-sys-color-surface-container: #201f25;
  --md-sys-color-surface-container-high: #2b292f;
  --md-sys-color-surface-container-highest: #36343a;

  --md-sys-color-on-surface: #e6e1e9;
  --md-sys-color-on-surface-variant: #cac4cf;
  --md-sys-color-outline: #938f99;
  --md-sys-color-outline-variant: #48454e;

  --md-sys-elevation-1: 0 1px 3px 1px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.45);
  --md-sys-elevation-2: 0 2px 6px 2px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.5);
  --md-sys-elevation-3: 0 4px 12px 3px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.6);
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Roboto", "Noto Sans SC", "Noto Sans JP", system-ui, -apple-system, sans-serif;
  background-color: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s var(--md-sys-motion-standard), color 0.25s var(--md-sys-motion-standard);
}

.material-symbols-outlined {
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  user-select: none;
}

/* Top App Bar */
.top-app-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: var(--md-sys-color-surface);
  transition: background-color 0.2s var(--md-sys-motion-standard), box-shadow 0.2s var(--md-sys-motion-standard);
}

.top-app-bar.is-scrolled {
  background-color: var(--md-sys-color-surface-container);
  box-shadow: var(--md-sys-elevation-2);
}

.top-app-bar__inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.app-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--md-sys-shape-corner-md);
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-size: 24px;
  flex-shrink: 0;
}

.top-app-bar__titles {
  min-width: 0;
}

.top-app-bar__title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 500;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-app-bar__subtitle {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--md-sys-color-on-surface-variant);
}

.top-app-bar__actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* MD3 Icon Button */
.md-icon-button {
  width: 40px;
  height: 40px;
  border-radius: var(--md-sys-shape-corner-full);
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s var(--md-sys-motion-standard), color 0.2s var(--md-sys-motion-standard);
}

.md-icon-button:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
  color: var(--md-sys-color-on-surface);
}

.md-icon-button:active {
  background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
}

.md-icon-button.is-spinning .material-symbols-outlined {
  animation: spin 0.9s linear infinite;
}

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

/* MD3 Linear Progress */
.linear-progress {
  height: 3px;
  width: 100%;
  background-color: var(--md-sys-color-surface-container-highest);
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.linear-progress.is-active {
  opacity: 1;
}

.linear-progress__bar {
  height: 100%;
  width: 40%;
  background-color: var(--md-sys-color-primary);
  animation: indeterminate 1.4s infinite ease-in-out;
}

@keyframes indeterminate {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(350%);
  }
}

/* Main Layout */
.main-container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 20px 48px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background-color: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-lg);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat-card__icon {
  width: 42px;
  height: 42px;
  border-radius: var(--md-sys-shape-corner-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-card__icon--primary {
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.stat-card__icon--secondary {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.stat-card__icon--tertiary {
  background-color: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
}

.stat-card__icon--surface {
  background-color: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
}

.stat-card__content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.stat-card__label {
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
}

.stat-card__value {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.25;
}

.stat-card__value--sm {
  font-size: 0.95rem;
  font-weight: 600;
}

/* Controls Panel */
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 28px;
}

.search-field {
  position: relative;
  display: flex;
  align-items: center;
  background-color: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-corner-full);
  padding: 0 16px;
  height: 48px;
  transition: box-shadow 0.2s var(--md-sys-motion-standard);
}

.search-field:focus-within {
  box-shadow: 0 0 0 2px var(--md-sys-color-primary);
}

.search-field__icon {
  color: var(--md-sys-color-on-surface-variant);
  margin-right: 10px;
}

.search-field__input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font-size: 0.95rem;
  outline: none;
  font-family: inherit;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* MD3 Filter Chips */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-chip {
  height: 34px;
  padding: 0 14px;
  border-radius: var(--md-sys-shape-corner-sm);
  border: 1px solid var(--md-sys-color-outline);
  background-color: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.18s var(--md-sys-motion-standard);
}

.filter-chip .chip-check {
  display: none;
  font-size: 18px;
}

.filter-chip.is-selected {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border-color: transparent;
  padding-left: 10px;
}

.filter-chip.is-selected .chip-check {
  display: inline-flex;
}

.filter-chip:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}

.filter-chip.is-selected:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-on-secondary-container) 12%, var(--md-sys-color-secondary-container));
}

/* MD3 Segmented Button */
.segmented-button {
  display: inline-flex;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-full);
  overflow: hidden;
}

.segmented-button__item {
  border: none;
  border-right: 1px solid var(--md-sys-color-outline);
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  padding: 7px 14px;
  cursor: pointer;
  transition: background-color 0.18s var(--md-sys-motion-standard);
}

.segmented-button__item:last-child {
  border-right: none;
}

.segmented-button__item.is-selected {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.segmented-button__item:hover:not(.is-selected) {
  background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}

/* Error Banner */
.error-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-radius: var(--md-sys-shape-corner-lg);
  background-color: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  margin-bottom: 24px;
}

.error-banner[hidden] {
  display: none;
}

.error-banner__text {
  flex: 1;
}

.error-banner__title {
  margin: 0;
  font-size: 1rem;
}

.error-banner__desc {
  margin: 4px 0 0;
  font-size: 0.875rem;
}

/* MD3 Buttons */
.md-filled-button {
  height: 40px;
  padding: 0 22px;
  border-radius: var(--md-sys-shape-corner-full);
  border: none;
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: box-shadow 0.2s, filter 0.2s;
}

.md-filled-button:hover {
  box-shadow: var(--md-sys-elevation-1);
  filter: brightness(1.06);
}

.md-text-button {
  height: 40px;
  padding: 0 16px;
  border-radius: var(--md-sys-shape-corner-full);
  background: transparent;
  color: var(--md-sys-color-primary);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.md-text-button:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent);
}

/* ==========================================================================
   Timeline Layout
   ========================================================================== */

.timeline {
  position: relative;
  padding-left: 32px;
}

.timeline::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background-color: var(--md-sys-color-outline-variant);
}

.timeline-date-group {
  position: relative;
  margin: 24px 0 12px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--md-sys-color-primary);
  letter-spacing: 0.02em;
}

.timeline-date-group:first-child {
  margin-top: 0;
}

.timeline-date-group::before {
  content: "";
  position: absolute;
  left: -26px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: var(--md-sys-color-primary);
  border: 3px solid var(--md-sys-color-surface);
}

.timeline-item {
  position: relative;
  margin-bottom: 16px;
}

.timeline-item__dot {
  position: absolute;
  left: -25px;
  top: 22px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--md-sys-color-outline);
  border: 2px solid var(--md-sys-color-surface);
}

.timeline-item--artist .timeline-item__dot {
  background-color: var(--md-sys-color-primary);
}

.timeline-item--media .timeline-item__dot {
  background-color: var(--md-sys-color-tertiary);
}

/* MD3 Card */
.timeline-card {
  background-color: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-lg);
  overflow: hidden;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  transition: box-shadow 0.2s var(--md-sys-motion-standard), transform 0.2s var(--md-sys-motion-standard), background-color 0.2s;
  cursor: pointer;
}

.timeline-card--no-media {
  grid-template-columns: 1fr;
}

.timeline-card:hover {
  background-color: var(--md-sys-color-surface-container);
  box-shadow: var(--md-sys-elevation-2);
  transform: translateY(-1px);
}

.timeline-card__media {
  position: relative;
  background-color: var(--md-sys-color-surface-container-highest);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.timeline-card__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.timeline-card__no-image {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.timeline-card__body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.timeline-card__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--md-sys-shape-corner-full);
  font-size: 0.72rem;
  font-weight: 600;
}

.badge--artist {
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.badge--media {
  background-color: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
}

.badge--warning {
  background-color: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

.badge--neutral {
  background-color: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
}

.timeline-card__time {
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--md-sys-color-on-surface-variant);
  font-variant-numeric: tabular-nums;
}

.timeline-card__title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  word-break: break-word;
}

.timeline-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 0.8rem;
  color: var(--md-sys-color-on-surface-variant);
}

.timeline-card__meta code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background-color: var(--md-sys-color-surface-container-high);
  padding: 1px 6px;
  border-radius: var(--md-sys-shape-corner-xs);
  font-size: 0.76rem;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--md-sys-color-on-surface-variant);
}

.empty-state[hidden] {
  display: none;
}

.empty-state__icon {
  font-size: 48px;
  opacity: 0.7;
}

/* Footer */
.site-footer {
  text-align: center;
  padding: 20px;
  font-size: 0.8rem;
  color: var(--md-sys-color-on-surface-variant);
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.site-footer a {
  color: var(--md-sys-color-primary);
  text-decoration: none;
}

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

/* MD3 Dialog */
.md-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: none;
  border-radius: var(--md-sys-shape-corner-xl);
  background-color: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--md-sys-elevation-3);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.md-dialog:not([open]) {
  display: none;
}

.md-dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(2px);
}

.md-dialog__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 24px 12px;
}

.md-dialog__eyebrow {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--md-sys-color-primary);
  margin-bottom: 4px;
}

.md-dialog__title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  word-break: break-word;
}

.md-dialog__body {
  padding: 0 24px 16px;
  overflow-y: auto;
}

.dialog-preview-img {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  background-color: var(--md-sys-color-surface-container-lowest);
  border-radius: var(--md-sys-shape-corner-md);
  margin-bottom: 16px;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.detail-table th,
.detail-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  text-align: left;
  vertical-align: top;
}

.detail-table th {
  width: 140px;
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 500;
}

.detail-table td {
  word-break: break-all;
}

.md-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 24px 20px;
}

/* Responsive */
@media (max-width: 820px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .timeline-card {
    grid-template-columns: 1fr;
  }

  .timeline-card__media {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .top-app-bar__title {
    font-size: 1.05rem;
  }

  .timeline {
    padding-left: 22px;
  }

  .timeline::before {
    left: 6px;
  }

  .timeline-date-group::before {
    left: -21px;
  }

  .timeline-item__dot {
    left: -20px;
  }
}
