:root {
  --bg: #f7f7fa;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --success: #16a34a;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14141c;
    --surface: #1e1e2a;
    --text: #f1f1f5;
    --text-muted: #9ca3af;
    --border: #2e2e3d;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.25);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 20px 64px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.site-header {
  text-align: center;
  margin-bottom: 32px;
}

.site-header h1 {
  font-size: 2rem;
  margin: 0 0 6px;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-muted);
  margin: 0 0 12px;
}

.site-nav a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}
.site-nav a:hover { text-decoration: underline; }

main { flex: 1; }

.upload-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.dropzone {
  width: 100%;
  min-height: 260px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  overflow: hidden;
  position: relative;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

.source-tabs {
  display: flex;
  gap: 8px;
  width: 100%;
}

.source-tab {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.source-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.source-tab:hover:not(.active) {
  border-color: var(--accent);
  color: var(--text);
}

.camera-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.camera-video, #cameraCanvas {
  width: 100%;
  max-height: 400px;
  border-radius: var(--radius);
  background: #000;
  object-fit: cover;
}

.camera-controls {
  display: flex;
  gap: 10px;
}

.secondary-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 24px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s;
}

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

#dropzoneContent {
  text-align: center;
  color: var(--text-muted);
  padding: 24px;
}

.dropzone-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

.hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.preview-img {
  max-width: 100%;
  max-height: 400px;
  object-fit: contain;
  border-radius: 10px;
}

.primary-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px 32px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.primary-btn:hover:not(:disabled) { background: var(--accent-hover); }
.primary-btn:active:not(:disabled) { transform: scale(0.98); }
.primary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.error-msg {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0;
  text-align: center;
}

.loading-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px 0;
  color: var(--text-muted);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.result-section { margin-top: 40px; }
.result-section h2 {
  font-size: 1.2rem;
  margin-bottom: 16px;
}
.meta-info {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-muted);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}

.result-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  text-align: center;
  position: relative;
}

.result-card.rank-1 {
  outline: 2px solid var(--accent);
}

.result-rank {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,0.6);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.result-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--border);
}

.result-info { padding: 10px 8px 14px; }

.result-name {
  font-weight: 600;
  font-size: 0.95rem;
  margin: 0 0 6px;
  word-break: keep-all;
}

.score-bar-track {
  background: var(--border);
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
  margin-bottom: 4px;
}

.score-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.score-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.site-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 48px;
}

/* 관리자 페이지 */
.admin-panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 28px;
}

.admin-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
}

.status-msg {
  font-size: 0.9rem;
  color: var(--text-muted);
}
.status-msg.success { color: var(--success); }
.status-msg.error { color: var(--danger); }

.people-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 14px;
}

.person-card {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  text-align: center;
}

.person-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--border);
}

.person-name {
  padding: 8px 6px;
  font-size: 0.85rem;
  font-weight: 600;
}

.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 40px 0;
}
