:root{
  --bg: #ffffff;
  --fg: #111111;
  --muted: #666;
  --accent: #0a84ff;
  --stop: #ff3b30;
  --gap: 12px;
  font-family: "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}
*[hidden]{display:none!important}
*{box-sizing:border-box}
html,body,#app{height:100%;margin:0;background:var(--bg);color:var(--fg)}
body{display:flex;align-items:stretch;justify-content:center}
#app{width:100%;max-width:450px;display:flex;flex-direction:column;height:100vh;padding:0}

/* Theme */
#app[data-theme="dark"]{
  --bg:#0e0e10; --fg:#f7f7f7; --muted:#9aa0a6; --accent:#4f8cff;
  background:var(--bg); color:var(--fg);
}

/* Welcome screen */
#welcome{
  position:fixed; inset:0; display:flex; align-items:center; justify-content:center;
  background:var(--bg); z-index:2000;
}
#welcome[aria-hidden="true"]{display:none}
.welcome-inner{ width:90%; max-width:420px; text-align:center; }
.welcome-inner h1{ margin:0 0 6px 0; font-size:1.6rem; }
.welcome-inner p{ margin:0 0 14px 0; color:var(--muted); }
.welcome-actions{ display:flex; gap:10px; justify-content:center; margin-bottom:10px; }
.project-list{ display:flex; flex-direction:column; gap:8px; max-height:50vh; overflow:auto; }
.project-item{ display:flex; align-items:center; justify-content:space-between; padding:8px 10px; border:1px solid #e0e0e0; border-radius:10px; }
#app[data-theme="dark"] .project-item{ border-color:#2a2a2e; }
.project-item .name{ font-weight:600; }
.project-item .actions{ display:flex; gap:8px; }

/* Header */
header{
  padding:10px 12px;
  display:flex; align-items:center; gap:8px; border-bottom:1px solid #eee;
}
.header-camera-select{
  margin-left:8px;
  height:34px;
  padding:6px 8px;
  border-radius:10px;
  border:1px solid #e0e0e0;
  background:var(--bg);
  color:var(--fg);
  font-size:0.85rem;
}
#app[data-theme="dark"] .header-camera-select{ border-color:#2a2a2e; background:#141416; color:#fff; }
#app[data-theme="dark"] header{ border-bottom-color:#1b1b1e; }
.brand{ font-weight:700; }
.spacer{ flex:1; }

/* Icon buttons */
.icon-btn{
  width:38px; height:38px; border-radius:10px; border:1px solid #e0e0e0; background:#fff; color:var(--fg);
  display:inline-flex; align-items:center; justify-content:center; font-size:1.1rem; cursor:pointer;
}
#app[data-theme="dark"] .icon-btn{ border-color:#2a2a2e; background:#141416; }
.icon-btn.primary{ background:var(--accent); color:#fff; border:none; }

/* Camera area */
#camera-area{
  position:relative;
  flex:1;
  background:#000;
  display:flex; align-items:center; justify-content:center; overflow:hidden;
}
#camera-viewport{
  width:100%;
  max-width:100%;
  aspect-ratio: 16 / 9;
  background: #000;
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
  position:relative;
}
#video{
  width:100%;
  height:100%;
  object-fit:contain;
  display:block;
  transform-origin:center center;
  will-change:transform;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* Camera fullscreen exit button */
.cam-exit-btn{
  position:absolute;
  top:8px;
  right:8px;
  z-index:60;
  width:40px;
  height:40px;
  border-radius:10px;
  background:rgba(255,255,255,0.9);
  border:none;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-size:1.1rem;
  cursor:pointer;
  box-shadow:0 4px 10px rgba(0,0,0,0.2);
  pointer-events:auto;
}
#app[data-theme="dark"] .cam-exit-btn{ background:rgba(20,20,22,0.95); color:#fff; }
.cam-exit-btn[hidden]{ display:none !important; }

