* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --accent: #ff6b35;
}

html, body {
  height: 100%;
  background: #000;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.viewfinder {
  flex: 1;
  position: relative;
  background: #111;
  overflow: hidden;
  min-height: 0;
  touch-action: none;
}

.viewfinder video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.25s ease;
}

.viewfinder .no-camera {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  opacity: 0.5;
  z-index: 5;
}

.viewfinder .no-camera svg {
  width: 48px;
  height: 48px;
}

.grid-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.2s;
}

.grid-overlay.visible {
  opacity: 1;
}

.grid-overlay .grid-line {
  position: absolute;
  background: rgba(255,255,255,0.35);
}

.grid-overlay .grid-h1 { left: 0; right: 0; top: 33.333%; height: 1px; }
.grid-overlay .grid-h2 { left: 0; right: 0; top: 66.666%; height: 1px; }
.grid-overlay .grid-v1 { top: 0; bottom: 0; left: 33.333%; width: 1px; }
.grid-overlay .grid-v2 { top: 0; bottom: 0; left: 66.666%; width: 1px; }

.level-line {
  position: absolute;
  bottom: 24px;
  left: 50%;
  width: 120px;
  height: 2px;
  background: rgba(255,255,255,0.7);
  transform: translateX(-50%) rotate(0deg);
  transform-origin: center center;
  z-index: 12;
  border-radius: 1px;
  display: none;
  transition: background 0.2s, transform 0.1s linear;
}

.focus-ring {
  position: absolute;
  width: 60px;
  height: 60px;
  border: 2px solid var(--accent);
  border-radius: 4px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 15;
  opacity: 0;
}

.focus-ring.animate {
  animation: focusPulse 0.8s ease-out forwards;
}

@keyframes focusPulse {
  0% { opacity: 1; width: 80px; height: 80px; }
  50% { opacity: 1; width: 55px; height: 55px; }
  100% { opacity: 0; width: 60px; height: 60px; }
}

.camera-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  z-index: 20;
}

.res-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  font-family: "SF Mono", Menlo, monospace;
  color: var(--accent);
  z-index: 20;
}

.timer-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 72px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 20px rgba(0,0,0,0.8);
  z-index: 25;
  opacity: 0;
  pointer-events: none;
}

.timer-badge.visible {
  opacity: 1;
  animation: timerPulse 1s ease-in-out;
}

@keyframes timerPulse {
  0% { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.zoom-indicator {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  z-index: 20;
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
}

.controls {
  background: rgba(0,0,0,0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 10px 0 14px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 8px;
  gap: 6px;
}

.tool-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1.5px solid rgba(255,255,255,0.25);
  background: transparent;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
  padding: 4px;
}

.tool-btn.active {
  background: rgba(255,107,53,0.85);
  border-color: var(--accent);
}

.cam-info {
  flex: 1;
  text-align: center;
  font-size: 10px;
  font-family: "SF Mono", Menlo, monospace;
  opacity: 0.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brightness-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 16px 8px;
}

.brightness-icon {
  font-size: 14px;
  opacity: 0.5;
  flex-shrink: 0;
}

.brightness-icon.bright {
  opacity: 0.8;
}

.brightness-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: linear-gradient(to right, #444, #fff, #ffa500);
  border-radius: 2px;
  outline: none;
}

.brightness-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  cursor: pointer;
}

.ev-label {
  background: none;
  border: 1.5px solid rgba(255,255,255,0.25);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  font-family: "SF Mono", Menlo, monospace;
  min-width: 40px;
  padding: 3px 4px;
  text-align: center;
  cursor: pointer;
  border-radius: 6px;
  flex-shrink: 0;
  transition: all 0.15s;
}

.ev-label:active {
  background: rgba(255,107,53,0.3);
}

#formatBtn, #proBtn {
  width: auto;
  min-width: 44px;
  padding: 4px 8px;
  font-size: 10px;
  letter-spacing: 0.5px;
}

.pro-panel {
  padding: 4px 16px 8px;
  max-height: 180px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.pro-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 3px 0;
}

.pro-label {
  font-size: 10px;
  font-weight: 700;
  font-family: "SF Mono", Menlo, monospace;
  width: 62px;
  flex-shrink: 0;
  opacity: 0.7;
  letter-spacing: 0.5px;
}

