/* ── Variables ─────────────────────────────────────────── */
:root {
  /* Sage green — primary */
  --primary:       #5b7b60;
  --primary-hover: #496050;
  --primary-light: #ecf3ee;
  --primary-dim:   #8fad93;   /* lighter sage for decorative use */

  /* Semantic — warm naturalistic */
  --danger:        #b85545;
  --danger-light:  #fdf0ee;
  --success:       #4e7050;
  --success-light: #ecf3ee;
  --warning:       #a87828;
  --warning-light: #faf4e6;

  /* Surfaces — warm cream palette */
  --bg:         #f5f2eb;
  --surface:    #fdfcf8;
  --border:     #ddd6c8;
  --text:       #1c1916;
  --text-muted: #655d51;
  --text-light: #9a9186;

  /* Shape */
  --radius:    10px;
  --radius-sm: 6px;
  --radius-lg: 16px;

  /* Shadows — warm-tinted */
  --shadow:    0 1px 3px rgba(40,28,12,.08), 0 1px 2px rgba(40,28,12,.05);
  --shadow-md: 0 4px 14px rgba(40,28,12,.11), 0 2px 4px rgba(40,28,12,.07);
  --shadow-lg: 0 8px 28px rgba(40,28,12,.13), 0 4px 8px rgba(40,28,12,.08);

  /* Easing */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out:    cubic-bezier(0.4, 0, 0.2, 1);
  --ease-smooth: cubic-bezier(0.25, 0.46, 0.45, 0.94);

  /* Layout */
  --bottom-nav-h: 64px;
  --header-h:     52px;
  --max-w:        720px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Header ────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 10000;
  background: rgba(253,252,248,.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
}

.nav {
  height: 100%;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  letter-spacing: -.5px;
  flex: 1;
  transition: color .2s var(--ease-out);
}

.nav-brand:hover { color: var(--primary-hover); }

/* Top nav links hidden on mobile */
.nav-links { display: none; }

/* ── Auth Button ───────────────────────────────────────── */
.auth-btn {
  border: 1px solid var(--border);
  background: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .2s var(--ease-out), border-color .2s var(--ease-out);
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.auth-btn:hover { color: var(--text); border-color: var(--text-light); }
.auth-btn.auth-signed-in { color: var(--primary); border-color: var(--primary-dim); }
.auth-btn.auth-signed-in:hover { border-color: var(--primary); }

/* ── Feedback Toggle ───────────────────────────────────── */
.feedback-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 0;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-muted);
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  transition: color .2s var(--ease-out);
}

.feedback-toggle:hover { color: var(--text); }

.toggle-text { font-size: .8rem; }

.toggle-track {
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--border);
  transition: background .28s var(--ease-out);
  flex-shrink: 0;
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 4px rgba(0,0,0,.22), 0 0 0 0.5px rgba(0,0,0,.05);
  transition: transform .28s var(--ease-spring);
}

.feedback-toggle.active .toggle-track  { background: var(--warning); }
.feedback-toggle.active .toggle-thumb  { transform: translateX(18px); }
.feedback-toggle:active .toggle-track  { opacity: .85; }

.feedback-toggle:focus-visible .toggle-track {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

/* ── Bottom Nav ────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--bottom-nav-h);
  background: rgba(253,252,248,.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-link {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--text-light);
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .02em;
  transition: color .2s var(--ease-out), transform .18s var(--ease-spring);
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav-link:active { transform: scale(.93); }
.bottom-nav-link.active { color: var(--primary); }
.bottom-nav-link svg    { transition: stroke .2s var(--ease-out); }

/* ── Main ──────────────────────────────────────────────── */
.main {
  padding: 20px 16px calc(var(--bottom-nav-h) + 16px);
}

.page-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -.4px;
  margin-bottom: 20px;
}

/* ── About Page ────────────────────────────────────────── */
.about-lead {
  font-size: 1rem;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 16px;
}

.about-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.about-section h2 {
  font-size: .95rem;
  font-weight: 600;
  margin-bottom: 10px;
}