/* Camera overlay controls */
#cam-overlay{ position:absolute; inset:0; pointer-events:none; }
#cam-overlay .cam-left, #cam-overlay .cam-right, #cam-overlay .cam-bottom{
  position:absolute; padding:8px; pointer-events:auto;
}
#cam-overlay .cam-left{ top:6px; left:6px; }
#cam-overlay .cam-right{ top:6px; right:6px; }
#cam-overlay .cam-bottom{ bottom:8px; left:6px; }
.icon-overlay{
  width:36px; height:36px; border-radius:50%; background:rgba(255,255,255,0.85); border:none; box-shadow:0 2px 6px rgba(0,0,0,0.2);
  display:inline-flex; align-items:center; justify-content:center; font-size:1.1rem; cursor:pointer;
}
#app[data-theme="dark"] .icon-overlay{ background:rgba(20,20,22,0.85); color:#fff; }

/* Reference overlay */
#reference-stack{ position:absolute; inset:0; pointer-events:none; }
#reference-stack img{ position:absolute; inset:0; width:100%; height:100%; object-fit:contain; }

/* Power button states */
#power-btn.power-on{
  background:#35d07f;
  color:#fff;
  box-shadow:0 4px 10px rgba(53,208,127,0.18);
}
#power-btn.power-off{
  background:#ff3b30;
  color:#fff;
  box-shadow:0 4px 10px rgba(255,59,48,0.18);
}
#app[data-theme="dark"] #power-btn.power-on{
  background:#2fb86e;
  color:#fff;
}
#app[data-theme="dark"] #power-btn.power-off{
  background:#e23a2a;
  color:#fff;
}

/* Placeholder */
#placeholder{ position:absolute; inset:0; display:flex; align-items:center; justify-content:center; pointer-events:none; background:linear-gradient(0deg, rgba(0,0,0,0.35), rgba(0,0,0,0.15)); }
.placeholder-inner{ color:#fff; padding:14px; border-radius:10px; text-align:center; }

/* Countdown */
#countdown{ position:absolute; inset:0; display:none; align-items:center; justify-content:center; font-size:4rem; color:#fff; pointer-events:none; text-shadow:0 2px 10px rgba(0,0,0,0.7); font-weight:700; }

/* Footer */
footer{ display:flex; flex-direction:column; gap:8px; padding:8px; }
#thumbs{ margin-top:4px; display:flex; gap:6px; overflow-x:auto; padding-bottom:4px; }
#thumbs img{ width:64px; height:84px; object-fit:cover; border-radius:8px; border:1px solid #d0d0d0; box-shadow:0 1px 3px rgba(0,0,0,0.1); cursor:pointer; }
.plus-thumb{
  width:36px; height:36px; display:inline-flex; align-items:center; justify-content:center; border-radius:50%; border:1px dashed #d0d0d0;
  background:var(--bg); color:var(--muted); font-size:1.1rem; cursor:pointer; flex:0 0 auto;
  margin-left:-18px; margin-right:-18px; z-index:5; box-shadow:0 2px 6px rgba(0,0,0,0.12); align-self:center; transition:transform .08s ease;
}
.plus-thumb.active{
  border-style:solid;
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(10,132,255,0.08);
}
.plus-thumb:active{ transform:scale(0.96) }

/* Control rows */
.control-row{ display:flex; gap:8px; align-items:center; padding:4px 4px; }

/* Zoom row */
#zoom-row{ 
  display:flex; 
  gap:8px; 
  align-items:center; 
  padding:6px 4px;
  margin-top:2px;
}
#zoom-label{ font-size:0.8rem; color:var(--muted); min-width:50px; }
#zoom-value{ font-size:0.8rem; color:var(--muted); min-width:45px; text-align:right; }
#zoom{
  -webkit-appearance:none;
  appearance:none;
  flex:1;
  height:6px;
  background:#eee;
  border-radius:6px;
  outline:none;
}
#zoom::-webkit-slider-thumb{
  -webkit-appearance:none;
  width:16px;
  height:16px;
  background:var(--accent);
  border-radius:50%;
  box-shadow:0 1px 2px rgba(0,0,0,0.2);
  cursor:pointer;
}

