/* =========================================
   Camera App - Main Styles
   ========================================= */

/* ── CSS Variables ─────────────────────── */
:root {
  --bg: #0a0a0a;
  --glass: rgba(8, 8, 8, 0.62);
  --glass-border: rgba(255,255,255,0.08);
  --accent: #f0f0f0;
  --btn-ring: rgba(255,255,255,0.85);
  --text-muted: rgba(255,255,255,0.45);
  --success: #3dffa0;
  --danger: #ff4d6a;
  --font-ui: 'Sora', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-mono: 'DM Mono', 'Roboto Mono', monospace;
}

/* ── Reset ──────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  font-family: var(--font-ui);
  color: var(--accent);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ── App Container ─────────────────────── */
#app {
  position: relative;
  width: 100vw;
  height: 100dvh;
  background: #000;
}

/* ── Loading Overlay ───────────────────── */
#loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  z-index: 80;
  transition: opacity 0.5s ease;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.loading-ring {
  position: relative;
  width: 52px;
  height: 52px;
}

.ring-dot {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: ring-pulse 1.2s ease-in-out infinite;
}

.ring-dot:nth-child(1) { top: 0; left: 50%; transform: translateX(-50%); animation-delay: 0s; }
.ring-dot:nth-child(2) { top: 50%; right: 0; transform: translateY(-50%); animation-delay: 0.1s; }
.ring-dot:nth-child(3) { bottom: 0; left: 50%; transform: translateX(-50%); animation-delay: 0.2s; }
.ring-dot:nth-child(4) { top: 50%; left: 0; transform: translateY(-50%); animation-delay: 0.3s; }
.ring-dot:nth-child(5) { top: 14%; left: 14%; animation-delay: 0.4s; }
.ring-dot:nth-child(6) { top: 14%; right: 14%; animation-delay: 0.5s; }

@keyframes ring-pulse {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1.1); }
}

.loading-text {
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 0.05em;
  animation: text-blink 2s ease-in-out infinite;
}

@keyframes text-blink {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.8; }
}

/* ── Video ──────────────────────────────── */
#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ── Shutter Flash ─────────────────────── */
#shutter {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 30;
  transition: opacity 0.05s;
}

#shutter.flash {
  opacity: 0.75;
  transition: opacity 0s;
}

/* ── Frame Guide ───────────────────────── */
#frame-guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  opacity: 0.18;
}

#frame-guide::before,
#frame-guide::after {
  content: '';
  position: absolute;
  background: #fff;
}

#frame-guide::before {
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
}

#frame-guide::after {
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
}

/* ── Hidden Canvas ─────────────────────── */
#canvas {
  display: none;
}

/* ── Top Bar ───────────────────────────── */
#top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: env(safe-area-inset-top, 0) 24px 14px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  z-index: 20;
  background: linear-gradient(to bottom, rgba(0,0,0,0.55) 0%, transparent 100%);
}

#app-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
}

#live-dot {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--success);
}

#live-dot::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Settings Button ───────────────────── */
#settings-btn {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  left: 20px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1.5px solid var(--glass-border);
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  transition: transform 0.15s, background 0.2s;
  z-index: 21;
}

#settings-btn:active {
  transform: scale(0.88);
}

#settings-btn:hover {
  background: rgba(255,255,255,0.1);
}

/* ── Bottom Controls ───────────────────── */
#controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 14px 28px;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 28px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 20;
  background: linear-gradient(to top, rgba(0,0,0,0.72) 0%, transparent 100%);
}

/* ── Thumbnail Cluster ────────────────── */
#thumb-cluster {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#thumb-btn {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 1.5px solid var(--glass-border);
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, transform 0.15s;
}

#thumb-btn:active {
  transform: scale(0.92);
}

#thumb-btn.has-photo {
  border-color: rgba(255,255,255,0.25);
}

#thumb-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

#thumb-btn.has-photo #thumb-preview {
  display: block;
}

#thumb-placeholder {
  width: 20px;
  height: 20px;
  opacity: 0.25;
}

#thumb-btn.has-photo #thumb-placeholder {
  display: none;
}

#thumb-count {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  display: none;
}

#thumb-count.visible {
  display: block;
}

/* ── Capture Button ───────────────────── */
#capture-btn {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 3px solid var(--btn-ring);
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s cubic-bezier(0.34,1.56,0.64,1);
  flex-shrink: 0;
}

#capture-btn::before {
  content: '';
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: rgba(255,255,255,0.92);
  transition: background 0.15s, transform 0.15s cubic-bezier(0.34,1.56,0.64,1);
}

#capture-btn:hover::before {
  background: rgba(255,255,255,1);
}

#capture-btn:active {
  transform: scale(0.88);
}

#capture-btn:active::before {
  transform: scale(0.82);
}

#capture-btn.capturing::before {
  transform: scale(0.72);
  background: rgba(255,255,255,0.5);
}

/* ── Right Cluster ─────────────────────── */
#right-cluster {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* ── Control Icon Buttons ──────────────── */
.ctrl-icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--glass-border);
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, transform 0.15s, background 0.2s;
  color: var(--accent);
}

@keyframes switch-rotate {
  0%   { transform: rotate(0deg)   scale(1); }
  40%  { transform: rotate(180deg) scale(1.15); }
  100% { transform: rotate(360deg) scale(1); }
}

.ctrl-icon-btn.switching svg {
  animation: switch-rotate 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) forwards;
}