.about-section p,
.about-section li {
  font-size: .9rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.about-section ol,
.about-section ul {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── Record Page — Input Row ───────────────────────────── */
.input-row {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.upload-zone {
  padding: 28px 20px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background  .22s var(--ease-out),
    box-shadow  .22s var(--ease-smooth),
    transform   .22s var(--ease-spring);
}

.upload-zone:hover,
.upload-zone:focus {
  background: var(--primary-light);
}

.upload-zone.drag-over {
  background: var(--primary-light);
  outline: 2px dashed var(--primary);
  outline-offset: -8px;
}

.upload-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
  transition: transform .22s var(--ease-spring), background .2s var(--ease-out);
}

.upload-zone:hover .upload-icon,
.upload-zone:focus .upload-icon {
  transform: scale(1.08);
  background: color-mix(in srgb, var(--primary-light) 60%, var(--primary-dim) 40%);
}

.upload-primary   { font-weight: 600; font-size: .9rem; }
.upload-secondary { font-size: .85rem; color: var(--text-muted); }
.upload-secondary .link {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.upload-hint { font-size: .75rem; color: var(--text-light); }

/* Divider — horizontal on mobile */
.input-divider {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
  height: 40px;
  color: var(--text-light);
  font-size: .8rem;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.input-divider::before,
.input-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Record Zone */
.record-zone {
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.record-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(184,85,69,.38), 0 2px 4px rgba(184,85,69,.2);
  transition:
    transform   .18s var(--ease-spring),
    box-shadow  .2s  var(--ease-smooth);
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.record-btn::before {
  content: '';
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: white;
  transition: border-radius .22s var(--ease-spring), width .22s var(--ease-spring), height .22s var(--ease-spring);
}

.record-btn.recording::before  { width: 22px; height: 22px; border-radius: 5px; }
.record-btn:active             { transform: scale(.93); box-shadow: 0 2px 8px rgba(184,85,69,.3); }

.record-btn.recording {
  animation: pulse-record 1.6s ease-in-out infinite;
}

@keyframes pulse-record {
  0%, 100% { box-shadow: 0 4px 16px rgba(184,85,69,.38), 0 2px 4px rgba(184,85,69,.2); }
  50%       { box-shadow: 0 4px 36px rgba(184,85,69,.65), 0 2px 8px rgba(184,85,69,.3); }
}

.record-label { font-size: .875rem; font-weight: 500; color: var(--text-muted); }
.record-timer { font-size: .875rem; font-weight: 600; color: var(--danger); font-variant-numeric: tabular-nums; }

/* ── Panels ────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

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

.panel-title {
  font-size: .95rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.panel-caption {
  font-size: .8rem;
  color: var(--text-light);
  font-style: italic;
  margin-bottom: 18px;
}

.panel-header .panel-title { margin-bottom: 0; }
.panel-actions { margin-top: 16px; }

#analyze-btn { width: 100%; }

.panel-feedback {
  border-color: color-mix(in srgb, var(--warning) 40%, var(--border) 60%);
  background: var(--warning-light);
}

/* Audio */
.audio-filename { font-size: .85rem; color: var(--text-muted); margin-bottom: 12px; font-style: italic; }
.audio-player   { width: 100%; border-radius: var(--radius-sm); margin-bottom: 2px; }

/* Result */
.result-placeholder { display: flex; flex-direction: column; gap: 8px; }

.result-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
  background: color-mix(in srgb, var(--border) 80%, transparent);
  color: var(--text-muted);
}

.result-hint { font-size: .875rem; color: var(--text-muted); }
.result-hook { font-size: .8rem; color: var(--text-light); }
.result-hook code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: .85em;
}

/* Feedback internals */
.feedback-prompt  { font-size: .9rem; color: var(--text-muted); margin-bottom: 14px; }
.feedback-options { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.feedback-options .btn { flex: 1; }

.feedback-note {
  width: 100%;
  padding: 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .9rem;
  resize: vertical;
  min-height: 72px;
  margin-bottom: 12px;
  background: var(--surface);
  color: var(--text);
  transition: border-color .2s var(--ease-out), box-shadow .2s var(--ease-out);
}

.feedback-note:focus {
  outline: none;
  border-color: var(--warning);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning) 18%, transparent);
}

.feedback-row { display: flex; gap: 8px; align-items: center; }

.feedback-public-row { display: flex; align-items: flex-start; gap: 10px; }
.feedback-public-label { display: flex; align-items: center; gap: 6px; font-size: 1rem; font-weight: 700; white-space: nowrap; cursor: pointer; }
.feedback-public-check { flex-shrink: 0; }
.feedback-public-caption { font-size: 0.75rem; color: var(--color-text-muted, #888); line-height: 1.4; }

.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-group:last-of-type { margin-bottom: 0; }

.rating-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}
.rating-min, .rating-max {
  font-size: .78rem;
  color: var(--text-light);
  flex-shrink: 0;
}
.rating-slider {
  flex: 1;
  accent-color: var(--primary);
  cursor: pointer;
  height: 4px;
}
.rating-val {
  min-width: 2ch;
  text-align: right;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
}

.frogwatch-opts { display: flex; gap: 8px; }
.frogwatch-opt {
  flex: 1;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: .9rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.frogwatch-opt.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.feedback-thanks { display: flex; align-items: center; gap: 10px; color: var(--success); font-size: .9rem; }

.check-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--success);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  flex-shrink: 0;
}

/* ── History Page ──────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

/* ── Collection (frog storage boxes) ───────────────────── */
.collection-section { margin-bottom: 28px; }

.collection-section-title {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.collection-count {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--primary);
  background: var(--primary-light);
  border-radius: 999px;
  padding: 1px 8px;
}

.collection-hint {
  font-size: .8rem;
  color: var(--text-light);
  margin-top: 10px;
}

.frog-box-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
  gap: 10px;
  background: var(--primary-light);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: inset 0 1px 4px rgba(40,28,12,.06);
}

.frog-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 6px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform .18s var(--ease-smooth), box-shadow .18s var(--ease-smooth);
}