/* Sensitivity and FPS rows */
#sensitivity-row, #playback-row{
  display:flex;
  gap:8px;
  align-items:center;
  padding:4px 4px;
}
#sensitivity-label, #fps-label{ font-size:0.8rem; color:var(--muted); min-width:110px }
#sensitivity, #fps{
  -webkit-appearance:none;
  appearance:none;
  flex:1;
  height:6px;
  background:#eee;
  border-radius:6px;
  outline:none;
}
#sensitivity::-webkit-slider-thumb, #fps::-webkit-slider-thumb{
  -webkit-appearance:none;
  width:16px;
  height:16px;
  background:var(--accent);
  border-radius:50%;
  box-shadow:0 1px 2px rgba(0,0,0,0.2);
  cursor:pointer;
}

/* Interaction zone: AF/AE controls + record button */
#interaction-zone{
  display:grid;
  grid-template-columns: 2fr 1fr; /* left 2/3 for AF/AE + sliders, right 1/3 for start button */
  gap:10px;
  align-items:center;
  padding:6px 4px;
}

#controls-left{ display:flex; flex-direction:column; gap:8px; }

#af-ae-column{
  display:grid;
  grid-template-columns: auto 1fr;
  gap:8px;
  align-items:center;
}

#sliders-column{ display:flex; flex-direction:column; gap:8px; }

#controls-right{ display:flex; align-items:center; justify-content:center; }
.controls-right .record-btn{
  width:84px;
  height:84px;
  border-radius:50%;
  border-width:6px;
  justify-self:center;
  margin:0;
}

/* Ensure zoom and sensitivity rows are full width when inside left column */
#zoom-row, #sensitivity-row{
  display:flex; gap:8px; align-items:center; padding:4px 0; width:100%;
  justify-content:space-between;
}

/* labels adjusted for stacked layout */
#zoom-label{ font-size:0.85rem; color:var(--muted); min-width:70px; }
#zoom-value{ font-size:0.85rem; color:var(--muted); min-width:50px; text-align:right; }

/* Lock button */
.lock-btn{
  width:40px;
  height:40px;
  border-radius:10px;
  border:1px solid #e0e0e0;
  background:#fff;
  color:var(--fg);
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-size:1rem;
  cursor:pointer;
  transition: all 0.2s ease;
}
#app[data-theme="dark"] .lock-btn{ border-color:#2a2a2e; background:#141416; }
.lock-btn.locked{
  background:var(--accent);
  color:#fff;
  border-color:var(--accent);
}

.lock-slider{
  -webkit-appearance:none;
  appearance:none;
  width:100%;
  height:8px;
  background:#eee;
  border-radius:8px;
  outline:none;
  cursor:pointer;
}

/* Record button */
.record-btn{
  width:80px;
  height:80px;
  border-width:5px;
  font-size:1.6rem;
  justify-self:center;
}

/* Help text */
#help{ margin-top:4px; font-size:0.75rem; color:var(--muted); text-align:center }

/* Photo modal */
#photo-modal{ position:fixed; inset:0; display:none; align-items:center; justify-content:center; background:rgba(0,0,0,0.6); z-index:1000; }
#photo-modal[aria-hidden="false"]{ display:flex }
#photo-modal-inner{ position:relative; max-width:90%; max-height:90%; background:transparent; border-radius:8px; }
#photo-modal-inner img{ display:block; max-width:100%; max-height:100%; border-radius:8px; touch-action:none; -webkit-user-drag:none; user-select:none; }
#photo-close, #photo-delete{
  position:absolute; width:36px; height:36px; border:none; border-radius:10px; background:rgba(255,255,255,0.7);
  box-shadow:0 2px 6px rgba(0,0,0,0.2); cursor:pointer; z-index:10; font-weight:600; font-size:1.2rem; line-height:1;
}
#photo-close{ top:10px; right:10px; }
#photo-delete{ bottom:10px; right:10px; }

