/* Base page */
html {
  scroll-behavior: smooth;
  scroll-snap-type: y mandatory;
  overflow-x: clip;
}

body {
  margin: 0;
  background: #1e1e1e;
  min-height: 100vh;
}

/* Camera sections: each one is a full-screen, full-bleed frame. */
.camera-section {
  position: relative;
  overflow: hidden;
  height: 100vh;
  height: 100svh;
  background: #000;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.camera {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
}

.camera-frame {
  position: absolute;
  inset: 0;
  line-height: 0;
}

.camera-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.camera-label {
  position: absolute;
  z-index: 1;
  top: 0.75rem;
  left: 0.75rem;
  max-width: calc(100% - 14rem);
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
  padding: 0.3rem 0.7rem;
  border-radius: 0.35rem;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: #e4e4e7;
}

/* Picture actions: fit and fullscreen pills in the top-right corner. */
.camera-actions {
  position: absolute;
  z-index: 2;
  top: 0.75rem;
  right: 0.75rem;
  display: flex;
  gap: 0.35rem;
}

.camera-zoom,
.camera-fullscreen {
  padding: 0.3rem 0.7rem;
  border: 0;
  border-radius: 0.35rem;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #e4e4e7;
}

.camera-zoom:focus-visible,
.camera-fullscreen:focus-visible {
  outline: 2px solid #ca8a04;
  outline-offset: 2px;
}

.camera-zoom[aria-pressed="true"],
.camera-fullscreen[aria-pressed="true"] {
  color: #facc15;
}

.camera-section.camera-zoom-out .camera-image {
  object-fit: contain;
}

/* Fallback fullscreen for browsers without the element API (iOS). */
.camera-section.camera-fullscreen-fallback {
  position: fixed;
  inset: 0;
  z-index: 1000;
  width: 100vw;
  height: 100svh;
  margin: 0;
}

html.camera-fullscreen-lock,
html.camera-fullscreen-lock body {
  overflow: hidden;
  scroll-snap-type: none;
}

.camera-image:not([src]) {
  opacity: 0;
}

/* Catpi status line */
.catpi-status {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  margin: 0 auto;
  padding: 0 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
}

/* The status sits over the picture, directly under the camera label. */
.camera-section > .catpi-status {
  position: absolute;
  z-index: 1;
  top: 3rem;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 1.5rem);
  margin: 0;
  padding: 0.35rem 0.75rem;
  border-radius: 0.35rem;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
}

.status-meta {
  color: #a1a1aa;
}

.status-error {
  color: #f87171;
}

.status-error-strong {
  font-weight: 600;
  color: #f87171;
}

.status-battery-line {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}

.status-percent {
  font-weight: 700;
}

.status-battery {
  width: 5rem;
  height: 0.5rem;
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: #3f3f46;
}

.status-battery::-webkit-progress-bar {
  background: #3f3f46;
  border-radius: 999px;
}

.status-battery::-webkit-progress-value {
  background: #4ade80;
  border-radius: 999px;
}

.status-battery::-moz-progress-bar {
  background: #4ade80;
  border-radius: 999px;
}

.status-battery.battery-warn::-webkit-progress-value {
  background: #facc15;
}

.status-battery.battery-warn::-moz-progress-bar {
  background: #facc15;
}

.status-battery.battery-low::-webkit-progress-value {
  background: #f87171;
}

.status-battery.battery-low::-moz-progress-bar {
  background: #f87171;
}

.status-charge {
  font-weight: 600;
}

.charge-good {
  color: #4ade80;
}

.charge-idle {
  color: #a1a1aa;
}

.status-line-sensors {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.line-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  border: 1px solid #52525b;
  background: #e4e4e7;
}

.line-dot.line-black {
  background: #18181b;
}

/* Catpi controls over the picture */
.catpi-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.catpi-drag {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.catpi-drag.catpi-aiming {
  cursor: crosshair;
}

.catpi-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: auto;
  touch-action: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.5rem;
  align-items: end;
  padding: 0.5rem 0.75rem;
  padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.68), rgba(0, 0, 0, 0));
}

.catpi-pad {
  display: grid;
  grid-template-columns: repeat(3, 2.6rem);
  gap: 0.3rem;
  touch-action: none;
}

.catpi-button {
  width: 2.6rem;
  height: 2.4rem;
  padding: 0;
  font-size: 1rem;
  background: rgba(63, 63, 70, 0.9);
  color: #fafafa;
  border: 1px solid #52525b;
  border-radius: 0.45rem;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

.catpi-strength {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.6rem;
  border-radius: 0.45rem;
  background: rgba(24, 24, 27, 0.82);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  color: #a1a1aa;
}

.catpi-range {
  width: 7rem;
  accent-color: #ca8a04;
}

#catpi-pad button:active {
  background: #a16207;
  border-color: #ca8a04;
  color: #fff;
}

#catpi-pad button:hover {
  background: #52525b;
}

#catpi-pad .catpi-key-active {
  background: #a16207;
  border-color: #ca8a04;
  color: #fff;
}

#catpi-pad button:disabled {
  opacity: 0.45;
  cursor: default;
  background: rgba(63, 63, 70, 0.9);
  border-color: #52525b;
}

#catpi-pad .catpi-routine[aria-pressed="true"] {
  background: #a16207;
  border-color: #ca8a04;
  color: #fff;
  opacity: 1;
}

#catpi-pad[data-routine] #catpi-drag {
  pointer-events: none;
  cursor: default;
}

@media (max-width: 700px) {
  .camera-label {
    max-width: calc(100% - 12rem);
    font-size: 0.7rem;
    letter-spacing: 0.2em;
  }

  .camera-zoom,
  .camera-fullscreen {
    font-size: 0.65rem;
    padding: 0.25rem 0.55rem;
  }

  .camera-section > .catpi-status {
    top: 2.75rem;
    font-size: 0.75rem;
  }

  /* Keep the centered pad clear of the strength slider on narrow screens. */
  .catpi-strength {
    padding: 0.25rem 0.4rem;
  }

  .catpi-strength label,
  .catpi-strength output {
    display: none;
  }

  .catpi-range {
    width: 4.5rem;
  }
}

@media (pointer: coarse) {
  /* Thumbs need bigger targets, and opposite directions are easier to hold
     together when the pad is not cramped. */
  .catpi-pad {
    grid-template-columns: repeat(3, 3.4rem);
    gap: 0.4rem;
  }

  .catpi-button {
    width: 3.4rem;
    height: 3.1rem;
    font-size: 1.15rem;
  }

  .camera-zoom,
  .camera-fullscreen {
    font-size: 0.7rem;
    padding: 0.4rem 0.7rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
