/* ── Forage Design System ──────────────────────────── */

:root {
  /* Warm (light) theme */
  --bg: #F5F0E8;
  --bg-secondary: #EDE8DD;
  --card-bg: #FFFFFF;
  --card-border: rgba(139, 105, 20, 0.12);
  --text: #2C2416;
  --text-secondary: #6B5D4A;
  --text-muted: #8A7E6B;
  --accent: #8B6914;
  --accent-hover: #A37D1A;
  --accent-glow: rgba(139, 105, 20, 0.15);
  --sage: #5C7A3A;
  --sage-light: rgba(92, 122, 58, 0.1);
  --score-high: #8B6914;
  --score-mid: #6B5D4A;
  --score-low: #8A7E6B;
  --overlay: rgba(44, 36, 22, 0.6);
  --glass: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.3);
  --shadow: 0 2px 16px rgba(44, 36, 22, 0.08);
  --shadow-lg: 0 8px 32px rgba(44, 36, 22, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg: #1A1612;
  --bg-secondary: #231E18;
  --card-bg: #252019;
  --card-border: rgba(212, 168, 67, 0.12);
  --text: #E8E0D4;
  --text-secondary: #B8AE9C;
  --text-muted: #6B6054;
  --accent: #D4A843;
  --accent-hover: #E0BA5A;
  --accent-glow: rgba(212, 168, 67, 0.15);
  --sage: #7BA05B;
  --sage-light: rgba(123, 160, 91, 0.1);
  --score-high: #D4A843;
  --score-mid: #B8AE9C;
  --score-low: #6B6054;
  --overlay: rgba(0, 0, 0, 0.7);
  --glass: rgba(37, 32, 25, 0.8);
  --glass-border: rgba(255, 255, 255, 0.06);
  --shadow: 0 2px 16px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* ── Reset & Base ──────────────────────────────────── */

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

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ── Typography ────────────────────────────────────── */

.font-display {
  font-family: 'DM Serif Display', Georgia, serif;
}

h1, h2, h3 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-weight: 400;
  line-height: 1.2;
}

/* ── Layout ────────────────────────────────────────── */

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
}

.view {
  display: none;
  min-height: 100dvh;
}

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

/* ── Header ────────────────────────────────────────── */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
}

.app-logo {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.25rem;
  color: var(--accent);
  letter-spacing: 0.02em;
  cursor: pointer;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  font-size: 1.1rem;
  line-height: 1;
}

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

/* ── Prompt View ───────────────────────────────────── */

.prompt-view {
  justify-content: center;
  align-items: center;
  padding: 40px 24px;
  text-align: center;
  flex: 1;
}

.prompt-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  max-width: 360px;
  gap: 32px;
}

.prompt-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-muted);
}

.prompt-text {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 2rem;
  line-height: 1.25;
  color: var(--text);
  font-weight: 400;
}

.prompt-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.prompt-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--sage-light);
  color: var(--sage);
  font-weight: 500;
}

.prompt-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 280px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: 0.01em;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

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

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  cursor: pointer;
  transition: var(--transition);
}

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

/* ── Camera / Upload ───────────────────────────────── */

.upload-area {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-width: 360px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-secondary);
  border: 2px dashed var(--card-border);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

.upload-area:hover {
  border-color: var(--accent);
}

.upload-area.has-photo {
  border-style: solid;
  border-color: var(--accent);
}

.upload-area img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upload-placeholder {
  text-align: center;
  color: var(--text-muted);
}

.upload-placeholder .icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
  display: block;
}

.upload-prompt-text {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
  text-align: center;
  padding: 0 20px;
}

#photoInput {
  display: none;
}

.capture-buttons {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
}

.capture-buttons .btn-primary,
.capture-buttons .btn-secondary {
  flex: 1;
}

/* ── Camera Viewfinder ─────────────────────────────── */

.viewfinder-container {
  position: relative;
  width: 100%;
  max-width: 360px;
  aspect-ratio: 3/4;
  margin: 0 auto;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
}

