* {
  box-sizing: border-box;
}

/* Our display rules (flex etc.) would otherwise override the hidden
   attribute's built-in display: none. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: #14181d;
  color: #e8eaed;
}

header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 1rem 1.5rem;
}

h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  margin: 0 1.5rem 1rem;
  border-bottom: 1px solid #2c333b;
}

.tabs a {
  padding: 0.5rem 1rem;
  margin-bottom: -1px;
  color: #9aa0a6;
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}

.tabs a:hover {
  color: #e8eaed;
}

.tabs a.active {
  color: #e8eaed;
  border-bottom-color: #8ab4f8;
}

.last-updated {
  margin-left: auto;
  font-size: 0.8rem;
  color: #9aa0a6;
  font-variant-numeric: tabular-nums;
}

.grid-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  align-self: center;
  padding: 0.35rem;
  background: none;
  border: 1px solid #2c333b;
  color: #9aa0a6;
  cursor: pointer;
}

.grid-toggle:hover {
  color: #e8eaed;
  border-color: #9aa0a6;
}

.grid-toggle::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  padding: 0.3rem 0.6rem;
  background: #2c333b;
  color: #e8eaed;
  font-size: 0.75rem;
  line-height: 1.4;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 1;
}

.grid-toggle:hover::after,
.grid-toggle:focus-visible::after {
  opacity: 1;
}

.back-link {
  color: #9aa0a6;
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}

.back-link:hover {
  color: #e8eaed;
}

main {
  padding: 0 1.5rem 1.5rem;
}

/* Grid page */

.camera-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.camera-grid.small {
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}

.camera-grid.small .camera-label {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

@media (max-width: 700px) {
  .camera-grid {
    grid-template-columns: 1fr;
  }

  .camera-grid.small {
    grid-template-columns: repeat(2, 1fr);
  }
}

.camera-card {
  position: relative;
  display: block;
  overflow: hidden;
  background: #1e242b;
  line-height: 0;
}

.camera-card img {
  width: 100%;
  height: auto;
  /* Placeholder ratio before the first frame loads; once loaded the
     image's own intrinsic ratio takes over — nothing is ever cropped. */
  aspect-ratio: auto 4 / 3;
}

/* Images start without src (frames are swapped in only once fully
   loaded) — hide them until then so no broken-image icon flashes.
   The card keeps its size via the aspect-ratio placeholder. */
.camera-card img:not([src]),
.camera-single img:not([src]) {
  visibility: hidden;
}

/* The whole grid stays hidden until every camera's first frame has
   settled (see renderGrid) — no flash of bare labels. */
.camera-grid.loading {
  visibility: hidden;
}

.camera-label {
  position: absolute;
  left: 0;
  bottom: 0;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  line-height: 1.4;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
}

/* Single camera page — full height, sidebar left, image centered */

body.camera-view {
  height: 100vh;
  overflow: hidden;
}

/* Sidebar floats on top of the image area, top left. */
body.camera-view header {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1.5rem;
  background: rgba(20, 24, 29, 0.75);
}

body.camera-view #page-title {
  order: 1;
}

body.camera-view .last-updated {
  order: 2;
  margin-left: 0;
}

body.camera-view .back-link {
  order: 3;
}

/* The image gets the entire viewport; object-fit: contain letterboxes
   the frame centered within it. The letterbox bars are transparent, so
   they show the page background. */
body.camera-view main {
  width: 100vw;
  height: 100vh;
  padding: 0;
}

.camera-single {
  margin: 0;
  width: 100%;
  height: 100%;
}

.camera-single a {
  display: block;
  width: 100%;
  height: 100%;
}

.camera-single img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.not-found {
  padding: 3rem 0;
  text-align: center;
  color: #9aa0a6;
}