.frog-box:not(.frog-box-empty):hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.frog-box-empty {
  background: transparent;
  border-style: dashed;
  border-color: rgba(150,140,120,.35);
  box-shadow: inset 0 1px 3px rgba(40,28,12,.04);
  min-height: 92px;
}

.frog-sprite-wrap {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}

.frog-sprite {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  max-width: 56px;
}

.frog-box-name {
  font-size: .72rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
  width: 100%;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.frog-box-conf {
  font-size: .66rem;
  color: var(--text-light);
}

.frog-box-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .62rem;
  font-weight: 700;
  color: #fff;
}
.frog-box-badge.correct   { background: var(--success); }
.frog-box-badge.incorrect { background: var(--danger); }

.frog-box[data-id] { cursor: pointer; }

.frog-box.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 2px var(--primary-dim), var(--shadow-md);
}

/* Remove control — only visible once the box is selected */
.frog-box-remove {
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 2;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}
.frog-box-remove svg { width: 13px; height: 13px; }
.frog-box.selected .frog-box-remove { display: flex; }
.frog-box-remove:hover { filter: brightness(1.08); }

.frog-box.frog-box-removing {
  animation: frogBoxRemove .3s var(--ease-out) forwards;
  pointer-events: none;
}
@keyframes frogBoxRemove {
  to { opacity: 0; transform: scale(.7); }
}

/* Frog hops in place when its box is selected */
.frog-sprite-wrap.frog-jump .frog-sprite { animation: frogJump .55s var(--ease-spring); }
@keyframes frogJump {
  0%, 100% { transform: translateY(0); }
  25%      { transform: translateY(-10px) scaleY(1.06); }
  50%      { transform: translateY(-15px); }
  75%      { transform: translateY(-5px); }
}

