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

:root {
  --bg:      #faf9f7;
  --surface: #ffffff;
  --border:  rgba(0,0,0,0.09);
  --text:    #1a1a1a;
  --muted:   #6b7280;
  --accent:  #e85d2f;
  --green:   #10b981;
  --blue:    #3b82f6;
  --radius:  14px;
  --radius-sm: 8px;
  --shadow:  0 2px 8px rgba(0,0,0,0.08);
  --shadow-md:0 4px 16px rgba(0,0,0,0.11);
  font-size: 16px;
}

html { background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, sans-serif; }
body { min-height: 100dvh; padding-bottom: 40px; }

/* ── HEADER ── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  position: sticky; top: 0; z-index: 200;
}
.header-left { display: flex; align-items: center; gap: 10px; font-size: 1.4rem; }
.header-left h1 { font-size: 1.1rem; font-weight: 700; line-height: 1.1; }
.level-badge {
  display: inline-block;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em;
  background: var(--bg); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 20px; color: var(--muted); margin-top: 2px;
}
.header-right { display: flex; align-items: center; gap: 10px; }
.score-label { font-size: 0.75rem; color: var(--muted); }
.score-val { font-size: 1.2rem; font-weight: 800; color: var(--accent); min-width: 36px; text-align: right; }
.exit-btn { font-size: 0.78rem; color: var(--muted); text-decoration: none; white-space: nowrap; padding: 4px 8px; border-radius: 6px; }
.exit-btn:hover { color: var(--accent); }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── MAIN ── */
#game { max-width: 960px; margin: 0 auto; padding: 0 16px; }

/* ── CARD SECTION ── */
.card-section { padding: 20px 0 8px; text-align: center; }
.hint-text { font-size: 0.9rem; color: var(--muted); margin-bottom: 14px; min-height: 1.4em; }

.card-stage {
  display: flex; justify-content: center; margin-bottom: 12px;
  user-select: none; -webkit-user-select: none;
}

.animal-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  width: 120px; height: 130px;
  background: var(--surface);
  border: 2.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  cursor: grab;
  touch-action: none;
  transition: box-shadow 0.15s;
  position: relative;
}
.animal-card:active, .animal-card.dragging { cursor: grabbing; box-shadow: 0 8px 28px rgba(0,0,0,0.16); }
.animal-card.dragging { z-index: 1000; }
.card-emoji { font-size: 3.5rem; line-height: 1; display: block; }
.card-name  { font-size: 0.85rem; font-weight: 700; color: var(--text); }

/* Card animations */
@keyframes fly-in {
  from { opacity: 0; transform: translateY(-20px) scale(0.85); }
  to   { opacity: 1; transform: translateY(0)     scale(1);    }
}
@keyframes pop-in {
  0%   { transform: scale(1);    }
  40%  { transform: scale(1.25); }
  70%  { transform: scale(0.9);  }
  100% { transform: scale(0) translateY(-40px); opacity: 0; }
}
.animal-card.fly-in    { animation: fly-in 0.3s ease-out; }
.animal-card.pop-in    { animation: pop-in 0.5s ease forwards; }

.wrong-hint {
  font-size: 0.85rem; color: var(--accent); font-weight: 600;
  padding: 6px 14px; background: #fff5f2; border: 1px solid #fecaca;
  border-radius: 20px; display: inline-block; margin-bottom: 8px;
}

/* ── PROGRESS ── */
.progress-row { display: flex; align-items: center; gap: 10px; justify-content: center; margin-top: 10px; }
.progress-track {
  width: 180px; height: 8px;
  background: var(--border); border-radius: 4px; overflow: hidden;
}
.progress-fill { height: 100%; background: var(--green); border-radius: 4px; transition: width 0.3s ease; }
.progress-text { font-size: 0.78rem; color: var(--muted); font-weight: 600; }

/* ── TREE SECTION ── */
.tree-section { padding: 12px 0 24px; }
.tree-label { font-size: 0.82rem; font-weight: 700; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 12px; text-align: center; }

.tree-container {
  display: flex; gap: 12px; flex-wrap: wrap; justify-content: center;
  overflow-x: auto; padding-bottom: 8px;
}

/* ── TREE NODES ── */
.t-node {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  min-width: 100px;
  flex: 1 0 auto;
  max-width: 100%;
}

