:root {
  --bg-primary: #0f0f23;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;
  --accent: #00d4ff;
  --accent-dark: #0099cc;
  --success: #00ff88;
  --error: #ff4444;
  --border: #2a2a4e;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  --shadow-light: 0 4px 16px rgba(0, 0, 0, 0.2);
  --radius: 16px;
  --radius-small: 12px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
  color: var(--text-primary);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  min-height: 100vh;
  line-height: 1.6;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  position: relative;
  text-align: center;
  padding: 20px 0;
  margin-bottom: 0;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  backdrop-filter: blur(10px);
}

.settings-toggle-btn {
  position: absolute;
  top: 50%;
  right: 16px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.settings-toggle-btn:hover,
.settings-toggle-btn.active {
  background: var(--bg-secondary);
  color: var(--accent);
  border-color: var(--accent);
}

.logo {
  max-width: 200px;
  height: auto;
  max-height: 80px;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  transition: var(--transition);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.hidden {
  display: none !important;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 24px;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  border: none;
  border-radius: var(--radius-small);
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
  min-height: 48px;
  box-shadow: var(--shadow-light);
  letter-spacing: 0.02em;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0, 212, 255, 0.3);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
}

.btn-secondary {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.status {
  padding: 16px;
  border-radius: var(--radius-small);
  text-align: center;
  font-weight: 500;
  margin-bottom: 0;
  font-size: 0.95rem;
  backdrop-filter: blur(10px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  margin: 0 16px;
}

.status.error {
  background: rgba(255, 68, 68, 0.1);
  border: 1px solid rgba(255, 68, 68, 0.3);
  color: var(--error);
}

input, textarea {
  width: 100%;
  padding: 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 1rem;
  transition: var(--transition);
  margin-bottom: 16px;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

input::placeholder {
  color: var(--text-muted);
}

/* Tab Bar */
.tab-bar {
  display: flex;
  gap: 4px;
  margin: 0 -24px 20px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: -1px;
  letter-spacing: 0.01em;
}

.tab:hover {
  color: var(--text-secondary);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Settings */
.settings-group {
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Settings Image Grid */
.settings-image-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.settings-thumb-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-small);
  overflow: hidden;
  background: var(--bg-secondary);
}

.settings-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: var(--transition);
}


.settings-delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  backdrop-filter: blur(4px);
}

.settings-delete-btn:hover {
  background: var(--error);
}

.settings-no-images {
  color: var(--text-muted);
  font-size: 0.85rem;
  grid-column: 1 / -1;
}

/* Gallery Styles */
.gallery-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border-radius: 0 0 var(--radius) var(--radius);
  border: 1px solid var(--border);
  border-top: none;
  padding: 24px;
  margin-bottom: 0;
  backdrop-filter: blur(10px);
}

.gallery-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.gallery-header h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

.gallery-slider {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

.main-image {
  width: 85%;
  margin: 0 auto 24px;
  background: #fff;
  padding: 10px 10px 40px;
  border-radius: 2px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.45), 0 3px 10px rgba(0,0,0,0.25);
  transform: rotate(-1.5deg);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: zoom-in;
}

.main-image img {
  display: block;
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  border-radius: 0;
}

.no-images {
  color: var(--text-secondary);
  font-size: 1.2rem;
  text-align: center;
  padding: 40px 20px;
}

.thumbnails {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 12px 0;
  max-width: 100%;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.thumbnails::-webkit-scrollbar {
  display: none;
}

.thumbnail {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 0;
  cursor: pointer;
  flex-shrink: 0;
  border: 4px solid #fff;
  border-bottom: 14px solid #fff;
  box-shadow: 0 3px 10px rgba(0,0,0,0.4);
  transition: var(--transition);
}

.thumbnail.active {
  box-shadow: 0 0 0 3px var(--accent), 0 3px 10px rgba(0,0,0,0.4);
}

.thumbnail:hover {
  transform: scale(1.08) rotate(1deg);
}

.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(26, 26, 46, 0.9);
  border: 2px solid var(--border);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  font-size: 1.2rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
  display: none;
  backdrop-filter: blur(10px);
  z-index: 10;
}

.nav-btn:hover {
  background: var(--bg-card);
  border-color: var(--accent);
  color: var(--accent);
}

.prev-btn {
  left: 12px;
}

.next-btn {
  right: 12px;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
}

.lightbox-polaroid {
  background: #fff;
  padding: 10px 10px 48px;
  border-radius: 2px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.8), 0 6px 24px rgba(0,0,0,0.5);
  max-width: calc(100vw - 120px);
  max-height: calc(100dvh - 80px);
  display: flex;
}