/* Insert/capture modal */
#insert-modal{ position:fixed; inset:0; display:none; align-items:center; justify-content:center; background:rgba(0,0,0,0.6); z-index:1050; }
#insert-modal[aria-hidden="false"]{ display:flex }
#insert-modal-inner{ width:92%; max-width:420px; background:var(--bg); border-radius:12px; box-shadow:0 6px 24px rgba(0,0,0,0.2); max-height:90vh; overflow-y:auto; }
.insert-header{ display:flex; align-items:center; justify-content:space-between; padding:10px 12px; border-bottom:1px solid #eee; }
#app[data-theme="dark"] .insert-header{ border-bottom-color:#1b1b1e; }
.insert-body{ padding:12px; display:flex; flex-direction:column; gap:10px; }
.insert-action-btn{
  padding:12px;
  border-radius:10px;
  border:1px solid #e0e0e0;
  background:#fff;
  color:var(--fg);
  font-size:0.95rem;
  font-weight:600;
  cursor:pointer;
  transition: all 0.2s ease;
}
#app[data-theme="dark"] .insert-action-btn{ border-color:#2a2a2e; background:#141416; }
.insert-action-btn:active{ transform:scale(0.98); }

#insert-indicator{
  margin-top:4px;
  padding:6px 8px;
  font-size:0.75rem;
  color:var(--muted);
  text-align:center;
}

#capture-preview-section{
  padding:12px;
  display:flex;
  flex-direction:column;
  gap:10px;
}
#capture-viewport{
  width:100%;
  aspect-ratio:16/9;
  background:#000;
  border-radius:8px;
  overflow:hidden;
  display:flex;
  align-items:center;
  justify-content:center;
  position:relative;
}
#capture-video{
  width:100%;
  height:100%;
  object-fit:contain;
  display:block;
}
#capture-countdown{
  position:absolute;
  inset:0;
  display:none;
  align-items:center;
  justify-content:center;
  font-size:3rem;
  color:#fff;
  font-weight:700;
  text-shadow:0 2px 8px rgba(0,0,0,0.7);
}
#capture-countdown[aria-hidden="false"]{
  display:flex;
}
.capture-controls{
  display:flex;
  gap:8px;
  justify-content:center;
}
.capture-controls .icon-btn{
  width:50px;
  height:50px;
  font-size:1.3rem;
}

#captured-image-section{
  padding:12px;
  display:flex;
  flex-direction:column;
  gap:10px;
}
#captured-image-preview{
  width:100%;
  border-radius:8px;
  display:block;
  max-height:50vh;
  object-fit:contain;
}
.capture-confirm-controls{
  display:flex;
  gap:8px;
  justify-content:center;
}
.capture-confirm-controls .icon-btn{
  width:50px;
  height:50px;
  font-size:1.3rem;
}

/* Playback modal */
#play-modal{ position:fixed; inset:0; display:none; align-items:center; justify-content:center; background:rgba(0,0,0,0.6); z-index:1000; }
#play-modal[aria-hidden="false"]{ display:flex }
#play-modal-inner{ position:relative; max-width:90%; max-height:90%; }
#play-canvas{ display:block; max-width:100%; max-height:100%; border-radius:8px; background:#000; }
#play-close{
  position:absolute; top:10px; right:10px; width:36px; height:36px; border:none; border-radius:10px; background:rgba(255,255,255,0.7);
  box-shadow:0 1px 3px rgba(0,0,0,0.2); cursor:pointer; z-index:10; font-weight:600; font-size:1.2rem; line-height:1;
}

