* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #000;
  --fg: #fff;
  --muted: #555;
  --accent: #fff;
}

html, body {
  height: var(--app-height, 100svh);
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, 'Helvetica Neue', sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app {
  position: fixed;
  inset: 0;
  height: var(--app-height, 100svh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}


/* ── Login ── */
#login-screen {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

#login-screen.hidden {
  display: none;
}

#login-box {
  width: 100%;
  max-width: 280px;
  padding: 0 20px;
  text-align: center;
}

#login-title {
  font-size: 42px;
  font-weight: 200;
  letter-spacing: 12px;
  margin-bottom: 4px;
}

#login-sub {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 3px;
  text-transform: lowercase;
  margin-bottom: 48px;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#login-form input {
  width: 100%;
  padding: 14px 16px;
  background: #111;
  border: 1px solid #222;
  border-radius: 8px;
  color: var(--fg);
  font-family: inherit;
  font-size: 15px;
  outline: none;
  -webkit-appearance: none;
}

#login-form input:focus {
  border-color: #444;
}

#login-form input::placeholder {
  color: #444;
}

#login-submit {
  width: 100%;
  padding: 14px;
  background: var(--fg);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  letter-spacing: 0.5px;
}

#login-submit:active {
  opacity: 0.85;
}

#login-error {
  color: #ff3b30;
  font-size: 13px;
  min-height: 20px;
}

/* ── Admin Controls ── */
#admin-controls {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(255, 59, 48, 0.9);
  padding: 6px 10px;
  gap: 6px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

#admin-controls.visible {
  display: flex;
}

#admin-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #fff;
  margin-right: 4px;
}

.admin-btn {
  background: rgba(0,0,0,0.3);
  border: none;
  color: #fff;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
}

.admin-btn:active {
  background: rgba(0,0,0,0.5);
}

@supports (padding-top: env(safe-area-inset-top)) {
  #admin-controls { padding-top: calc(6px + env(safe-area-inset-top)); }
}

/* ── Camera View ── */
#camera-screen {
  position: fixed;
  inset: 0;
  height: var(--app-height, 100svh);
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--bg);
}

#viewfinder-wrap {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

video#preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  filter: sepia(0.4) contrast(1.15) saturate(1.25) hue-rotate(-8deg) brightness(0.95);
}

canvas#lo-res {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  background: #000;
  z-index: 2;
  filter: sepia(0.4) contrast(1.15) saturate(1.25) hue-rotate(-8deg) brightness(0.95);
}

#countdown-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 120px;
  font-weight: 200;
  color: rgba(255,255,255,0.8);
  pointer-events: none;
  z-index: 5;
}

#countdown-overlay.visible {
  display: flex;
}

#recording-dot {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ff3b30;
  display: none;
  z-index: 6;
}

#recording-dot.visible {
  display: block;
  animation: pulse-dot 1s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Controls ── */
#controls {
  flex: 0 0 auto;
  width: 100%;
  padding: 20px 0 max(28px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 50px;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  pointer-events: auto;
}

#gallery-btn {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 2px solid var(--muted);
  background-size: cover;
  background-position: center;
  background-color: #111;
  cursor: pointer;
}

#shutter-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid var(--fg);
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: opacity 0.2s;
}

#shutter-btn::after {
  content: '';
  position: absolute;
  top: 4px; left: 4px; right: 4px; bottom: 4px;
  border-radius: 50%;
  background: var(--fg);
  transition: transform 0.15s;
}

#shutter-btn:active::after {
  transform: scale(0.9);
}

#shutter-btn.disabled {
  opacity: 0.25;
  pointer-events: none;
}

#flip-btn {
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#flip-btn svg {
  width: 28px;
  height: 28px;
  fill: var(--fg);
  opacity: 0.7;
}

/* ── Status Bar ── */
#status-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.5px;
  color: rgba(255,255,255,0.6);
}

#retries-left {
  font-variant-numeric: tabular-nums;
}

#cooldown-timer {
  font-variant-numeric: tabular-nums;
}

/* ── Review Screen ── */
#review-screen {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  display: none;
  flex-direction: column;
  z-index: 20;
}

#review-screen.visible {
  display: flex;
}

#review-logo {
  padding: 20px 0 12px;
  text-align: center;
  font-size: 22px;
  font-weight: 200;
  letter-spacing: 8px;
  color: rgba(255,255,255,0.5);
}

#review-image {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  margin: 0 16px;
  border-radius: 4px;
}

#review-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
}

#review-info {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 16px;
  padding: 16px 0 4px;
}

#review-countdown {
  font-size: 32px;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}

#review-retries {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.5px;
}

#review-actions {
  padding: 8px 30px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.review-btn {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 16px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  padding: 12px 20px;
  letter-spacing: 0.5px;
}

.review-btn.keep {
  opacity: 1;
}