.viewfinder-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.viewfinder-snap {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: rgba(255, 255, 255, 0.25);
  cursor: pointer;
  transition: var(--transition);
  backdrop-filter: blur(4px);
}

.viewfinder-snap:active {
  transform: translateX(-50%) scale(0.9);
  background: rgba(255, 255, 255, 0.5);
}

.viewfinder-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

/* ── Judging View ──────────────────────────────────── */

.judging-view {
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 40px 24px;
}

.eye-container {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 32px;
}

.eye-ring {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  opacity: 0.3;
  animation: eyePulse 2s ease-in-out infinite;
}

.eye-iris {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border-radius: 50%;
  background: var(--accent);
  animation: irisContract 1.5s ease-in-out infinite;
}

@keyframes eyePulse {
  0%, 100% { opacity: 0.3; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.05); }
}

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

.judging-text {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.25rem;
  color: var(--text-secondary);
}

.judging-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* ── Verdict View ──────────────────────────────────── */

.verdict-view {
  padding: 0;
}

.verdict-photo {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.verdict-content {
  padding: 24px 20px 40px;
}

.verdict-score-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}

.verdict-score {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 3rem;
  line-height: 1;
  color: var(--accent);
}

.verdict-score.high {
  color: var(--score-high);
}

.verdict-score-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.verdict-prompt {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  font-style: italic;
}

.verdict-text {
  font-size: 1.05rem;
  line-height: 1.65;
  color: var(--text);
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg-secondary);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.verdict-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 24px;
}

.verdict-tag {
  padding: 4px 10px;
  background: var(--sage-light);
  color: var(--sage);
  border-radius: 20px;
  font-size: 0.72rem;
  text-transform: lowercase;
  letter-spacing: 0.02em;
}

.verdict-actions {
  display: flex;
  gap: 12px;
}

.verdict-actions .btn-primary,
.verdict-actions .btn-secondary {
  flex: 1;
}

/* Score celebration effects */
.celebration {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
}

/* ── History View ──────────────────────────────────── */

.history-view {
  padding: 0 0 40px;
}

.history-header {
  padding: 16px 20px;
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.5rem;
}

.history-empty {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}

.history-empty .icon {
  font-size: 3rem;
  margin-bottom: 12px;
  display: block;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 0 2px;
}

.history-card {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition);
}

.history-card:hover {
  opacity: 0.85;
}

.history-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-card-score {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: var(--overlay);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
  backdrop-filter: blur(4px);
}

/* ── Submission Detail (expanded history card) ────── */

.detail-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  z-index: 200;
  overflow-y: auto;
  display: none;
}

.detail-overlay.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

.detail-close {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 210;
  background: var(--overlay);
  color: #fff;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

/* ── Animations ────────────────────────────────────── */

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

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

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.fade-in {
  animation: fadeIn 0.4s ease;
}

.fade-in-up {
  animation: fadeInUp 0.5s ease both;
}

.stagger-1 { animation-delay: 0.1s; }
.stagger-2 { animation-delay: 0.2s; }
.stagger-3 { animation-delay: 0.3s; }
.stagger-4 { animation-delay: 0.5s; }

/* ── Utilities ─────────────────────────────────────── */

.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.gap-12 { gap: 12px; }

/* ── Responsive ────────────────────────────────────── */

@media (min-width: 481px) {
  .app-shell {
    border-left: 1px solid var(--card-border);
    border-right: 1px solid var(--card-border);
  }
}

/* ── Nav bar ───────────────────────────────────────── */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  justify-content: center;
  gap: 32px;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--glass-border);
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.nav-item .nav-icon {
  font-size: 1.3rem;
}

.nav-item.active,
.nav-item:hover {
  color: var(--accent);
}

/* ── Dark/Light toggle ─────────────────────────────── */

.theme-toggle {
  font-size: 1rem;
}