/* ── Observation card modal ── */
.card-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  transition: opacity .25s var(--ease-out);
}
.card-modal.open { opacity: 1; }

.card-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 15, 8, .55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.card-modal-body {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  transform: scale(.82) translateY(12px);
  transition: transform .32s var(--ease-spring);
}
.card-modal.open .card-modal-body { transform: scale(1) translateY(0); }

.card-modal .tcg-card {
  width: clamp(220px, 72vw, 280px);
  animation: none;            /* the modal body handles the entrance */
}
.card-modal .tcg-card-sprite {
  width: 112px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-modal .tcg-card-sprite .frog-sprite { max-width: 112px; }

.card-modal-meta {
  color: rgba(255, 255, 255, .85);
  font-size: .85rem;
}
.card-modal-close {
  background: rgba(255, 255, 255, .15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 999px;
  padding: 8px 24px;
  font-size: .85rem;
  font-family: inherit;
  cursor: pointer;
  transition: background .2s;
}
.card-modal-close:hover { background: rgba(255, 255, 255, .25); }

@media (prefers-reduced-motion: reduce) {
  .frog-sprite-wrap.frog-jump .frog-sprite { animation: none; }
  .card-modal, .card-modal-body { transition: none; }
}

.feedback-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}

.feedback-chip.correct   { background: var(--success-light); color: var(--success); }
.feedback-chip.incorrect { background: var(--danger-light);  color: var(--danger);  }

/* ── Empty State ───────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 52px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.empty-icon  { font-size: 2.5rem; margin-bottom: 14px; opacity: .3; }
.empty-title { font-size: 1rem; font-weight: 600; margin-bottom: 8px; }
.empty-desc  { font-size: .875rem; color: var(--text-muted); }
.empty-desc a { color: var(--primary); text-decoration-offset: 2px; }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  font-family: inherit;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform      .18s var(--ease-spring),
    box-shadow     .2s  var(--ease-smooth),
    background     .18s var(--ease-out),
    border-color   .18s var(--ease-out),
    color          .18s var(--ease-out),
    opacity        .15s;
}

.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(91,123,96,.28);
}
.btn-primary:active:not(:disabled) {
  background: var(--primary-hover);
  transform: scale(.97);
  box-shadow: none;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:active:not(:disabled) {
  background: var(--border);
  transform: scale(.97);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:active:not(:disabled) {
  background: var(--primary-light);
  color: var(--text);
  transform: scale(.97);
}

.btn-success {
  background: var(--success);
  color: white;
  border-color: var(--success);
  box-shadow: 0 2px 8px rgba(78,112,80,.28);
}
.btn-success:active:not(:disabled) { background: #3d5e3f; transform: scale(.97); box-shadow: none; }
.btn-success.selected {
  outline: 3px solid var(--success);
  outline-offset: 2px;
  box-shadow: 0 2px 12px rgba(78,112,80,.35);
}

.btn-outline-danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--danger);
}
.btn-outline-danger:active:not(:disabled) { background: var(--danger-light); transform: scale(.97); }
.btn-outline-danger.selected {
  background: var(--danger);
  color: white;
  outline: 3px solid var(--danger);
  outline-offset: 2px;
}

.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .82rem; }

/* ── Loading ───────────────────────────────────────────── */
.loading { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: .9rem; padding: 6px 0; }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

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

/* ── Analyze Loader (frog hopping on lily pad) ─────────────── */
.analyze-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 36px 0 28px;
  pointer-events: none;
  animation: loader-appear .3s var(--ease-out) both;
}

@keyframes loader-appear {
  from { opacity: 0; transform: scale(.88); }
  to   { opacity: 1; transform: scale(1);   }
}

.analyze-loader-scene {
  position: relative;
  width: 84px;
  height: 64px;
}