.lightbox-img {
  display: block;
  max-width: calc(100vw - 140px);
  max-height: calc(100dvh - 80px - 58px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 0;
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.1);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.lightbox-close:hover {
  background: rgba(255,255,255,0.2);
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.1);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.lightbox-nav:hover {
  background: rgba(255,255,255,0.2);
}

.lightbox-prev { left: 12px; }
.lightbox-next { right: 12px; }

@media (orientation: landscape) {
  .lightbox-prev { left: max(12px, env(safe-area-inset-left)); }
  .lightbox-next { right: max(12px, env(safe-area-inset-right)); }
  .lightbox-close { top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); }
}

.lightbox-counter {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.85rem;
  color: rgba(255,255,255,0.5);
  letter-spacing: 0.05em;
}

/* Upload Page Styles */
.upload-app {
  gap: 0;
}

.button-group {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 24px;
  flex-wrap: wrap;
}

/* Topbar Navigation */
.topbar {
  display: flex;
  align-items: center;
  padding: 8px 0 20px;
}

.topbar h1 {
  flex: 1;
  font-size: 1.15rem;
  font-weight: 600;
  text-align: center;
  letter-spacing: -0.01em;
}

.topbar-spacer {
  width: 44px;
  flex-shrink: 0;
}

.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
}

.back-btn:hover {
  background: var(--border);
  color: var(--accent);
  border-color: var(--accent);
}

/* Step Indicator */
.step-indicator {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  margin-bottom: 24px;
}

.step-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 90px;
}

.step-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--border);
  transition: var(--transition);
}

.step-item.active .step-dot {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 14px rgba(0, 212, 255, 0.45);
}

.step-item.done .step-dot {
  background: var(--success);
  border-color: var(--success);
}

.step-label {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.step-item.active .step-label {
  color: var(--accent);
}

.step-connector {
  height: 2px;
  flex: 0 0 44px;
  background: var(--border);
  margin-top: 11px;
  border-radius: 1px;
}

/* Camera Viewfinder */
.viewfinder-wrap {
  position: relative;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  box-shadow: var(--shadow);
  margin-bottom: 8px;
}

.viewfinder-wrap video {
  width: 100%;
  display: block;
  border-radius: 0;
  margin-bottom: 0;
  aspect-ratio: 4/3;
  object-fit: cover;
  background: #000;
}

.viewfinder-frame {
  position: absolute;
  inset: 16px;
  pointer-events: none;
}

.viewfinder-frame span {
  position: absolute;
  width: 22px;
  height: 22px;
  border-color: rgba(0, 212, 255, 0.9);
  border-style: solid;
  border-width: 0;
}

.viewfinder-frame span:nth-child(1) {
  top: 0; left: 0;
  border-top-width: 3px; border-left-width: 3px;
  border-radius: 3px 0 0 0;
}
.viewfinder-frame span:nth-child(2) {
  top: 0; right: 0;
  border-top-width: 3px; border-right-width: 3px;
  border-radius: 0 3px 0 0;
}
.viewfinder-frame span:nth-child(3) {
  bottom: 0; left: 0;
  border-bottom-width: 3px; border-left-width: 3px;
  border-radius: 0 0 0 3px;
}
.viewfinder-frame span:nth-child(4) {
  bottom: 0; right: 0;
  border-bottom-width: 3px; border-right-width: 3px;
  border-radius: 0 0 3px 0;
}

/* Shutter Controls */
.shutter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px 20px;
}