.ctrl-icon-btn:active {
  transform: scale(0.88);
}

.ctrl-icon-btn:hover {
  border-color: rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.08);
}

/* ── Preview Overlay ──────────────────── */
#preview-overlay {
  position: absolute;
  inset: 0;
  background: #000;
  z-index: 50;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#preview-overlay.show {
  display: flex;
  animation: slideUp 0.35s cubic-bezier(0.32, 0.72, 0, 1) forwards;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
    opacity: 0.4;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

#preview-overlay.close {
  animation: slideDown 0.25s cubic-bezier(0.32, 0.72, 0, 1) forwards;
}

@keyframes slideDown {
  from {
    transform: translateY(0);
    opacity: 1;
  }
  to {
    transform: translateY(100%);
    opacity: 0;
  }
}

#preview-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

/* ── Preview Bar ──────────────────────── */
#preview-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 14px 28px;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 28px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, transparent 100%);
}

#preview-time {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.1em;
}

/* ── Preview Actions ──────────────────── */
.preview-action {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1.5px solid var(--glass-border);
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  transition: transform 0.15s, background 0.2s;
}

.preview-action:active {
  transform: scale(0.88);
}

.preview-action:hover {
  background: rgba(255,255,255,0.1);
}

#download-btn {
  background: rgba(61,255,160,0.12);
  border-color: rgba(61,255,160,0.3);
}

#download-btn:hover {
  background: rgba(61,255,160,0.22);
}

/* ── Preview Close Button ─────────────── */
#preview-close {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  right: 20px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1.5px solid var(--glass-border);
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  transition: transform 0.15s;
}

#preview-close:active {
  transform: scale(0.88);
}

/* ── Gallery Navigation Buttons ────────── */
.gallery-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--glass-border);
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  transition: transform 0.15s, background 0.2s, opacity 0.2s;
  z-index: 5;
}

.gallery-nav-btn:hover {
  background: rgba(255,255,255,0.15);
}

.gallery-nav-btn:active {
  transform: translateY(-50%) scale(0.9);
}

.gallery-nav-left {
  left: 12px;
}

.gallery-nav-right {
  right: 12px;
}

.gallery-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ── Error Screen ─────────────────────── */
#error-screen {
  position: absolute;
  inset: 0;
  background: var(--bg);
  z-index: 60;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 40px;
}

#error-screen.show {
  display: flex;
}

#error-icon {
  opacity: 0.35;
}

#error-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-align: center;
}

#error-msg {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
  max-width: 280px;
}

#retry-btn {
  margin-top: 8px;
  padding: 12px 32px;
  border-radius: 100px;
  border: 1.5px solid var(--glass-border);
  background: rgba(255,255,255,0.07);
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: background 0.2s, transform 0.15s;
}

#retry-btn:hover {
  background: rgba(255,255,255,0.14);
}

#retry-btn:active {
  transform: scale(0.96);
}

/* ── Permission Prompt ────────────────── */
#permission-prompt {
  position: absolute;
  inset: 0;
  background: var(--bg);
  z-index: 60;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 40px;
}

#permission-prompt.show {
  display: flex;
}

#perm-icon {
  opacity: 0.4;
}

#perm-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-align: center;
}

#perm-sub {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.65;
  max-width: 260px;
}

#perm-btn {
  margin-top: 10px;
  padding: 13px 36px;
  border-radius: 100px;
  background: var(--accent);
  color: #000;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: opacity 0.2s, transform 0.15s;
}

#perm-btn:hover {
  opacity: 0.88;
}

#perm-btn:active {
  transform: scale(0.96);
}

/* ── Gallery Overlay ──────────────────── */
#gallery-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg);
  z-index: 50;
  display: none;
  flex-direction: column;
}

#gallery-overlay.show {
  display: flex;
  animation: fadeIn 0.2s ease forwards;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Gallery Header ────────────────────── */
#gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 20px 14px;
  background: rgba(10, 10, 10, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  flex-shrink: 0;
}

#gallery-back {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1.5px solid var(--glass-border);
  background: var(--glass);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  transition: transform 0.15s;
}

#gallery-back:active {
  transform: scale(0.88);
}

#gallery-title {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

#gallery-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

#gallery-clear-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 77, 106, 0.35);
  background: rgba(255, 77, 106, 0.08);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.2s;
}

#gallery-clear-btn:active {
  transform: scale(0.88);
}

#gallery-clear-btn:hover {
  background: rgba(255, 77, 106, 0.18);
}

/* ── Gallery Grid ──────────────────────── */
#gallery-grid {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  align-content: start;
  -webkit-overflow-scrolling: touch;
}

#gallery-grid::-webkit-scrollbar {
  width: 0;
}

.gallery-item {
  aspect-ratio: 1;
  overflow: hidden;
  cursor: pointer;
  border-radius: 4px;
  background: rgba(255,255,255,0.03);
  transition: transform 0.15s;
}

.gallery-item:active {
  transform: scale(0.95);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ── Gallery Empty ─────────────────────── */
#gallery-empty {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex: 1;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Toast ─────────────────────────────── */
#toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.85);
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  padding: 14px 28px;
  border-radius: 100px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.25s, transform 0.25s;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#toast.warning {
  border-color: rgba(255, 77, 106, 0.4);
  color: var(--danger);
}

#toast.success {
  border-color: rgba(61, 255, 160, 0.4);
  color: var(--success);
}
