:root {
  --primary: #1b6b4a;
  --primary-dark: #124c34;
  --danger: #c0392b;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #1c1c1c;
  --muted: #6b6b6b;
  --border: #e0e0e0;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  background: var(--primary);
  color: white;
  padding: env(safe-area-inset-top, 0) 16px 12px;
  padding-top: calc(env(safe-area-inset-top, 0) + 12px);
}
.topbar h1 { margin: 0; font-size: 1.25rem; text-align: center; }

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: calc(100vh - 52px);
  position: relative;
}

.screen { display: none; padding: 20px 16px 40px; }
.screen.active { display: block; }
#screen-capture.active { display: flex; flex-direction: column; min-height: calc(100dvh - 76px); }

.screen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.screen-header h2 { margin: 0; font-size: 1.2rem; }
.screen-header .btn { flex-shrink: 0; }

/* HOME */
.home-actions {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 40px;
}

.btn {
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: var(--surface); color: var(--primary); border: 2px solid var(--primary); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { background: var(--danger); color: white; width: 100%; }

.btn-huge { padding: 22px; font-size: 1.15rem; border-radius: 18px; box-shadow: 0 2px 6px rgba(0,0,0,0.08); }
.btn-huge .icon { font-size: 1.4rem; }

/* CAPTURE */
.capture-stage {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 200px;
  max-height: 60vh;
  background: #000;
  border-radius: 16px;
  overflow: hidden;
}
#video, #captured-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.hidden { display: none !important; }

.controls {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 18px;
  min-height: 72px;
  flex-shrink: 0;
}

.btn-shutter {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: white;
  border: 4px solid var(--primary);
  flex-shrink: 0;
}
.btn-shutter:active { background: var(--border); }

.btn-switch-camera {
  position: absolute;
  right: 0;
  font-size: 1.3rem;
}

.answer-panel {
  margin-top: 20px;
  background: var(--surface);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.question { font-size: 1.1rem; font-weight: 600; margin: 0 0 14px; }

.record-row { display: flex; align-items: center; gap: 12px; }

.btn-record {
  background: var(--primary);
  color: white;
  border-radius: 30px;
  padding: 12px 20px;
  flex: 1;
}
.btn-record.recording { background: var(--danger); }
.btn-record .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: white;
}
.btn-record.recording .dot { animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.record-timer { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; }

.transcript-box { margin-top: 16px; }
.transcript-box label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.transcript-box input {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 1rem;
}

#audio-preview { width: 100%; margin-top: 14px; }

.answer-actions {
  display: flex;
  gap: 12px;
  margin-top: 18px;
}
.answer-actions .btn { flex: 1; }

/* GALLERY */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.gallery-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  background: var(--border);
}
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-item .gallery-item-name {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  color: white;
  font-size: 0.72rem;
  padding: 12px 6px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-state { text-align: center; color: var(--muted); margin-top: 60px; }

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-content {
  background: var(--surface);
  border-radius: 16px;
  padding: 18px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 8px; right: 8px;
  font-size: 1.2rem;
  z-index: 1;
}
#detail-photo { width: 100%; border-radius: 12px; display: block; }
.detail-name { font-size: 1.1rem; font-weight: 700; margin: 14px 0 4px; }
.detail-date { font-size: 0.8rem; color: var(--muted); margin: 8px 0 16px; }
#detail-audio { width: 100%; }

/* TOAST */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1c1c1c;
  color: white;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 0.9rem;
  z-index: 200;
  opacity: 0.95;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1e1e1e;
    --text: #f0f0f0;
    --muted: #a0a0a0;
    --border: #333;
  }
}
