:root {
  --bg: #000000;
  --surface: rgba(28, 28, 30, 0.86);
  --surface-light: rgba(255, 255, 255, 0.14);
  --text: #ffffff;
  --text-muted: rgba(255, 255, 255, 0.65);
  --accent: #ffd60a;
  --danger: #ff453a;
  --blue: #0a84ff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

/* Main layout: landscape default (iPad primary) */
.camera-app {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100dvh;
  background: var(--bg);
}

.viewfinder {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  background: #000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: center center;
  transition: transform 0.08s ease-out;
  background: #000;
}

.shutter-flash {
  position: absolute;
  inset: 0;
  background: #ffffff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease-out;
}

.shutter-flash.active {
  opacity: 0.22;
  transition: none;
}

/* Permission / error overlay */
.camera-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  z-index: 10;
}

.camera-overlay p {
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
}

.overlay-btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #000;
  font-size: 15px;
  font-weight: 600;
  padding: 10px 24px;
  cursor: pointer;
}

/* Continuous mode toggle pill */
.mode-pill {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  cursor: pointer;
  z-index: 5;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.mode-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #000000;
}

/* Quick save floating bar (default single-shot mode) */
.quick-save-bar {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 6px;
  border-radius: 999px;
  background: rgba(28, 28, 30, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 7;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.quick-save-thumb {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.quick-save-btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  background: var(--blue);
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
}

.quick-save-btn:active {
  opacity: 0.85;
}

.quick-save-close {
  appearance: none;
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Burst counter */
.burst-pill {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 214, 10, 0.92);
  color: #000;
  font-weight: 700;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  padding: 4px 12px;
  border-radius: 999px;
  z-index: 6;
}

/* Zoom controls (landscape: right side of viewfinder) */
.zoom-container {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  z-index: 5;
}

.zoom-pills {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.zoom-pill {
  appearance: none;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s, background 0.12s, color 0.12s;
}

.zoom-pill.active {
  background: rgba(0, 0, 0, 0.65);
  color: var(--accent);
  transform: scale(1.12);
  box-shadow: 0 0 0 1.5px rgba(255, 214, 10, 0.65);
}

.zoom-slider-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 8px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.zoom-slider-wrap input[type="range"] {
  width: 120px;
  accent-color: var(--accent);
}

.zoom-readout {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* Control rail (right side in landscape) */
.control-rail {
  flex: 0 0 auto;
  width: calc(116px + env(safe-area-inset-right));
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) 16px;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
}

/* Shutter button */
.shutter-btn {
  appearance: none;
  border: 4px solid #ffffff;
  background: transparent;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  padding: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  transition: border-color 0.15s;
}

.shutter-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.08s ease-out, background 0.1s;
}

.shutter-btn:active .shutter-inner,
.shutter-btn.pressing .shutter-inner {
  transform: scale(0.86);
  background: #e5e5ea;
}

.shutter-btn.bursting {
  border-color: var(--accent);
}

.shutter-btn.bursting .shutter-inner {
  transform: scale(0.82);
  background: var(--accent);
}

/* Thumbnail button */
.thumb-btn {
  position: relative;
  appearance: none;
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  width: 50px;
  height: 50px;
  border-radius: 10px;
  padding: 0;
  overflow: visible;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumb-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.thumb-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
}

.thumb-placeholder {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1.5px solid rgba(255, 255, 255, 0.4);
}

.thumb-count {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #000;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Camera flip button */
.flip-btn {
  appearance: none;
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.12s, transform 0.15s;
}

.flip-btn:active {
  background: rgba(255, 255, 255, 0.28);
  transform: scale(0.94);
}

/* Portrait layout */
@media (orientation: portrait) {
  .camera-app {
    flex-direction: column;
  }

  .zoom-container {
    right: auto;
    top: auto;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    flex-direction: column;
  }

  .zoom-pills {
    flex-direction: row;
  }

  .quick-save-bar {
    bottom: 78px;
  }

  .control-rail {
    width: 100%;
    height: calc(122px + env(safe-area-inset-bottom));
    padding: 16px max(24px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
    flex-direction: row;
  }
}

/* Session Gallery Sheet */
.gallery-sheet {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.gallery-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.sheet-btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
}

.sheet-btn.primary {
  background: var(--blue);
  color: #fff;
}

.sheet-btn.danger {
  background: rgba(255, 69, 58, 0.18);
  color: var(--danger);
}

.sheet-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.gallery-grid {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  align-content: start;
}

.gallery-item {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  overflow: hidden;
  background: #1c1c1e;
  cursor: pointer;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.gallery-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* Single Preview Modal */
.preview-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.96);
  z-index: 40;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.preview-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}

.preview-actions {
  display: flex;
  gap: 8px;
}

.preview-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.preview-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
}
