/* Phase 1: functional shell. The retro 2007 styling lands in Phase 3. */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: #fff;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { opacity: 0.4; }

.view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}

/* ---- Viewfinder ---- */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.finder { position: relative; overflow: hidden; background: #111; }
.finder video { width: 100%; height: 100%; object-fit: cover; display: block; }
.finder.mirrored video { transform: scaleX(-1); }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
#flash.on { animation: flash 0.25s ease-out; }
@keyframes flash { from { opacity: 0.9; } to { opacity: 0; } }

.cam-message {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px;
  text-align: center;
  background: #000;
  line-height: 1.4;
}
.cam-message p { margin: 0; max-width: 28em; }

.bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px calc(12px + env(safe-area-inset-bottom));
  background: #1c1c1e;
  border-top: 1px solid #3a3a3c;
}
.thumb-btn {
  width: 52px; height: 52px;
  border: 2px solid #8e8e93;
  border-radius: 6px;
  overflow: hidden;
  background: #000;
}
.thumb-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shutter {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: #e5e5ea;
  color: #1c1c1e;
  border: 4px solid #8e8e93;
  display: flex; align-items: center; justify-content: center;
}
.shutter:active:not(:disabled) { background: #aeaeb2; }
.shutter svg { width: 40px; height: 40px; }
.icon-btn { width: 52px; height: 52px; display: flex; align-items: center; justify-content: center; }
.icon-btn svg { width: 34px; height: 34px; }
/* keep the shutter centred when the flip button is hidden */
.bar > [hidden] { display: block !important; visibility: hidden; }

@media (orientation: landscape) {
  #view-camera { flex-direction: row; padding-top: 0; }
  #view-camera .bar {
    flex-direction: column-reverse;
    padding: 24px calc(12px + env(safe-area-inset-right)) 24px 12px;
    border-top: 0;
    border-left: 1px solid #3a3a3c;
  }
}

/* ---- Roll + photo ---- */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: #1c1c1e;
  border-bottom: 1px solid #3a3a3c;
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: bold; flex: 1; text-align: center; }
.topbar > :first-child, .topbar > :last-child { min-width: 84px; }
.topbar-nav { display: flex; justify-content: flex-end; gap: 4px; }
.text-btn {
  padding: 8px 12px;
  border: 1px solid #636366;
  border-radius: 6px;
  background: #2c2c2e;
  font-size: 15px;
}
.text-btn:active:not(:disabled) { background: #48484a; }
.text-btn.danger { color: #ff6961; }

.grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: min-content;
  gap: 4px;
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  align-content: start;
}
.grid button { aspect-ratio: 1; overflow: hidden; background: #111; }
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.empty { position: absolute; inset: 0; margin: auto; height: 1.4em; text-align: center; color: #8e8e93; pointer-events: none; }

.photo-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.photo-stage img { max-width: 100%; max-height: 100%; display: block; }
.bar-actions { justify-content: space-around; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(120px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 86vw;
  padding: 10px 16px;
  border-radius: 8px;
  background: rgba(40, 40, 42, 0.95);
  border: 1px solid #636366;
  font-size: 14px;
  text-align: center;
  z-index: 10;
}
