/* ===== RESET & BASE ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #1e2a45;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0b8;
  --text-muted: #6b6b80;
  --accent: #4fc3f7;
  --accent-glow: rgba(79, 195, 247, 0.3);
  --success: #66bb6a;
  --warning: #ffa726;
  --score-bar: #4fc3f7;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.25s ease;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  min-height: 100dvh;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* ===== UTILITIES ===== */
.hidden {
  display: none !important;
}

.hidden-canvas {
  position: absolute;
  left: -9999px;
  top: -9999px;
  width: 0;
  height: 0;
}

/* ===== HOME SCREEN ===== */
.home-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  text-align: center;
  gap: 1rem;
}

.home-logo {
  font-size: 4rem;
  margin-bottom: 0.5rem;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.home-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #4fc3f7, #e1bee7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.home-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.5;
}

.home-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 280px;
  margin-top: 1.5rem;
}

.home-privacy-note {
  margin-top: 2rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn-primary {
  background: linear-gradient(135deg, #4fc3f7, #29b6f6);
  color: #0d1b2a;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:active {
  transform: scale(0.96);
  box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

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

.btn-secondary:active {
  transform: scale(0.96);
  background: var(--bg-secondary);
}

.btn-large {
  padding: 1rem 2rem;
  font-size: 1.1rem;
}

.btn-small {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  cursor: pointer;
}

.btn-icon {
  font-size: 1.1em;
}

.btn-icon-only {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.2rem;
}

/* ===== FOOTER ===== */
.footer {
  padding: 1rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

/* ===== CAMERA SCREEN ===== */
.camera-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #000;
  position: relative;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

.camera-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

#camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Rule of Thirds Grid */
.grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

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

.grid-h1, .grid-h2 {
  left: 0;
  width: 100%;
  height: 1px;
}

.grid-h1 { top: 33.33%; }
.grid-h2 { top: 66.66%; }

.grid-v1, .grid-v2 {
  top: 0;
  height: 100%;
  width: 1px;
}

.grid-v1 { left: 33.33%; }
.grid-v2 { left: 66.66%; }

.grid-dot {
  position: absolute;
  width: 8px;
  height: 8px;
  background: rgba(79, 195, 247, 0.6);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

/* Level Indicator */
.level-indicator {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  z-index: 5;
}

.level-bar {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
  position: relative;
}

.level-bubble {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: left 0.15s ease;
  box-shadow: 0 0 6px var(--accent-glow);
}

.level-bubble.level-ok {
  background: var(--success);
  box-shadow: 0 0 6px rgba(102, 187, 106, 0.4);
}

/* Camera Tip */
.camera-tip {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  color: rgba(255, 255, 255, 0.8);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 5;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: transform 0.3s ease;
}

/* Landscape rotation (applied via JS data-orientation attribute) */
.camera-tip[data-orientation="landscape-right"] {
  top: 50%;
  left: 12px;
  transform: translateY(-50%) rotate(-90deg);
}

.camera-tip[data-orientation="landscape-left"] {
  top: 50%;
  left: auto;
  right: 12px;
  transform: translateY(-50%) rotate(90deg);
}

/* Camera Controls */
.camera-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 2rem;
  padding-bottom: calc(1.25rem + var(--safe-bottom));
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.btn-back {
  background: rgba(255, 255, 255, 0.12);
  color: white;
  font-size: 1.2rem;
}

.camera-spacer {
  width: 44px;
}

.btn-capture {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.capture-ring {
  width: 68px;
  height: 68px;
  border: 3px solid white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.capture-inner {
  width: 56px;
  height: 56px;
  background: white;
  border-radius: 50%;
  transition: all var(--transition);
}

.btn-capture:active .capture-ring {
  transform: scale(0.9);
}

.btn-capture:active .capture-inner {
  background: #ccc;
}

/* Capture Flash */
.capture-flash {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: white;
  pointer-events: none;
  z-index: 100;
  animation: flash 0.3s ease-out forwards;
}

@keyframes flash {
  0% { opacity: 0.8; }
  100% { opacity: 0; }
}

/* ===== RESULT SCREEN ===== */
.result-container {
  flex: 1;
  padding: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.result-photo-section {
  width: 100%;
  background: #000;
  display: flex;
  justify-content: center;
  align-items: center;
  max-height: 50vh;
  overflow: hidden;
}

.result-canvas {
  max-width: 100%;
  max-height: 50vh;
  object-fit: contain;
}

.result-section {
  padding: 1.25rem 1.25rem 0;
}

.section-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
}

/* Score */
.result-score-section {
  text-align: center;
  padding-top: 1.5rem;
}

.score-main {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  margin-bottom: 1.25rem;
}

.score-total {
  font-size: 3.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, #4fc3f7, #81d4fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
}

.score-unit {
  font-size: 1.2rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.score-breakdown {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: 320px;
  margin: 0 auto;
}

.score-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.score-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  width: 36px;
  text-align: right;
  flex-shrink: 0;
}

.score-bar-track {
  flex: 1;
  height: 6px;
  background: var(--bg-card);
  border-radius: 3px;
  overflow: hidden;
}

.score-bar {
  height: 100%;
  background: linear-gradient(90deg, #4fc3f7, #81d4fa);
  border-radius: 3px;
  transition: width 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.score-value {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
  width: 28px;
  text-align: left;
  flex-shrink: 0;
}

/* Coach Comment */
.coach-comment {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  line-height: 1.7;
  font-size: 0.95rem;
  border-left: 3px solid var(--accent);
  min-height: 60px;
  display: flex;
  align-items: center;
}

.coach-mode-badge {
  margin-top: 0.5rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: right;
}

/* Loading Dots */
.loading-dots {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: dotPulse 1.2s ease-in-out infinite;
  opacity: 0.3;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1); }
}

/* Style Tags */
.style-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 36px;
  align-items: center;
}

.style-tag {
  display: inline-block;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--accent);
  padding: 0.4rem 0.9rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  animation: tagIn 0.3s ease backwards;
}

.style-tag:nth-child(2) { animation-delay: 0.1s; }
.style-tag:nth-child(3) { animation-delay: 0.2s; }

@keyframes tagIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Crop Suggestions */
.remake-caption {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  line-height: 1.5;
}

.crop-thumbnails {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 0.5rem;
}

.crop-thumb {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all var(--transition);
  aspect-ratio: 1;
}

.crop-thumb:active,
.crop-thumb.selected {
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.crop-thumb canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.crop-thumb-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.65);
  color: white;
  font-size: 0.6rem;
  padding: 2px 4px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Crop Preview */
.crop-preview-container {
  margin-top: 1rem;
  text-align: center;
}

.crop-preview-canvas {
  max-width: 100%;
  max-height: 280px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.crop-preview-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin: 0.5rem 0;
}

/* Action Buttons */
.result-actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1.5rem 1.25rem;
  padding-bottom: calc(0.5rem + var(--safe-bottom));
}

.result-actions .btn {
  width: 100%;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  max-width: 340px;
  width: 100%;
  text-align: center;
  animation: slideUp 0.3s ease;
  border: 1px solid var(--border);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  color: var(--accent);
}

.modal-body {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.8;
}

.modal-body p {
  margin-bottom: 1rem;
}

.modal-body strong {
  color: var(--text-primary);
}

.modal-close-btn {
  margin-top: 1rem;
  min-width: 120px;
}

/* ===== UPLOAD SCREEN ===== */
.upload-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}

.upload-back-btn {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 5;
}

.upload-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  text-align: center;
  gap: 0.75rem;
}

.upload-icon {
  font-size: 3.5rem;
  margin-bottom: 0.25rem;
}

.upload-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
}

.upload-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.upload-file-btn {
  margin-top: 1rem;
  cursor: pointer;
}

.file-input-hidden {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.upload-privacy-note {
  margin-top: 2rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* Upload variant button on home */
.btn-upload {
  background: linear-gradient(135deg, #ce93d8, #ab47bc);
  box-shadow: 0 4px 15px rgba(171, 71, 188, 0.3);
}

.btn-upload:active {
  box-shadow: 0 2px 8px rgba(171, 71, 188, 0.3);
}

/* Source badge on result screen */
.result-source-badge {
  text-align: center;
  padding: 0.5rem 0 0;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.result-source-badge:empty {
  display: none;
}

/* ===== ANIMATIONS ===== */
@keyframes scoreCount {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: scale(1); }
}

.score-animate {
  animation: scoreCount 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* ===== RESPONSIVE ===== */
@media (min-width: 480px) {
  .crop-thumbnails {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-height: 700px) {
  .home-container {
    gap: 1.5rem;
  }
}

/* Landscape adjustments */
@media (orientation: landscape) and (max-height: 500px) {
  .camera-controls {
    padding: 0.75rem 2rem;
  }
  .capture-ring {
    width: 52px;
    height: 52px;
  }
  .capture-inner {
    width: 42px;
    height: 42px;
  }
}
