/* ============================================================
   Base — dark theme
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  background-color: #0d0d0d;
  color: #cccccc;
  font-family: system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

a { color: #aaaaaa; text-decoration: none; }
a:hover { color: #ffffff; }

/* ============================================================
   Site nav (public)
   ============================================================ */
.site-nav {
  position: absolute;
  top: 1rem;
  left: 1.5rem;
  z-index: 10;
  font-size: 1.1rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.site-nav a { color: #ffffff; }

/* ============================================================
   Flash messages
   ============================================================ */
.flash {
  padding: 0.75rem 1.5rem;
  font-size: 0.9rem;
}
.flash-notice { background: #1a3a1a; color: #7ecf7e; }
.flash-alert  { background: #3a1a1a; color: #cf7e7e; }

/* ============================================================
   Homepage
   ============================================================ */
.featured-section {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  position: relative;
  z-index: 0;
}

.featured-section::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.5) 0%, transparent 20%);
  z-index: 1;
}

.featured-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.featured-placeholder {
  width: 100%;
  height: 100%;
  background: #111;
}

.homepage-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  justify-content: center;
  padding: 3rem 2rem 1.5rem;
}

.homepage-description {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem 2rem 3rem;
  text-align: center;
  color: #888;
  font-size: 0.95rem;
  line-height: 1.7;
}

/* ============================================================
   Tag links
   ============================================================ */
.tag-link {
  font-size: 1.2rem; 
  color: #777;
  transition: color 0.15s;
}
.tag-link::before {
  content: '#';
  color: #c55;
}
.tag-link:hover {
  color: #f55;
}

/* ============================================================
   Photo show
   ============================================================ */
.photo-show {
  display: flex;
  justify-content: center;
  min-height: 80vh;
  padding: 2rem 0;
}

.photo-frame {
  position: relative;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  max-width: 100%;
  touch-action: pan-y;
}

/* Desktop: hide adjacent slides, current slide participates in inline-flex normally */
.photo-slide-prev,
.photo-slide-next { display: none; }

.photo-slide-current {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

@keyframes photo-spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

.photo-slide-current.is-loading::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2rem;
  height: 2rem;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-top-color: rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  animation: photo-spin 0.7s linear infinite;
  pointer-events: none;
}

/* Mobile: full-width carousel */
@media (max-width: 767px) {
  .photo-frame {
    width: 100%;
    overflow: hidden;
  }

  /* Current slide is in-flow — its height drives the frame height */
  .photo-slide-current {
    position: relative;
    width: 100%;
    min-height: 50vw;
    justify-content: center;
    align-items: center;
  }

  /* Prev/next are absolutely positioned beside the current slide */
  .photo-slide-prev,
  .photo-slide-next {
    display: flex;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    justify-content: center;
    align-items: center;
    transform: translateX(-100%);
  }

  .photo-slide-next {
    transform: translateX(100%);
  }
}

.photo-display {
  display: block;
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
}

.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  font-size: 1.5rem;
  color: rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.25);
  transition: color 0.15s, background 0.15s;
  user-select: none;
  border-radius: 1.5rem;
  -webkit-tap-highlight-color: transparent;
}
.nav-arrow:hover {
  color: rgba(255, 255, 255, 0.9);
  background: rgba(0, 0, 0, 0.5);
}

.nav-arrow-prev { left: 0; }
.nav-arrow-next { right: 0; }

@media (max-width: 767px) {
  .nav-arrow { display: none; }
}

@media (min-width: 768px) {
  .photo-show {
    padding: 3rem 3rem 1rem 3rem;
  }
  .nav-arrow {
    color: #666;
    background: #222;
  }
  .nav-arrow:hover {
    color: #fff;
    background: #444;
  }
  .nav-arrow-prev { left: -3.5rem; }
  .nav-arrow-next { right: -3.5rem; }
}

.photo-meta {
  text-align: center;
  padding: 0rem 1rem 3rem;
}

.photo-title {
  font-size: 1.2rem; 
  font-weight: normal;
  letter-spacing: 0.06em;
  color: #ccc;
  margin-bottom: 0.75rem;
}

.photo-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
}

/* ============================================================
   Tag collection (grid)
   ============================================================ */
.tag-header {
  text-align: center;
  padding: 2.5rem 1rem 1rem;
}

.tag-title {
  font-size: 1rem;
  font-weight: normal;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #888;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 4px;
  padding: 1rem;
}

