/* Force light theme (Pexels-like) over simple.css dark mode */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --text: #1a1a1a;
  --text-light: #5a5a5a;
  --accent: #05a081;
  --accent-hover: #04856c;
  --accent-text: #ffffff;
  --accent-bg: #e8f7f4;
  --border: #e0e0e0;
  --hero-bg: #232a34;
  --hero-text: #ffffff;
  --hero-muted: #c8cdd3;
}

html {
  color-scheme: light;
}

body {
  background-color: var(--bg);
  color: var(--text);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: var(--accent-text);
}

.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

/* Full-bleed dark hero like Pexels */
body > header {
  grid-column: 1 / -1;
  background-color: var(--hero-bg);
  background-image: linear-gradient(160deg, #1c2430 0%, #243447 55%, #1a4d45 100%);
  color: var(--hero-text);
  border-bottom: none;
  padding: 4rem 1rem 3.5rem;
  text-align: center;
}

body > header h1 {
  color: var(--hero-text);
  border: none;
  margin-bottom: 0.35rem;
  font-size: clamp(2rem, 5vw, 3rem);
}

body > header > p {
  color: var(--hero-muted);
  margin-top: 0;
  margin-bottom: 1.75rem;
}

body > header a {
  color: var(--hero-text);
}

/* Search in hero */
search {
  display: block;
  max-width: 40rem;
  margin: 0 auto;
}

#search-form {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}

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

#search-form input[type="search"] {
  flex: 1 1 12rem;
  margin: 0;
  border: none;
  border-radius: var(--standard-border-radius);
  padding: 0.85rem 1rem;
  font-size: 1.05rem;
  background: #ffffff;
  color: var(--text);
}

#search-form button {
  margin: 0;
  border: none;
  border-radius: var(--standard-border-radius);
  padding: 0.85rem 1.25rem;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

#search-form button:hover,
#search-form button:focus-visible {
  background: var(--accent-hover);
}

/* Results status + full-bleed grid */
main {
  grid-column: 1 / -1;
  width: min(90rem, 94%);
  margin-inline: auto;
  padding: 1.5rem 0 3rem;
}

#results-status {
  color: var(--text-light);
  margin: 0 0 1rem;
  font-size: 0.95rem;
}

#results-status:empty {
  display: none;
}

.photo-grid {
  column-count: 1;
  column-gap: 1rem;
}

@media (min-width: 40rem) {
  .photo-grid {
    column-count: 2;
  }
}

@media (min-width: 64rem) {
  .photo-grid {
    column-count: 3;
  }
}

@media (min-width: 90rem) {
  .photo-grid {
    column-count: 4;
  }
}

.photo-grid figure {
  break-inside: avoid;
  margin: 0 0 1rem;
  padding: 0;
  border: none;
  background: transparent;
}

.photo-grid img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  vertical-align: middle;
  background-color: var(--accent-bg);
}

.photo-card {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
}

/* Pexels-style green download button */
.download-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 8px;
  background-color: var(--accent);
  color: var(--accent-text) !important;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none !important;
  cursor: pointer;
}

.download-btn:hover,
.download-btn:focus-visible {
  background-color: var(--accent-hover);
  color: var(--accent-text) !important;
  outline: 2px solid var(--accent-text);
  outline-offset: 2px;
}

/* Hover overlay on grid cards */
.photo-card-download {
  position: absolute;
  right: 0.65rem;
  bottom: 0.65rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.photo-card:hover .photo-card-download,
.photo-card:focus-within .photo-card-download {
  opacity: 1;
  pointer-events: auto;
}

/* Photo detail dialog (Pexels-style large view) */
/* Escape simple.css body grid + dialog max-width: 40rem */
body > #photo-dialog {
  grid-column: 1 / -1;
}

#photo-dialog {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: min(56rem, calc(100vw - 1.5rem));
  max-width: calc(100vw - 1.5rem); /* overrides simple.css dialog { max-width: 40rem } */
  max-height: calc(100dvh - 1.5rem);
  margin: auto;
  padding: 1rem;
  overflow: auto;
  overscroll-behavior: contain;
  border: var(--border-width) solid var(--border);
  border-radius: 12px;
  background-color: var(--bg);
  color: var(--text);
}

#photo-dialog:not([open]) {
  display: none;
}

#photo-dialog::backdrop {
  background-color: var(--text);
  opacity: 0.45;
}

.photo-dialog-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin: 0;
  flex-shrink: 0;
}

.photo-dialog-bar h2 {
  margin: 0;
  flex: 1 1 12rem;
  min-width: 0;
  font-size: clamp(1rem, 2.5vw, 1.15rem);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.photo-dialog-bar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex: 1 1 auto;
}

#photo-dialog-image {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: min(65dvh, 40rem);
  height: auto;
  object-fit: contain;
  margin: 0 auto;
  background-color: var(--accent-bg);
  border-radius: 12px;
  flex: 0 1 auto;
}

.photo-dialog-open {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.photo-dialog-open:hover,
.photo-dialog-open:focus-visible {
  background-color: var(--accent-bg);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#photo-dialog-close {
  margin: 0;
  flex-shrink: 0;
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  white-space: nowrap;
}

.photo-card {
  cursor: zoom-in;
}

.photo-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

@media (hover: none) {
  .photo-card-download {
    opacity: 1;
    pointer-events: auto;
  }
}

/* Narrow phones / small tablets */
@media (max-width: 40rem) {
  body > header {
    padding: 2.25rem 1rem 2rem;
  }

  body > header > p {
    margin-bottom: 1.25rem;
    font-size: 0.95rem;
  }

  #search-form {
    flex-direction: column;
  }

  #search-form input[type="search"],
  #search-form button {
    flex: 1 1 auto;
    width: 100%;
  }

  main {
    width: min(90rem, calc(100% - 1.5rem));
    padding: 1rem 0 2rem;
  }

  .photo-grid {
    column-gap: 0.75rem;
  }

  .photo-grid figure {
    margin-bottom: 0.75rem;
  }

  .download-btn {
    padding: 0.5rem 0.85rem;
    font-size: 0.85rem;
  }

  .photo-card-download {
    right: 0.5rem;
    bottom: 0.5rem;
  }

  #photo-dialog {
    width: calc(100vw - 0.75rem);
    max-width: calc(100vw - 0.75rem);
    max-height: calc(100dvh - 0.75rem);
    padding: 0.75rem;
    border-radius: 10px;
  }

  .photo-dialog-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .photo-dialog-bar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .photo-dialog-bar-actions > * {
    flex: 1 1 auto;
    text-align: center;
  }

  #photo-dialog-image {
    max-height: min(55dvh, 28rem);
    border-radius: 10px;
  }
}

/* Very small screens */
@media (max-width: 22rem) {
  .photo-dialog-bar-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .photo-dialog-bar-actions > * {
    width: 100%;
  }
}

/* Short viewports (landscape phones) */
@media (max-height: 30rem) {
  body > header {
    padding: 1.25rem 1rem 1.5rem;
  }

  #photo-dialog {
    max-height: calc(100dvh - 0.5rem);
  }

  #photo-dialog-image {
    max-height: min(45dvh, 18rem);
  }
}
