* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  padding: 16px 24px 60px;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: var(--font-family);
  line-height: 1.5;
  transition: background-color 0.35s ease, color 0.35s ease;
}

.photos-header {
  width: 100%;
  max-width: 1200px;
  min-height: 48px;
  margin: 0 auto 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.home-link {
  min-width: 48px;
  min-height: 48px;
  padding: 12px;
  border-radius: var(--radius);
  color: var(--md-sys-color-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.2s ease;
}

.home-link:hover {
  background: var(--md-sys-state-hover-on-surface);
}

.home-link:active {
  background: var(--md-sys-state-pressed-on-surface);
}

.home-link:focus-visible,
.photos-theme-toggle:focus-visible,
button.photo-card:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.photos-theme-toggle {
  position: relative;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}

.photos-theme-toggle::after {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--md-sys-state-hover-on-surface);
  content: "";
  opacity: 0;
  pointer-events: none;
}

.photos-theme-toggle:hover::after {
  opacity: 1;
}

.photos-theme-toggle:active::after {
  background: var(--md-sys-state-pressed-on-surface);
  opacity: 1;
}

.photos-theme-toggle:focus-visible::after {
  opacity: 0;
}

.photos-main {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

h1 {
  margin: 0 0 40px;
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 32px;
}

.category-header {
  grid-column: 1 / -1;
  margin: 40px 0 10px;
  color: var(--md-sys-color-on-surface);
  font-size: 1.4rem;
  font-weight: 500;
}

.photo-card {
  position: relative;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: center;
  cursor: pointer;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

button.photo-card:hover {
  box-shadow: 0 4px 16px color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}

button.photo-card:active {
  background: var(--md-sys-state-pressed-on-surface);
}

.photo-card img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 5%, var(--md-sys-color-surface));
  display: block;
  object-fit: cover;
}

.photo-card-unavailable {
  aspect-ratio: 1;
  padding: 24px;
  border: 1px solid var(--md-sys-color-outline);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: default;
  overflow-wrap: anywhere;
}

.unavailable-message,
.unavailable-description {
  margin: 0;
}

.unavailable-message {
  font-weight: 500;
}

.unavailable-description {
  margin-top: 8px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.label {
  display: block;
  margin-top: 12px;
  color: var(--md-sys-color-outline);
  font-size: 0.85rem;
}

.title {
  margin-top: 4px;
  font-size: 1rem;
  font-weight: 500;
}

.gallery-feedback {
  min-height: 24px;
  margin-bottom: 16px;
  color: var(--md-sys-color-outline);
  text-align: center;
}

.retry-button {
  min-width: 48px;
  min-height: 48px;
  margin-left: 8px;
  padding: 8px 16px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-primary);
  font: inherit;
  cursor: pointer;
}

.retry-button:hover {
  background: var(--md-sys-state-hover-on-surface);
}

.retry-button:active {
  background: var(--md-sys-state-pressed-on-surface);
}

.retry-button:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.spinner {
  grid-column: 1 / -1;
  width: 40px;
  height: 40px;
  margin: 40px auto;
  border: 3px solid color-mix(in srgb, var(--md-sys-color-on-surface) 10%, transparent);
  border-top-color: var(--md-sys-color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.photo-viewer {
  position: relative;
  width: min(94vw, 1100px);
  max-width: 94vw;
  max-height: 92vh;
  max-height: 92dvh;
  margin: auto;
  padding: 64px 24px 24px;
  overflow: auto;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: var(--font-family);
}

.photo-viewer::backdrop {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 85%, transparent);
}

.viewer-title {
  margin: 0 56px 16px 0;
  font-size: 1.25rem;
}

.viewer-status {
  margin: 0;
  color: var(--md-sys-color-on-surface);
}

.viewer-image {
  max-width: 100%;
  max-height: calc(92vh - 200px);
  max-height: calc(92dvh - 200px);
  margin: 0 auto;
  display: block;
  object-fit: contain;
  border-radius: var(--radius);
}

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

.viewer-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.viewer-close:hover {
  background: var(--md-sys-state-hover-on-surface);
}

.viewer-close:active {
  background: var(--md-sys-state-pressed-on-surface);
}

.viewer-close:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  body {
    padding: 16px 24px 40px;
  }

  h1 {
    margin-bottom: 32px;
    font-size: 1.75rem;
  }

  .photo-viewer {
    width: 94vw;
    max-width: 94vw;
    padding: 64px 16px 16px;
  }

  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
    gap: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