.photo-thumb-link {
  display: block;
  overflow: hidden;
  aspect-ratio: 4/3;
  background: #111;
}

.photo-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.2s;
}
.photo-thumb-link:hover .photo-thumb { opacity: 0.8; }

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.75rem;
  color: #444;
  letter-spacing: 0.04em;
}

.site-footer a { color: #555; }
.site-footer a:hover { color: #999; }

.footer-sep {
  margin: 0 0.6rem;
}

/* ============================================================
   License page
   ============================================================ */
.license-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 4rem 2rem 6rem;
}

.license-heading {
  font-size: 0.9rem;
  font-weight: normal;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #888;
  margin-bottom: 2.5rem;
}

.license-section {
  margin-bottom: 2rem;
}

.license-section h2 {
  font-size: 0.75rem;
  font-weight: normal;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #666;
  margin-bottom: 0.75rem;
}

.license-section p,
.license-section li {
  font-size: 0.85rem;
  color: #999;
  line-height: 1.75;
}

.license-section ul {
  padding-left: 1.25rem;
  margin: 0.5rem 0;
}

.license-section strong { color: #bbb; font-weight: normal; }
.license-section a { color: #888; text-decoration: underline; text-underline-offset: 3px; }
.license-section a:hover { color: #ccc; }

/* ============================================================
   Admin — general
   ============================================================ */
.admin-body {
  background: #1a1a1a;
  color: #ddd;
  font-family: system-ui, sans-serif;
  min-height: 100vh;
}

.admin-nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: #111;
  border-bottom: 1px solid #333;
}

.admin-nav-brand {
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #666;
  margin-right: auto;
}

.admin-nav a { color: #aaa; font-size: 0.9rem; }
.admin-nav a:hover { color: #fff; }

.admin-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.admin-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.admin-header h1 {
  font-size: 1.2rem;
  font-weight: normal;
  color: #ddd;
  margin: 0;
}

.bulk-tag-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  font-size: 0.9rem;
  color: #aaa;
}

/* ============================================================
   Admin — login
   ============================================================ */
.admin-login-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 80vh;
}

.admin-login-card {
  background: #222;
  border: 1px solid #333;
  padding: 2rem;
  width: 100%;
  max-width: 360px;
}

.admin-login-title {
  font-size: 1rem;
  font-weight: normal;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 1.5rem;
  color: #ccc;
}

/* ============================================================
   Admin — forms
   ============================================================ */
.field { margin-bottom: 1.2rem; }

.label {
  display: block;
  font-size: 0.85rem;
  color: #aaa;
  margin-bottom: 0.35rem;
  letter-spacing: 0.04em;
}

.input, .textarea, .select {
  display: block;
  width: 100%;
  background: #2a2a2a;
  border: 1px solid #444;
  color: #ddd;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  border-radius: 3px;
  outline: none;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: #777;
}

.textarea { resize: vertical; }

.help {
  font-size: 0.8rem;
  color: #666;
  margin-bottom: 0.35rem;
}

.tag-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.current-image { margin-top: 0.5rem; }

.form-errors {
  background: #3a1a1a;
  border: 1px solid #7a2a2a;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: #cf7e7e;
}

/* ============================================================
   Admin — table
   ============================================================ */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.admin-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #333;
  color: #888;
  font-weight: normal;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.admin-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #222;
  vertical-align: middle;
}

.admin-table .actions {
  display: flex;
  gap: 0.5rem;
  white-space: nowrap;
}

.visibility-badge {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  border-radius: 2px;
}
.visibility-public  { background: #1a3a1a; color: #7ecf7e; }
.visibility-private { background: #2a2a2a; color: #666; }

.help-inline {
  font-size: 0.8rem;
  color: #666;
  margin-left: 0.25rem;
}

.admin-thumb {
  width: 80px;
  height: 60px;
  object-fit: cover;
  display: block;
  background: #111;
}

.exif-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.exif-table tr:not(:last-child) td { border-bottom: 1px solid #eee; }
.exif-key {
  width: 40%;
  padding: 0.35rem 0.5rem;
  color: #888;
  font-weight: 500;
}
.exif-value {
  padding: 0.35rem 0.5rem;
  word-break: break-all;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-block;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  text-align: center;
  line-height: 1.4;
  transition: opacity 0.15s;
  font-family: inherit;
}
.btn:hover { opacity: 0.85; }

.btn-primary   { background: #3a6ea5; color: #fff; border-color: #3a6ea5; }
.btn-secondary { background: transparent; color: #aaa; border-color: #555; }
.btn-danger    { background: #7a2a2a; color: #fff; border-color: #7a2a2a; }
.btn-sm        { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

.nav-logout {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: #aaa;
  font-size: 0.9rem;
}
.nav-logout:hover { color: #fff; }

/* ============================================================
   Homepage grid (public)
   ============================================================ */
.homepage-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-auto-rows: 1fr;
  grid-auto-flow: dense;
  gap: 4px;
  /* Start below the top zone occupied by the absolutely-positioned
     "PICTALOGUE" wordmark so the grid doesn't sit under it. */
  margin-top: 3.75rem;
}

.grid-tile {
  position: relative;
  overflow: hidden;
  display: block;
}

.grid-tile-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.4s ease;
}
.grid-tile:hover .grid-tile-img { transform: scale(1.04); }

.grid-tile-tag {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  padding: 0.15rem 0.5rem;
  font-size: 0.85rem;
  border-radius: 3px;
}
.grid-tile-tag::before {
  content: '#';
  color: #f55;
}

/* Each tile's aspect ratio matches its span so every grid cell keeps a
   consistent 3:2 (landscape) shape. Ratio = (cols / rows) * (3/2).
   These rules are shared by the public grid and the admin builder preview. */
.span-1x1 { aspect-ratio: 3 / 2; }
.span-2x1 { grid-column: span 2; aspect-ratio: 3 / 1; }
.span-1x2 { grid-row: span 2; aspect-ratio: 3 / 4; }
.span-2x2 { grid-column: span 2; grid-row: span 2; aspect-ratio: 3 / 2; }
.span-3x2 { grid-column: span 3; grid-row: span 2; aspect-ratio: 9 / 4; }
.span-2x3 { grid-column: span 2; grid-row: span 3; aspect-ratio: 1 / 1; }
.span-3x3 { grid-column: span 3; grid-row: span 3; aspect-ratio: 3 / 2; }

@media (max-width: 700px) {
  .homepage-grid { grid-template-columns: repeat(2, 1fr); }
  /* Clamp wide tiles so they never overflow the 2-column mobile grid. */
  .span-2x1, .span-2x2 { grid-column: span 2; }
  .span-1x2, .span-2x2 { grid-row: span 2; }
  /* 3-wide tiles can't fit in 2 columns — fall back to narrower cells. */
  .span-3x2 { grid-column: span 2; grid-row: span 2; aspect-ratio: 3 / 2; }
  .span-3x3 { grid-column: span 2; grid-row: span 3; aspect-ratio: 1 / 1; }
}

/* ============================================================
   Admin — homepage grid builder
   ============================================================ */
.builder { margin-bottom: 1.5rem; }
.builder-heading { font-size: 1.1rem; margin-bottom: 0.35rem; }
.builder-subheading { font-size: 0.95rem; color: #aaa; margin: 1.25rem 0 0.5rem; }
.builder-divider { border: none; border-top: 1px solid #333; margin: 2rem 0; }

.builder-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-auto-rows: 1fr;
  grid-auto-flow: dense;
  gap: 4px;
  background: #161616;
  border: 1px solid #333;
  border-radius: 4px;
  padding: 4px;
  min-height: 80px;
}

.builder-tile {
  position: relative;
  overflow: hidden;
  border-radius: 3px;
  cursor: grab;
  background: #111;
}
.builder-tile.is-dragging { opacity: 0.4; }

.builder-tile-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.builder-tile-missing { background: #2a2a2a; }

.builder-tile-bar {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75), transparent);
}

.builder-size,
.builder-remove {
  border: 1px solid #555;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.75rem;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
}
.builder-size:hover,
.builder-remove:hover { border-color: #f55; }
.builder-remove { margin-left: auto; }

.builder-tag {
  flex: 1;
  min-width: 0;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid #555;
  color: #ddd;
  font-size: 0.75rem;
  padding: 0.15rem;
  border-radius: 3px;
}

.builder-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.builder-pick {
  border: 2px solid transparent;
  padding: 0;
  background: none;
  cursor: pointer;
  border-radius: 3px;
  line-height: 0;
}
.builder-pick:hover { border-color: #f55; }
.builder-pick-img {
  width: 90px;
  height: 68px;
  object-fit: cover;
  display: block;
  border-radius: 2px;
}