/* Settings modal */
#settings-modal{ position:fixed; inset:0; display:none; align-items:center; justify-content:center; background:rgba(0,0,0,0.6); z-index:1100; }
#settings-modal[aria-hidden="false"]{ display:flex; }
#settings-inner{ width:92%; max-width:460px; background:var(--bg); color:var(--fg); border-radius:12px; box-shadow:0 6px 24px rgba(0,0,0,0.2); max-height:90vh; overflow-y:auto; }
.settings-header{ display:flex; align-items:center; justify-content:space-between; padding:10px 12px; border-bottom:1px solid #eee; }
#app[data-theme="dark"] .settings-header{ border-bottom-color:#1b1b1e; }
.settings-body{ padding:12px; display:grid; grid-template-columns:1fr; gap:10px; }
.setting{ display:grid; grid-template-columns: 1fr auto; gap:8px; align-items:center; }
.settings-footer{ padding:10px 12px; display:flex; justify-content:flex-end; }

/* Export modal */
#export-modal{ position:fixed; inset:0; display:none; align-items:center; justify-content:center; background:rgba(0,0,0,0.6); z-index:1100; }
#export-modal[aria-hidden="false"]{ display:flex; }
#export-inner{ width:92%; max-width:420px; background:var(--bg); color:var(--fg); border-radius:12px; box-shadow:0 6px 24px rgba(0,0,0,0.2); }
.export-row{ padding:14px; display:flex; gap:10px; justify-content:center; }

/* Grid overlay */
#grid-overlay{
  position:absolute; inset:0; pointer-events:none; display:none;
  background:
    linear-gradient(to right, rgba(255,255,255,0.18) 0, rgba(255,255,255,0.18) 1px, transparent 1px) 0 0/33.333% 100%,
    linear-gradient(to bottom, rgba(255,255,255,0.18) 0, rgba(255,255,255,0.18) 1px, transparent 1px) 0 0/100% 33.333%;
}
#app[data-theme="dark"] #grid-overlay{
  background:
    linear-gradient(to right, rgba(255,255,255,0.22) 0, rgba(255,255,255,0.22) 1px, transparent 1px) 0 0/33.333% 100%,
    linear-gradient(to bottom, rgba(255,255,255,0.22) 0, rgba(255,255,255,0.22) 1px, transparent 1px) 0 0/100% 33.333%;
}

/* Flash effect */
#flash{ position:absolute; inset:0; background:#fff; pointer-events:none; opacity:0; }
#flash.active{ animation: flashPulse 250ms ease; }
@keyframes flashPulse{ from{opacity:.9} to{opacity:0} }

/* Force photo button */
.force-photo-btn{
  position:absolute;
  bottom:12px;
  right:12px;
  width:44px;
  height:44px;
  border-radius:10px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-size:1.1rem;
  pointer-events:auto;
  background:rgba(255,255,255,0.92);
  border:1px solid rgba(0,0,0,0.08);
  box-shadow:0 4px 10px rgba(0,0,0,0.12);
  cursor:pointer;
  z-index:30;
}
#app[data-theme="dark"] .force-photo-btn{
  background:rgba(20,20,22,0.92);
  color:#fff;
  border:1px solid rgba(255,255,255,0.04);
}

/* Compact select */
.compact-select{ padding:6px 10px; border-radius:10px; border:1px solid #e0e0e0; min-height:40px; font-size:0.8rem; background:#fff; color:var(--fg); }
#app[data-theme="dark"] .compact-select{ border-color:#2a2a2e; background:#141416; color:#fff; }

/* Accessibility */
button:active{ transform:none }
@media (orientation:landscape){ #app{ max-width:none } }

/* Sensitivity row */
.control-row{
  display:flex;
  gap:8px;
  align-items:center;
  padding:4px 4px; /* Reduced padding */
}
#sensitivity{
  -webkit-appearance:none;
  appearance:none;
  width:100%;
  height:6px;
  background:#eee;
  border-radius:6px;
  outline:none;
}
#sensitivity::-webkit-slider-thumb{
  -webkit-appearance:none;
  width:16px;
  height:16px;
  background:var(--accent); /* Consistent accent color */
  border-radius:50%;
  box-shadow:0 1px 2px rgba(0,0,0,0.2);
  cursor:pointer;
}
#sensitivity-label{font-size:0.8rem;color:var(--muted);min-width:110px}