.t-header {
  padding: 8px 12px;
  font-size: 0.82rem; font-weight: 700;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.t-children {
  display: flex; gap: 8px; padding: 8px;
  flex-wrap: wrap;
}

/* Depth-based background tints */
.t-node.d0 > .t-header { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.t-node.d0 { border-color: #86efac; }
.t-node.d1 > .t-header { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.t-node.d1 { border-color: #93c5fd; }
.t-node.d2 > .t-header { background: #fefce8; color: #854d0e; border-color: #fde68a; }
.t-node.d2 { border-color: #fcd34d; }
.t-node.d3 > .t-header { background: #fdf4ff; color: #6b21a8; border-color: #e9d5ff; }
.t-node.d3 { border-color: #c084fc; }

/* Drop zones */
.drop-zone {
  cursor: pointer;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
}
.drop-zone:hover, .drop-zone.hover {
  background: #fffbeb;
  transform: scale(1.03);
  box-shadow: var(--shadow-md);
}
.drop-zone.hover { box-shadow: 0 0 0 3px var(--accent); }

/* Sorted pile */
.sorted-pile {
  padding: 6px 8px;
  min-height: 36px;
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
}
.animal-chip {
  font-size: 1.5rem; display: inline-block;
  animation: chip-in 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes chip-in {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* Shake animation for wrong drop */
@keyframes shake-no {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX(8px); }
  60%      { transform: translateX(-6px); }
  80%      { transform: translateX(6px); }
}
.drop-zone.shake-no { animation: shake-no 0.45s ease; }

/* ── COMPLETE OVERLAY ── */
.complete-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  backdrop-filter: blur(4px);
}
.complete-box {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.25);
  padding: 32px 28px;
  max-width: 480px; width: 100%;
  text-align: center;
  max-height: 90dvh; overflow-y: auto;
}
.complete-emoji { font-size: 3rem; margin-bottom: 8px; }
.complete-box h2 { font-size: 1.6rem; font-weight: 800; margin-bottom: 8px; }
.complete-box p  { color: var(--muted); margin-bottom: 20px; line-height: 1.6; }

.json-toggle-btn {
  display: block; width: 100%;
  padding: 12px 16px;
  background: #1e1e2e; color: #cdd6f4;
  border: none; border-radius: var(--radius-sm);
  font-size: 0.92rem; font-weight: 700; font-family: inherit;
  cursor: pointer; margin-bottom: 12px;
  transition: background 0.15s;
}
.json-toggle-btn:hover { background: #313244; }

.json-view {
  background: #1e1e2e; color: #cdd6f4;
  border-radius: var(--radius-sm);
  padding: 16px; font-size: 0.75rem;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  text-align: left; white-space: pre-wrap; word-break: break-word;
  overflow-x: auto; margin-bottom: 12px;
  max-height: 240px; overflow-y: auto;
}

.next-btn {
  display: block; width: 100%;
  padding: 14px 16px;
  background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius-sm);
  font-size: 1rem; font-weight: 800; font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.next-btn:hover    { background: #d44e22; }
.next-btn:active   { transform: scale(0.97); }

/* ── CONFETTI ── */
#confetti-canvas {
  position: fixed; inset: 0; pointer-events: none; z-index: 600;
  width: 100%; height: 100%;
}

/* ── SHOWCASE FOOTER ── */
.showcase-footer {
  text-align: center;
  padding: 24px 16px 40px;
  font-size: 0.82rem; color: var(--muted);
  border-top: 1px solid var(--border);
  margin-top: 24px;
}
.sf-link { color: var(--muted); text-decoration: none; }
.sf-link:hover { color: var(--accent); }
.sf-link strong { color: var(--text); }
.sf-sep { margin: 0 10px; opacity: 0.4; }

/* ── RESPONSIVE ── */
@media (min-width: 600px) {
  .card-emoji { font-size: 4rem; }
  .animal-card { width: 140px; height: 150px; }
}

@media (min-width: 768px) {
  #game { padding: 0 24px; }
  .tree-container { justify-content: flex-start; }
  .t-node { flex: 0 1 auto; }
}

/* ═══════════ v2 UPLIFT — age modes, guides, forgiving targets ═══════════ */

body:not([data-mode="big"]) .big-only { display: none !important; }

.score-chip { font-size: 0.85rem; font-weight: 800; color: var(--accent); margin-right: 4px; }

/* ── LITTLE MODE: huge everything, gentle everything ── */
body[data-mode="little"] .animal-card { width: 170px; height: 180px; }
body[data-mode="little"] .card-emoji { font-size: 5rem; }
body[data-mode="little"] .card-name { font-size: 1.05rem; }
body[data-mode="little"] .t-header { font-size: 1.15rem; padding: 16px 18px; }
body[data-mode="little"] .drop-zone { min-width: 150px; min-height: 130px; }
body[data-mode="little"] .sorted-pile { min-height: 64px; }
body[data-mode="little"] .animal-chip { font-size: 2rem; }
body[data-mode="little"] .hint-text { font-size: 1.05rem; color: var(--text); }
body[data-mode="little"] .tree-container { gap: 18px; }

/* All drop zones get invisible expanded hit area via generous padding */
.drop-zone { min-width: 120px; min-height: 90px; position: relative; }
.drop-zone::after { content: ''; position: absolute; inset: -14px; }
body[data-mode="little"] .drop-zone::after { inset: -20px; }

/* ── GENTLE WOBBLE (little mode wrong answer) ── */
@keyframes wobble-no {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-2.5deg); }
  50% { transform: rotate(2.5deg); }
  75% { transform: rotate(-1.5deg); }
}
.drop-zone.wobble-no { animation: wobble-no 0.55s ease; }

/* ── GUIDE GLOW toward the correct bucket ── */
@keyframes guide-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(16,185,129,0.35); }
  50%      { box-shadow: 0 0 0 8px rgba(16,185,129,0.15); }
}
.drop-zone.guide { animation: guide-pulse 1.2s ease-in-out infinite; border-color: var(--green); }
@keyframes guide-strong {
  0%, 100% { box-shadow: 0 0 0 4px rgba(16,185,129,0.55); transform: scale(1); }
  50%      { box-shadow: 0 0 0 12px rgba(16,185,129,0.2);  transform: scale(1.04); }
}
.drop-zone.guide-strong { animation: guide-strong 0.9s ease-in-out infinite; border-color: var(--green); background: #f0fdf4; }

/* ── COMPLETE OVERLAY EXTRAS ── */
.complete-stars { font-size: 2.2rem; letter-spacing: 0.15em; margin-bottom: 14px; }
.taxonomy-note {
  font-size: 0.85rem !important; line-height: 1.65 !important;
  text-align: left; color: var(--text) !important;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: 12px !important;
}
.next-btn { min-height: 56px; }
body[data-mode="little"] .next-btn { min-height: 68px; font-size: 1.15rem; }
.complete-secondary { display: flex; gap: 8px; margin-top: 10px; }
.sec-btn {
  flex: 1; min-height: 48px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  background: transparent; color: var(--muted);
  font-size: 0.85rem; font-weight: 700; font-family: inherit; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: flex; align-items: center; justify-content: center;
  text-decoration: none;
}
.sec-btn:hover { color: var(--text); background: var(--bg); }
.sec-btn:active { transform: scale(0.96); }
body[data-mode="little"] .sec-btn { min-height: 60px; font-size: 0.95rem; }

/* ── UNDO BUTTON (F-006 fix) ── */
.ss-undo {
  margin: 10px auto 0;
  display: block;
  padding: 8px 20px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem; font-weight: 700; font-family: inherit;
  color: var(--muted); cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.ss-undo:not(:disabled):hover { background: var(--bg); color: var(--text); }
.ss-undo:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── SCIENTIST PANEL (live JSON) ── */
.scientist-panel {
  max-width: 960px; margin: 0 auto;
  padding: 0 16px 24px;
  animation: sp-slide-in 0.3s ease-out;
}
@keyframes sp-slide-in {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.sp-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 8px;
}
.sp-label {
  font-size: 0.78rem; font-weight: 800; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted);
}
.sp-mode-btns { display: flex; gap: 4px; }
.sp-mode-btn {
  padding: 4px 10px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-size: 0.72rem; font-weight: 700; font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--muted); cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.sp-mode-btn.active, .sp-mode-btn[aria-pressed="true"] {
  background: #1e1e2e; color: #a6e3a1; border-color: #1e1e2e;
}
.ss-live-json {
  background: #1e1e2e; color: #cdd6f4;
  border-radius: var(--radius-sm);
  padding: 14px; font-size: 0.72rem;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  text-align: left; white-space: pre-wrap; word-break: break-word;
  overflow-x: auto; max-height: 220px; overflow-y: auto;
  transition: max-height 0.3s ease;
}

/* ── JSON HEADER (complete-overlay mode toggle) ── */
.json-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 8px;
}
.json-header-label {
  font-size: 0.75rem; font-weight: 700; color: var(--muted);
  letter-spacing: 0.05em; text-transform: uppercase;
}
.json-mode-btns { display: flex; gap: 4px; }
.json-mode-btn {
  padding: 4px 10px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-size: 0.72rem; font-weight: 700; font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--muted); cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.json-mode-btn.active, .json-mode-btn[aria-pressed="true"] {
  background: #1e1e2e; color: #a6e3a1; border-color: #1e1e2e;
}

/* Victory reveal animation */
@keyframes victory-reveal {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
.json-view.victory-reveal-active {
  animation: victory-reveal 0.5s cubic-bezier(0.16,1,0.3,1) forwards;
}

@media (prefers-reduced-motion: reduce) {
  .drop-zone.guide, .drop-zone.guide-strong, .drop-zone.wobble-no, .drop-zone.shake-no { animation: none; }
  .drop-zone.guide, .drop-zone.guide-strong { box-shadow: 0 0 0 4px rgba(16,185,129,0.5); }
  .animal-card.fly-in, .animal-card.pop-in { animation: none; }
}