/* Lily pad — CSS oval with a notch */
.analyze-loader-pad {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 58px;
  height: 20px;
  background: radial-gradient(ellipse at 38% 38%, #5d9944, #3b6b28);
  border-radius: 50%;
  box-shadow: 0 3px 8px rgba(0,0,0,.18);
  animation: pad-sway 3.2s ease-in-out infinite;
}

/* Notch cut-out */
.analyze-loader-pad::after {
  content: '';
  position: absolute;
  top: -5px;
  right: 12px;
  width: 15px;
  height: 13px;
  border-radius: 50%;
  background: var(--bg);
}

@keyframes pad-sway {
  0%, 100% { transform: translateX(-50%) translateY(0);    }
  50%       { transform: translateX(-50%) translateY(2px); }
}

/* Frog hopping */
.analyze-loader-frog {
  position: absolute;
  font-size: 1.65rem;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  animation: frog-hop 1.1s ease-in-out infinite;
  user-select: none;
  line-height: 1;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.14));
}

@keyframes frog-hop {
  0%   { transform: translateX(-50%) translateY(0)     scaleX(1.1)  scaleY(.88); }
  22%  { transform: translateX(-50%) translateY(-18px) scaleX(.88)  scaleY(1.12); }
  48%  { transform: translateX(-50%) translateY(-22px) scaleX(.9)   scaleY(1.1);  }
  72%  { transform: translateX(-50%) translateY(-4px)  scaleX(.96)  scaleY(1.04); }
  90%  { transform: translateX(-50%) translateY(1px)   scaleX(1.12) scaleY(.85); }
  100% { transform: translateX(-50%) translateY(0)     scaleX(1.1)  scaleY(.88); }
}

/* Water ripple rings (hidden during idle, animated on exit) */
.analyze-loader-ripple {
  position: absolute;
  bottom: 5px;
  left: 50%;
  transform: translateX(-50%) scale(.5);
  width: 58px;
  height: 20px;
  border: 2px solid var(--primary-dim);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}

.analyze-loader-ripple-2 {
  width: 84px;
  height: 28px;
}

/* "loading" label */
.analyze-loader-text {
  font-size: .78rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: .14em;
  opacity: .75;
}

/* ── Exit: frog jumps into water ── */
.analyze-loader.loader-exiting .analyze-loader-frog {
  animation: frog-jump-into-water .65s cubic-bezier(.4, 0, 1, 1) forwards;
}

.analyze-loader.loader-exiting .analyze-loader-pad {
  animation: pad-bob-after-jump .85s ease-out .28s both;
}

.analyze-loader.loader-exiting {
  overflow: hidden;
}

.analyze-loader.loader-exiting .analyze-loader-text {
  animation: none;
  opacity: 0;
  transition: opacity .2s ease;
}

.analyze-loader.loader-exiting .analyze-loader-ripple {
  animation: water-ring-out .75s ease-out .38s forwards;
}

.analyze-loader.loader-exiting .analyze-loader-ripple-2 {
  animation: water-ring-out 1s ease-out .52s forwards;
}

@keyframes frog-jump-into-water {
  0%   { transform: translateX(-50%) translateY(0)      rotate(0deg)   scale(1);    opacity: 1; }
  30%  { transform: translateX(-50%) translateY(-30px)  rotate(-12deg) scale(.9);   opacity: 1; }
  100% { transform: translateX(-50%) translateY(26px)   rotate(28deg)  scale(.65);  opacity: 0; }
}

@keyframes pad-bob-after-jump {
  0%   { transform: translateX(-50%) scaleX(1)    scaleY(1);   }
  28%  { transform: translateX(-50%) scaleX(1.28) scaleY(.72); }
  58%  { transform: translateX(-50%) scaleX(.88)  scaleY(1.1); }
  100% { transform: translateX(-50%) scaleX(1)    scaleY(1);   opacity: .35; }
}

@keyframes water-ring-out {
  0%   { opacity: .75; transform: translateX(-50%) scale(.5); }
  100% { opacity: 0;   transform: translateX(-50%) scale(3);  }
}

/* Feedback overlay form */
.overlay-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.form-label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text);
}

.form-optional {
  font-weight: 400;
  color: var(--text-light);
}