/* Help text */
#help{margin-top:2px;font-size:0.75rem;color:var(--muted);text-align:center} /* Smaller text and margin */

/* Thumbnails strip */
#thumbs{
  margin-top:4px; /* Reduced margin */
  display:flex;
  gap:6px; /* reduced gap */
  overflow-x:auto;
  padding-bottom:4px; /* reduced padding */
  flex-wrap: nowrap; /* prevent wrapping/expanding */
  white-space: nowrap; /* keep items on single line */
}
#thumbs img{
  width:64px; /* smaller thumbnails */
  height:84px;
  object-fit:cover;
  border-radius:8px;
  border:1px solid #d0d0d0;
  box-shadow:0 1px 3px rgba(0,0,0,0.1);
  cursor:pointer;
  flex: 0 0 auto; /* don't allow thumbnails to grow or shrink to change layout */
}

/* plus upload square between thumbnails */
.plus-thumb{
  width:36px;
  height:36px;
  display:flex;
  align-items:center;
  justify-content:center;
  border-radius:50%;
  border:1px dashed #d0d0d0;
  background:var(--bg);
  color:var(--muted);
  font-size:1.1rem;
  cursor:pointer;
  flex: 0 0 auto; /* ensure plus thumb doesn't expand the container */
  margin-left: -18px; /* overlap halfway into previous thumb */
  margin-right: -18px; /* overlap halfway into next thumb to stay centered between thumbs */
  z-index: 5; /* sit above thumbnails */
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
  display:inline-flex;
  align-self: center;
  transition:transform .08s ease;
}
.plus-thumb:active{transform:scale(0.96)}

/* Modal */
#photo-modal{
  position:fixed;
  inset:0;
  display:none;
  align-items:center;
  justify-content:center;
  background:rgba(0,0,0,0.6);
  z-index:1000;
}
#photo-modal[aria-hidden="false"]{display:flex}
#photo-modal-inner{
  position:relative;
  max-width:90%;
  max-height:90%;
  background:transparent;
  border-radius:8px;
}
#photo-modal-inner img{
  display:block;
  max-width:100%;
  max-height:100%;
  border-radius:8px;
  touch-action: none; /* allow JS swipe handling */
  -webkit-user-drag: none;
  user-select: none;
}
#photo-close{
  position:absolute;
  top:10px;
  right:10px;
  background:rgba(255,255,255,0.7);
  border-radius:10px; /* square-ish background */
  width:36px;height:36px;
  border:none;
  box-shadow:0 1px 3px rgba(0,0,0,0.2);
  cursor:pointer;
  z-index: 10;
  font-weight: 600;
  font-size: 1.2rem;
  line-height: 1;
}

#flash{ position:absolute; inset:0; background:#fff; pointer-events:none; opacity:0; }
#flash.active{ animation: flashPulse 250ms ease; }
@keyframes flashPulse{ from{opacity:.9} to{opacity:0} }

#playback-row{display:flex;gap:8px;align-items:center;padding:4px 4px;}
#playback-row #play-btn {
    flex-shrink: 0;
    width: 100px; /* Fixed width for play button */
    margin-left: auto;
    font-weight: 600;
    background: var(--accent);
    color: white;
    border: none;
}

#zoom{
  -webkit-appearance:none;
  appearance:none;
  width:100%;
  height:10px; /* increased height for easier touch */
  background:#eee;
  border-radius:10px;
  outline:none;
}
#zoom::-webkit-slider-thumb{
  -webkit-appearance:none;
  width:20px; /* larger thumb for accessibility */
  height:20px; /* larger thumb for accessibility */
  background:var(--accent);
  border-radius:50%;
  box-shadow:0 2px 4px rgba(0,0,0,0.25);
  cursor:pointer;
  margin-top:-5px; /* center thumb on taller track */
}
#zoom-label{ font-size:0.9rem; color:var(--muted); min-width:90px; } /* slightly larger label */