.pro-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: rgba(255,255,255,0.25);
  border-radius: 2px;
  outline: none;
}

.pro-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  cursor: pointer;
}

.pro-val {
  background: none;
  border: 1px solid rgba(255,255,255,0.25);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  font-family: "SF Mono", Menlo, monospace;
  min-width: 52px;
  padding: 3px 4px;
  text-align: center;
  cursor: pointer;
  border-radius: 6px;
  flex-shrink: 0;
}

.pro-empty {
  font-size: 11px;
  opacity: 0.5;
  text-align: center;
  padding: 6px 0;
  line-height: 1.5;
}

.overlay-row {
  padding: 0 12px 8px;
}

.overlay-bar {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.ov-btn {
  padding: 5px 10px;
  border: 1.5px solid rgba(255,255,255,0.25);
  background: transparent;
  color: #fff;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.15s;
}

.ov-btn.active {
  background: var(--accent);
  border-color: var(--accent);
}

.ov-btn.on {
  border-color: var(--accent);
  color: var(--accent);
}

.bake-hint {
  text-align: center;
  font-size: 9px;
  opacity: 0.4;
  padding-top: 4px;
  font-family: "SF Mono", Menlo, monospace;
}

.lens-selector {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 0 12px 10px;
}

.lens-btn {
  flex: 1;
  max-width: 85px;
  padding: 8px 0;
  border: 1.5px solid rgba(255,255,255,0.25);
  background: transparent;
  color: #fff;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.lens-btn .focal {
  font-size: 10px;
  opacity: 0.6;
  font-weight: 400;
}

.lens-btn.active {
  background: var(--accent);
  border-color: var(--accent);
}

.capture-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 0 24px;
}

.gallery-thumb-wrap {
  position: relative;
  flex-shrink: 0;
}

.gallery-thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #222;
  border: 2px solid rgba(255,255,255,0.2);
  overflow: hidden;
  cursor: pointer;
}

.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.shutter-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: transparent;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: transform 0.1s;
}

.shutter-btn:active {
  transform: scale(0.92);
}

.shutter-btn::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: #fff;
  transition: background 0.15s;
}

.shutter-btn:active::after {
  background: var(--accent);
}

.flip-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.12);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.flip-btn svg {
  width: 22px;
  height: 22px;
}

.flash-overlay {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.08s;
  z-index: 100;
}

.flash-overlay.flash {
  opacity: 1;
}

.gallery-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 200;
  display: none;
  flex-direction: column;
  padding: var(--safe-top) 0 var(--safe-bottom) 0;
}

.gallery-overlay.open {
  display: flex;
}

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

.gallery-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.gallery-header button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 8px;
}

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

.gallery-grid .photo {
  aspect-ratio: 1;
  overflow: hidden;
  cursor: pointer;
}

.gallery-grid .photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-viewer {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 300;
  display: none;
  flex-direction: column;
  padding: var(--safe-top) 0 var(--safe-bottom) 0;
}

.photo-viewer.open {
  display: flex;
}

.photo-viewer .photo-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.photo-viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.photo-viewer .photo-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  flex-wrap: wrap;
}

.photo-viewer .photo-actions button {
  padding: 10px 20px;
  border-radius: 10px;
  border: none;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.photo-viewer .photo-actions .btn-save {
  background: var(--accent);
  color: #fff;
}

.photo-viewer .photo-actions .btn-delete {
  background: rgba(255,255,255,0.12);
  color: #fff;
}

.photo-viewer .photo-actions .btn-close {
  background: rgba(255,255,255,0.12);
  color: #fff;
}

.photo-meta {
  text-align: center;
  padding: 4px 16px 8px;
  font-size: 11px;
  opacity: 0.5;
  font-family: "SF Mono", Menlo, monospace;
}

@media (max-height: 600px) {
  .lens-btn { padding: 6px 0; font-size: 12px; }
  .shutter-btn { width: 60px; height: 60px; }
  .controls { padding: 6px 0 10px; }
  .toolbar { padding: 0 10px 4px; }
  .brightness-row { padding: 0 12px 4px; }
  .lens-selector { padding: 0 10px 6px; }
  .tool-btn { width: 28px; height: 28px; }
}