.form-textarea,
.form-input {
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .9rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color .2s var(--ease-out), box-shadow .2s var(--ease-out);
}

.form-textarea {
  resize: vertical;
  min-height: 84px;
}

.form-input { min-height: 44px; }

.form-textarea:focus,
.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

/* ── Classification result ─────────────────────────────── */
.result-species {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.result-species-name {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.4px;
}
.result-uncertain {
  color: var(--text-muted);
  font-style: italic;
}

.result-confidence-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
  width: fit-content;
}

.result-confidence-badge.confidence-high { background: var(--success-light); color: var(--success); }
.result-confidence-badge.confidence-mid  { background: var(--warning-light); color: var(--warning); }
.result-confidence-badge.confidence-low  { background: var(--border);        color: var(--text-muted); }

.result-badge-error {
  background: var(--danger-light);
  color: var(--danger);
}

.result-probabilities {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.prob-row {
  display: grid;
  grid-template-columns: 108px 1fr 44px;
  align-items: center;
  gap: 10px;
}

.prob-label {
  font-size: .82rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.prob-bar-wrap {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.prob-bar {
  height: 100%;
  width: 0;                          /* starts at 0; JS sets data-width after paint */
  background: var(--primary-dim);
  border-radius: 999px;
  transition: width .6s var(--ease-smooth);
}

.prob-bar.prob-bar-top { background: var(--primary); }

.prob-pct {
  font-size: .8rem;
  color: var(--text-muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ── Result cards (TCG pack opening) ────────────────────── */
.tcg-pack {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  margin-bottom: 22px;
  perspective: 1000px;
}

.tcg-card {
  position: relative;
  width: clamp(150px, 44vw, 196px);
  aspect-ratio: 5 / 7;
  border-radius: 14px;
  padding: 4px;
  background: linear-gradient(150deg,
    hsl(var(--card-hue), 58%, 64%),
    hsl(calc(var(--card-hue) + 40), 52%, 40%));
  box-shadow: var(--shadow-lg);
  transform-origin: center bottom;
  animation: tcgIn .6s var(--ease-spring) backwards;
  animation-delay: calc(var(--i) * .14s);
  overflow: hidden;
}

.tcg-card-frame {
  height: 100%;
  border-radius: 11px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 8px;
}

.tcg-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.tcg-card-title {
  font-weight: 800;
  font-size: .9rem;
  line-height: 1.15;
  letter-spacing: -.02em;
}
.tcg-card-conf {
  flex-shrink: 0;
  font-size: .72rem;
  font-weight: 700;
  color: #fff;
  background: hsl(var(--card-hue), 45%, 44%);
  border-radius: 999px;
  padding: 2px 8px;
}

.tcg-card-art {
  flex: 1;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: radial-gradient(circle at 50% 38%,
    hsl(var(--card-hue), 60%, 90%),
    hsl(var(--card-hue), 45%, 74%));
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.tcg-card-frog {
  font-size: 3.4rem;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.25));
  animation: tcgBob 3s ease-in-out infinite;
}

.tcg-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .58rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-light);
}
.tcg-card-rarity { color: var(--success); font-weight: 700; }

.tcg-card-close {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.35);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .2s;
}
.tcg-card:hover .tcg-card-close,
.tcg-card:focus-within .tcg-card-close { opacity: 1; }

.tcg-card-shine {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 30%, rgba(255,255,255,.55) 48%, transparent 62%);
  transform: translateX(-120%);
  animation: tcgShine 1.1s var(--ease-out) backwards;
  animation-delay: calc(var(--i) * .14s + .4s);
}

@keyframes tcgIn {
  0%   { opacity: 0; transform: translateY(48px) scale(.6) rotate(-7deg); }
  60%  { opacity: 1; }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}
@keyframes tcgShine {
  to { transform: translateX(120%); }
}
@keyframes tcgBob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-5px); }
}