#fps{
  -webkit-appearance:none;
  appearance:none;
  width:100%;
  height:6px;
  background:#eee;
  border-radius:6px;
  outline:none;
}
#fps::-webkit-slider-thumb{ 
  -webkit-appearance:none;
  width:16px;
  height:16px;
  background:var(--accent); /* Consistent accent color */
  border-radius:50%;
  box-shadow:0 1px 2px rgba(0,0,0,0.2);
  cursor:pointer;
}

/* Small adjustments for accessibility */
button:active{transform:translateY(0)} /* Removed small Y offset for modern flat design feel */
@media (orientation:landscape){
  /* Keep UI usable on landscape but still vertical-first */
  #app{max-width:none}
}

#photo-delete{
  position:absolute;
  bottom:10px;
  right:10px;
  background:rgba(255,255,255,0.7);
  border-radius:10px;
  width:36px;height:36px;
  border:none;
  box-shadow:0 2px 6px rgba(0,0,0,0.2);
  cursor:pointer;
  z-index: 10;
  font-size: 1.2rem;
}

#play-modal{
  position:fixed;inset:0;display:none;align-items:center;justify-content:center;
  background:rgba(0,0,0,0.6);z-index:1000;
}
#play-modal[aria-hidden="false"]{display:flex}
#play-modal-inner{position:relative;max-width:90%;max-height:90%;}
#play-canvas{display:block;max-width:100%;max-height:100%;border-radius:8px;background:#000;}
#play-close{
  position:absolute;
  top:10px;right:10px;
  background:rgba(255,255,255,0.7);
  border-radius:10px;
  width:36px;height:36px;
  border:none;
  box-shadow:0 1px 3px rgba(0,0,0,0.2);
  cursor:pointer;
  z-index: 10;
  font-weight: 600;
  font-size: 1.2rem;
  line-height: 1;
}

#grid-overlay{
  position:absolute; inset:0; pointer-events:none; display:none;
  background:
    linear-gradient(to right, rgba(255,255,255,0.18) 0, rgba(255,255,255,0.18) 1px, transparent 1px) 0 0/33.333% 100%,
    linear-gradient(to bottom, rgba(255,255,255,0.18) 0, rgba(255,255,255,0.18) 1px, transparent 1px) 0 0/100% 33.333%;
}
#app[data-theme="dark"] #grid-overlay{
  background:
    linear-gradient(to right, rgba(255,255,255,0.22) 0, rgba(255,255,255,0.22) 1px, transparent 1px) 0 0/33.333% 100%,
    linear-gradient(to bottom, rgba(255,255,255,0.22) 0, rgba(255,255,255,0.22) 1px, transparent 1px) 0 0/100% 33.333%;
}

/* Force photo button at bottom-right of camera area */
.force-photo-btn{
  position:absolute;
  bottom:12px;
  right:12px;
  width:44px;
  height:44px;
  border-radius:10px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-size:1.1rem;
  pointer-events:auto;
  background:rgba(255,255,255,0.92);
  border:1px solid rgba(0,0,0,0.08);
  box-shadow:0 4px 10px rgba(0,0,0,0.12);
  cursor:pointer;
  z-index:30;
}
#app[data-theme="dark"] .force-photo-btn{
  background:rgba(20,20,22,0.92);
  color:#fff;
  border:1px solid rgba(255,255,255,0.04);
}

/* ===== Mobile-first layout refinements ===== */

/* Use full device width on mobile */
#app{
  max-width:100%;
}

/* Compact header for better vertical space on phones */
header{
  padding:8px 10px;
  gap:6px;
}
.icon-btn{
  width:34px; height:34px; font-size:1rem;
}

/* Camera viewport: keep 16:9 but allow tighter fit visually */
#camera-area{
  padding:0;
}
#camera-viewport{
  aspect-ratio:16/9;
  width:100%;
  max-width:100%;
}

/* Footer as a clean grid for harmony and coherence */
footer{
  display:grid;
  grid-template-columns: 1fr;
  grid-template-areas:
    "thumbs"
    "interaction"
    "zoom"
    "sensitivity"
    "playback"
    "help";
  gap:10px;
  padding:12px;
}

