
/* =========================
   Theme and base styles
   ========================= */

   :root {
    color-scheme: dark;
  
    --bg: #242426;
    --surface: #171719;
    --surface-hover: #202023;
    --surface-raised: #2c2c30;
    --border: #3a3a3f;
    --text: #f5f5f7;
    --text-secondary: #a1a1a6;
    --text-muted: #77777e;
    --accent: #d9d9de;
    --danger: #ff6961;
    --focus: #a8a8b3;
  }
  
  * {
    box-sizing: border-box;
  }
  
  html {
    background: var(--bg);
    scroll-behavior: smooth;
  }
  
  body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family:
      -apple-system, BlinkMacSystemFont, "SF Pro Display",
      "SF Pro Text", "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
  }
  
  [hidden] {
    display: none !important;
  }
  
  /* =========================
     Header and main layout
     ========================= */
  
  header {
    padding: 48px 20px;
    text-align: center;
    background: #111113;
    border-bottom: 1px solid var(--border);
  }
  
  header h1 {
    margin: 0 0 10px;
    font-size: clamp(2rem, 4vw, 2.7rem);
    font-weight: 650;
    letter-spacing: -0.045em;
  }
  
  header p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 1rem;
  }
  
  main {
    max-width: 1000px;
    margin: 36px auto;
    padding: 0 20px;
  }
  
  h2,
  h3 {
    color: var(--text);
    letter-spacing: -0.025em;
  }
  
  p {
    line-height: 1.6;
  }
  
  a {
    color: #d4d4dc;
    text-decoration: none;
    transition: color 0.2s ease;
  }
  
  a:hover {
    color: white;
    text-decoration: underline;
  }
  
  /* =========================
     Search and sighting count
     ========================= */
  
  #search {
    display: block;
    width: 100%;
    padding: 15px 17px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    outline: none;
    transition:
      border-color 0.2s ease,
      background 0.2s ease,
      box-shadow 0.2s ease;
  }
  
  #search::placeholder,
  main input::placeholder,
  main textarea::placeholder {
    color: var(--text-muted);
  }
  
  #search:focus {
    border-color: #777780;
    background: var(--surface-hover);
    box-shadow: 0 0 0 3px rgba(180, 180, 195, 0.08);
  }
  
  #count {
    color: var(--text-secondary);
    font-size: 0.92rem;
  }
  
  /* =========================
     Gallery / List controls
     ========================= */
  
  .view-toggle {
    display: flex;
    gap: 8px;
    margin: 18px 0 12px;
  }
  
  main button.view-toggle-button {
    padding: 9px 16px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition:
      background 0.2s ease,
      border-color 0.2s ease,
      color 0.2s ease;
  }
  
  main button.view-toggle-button:hover {
    background: var(--surface-hover);
    border-color: #606068;
    color: var(--text);
  }
  
  main button.view-toggle-button.active {
    background: #38383d;
    border-color: #626269;
    color: var(--text);
  }
  
  main button.view-toggle-button:focus-visible,
  .bird-card:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 3px;
  }
  
  /* =========================
     Bird cards — List mode
     ========================= */
  
  .bird-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    margin-top: 22px;
  }
  
  .bird-card {
    min-width: 0;
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    cursor: pointer;
    transition:
      border-color 0.18s ease,
      box-shadow 0.18s ease;
  }
  
  .bird-card:hover {
    border-color: #606068;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  }
  
  .bird-card-layout {
    display: flex;
    align-items: center;
    gap: 18px;
  }
  
  .bird-card-thumbnail {
    display: block;
    width: 120px;
    height: 100px;
    flex-shrink: 0;
    object-fit: cover;
    border-radius: 8px;
  }
  
  .bird-card-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    background: #313131;
    border: 2px solid #424141;
    color: #c9c9c9;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
  }
  
  .bird-card-placeholder span {
    max-width: 100%;
    overflow-wrap: anywhere;
  }
  
  .bird-card-details {
    flex: 1;
    min-width: 0;
  }
  
  .bird-card-details h2 {
    margin: 0 0 8px;
    color: var(--text);
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: -0.025em;
    overflow-wrap: anywhere;
  }
  
  .bird-card-details p {
    margin: 5px 0;
    color: var(--text-secondary);
    font-size: 0.93rem;
    overflow-wrap: anywhere;
  }
  
  .bird-card-details small {
    display: inline-block;
    margin-top: 6px;
    color: #d0d0d7;
    font-size: 0.82rem;
  }
  
  .bird-card-details small:hover {
    color: white;
  }
  
  .no-sightings {
    grid-column: 1 / -1;
    color: var(--text-secondary);
  }
  
  /* =========================
     Bird cards — Full-bleed gallery
     ========================= */
  
  #bird-list.gallery-mode {
    position: relative;
    display: grid;
    width: 100vw;
    max-width: none;
    margin-left: calc(50% - 50vw);
    margin-right: 0;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    align-items: start;
  }
  
  #bird-list.gallery-mode .bird-card {
    position: relative;
    display: block;
    min-width: 0;
    aspect-ratio: 1 / 1;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    background: var(--surface);
    box-shadow: none;
  }
  
  /* The image fills the square card.
     Explicit dimensions help avoid percentage-height issues. */
  
  #bird-list.gallery-mode .bird-card-layout {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
  }
  
  #bird-list.gallery-mode img.bird-card-thumbnail {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: cover;
    border: 0;
    border-radius: 0;
    opacity: 1;
    visibility: visible;
    transform: translateZ(0);
    transition: transform 0.35s ease;
  }
  
  /* Details overlay */
  
  #bird-list.gallery-mode .bird-card-details {
    position: absolute;
    z-index: 1;
    right: 0;
    bottom: 0;
    left: 0;
    min-width: 0;
    padding: 48px 16px 16px;
    background: linear-gradient(
      to bottom,
      transparent 0%,
      rgba(0, 0, 0, 0.68) 35%,
      rgba(0, 0, 0, 0.94) 100%
    );
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition:
      opacity 0.22s ease,
      transform 0.22s ease,
      visibility 0.22s ease;
    pointer-events: none;
  }
  
  #bird-list.gallery-mode .bird-card-details h2 {
    margin: 0 0 6px;
    color: #fff;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    overflow-wrap: anywhere;
  }
  
  #bird-list.gallery-mode .bird-card-details p {
    margin: 4px 0;
    color: #e1e1e1;
    font-size: 0.85rem;
  }
  
  #bird-list.gallery-mode .bird-card-details small {
    margin-top: 7px;
    color: #fff;
    font-size: 0.78rem;
  }
  
  /* Desktop hover and keyboard access */
  
  #bird-list.gallery-mode .bird-card:hover .bird-card-details,
  #bird-list.gallery-mode .bird-card:focus-visible .bird-card-details {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }
  
  #bird-list.gallery-mode .bird-card:hover .bird-card-thumbnail {
    transform: scale(1.04);
  }
  
  #bird-list.gallery-mode .bird-card:hover {
    border: 0;
    box-shadow: none;
  }
  
  #bird-list.gallery-mode .bird-card:focus-visible {
    z-index: 2;
    outline: 3px solid #fff;
    outline-offset: -3px;
  }
  
  #bird-list.gallery-mode .no-sightings {
    grid-column: 1 / -1;
    margin: 0;
    padding: 24px 20px;
  }
  
  /* =========================
     Admin forms and buttons
     ========================= */
  
  main form {
    max-width: 650px;
    margin-bottom: 30px;
  }
  
  main label {
    display: block;
    margin-bottom: 7px;
    color: var(--text);
    font-size: 0.94rem;
    font-weight: 500;
  }
  
  main input:not([type="checkbox"]):not([type="file"]),
  main textarea,
  main select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    transition:
      border-color 0.2s ease,
      background 0.2s ease;
  }
  
  main input:not([type="checkbox"]):not([type="file"]):focus,
  main textarea:focus,
  main select:focus {
    outline: none;
    border-color: #777780;
    background: var(--surface-hover);
  }
  
  main input[type="date"] {
    color-scheme: dark;
  }
  
  main input[type="file"] {
    max-width: 100%;
    color: var(--text-secondary);
    font: inherit;
  }
  
  main input[type="file"]::file-selector-button {
    margin-right: 12px;
    padding: 9px 13px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-raised);
    color: var(--text);
    font: inherit;
    cursor: pointer;
  }
  
  main input[type="file"]::file-selector-button:hover {
    background: #343439;
  }
  
  main textarea {
    resize: vertical;
  }
  
  main button {
    padding: 11px 17px;
    border: 1px solid #e1e1e6;
    border-radius: 10px;
    background: #e8e8ed;
    color: #151517;
    font: inherit;
    font-weight: 550;
    cursor: pointer;
    transition:
      background 0.2s ease,
      border-color 0.2s ease,
      transform 0.15s ease,
      opacity 0.2s ease;
  }
  
  main button:hover {
    background: white;
    border-color: white;
  }
  
  main button:active {
    transform: scale(0.98);
  }
  
  main button:disabled {
    opacity: 0.55;
    cursor: wait;
  }
  
  main button.secondary-button {
    background: #303034;
    color: var(--text);
    border-color: #45454b;
  }
  
  main button.secondary-button:hover {
    background: #414147;
    border-color: #58585f;
  }
  
  #status-message {
    max-width: 650px;
    color: var(--text-secondary);
    white-space: pre-wrap;
  }
  
  #login-section,
  #admin-section {
    margin: 24px 0;
    padding: 26px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
  }
  
  /* Admin layout */
  
  .admin-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
  }
  
  .admin-heading h2 {
    margin-top: 0;
  }
  
  .form-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 20px;
  }
  
  .checkbox-label {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 16px 0;
    color: var(--text-secondary);
  }
  
  main input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #d7d7df;
    cursor: pointer;
  }
  
  /* Existing sightings */
  
  .section-divider {
    margin: 32px 0;
    border: 0;
    border-top: 1px solid var(--border);
  }
  
  #existing-sightings-section {
    margin-top: 24px;
  }
  
  #sightings-list {
    display: grid;
    gap: 12px;
  }
  
  #existing-sightings-section > p {
    color: var(--text-secondary);
  }
  
  /* =========================
     Species autocomplete
     ========================= */
  
  .species-autocomplete {
    position: relative;
    width: 100%;
  }
  
  .species-autocomplete > label {
    margin-bottom: 8px;
  }
  
  .species-autocomplete input {
    display: block;
    width: 100%;
    margin: 8px 0 16px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
  }
  
  .species-autocomplete input:focus {
    outline: 2px solid var(--focus);
    outline-offset: 1px;
  }
  
  .species-suggestions {
    position: absolute;
    z-index: 1000;
    top: calc(100% - 16px);
    right: 0;
    left: 0;
    max-height: 220px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #202023;
    border: 1px solid #3b3b41;
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  }
  
  .species-suggestions[hidden] {
    display: none !important;
  }
  
  main button.species-option {
    display: block;
    width: 100%;
    padding: 11px 14px;
    border: 0;
    border-bottom: 1px solid #333338;
    border-radius: 0;
    background: transparent;
    color: var(--text);
    text-align: left;
    font: inherit;
  }
  
  main button.species-option:hover,
  main button.species-option:focus {
    background: #343439;
    color: white;
    outline: none;
  }
  
  main button.species-option:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: -2px;
  }
  
  .species-option:last-child {
    border-bottom: 0;
  }
  
  .species-empty {
    padding: 12px 14px;
    color: var(--text-secondary);
    font-size: 0.9rem;
  }
  
  .field-help {
    margin: -8px 0 18px;
    color: var(--text-secondary);
    font-size: 0.88rem;
  }
  
  /* =========================
     Responsive layouts
     ========================= */
  
  @media (max-width: 1000px) {
    #bird-list.gallery-mode {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }
  
  @media (max-width: 700px) {
    #bird-list.gallery-mode {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  
    #bird-list.gallery-mode .bird-card-details {
      padding: 34px 10px 10px;
    }
  
    #bird-list.gallery-mode .bird-card-details h2 {
      font-size: 0.95rem;
    }
  
    #bird-list.gallery-mode .bird-card-details p {
      font-size: 0.78rem;
    }
  
    #bird-list.gallery-mode .bird-card-details small {
      font-size: 0.7rem;
    }
  }
  
  @media (max-width: 600px) {
    header {
      padding: 34px 16px;
    }
  
    header h1 {
      font-size: 2rem;
    }
  
    main {
      margin: 22px auto;
      padding: 0 14px;
    }
  
    #login-section,
    #admin-section {
      padding: 18px;
      border-radius: 13px;
    }
  
    .species-suggestions {
      max-height: 200px;
    }
  
    .bird-grid {
      gap: 11px;
    }
  }
  
  @media (max-width: 480px) {
    #bird-list.list-mode .bird-card {
      padding: 12px;
      border-radius: 12px;
    }
  
    #bird-list.list-mode .bird-card-layout {
      gap: 12px;
    }
  
    #bird-list.list-mode .bird-card-thumbnail {
      width: 80px;
      height: 80px;
      flex-basis: 80px;
      border-radius: 8px;
    }
  
    #bird-list.list-mode .bird-card-details h2 {
      font-size: 1.05rem;
    }
  
    #bird-list.list-mode .bird-card-details p {
      font-size: 0.87rem;
    }
  
    #bird-list.list-mode .bird-card-details small {
      font-size: 0.78rem;
    }
  
    #bird-list.gallery-mode .bird-card-details h2 {
      font-size: 0.88rem;
    }
  
    #bird-list.gallery-mode .bird-card-details p {
      font-size: 0.74rem;
    }
  
    #bird-list.gallery-mode .bird-card-details small {
      font-size: 0.68rem;
    }
  
    main button {
      max-width: 100%;
    }
  }
  
  /* Touch devices: show bird names by default.
     birds.js reveals the remaining details after the first tap. */
  
  @media (hover: none), (pointer: coarse) {
    #bird-list.gallery-mode .bird-card-details {
      padding: 36px 10px 10px;
      background: linear-gradient(
        to bottom,
        transparent,
        rgba(0, 0, 0, 0.88)
      );
      opacity: 1;
      visibility: visible;
      transform: none;
      pointer-events: none;
    }
  
    #bird-list.gallery-mode .bird-card-details p,
    #bird-list.gallery-mode .bird-card-details small {
      display: none;
    }
  
    #bird-list.gallery-mode .bird-card.mobile-details-visible .bird-card-details {
      padding: 14px 10px;
      background: rgba(0, 0, 0, 0.88);
    }
  
    #bird-list.gallery-mode .bird-card.mobile-details-visible .bird-card-details p,
    #bird-list.gallery-mode .bird-card.mobile-details-visible .bird-card-details small {
      display: block;
    }
  }
  
  /* =========================
     Reduced motion
     ========================= */
  
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      scroll-behavior: auto !important;
      transition-duration: 0.01ms !important;
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
    }
  }
  