.tcg-card.tcg-card-dismiss {
  animation: tcgOut .5s var(--ease-out) forwards;
  pointer-events: none;
}
@keyframes tcgOut {
  0%   { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
  100% { opacity: 0; transform: translateY(-64px) scale(.7) rotate(8deg); }
}

/* ── Low-confidence section ── */
.lowconf { margin-top: 4px; }
.lowconf-title {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

@media (prefers-reduced-motion: reduce) {
  .tcg-card, .tcg-card-shine, .tcg-card-frog { animation: none; }
  .tcg-card.tcg-card-dismiss { animation: none; opacity: 0; }
}

/* ── Boot Screen ────────────────────────────────────────── */
.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #0a1608;
  overflow: hidden;
}

.boot-screen.boot-exit {
  animation: bootExit .7s var(--ease-smooth) forwards;
  pointer-events: none;
}

@keyframes bootExit {
  0%   { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.04); }
}

/* ── Welcome card ── */
.welcome-card {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  animation: welcomeIn .6s var(--ease-spring) forwards;
}

@keyframes welcomeIn {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 18px)); }
  to   { opacity: 1; transform: translate(-50%, -50%); }
}

.welcome-icon {
  font-size: 4rem;
  line-height: 1;
  filter: drop-shadow(0 6px 24px rgba(0, 0, 0, .45));
}

.welcome-title {
  margin: 0;
  font-size: 2.4rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -.03em;
}

.welcome-tagline {
  margin: 0;
  font-size: 1rem;
  color: rgba(255, 255, 255, .55);
  line-height: 1.5;
  max-width: 280px;
}

/* ── Loading dots ── */
.boot-loader {
  display: flex;
  gap: 7px;
  margin-top: 8px;
}
.boot-loader span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .55);
  animation: bootDot 1.2s ease-in-out infinite;
}
.boot-loader span:nth-child(2) { animation-delay: .18s; }
.boot-loader span:nth-child(3) { animation-delay: .36s; }

@keyframes bootDot {
  0%, 80%, 100% { opacity: .25; transform: scale(.8); }
  40%           { opacity: 1;   transform: scale(1); }
}

/* ── Skip button (shown if server takes too long) ── */
.boot-skip-btn {
  position: absolute;
  bottom: 44px;
  left: 50%;
  transform: translateX(-50%);
  background: none;
  border: 1px solid rgba(255, 255, 255, .25);
  color: rgba(255, 255, 255, .5);
  font-family: inherit;
  font-size: .7rem;
  letter-spacing: .06em;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.boot-skip-btn:hover { border-color: rgba(255,255,255,.5); color: rgba(255,255,255,.8); }

/* ── Utilities ─────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Feedback toast ─────────────────────────────────────── */
@keyframes fadeOut  { from { opacity: 1; } to { opacity: 0; } }
@keyframes slideUp  { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
.feedback-toast {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--success);
  color: #fff;
  padding: 10px 22px;
  border-radius: 999px;
  font-size: .875rem;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  z-index: 250;
  animation: slideUp .25s var(--ease-spring);
}
.feedback-toast.toast-exit {
  animation: fadeOut .3s var(--ease-out) forwards;
}

/* Post-analysis scroll target — keep clear of the sticky header */
#result-panel { scroll-margin-top: calc(var(--header-h) + 12px); }

/* ── "Go to Feedback" floating arrow ─────────────────────
   After an analysis the page centers on the results; if feedback mode is on,
   this quiet pill points down to the feedback form. Pops in, pulses gently,
   pops out when clicked. */
.feedback-arrow {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 8px 18px 6px;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 250;
  animation: arrow-pop-in .45s var(--ease-spring) both;
}

.feedback-arrow:hover {
  color: var(--text);
  border-color: var(--primary-dim);
}

.feedback-arrow svg {
  width: 20px;
  height: 20px;
  animation: arrow-pulse 1.8s ease-in-out infinite;
}

.feedback-arrow-caption {
  font-size: .8rem;
  font-weight: 500;
  white-space: nowrap;
}

@keyframes arrow-pop-in {
  from { opacity: 0; transform: translateX(-50%) scale(.6); }
  to   { opacity: 1; transform: translateX(-50%) scale(1); }
}

@keyframes arrow-pulse {
  0%, 100% { transform: translateY(0)   scale(1); }
  50%      { transform: translateY(3px) scale(1.06); }
}

.feedback-arrow.feedback-arrow-exit {
  /* gentle pop: brief swell, then shrink + fade */
  animation: arrow-pop-out .3s ease-in forwards;
}

@keyframes arrow-pop-out {
  0%   { opacity: 1; transform: translateX(-50%) scale(1); }
  30%  { opacity: 1; transform: translateX(-50%) scale(1.08); }
  100% { opacity: 0; transform: translateX(-50%) scale(.5); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-6px); }
  75%       { transform: translateX(6px); }
}