.shutter-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.75);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  padding: 0;
}

.shutter-btn:hover {
  border-color: var(--accent);
  transform: scale(1.05);
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.3);
}

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

.shutter-inner {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  display: block;
  transition: var(--transition);
}

.shutter-btn:hover .shutter-inner {
  background: var(--accent);
}

.shutter-placeholder {
  width: 44px;
  height: 44px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
}

.icon-btn:hover {
  background: var(--border);
  color: var(--accent);
}

/* Crop Section */
.crop-area-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

#cropContainer {
  position: relative;
  display: inline-block;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

#cropOverlay {
  position: absolute;
  top: 0;
  left: 0;
  border: 3px solid var(--accent);
  cursor: move;
  box-sizing: border-box;
  border-radius: var(--radius-small);
}

#cropBox {
  width: 100%;
  height: 100%;
  border: 3px solid var(--accent);
  box-sizing: border-box;
  border-radius: var(--radius-small);
}

.hint-text {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-bottom: 20px;
  letter-spacing: 0.01em;
}

.action-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  padding-bottom: 8px;
}

.action-row .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 130px;
}

video {
  width: 100%;
  border-radius: var(--radius);
  background: var(--bg-secondary);
  margin-bottom: 16px;
}

/* Responsive Design */
@media (max-width: 480px) {
  .app {
    padding: 12px;
  }

  .topbar h1 {
    font-size: 1.1rem;
  }

  .card {
    padding: 20px;
    margin-bottom: 16px;
  }

  .btn {
    padding: 12px 20px;
    font-size: 0.95rem;
    min-height: 44px;
  }

  .thumbnail {
    width: 56px;
    height: 56px;
  }

  .nav-btn {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
  }
}

@media (min-width: 481px) {
  .app {
    padding: 20px;
  }

  .topbar {
    padding: 10px 0 24px;
  }

  .topbar h1 {
    font-size: 1.2rem;
  }

  .card {
    padding: 28px;
  }
}

/* Landscape layout for mobile */
@media (orientation: landscape) and (max-height: 520px) {
  .app {
    padding: 6px max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left));
    min-height: 100dvh;
  }

  /* Compact header */
  .header {
    padding: 6px 0;
  }

  .logo {
    max-height: 32px;
  }

  .settings-toggle-btn {
    width: 30px;
    height: 30px;
    right: max(12px, env(safe-area-inset-right));
  }

  /* Compact gallery card */
  .gallery-main {
    padding: 10px 14px;
  }

  .gallery-header {
    margin-bottom: 8px;
  }

  .gallery-header h2 {
    font-size: 1.1rem;
  }

  .btn {
    padding: 8px 14px;
    min-height: 36px;
    font-size: 0.875rem;
  }

  /* Gallery: image left, thumbnails right */
  .tab-content {
    flex: 1;
    min-height: 0;
  }

  .gallery-slider {
    flex-direction: row;
    align-items: stretch;
    gap: 10px;
    flex: 1;
    min-height: 0;
  }

  .main-image {
    flex: 1;
    aspect-ratio: unset;
    margin-bottom: 0;
    min-height: 0;
    min-width: 0;
  }

  /* Thumbnails become a vertical strip on the right */
  .thumbnails {
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 4px 0;
    gap: 8px;
    width: 58px;
    min-width: 58px;
    max-width: 58px;
  }

  .thumbnail {
    width: 52px;
    height: 52px;
    flex-shrink: 0;
  }

  /* Nav buttons not needed — thumbnails handle navigation */
  .nav-btn {
    display: none !important;
  }

  /* Settings: two columns for better use of space */
  .settings-group + .settings-group {
    margin-top: 12px;
  }

  .settings-image-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* Loading Animation */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.loading {
  animation: pulse 1.5s ease-in-out infinite;
}

/* Focus States for Accessibility */
.btn:focus,
input:focus,
.thumbnail:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Safe Area for Mobile Devices */
@supports (padding: max(0px)) {
  .app {
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
}
(16px, env(safe-area-inset-right));
  }
}