/* Place sections into grid areas */
#thumbs{ grid-area: thumbs; margin-top:0; padding-bottom:6px; }
#interaction-zone{ grid-area: interaction; padding:8px 0; margin-top:0; }
#zoom-row{ grid-area: zoom; }
#sensitivity-row{ grid-area: sensitivity; }
#playback-row{ grid-area: playback; }
#help{ grid-area: help; margin-top:0; }

/* Harmonize AF/AE column and record button */
#af-ae-column{
  grid-template-columns: auto 1fr;
  column-gap:10px;
  row-gap:8px;
}
.lock-slider{ width:100%; }

/* Record button slightly smaller for balance and centered */
.record-btn{
  width:80px;
  height:80px;
  border-width:5px;
  font-size:1.6rem;
  justify-self:center;
}

/* Sliders: comfortable touch targets */
#zoom, #sensitivity, #fps, .lock-slider{
  height:8px;
  border-radius:8px;
}
#zoom::-webkit-slider-thumb,
#sensitivity::-webkit-slider-thumb,
#fps::-webkit-slider-thumb,
.lock-slider::-webkit-slider-thumb{
  width:18px;
  height:18px;
}

/* Improve visual balance of labels */
#zoom-label, #sensitivity-label, #fps-label{
  font-size:0.85rem;
  color:var(--muted);
}

/* Thumbnails: slightly larger strip spacing and ensure end visibility */
#thumbs img{
  width:68px;
  height:88px;
}
.plus-thumb{
  width:40px; height:40px; font-size:1.2rem;
}

/* Help text spacing and readability */
#help{
  font-size:0.8rem;
  color:var(--muted);
}

/* Keep grid overlay and flash unaffected */

/* Landscape: maintain full width and tighten gaps */
@media (orientation:landscape){
  footer{
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "thumbs thumbs"
      "interaction interaction"
      "zoom sensitivity"
      "playback playback"
      "help help";
    gap:12px;
  }

  /* Keep UI usable on landscape but still vertical-first */
  #app{max-width:none}

  /* Ensure camera area stays visible in landscape: allow camera area to shrink/grow and cap viewport height */
  #camera-area{
    flex: 1 1 auto;            /* allow flexible sizing */
    min-height: 40vh;          /* keep a reasonable minimum so camera is visible */
    display:flex;
    align-items:center;
    justify-content:center;
  }
  #camera-viewport{
    max-height: calc(100vh - 120px); /* cap viewport to remaining screen so footer/header remain accessible */
    width:100%;
    height:auto;
    aspect-ratio: 16/9;
  }
}
/* ===== End refinements ===== */

.card{
  border:1px solid #e0e0e0; border-radius:12px; background:#fff;
  padding:8px; display:flex; flex-direction:column; gap:6px;
  width:100%; max-width:100%; box-sizing:border-box; overflow:hidden; /* ensure card never grows beyond screen and clips internal overflow */
}
.card.compact{ padding:6px; gap:6px; }
#app[data-theme="dark"] .card{ border-color:#2a2a2e; background:#141416; }

.icon-btn.active, .icon-overlay.active{
  background: var(--accent) !important; color:#fff !important; border-color: var(--accent) !important;
}

#interaction-zone{ gap:8px; padding:4px 0; }
.record-btn{ width:78px; height:78px; border-width:5px; font-size:1.5rem; }
#help{ display:none }
.record-btn.recording{
  animation: pulse 1s ease-in-out infinite;
  border-color: var(--stop);
}
.record-btn.recording::before{ background:var(--stop); }
@keyframes pulse{
  0%{ transform:scale(1); box-shadow:0 0 0 0 rgba(255,59,48,0.5); }
  70%{ transform:scale(1.02); box-shadow:0 0 0 12px rgba(255,59,48,0); }
  100%{ transform:scale(1); box-shadow:0 0 0 0 rgba(255,59,48,0); }
}