.shake { animation: shake .3s ease; }

/* ─────────────────────────────────────────────────────────
   Desktop overrides  (min-width: 620px)
   ───────────────────────────────────────────────────────── */
@media (min-width: 620px) {
  :root {
    --header-h: 56px;
  }

  .nav { max-width: var(--max-w); margin: 0 auto; padding: 0 20px; gap: 8px; }
  .nav-brand { flex: none; margin-right: 8px; }
  .nav-links { display: flex; gap: 2px; flex: 1; }

  .nav-link {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-muted);
    font-size: .875rem;
    font-weight: 500;
    transition:
      background  .2s var(--ease-out),
      color       .2s var(--ease-out),
      transform   .18s var(--ease-spring);
  }

  .nav-link:hover {
    background: var(--primary-light);
    color: var(--primary);
    transform: translateY(-1px);
  }

  .nav-link.active {
    background: var(--primary-light);
    color: var(--primary);
  }

  .bottom-nav { display: none; }

  .main {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 32px 20px 64px;
  }

  .page-title { font-size: 1.5rem; margin-bottom: 24px; }

  .input-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    flex-direction: unset;
    min-height: 200px;
  }

  .input-divider {
    flex-direction: column;
    height: auto;
    border: none;
    padding: 0 20px;
    gap: 0;
    position: relative;
  }

  .input-divider::before,
  .input-divider::after {
    display: none;
  }

  .input-divider::after {
    content: '';
    display: block;
    position: absolute;
    top: 20px;
    bottom: 20px;
    left: 50%;
    width: 1px;
    height: auto;
    background: var(--border);
    transform: translateX(-50%);
    flex: none;
  }

  .input-divider span {
    background: var(--surface);
    padding: 6px 0;
    z-index: 1;
    position: relative;
  }

  .upload-zone { padding: 32px 24px; }
  .record-zone { padding: 32px 24px; }

  #analyze-btn { width: auto; }

  .panel { padding: 24px; }
  .panel-actions { display: flex; gap: 8px; }

  .about-section {
    padding: 24px 28px;
    margin-bottom: 14px;
    transition: transform .22s var(--ease-smooth), box-shadow .22s var(--ease-smooth);
  }
  .about-section:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }

  /* Restore hover states */
  .btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(91,123,96,.38);
  }

  .btn-secondary:hover:not(:disabled) {
    background: var(--border);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
  }

  .btn-ghost:hover:not(:disabled) {
    background: var(--primary-light);
    color: var(--primary);
    transform: translateY(-1px);
  }

  .btn-success:hover:not(:disabled) {
    background: #3d5e3f;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(78,112,80,.38);
  }

  .btn-outline-danger:hover:not(:disabled) {
    background: var(--danger-light);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(184,85,69,.18);
  }

  .upload-zone:hover {
    transform: none; /* contained within card, no lift */
  }

  .feedback-options .btn { flex: none; }
}

/* ── Very small phones (< 360px) ───────────────────────── */
@media (max-width: 359px) {
  .main { padding-left: 12px; padding-right: 12px; }
  .panel { padding: 16px; }
  .record-btn { width: 68px; height: 68px; }
}