.review-btn.retry {
  opacity: 0.5;
}

.review-btn.retry.disabled {
  opacity: 0.15;
  pointer-events: none;
}

#review-timer-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: var(--fg);
  transition: width linear;
  z-index: 21;
}

/* ── Gallery ── */
#gallery-screen {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  display: none;
  flex-direction: column;
  z-index: 25;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#gallery-screen.visible {
  display: flex;
}

#gallery-header {
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
}

#gallery-header h2 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

#gallery-close {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 28px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

#recap-btn {
  display: block;
  width: calc(100% - 32px);
  margin: 0 16px 16px;
  padding: 14px;
  background: #111;
  border: 1px solid #222;
  border-radius: 10px;
  color: var(--fg);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.5px;
  cursor: pointer;
  text-align: center;
}

#recap-btn:active {
  background: #1a1a1a;
}

#gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 2px;
}

.gallery-thumb {
  aspect-ratio: 1;
  object-fit: cover;
  width: 100%;
  cursor: pointer;
}

#gallery-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 15px;
  padding: 60px 0;
}

/* ── Detail View ── */
#detail-screen {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  display: none;
  flex-direction: column;
  z-index: 30;
}

#detail-screen.visible {
  display: flex;
}

#detail-header {
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#detail-back {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 28px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

#detail-time {
  font-size: 13px;
  color: var(--muted);
}

#detail-delete {
  background: none;
  border: none;
  color: #ff3b30;
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
}

#detail-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

#detail-content img,
#detail-content video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

#detail-hint {
  position: absolute;
  bottom: 20px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* ── Waiting state ── */
#waiting-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 15;
  background: rgba(0,0,0,0.85);
}

#waiting-overlay.visible {
  display: flex;
}

#waiting-message {
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 8px;
}

#waiting-time {
  font-size: 48px;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
}

/* ── Weekly Recap ── */
#recap-screen {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  display: none;
  flex-direction: column;
  z-index: 35;
}

#recap-screen.visible {
  display: flex;
}

#recap-header {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
}

#recap-close {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
}

#recap-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.5px;
  flex: 1;
}

#recap-date {
  font-size: 13px;
  color: var(--muted);
}

#recap-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 40px;
}

#recap-hero {
  width: 100%;
  aspect-ratio: 4/5;
  background: #111;
  position: relative;
  overflow: hidden;
}

#recap-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#recap-stats {
  display: flex;
  justify-content: center;
  gap: 48px;
  padding: 28px 16px;
}

.recap-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-num {
  font-size: 36px;
  font-weight: 300;
  line-height: 1;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

#recap-days {
  padding: 0 16px;
}

.recap-day {
  margin-bottom: 28px;
}

.recap-day-label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
  font-weight: 500;
  letter-spacing: 0.5px;
}

.recap-day-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
}

.recap-thumb {
  aspect-ratio: 1;
  width: 100%;
  object-fit: cover;
  border-radius: 2px;
  cursor: pointer;
}

.recap-thumb.placeholder {
  background: #111;
  position: relative;
}

.recap-thumb.placeholder::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border-radius: 50%;
  border: 1.5px solid #333;
}

.recap-day-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 20px;
  color: #333;
  font-size: 13px;
}

/* Safe area for notch phones */
@supports (padding-top: env(safe-area-inset-top)) {
  #status-bar { padding-top: calc(12px + env(safe-area-inset-top)); }
  #controls { padding-bottom: max(28px, calc(20px + env(safe-area-inset-bottom))); }
  #review-actions { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  #gallery-header { padding-top: calc(16px + env(safe-area-inset-top)); }
  #detail-header { padding-top: calc(16px + env(safe-area-inset-top)); }
  #review-logo { padding-top: calc(20px + env(safe-area-inset-top)); }
  #review-actions { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
}

/* ── Retro filter for saved moments ── */
.gallery-thumb,
#review-image img,
#detail-content img,
#detail-content video,
.recap-thumb,
#recap-hero img {
  filter: sepia(0.4) contrast(1.15) saturate(1.25) hue-rotate(-8deg) brightness(0.95);
}

/* ── Keepsafes (locked thumbs) ── */
#keepsafes-sub {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: lowercase;
  padding: 0 16px 12px;
}

.gallery-thumb-wrap {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  overflow: hidden;
  cursor: pointer;
}

.gallery-thumb-wrap .gallery-thumb {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}

.gallery-thumb-wrap.locked .gallery-thumb {
  filter: sepia(0.4) contrast(1.15) saturate(1.25) hue-rotate(-8deg) brightness(0.5) blur(14px);
  transform: scale(1.1);
}

.keepsafe-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(0,0,0,0.35);
  color: rgba(255,255,255,0.85);
  pointer-events: none;
}

.keepsafe-lock {
  font-size: 22px;
  opacity: 0.8;
}

.keepsafe-time {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}
