*, *::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;
  --blue:     #3b82f6;
  --green:    #10b981;
  --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; display: flex; flex-direction: column; }

/* ── HEADER ── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  position: sticky; top: 0; z-index: 200;
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.site-header h1 { font-size: 1.1rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.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; }

/* ── TABS ── */
.tab-bar {
  display: flex; gap: 4px; padding: 12px 16px 0;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
}
.tab-btn {
  padding: 10px 22px;
  border: none; background: transparent;
  font-size: 0.9rem; font-weight: 700; font-family: inherit;
  color: var(--muted); cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── VIEWS ── */
.view { display: none; flex: 1; flex-direction: column; }
.view.visible { display: flex; }

/* ── PALETTE ── */
.palette {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  flex-shrink: 0;
}
.palette-label { font-size: 0.72rem; font-weight: 700; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 8px; }
.palette-btns { display: flex; gap: 8px; flex-wrap: wrap; }

.palette-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 10px;
  min-width: 62px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer; font-family: inherit;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
  border-top: 3px solid var(--node-color, var(--accent));
  -webkit-tap-highlight-color: transparent;
}
.palette-btn:active { transform: scale(0.94); }
.palette-btn:hover  { box-shadow: var(--shadow-md); border-color: var(--node-color, var(--accent)); }
.pb-emoji { font-size: 1.5rem; line-height: 1; }
.pb-name  { font-size: 0.68rem; font-weight: 700; color: var(--muted); }

/* ── BUILD STATUS ── */
.build-status {
  padding: 8px 16px;
  font-size: 0.82rem; color: var(--muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 36px;
}

/* ── CYTOSCAPE CANVAS ── */
.cy-canvas {
  flex: 1;
  min-height: 300px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
}

/* ── CONTROLS ── */
.controls-row {
  display: flex; gap: 8px;
  padding: 10px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.save-bar {
  display: flex; gap: 8px;
  padding: 10px 12px;
  background: var(--bg);
  flex-shrink: 0;
}
.save-bar input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.92rem; font-family: inherit;
  background: var(--surface); color: var(--text);
}
.save-bar input:focus { outline: none; border-color: var(--accent); }

.ctrl-btn {
  padding: 10px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-size: 0.88rem; font-weight: 700; font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.ctrl-btn:hover   { background: var(--bg); }
.ctrl-btn:active  { transform: scale(0.96); }
.ctrl-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.ctrl-btn.primary:hover { background: #d44e22; }
.ctrl-btn.primary:disabled { background: #ccc; border-color: #ccc; cursor: not-allowed; }
.ctrl-btn.danger  { color: #ef4444; border-color: #ef4444; }
.ctrl-btn.danger:hover { background: #fef2f2; }

/* ── GALLERY ── */
.gallery-wrap { padding: 20px 16px 80px; flex: 1; }
.gallery-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.gallery-header h2 { font-size: 1.2rem; font-weight: 700; }
.gallery-count { font-size: 0.85rem; color: var(--muted); }

.gallery-empty {
  text-align: center; padding: 60px 24px; color: var(--muted);
}
.ge-icon { font-size: 3rem; display: block; margin-bottom: 12px; }
.gallery-empty p { font-size: 0.95rem; line-height: 1.6; }

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

.gallery-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s;
}
.gallery-card:hover { box-shadow: var(--shadow-md); }

.gc-preview {
  background: var(--bg);
  padding: 12px;
  min-height: 130px;
  display: flex; align-items: center; justify-content: center;
  border-bottom: 1px solid var(--border);
}
.gc-preview svg { display: block; max-width: 100%; }

.gc-body { padding: 14px; }
.gc-name { font-size: 1.05rem; font-weight: 700; margin-bottom: 4px; }
.gc-summary { font-size: 1rem; margin-bottom: 4px; letter-spacing: 0.05em; }
.gc-date { font-size: 0.73rem; color: var(--muted); margin-bottom: 8px; }
.gc-fact {
  font-size: 0.78rem; line-height: 1.5;
  color: #92400e; background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius-sm);
  padding: 7px 10px; margin-bottom: 10px;
}
.gc-actions { display: flex; gap: 8px; }

.gc-btn {
  flex: 1; padding: 9px 8px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: transparent;
  font-size: 0.83rem; font-weight: 600; font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.gc-btn:active { transform: scale(0.96); }
.gc-btn.remix  { color: var(--blue); border-color: var(--blue); }
.gc-btn.remix:hover  { background: #eff6ff; }
.gc-btn.delete { color: #ef4444; border-color: #ef4444; }
.gc-btn.delete:hover { background: #fef2f2; }

/* ── TOAST ── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: #1a1a1a; color: #fff;
  padding: 12px 24px; border-radius: 24px;
  font-size: 0.9rem; font-weight: 600;
  z-index: 900; pointer-events: none;
  opacity: 0; transition: transform 0.25s, opacity 0.25s;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ── SHOWCASE FOOTER ── */
.showcase-footer {
  text-align: center; padding: 20px 16px 36px;
  font-size: 0.82rem; color: var(--muted);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.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; }

/* ── UTIL ── */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

/* ── RESPONSIVE ── */
@media (min-width: 600px) {
  .palette-btns { flex-wrap: nowrap; }
  .controls-row { flex-wrap: nowrap; }
}

@media (min-width: 900px) {
  .cy-canvas { min-height: 400px; }
}

/* ═══════════ v2 UPLIFT — age modes, category tabs, physics UI ═══════════ */

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

/* ── CATEGORY TABS ── */
.cat-tabs {
  display: flex; gap: 6px; overflow-x: auto;
  padding-bottom: 8px; margin-bottom: 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.cat-tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 58px; min-height: 48px;
  padding: 6px 10px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer; font-family: inherit;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
}
.cat-tab:active { transform: scale(0.94); }
.cat-tab.active { border-color: var(--accent); background: #fff4f0; }
.ct-emoji { font-size: 1.25rem; line-height: 1; }
.ct-label { font-size: 0.62rem; font-weight: 700; color: var(--muted); }
.cat-tab.active .ct-label { color: var(--accent); }

body[data-mode="little"] .cat-tab { min-width: 68px; min-height: 60px; }
body[data-mode="little"] .ct-emoji { font-size: 1.6rem; }

/* ── PALETTE (little mode = huge targets) ── */
.palette-btns { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
.palette-btn { min-height: 64px; }
body[data-mode="little"] .palette-btn { min-width: 84px; min-height: 84px; }
body[data-mode="little"] .pb-emoji { font-size: 2.2rem; }
body[data-mode="little"] .pb-name { font-size: 0.72rem; }
.palette-btn.locked { opacity: 0.55; }
.palette-btn.locked .pb-emoji { filter: grayscale(1); }

/* ── CANVAS WRAP + STATS ── */
.cy-wrap { flex: 1; display: flex; flex-direction: column; position: relative; min-height: 300px; }
.cy-canvas { touch-action: none; }  /* stops iOS page-pinch fighting cytoscape gestures */
.stats-bar {
  position: absolute; left: 10px; bottom: 10px;
  background: rgba(255,255,255,0.92);
  border: 1.5px solid var(--border); border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.78rem; font-weight: 700; color: var(--text);
  pointer-events: none; z-index: 10;
  max-width: calc(100% - 20px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stats-bar:empty { display: none; }

/* ── BIG CONTROLS IN LITTLE MODE ── */
body[data-mode="little"] .ctrl-btn { min-height: 64px; font-size: 1.05rem; padding: 12px 20px; }
body[data-mode="little"] .save-bar input { min-height: 56px; font-size: 1.05rem; }
body[data-mode="little"] .tab-btn { padding: 14px 26px; font-size: 1rem; }

/* ── HOW IT REALLY WORKS (jsontology pattern: dark code on light page) ── */
.how-panel {
  margin: 0 16px 16px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1.5px solid var(--border); border-radius: var(--radius);
}
.how-panel h3 { font-size: 1rem; font-weight: 800; margin-bottom: 8px; }
.how-panel p { font-size: 0.88rem; line-height: 1.65; color: var(--text); margin-bottom: 10px; max-width: 68ch; }
.how-json {
  background: #1e1e2e; color: #cdd6f4;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 0.75rem;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  white-space: pre-wrap; word-break: break-word;
  max-height: 220px; overflow-y: auto;
  margin-bottom: 8px;
}
.how-foot { font-size: 0.78rem !important; color: var(--muted) !important; }

/* ── CELEBRATION OVERLAY ── */
.celebrate-overlay {
  position: fixed; inset: 0; z-index: 800;
  background: rgba(20,16,12,0.55); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.celebrate-overlay[hidden] { display: none; }
.celebrate-box {
  background: var(--surface);
  border-radius: 22px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.28);
  padding: 28px 24px;
  max-width: 440px; width: 100%;
  text-align: center;
  max-height: 92dvh; overflow-y: auto;
  animation: celebrate-in 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes celebrate-in { from { opacity: 0; transform: scale(0.85); } to { opacity: 1; transform: scale(1); } }
.cb-emoji { font-size: 3rem; margin-bottom: 6px; }
.celebrate-box h2 { font-size: 1.45rem; font-weight: 800; margin-bottom: 12px; }
.cb-preview { display: flex; justify-content: center; margin-bottom: 10px; }
.cb-preview svg { background: var(--bg); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.cb-stats { font-size: 0.88rem; color: var(--muted); line-height: 1.6; margin-bottom: 18px; }
.cb-big-line { font-size: 1.3rem; letter-spacing: 0.08em; }
.cb-actions { display: flex; flex-direction: column; gap: 10px; }
.cb-actions .ctrl-btn { width: 100%; min-height: 52px; }
.cb-exit { display: flex; align-items: center; justify-content: center; text-decoration: none; }
body[data-mode="little"] .cb-actions .ctrl-btn { min-height: 64px; }

/* ── GALLERY EXTRAS ── */
.gc-stats { font-size: 0.72rem; font-weight: 800; color: var(--blue); letter-spacing: 0.04em; margin-bottom: 4px; }
.gc-btn { min-height: 48px; }
.gc-btn.delete.armed { background: #ef4444; color: #fff; }

/* ── REDUCED MOTION ── */
@media (prefers-reduced-motion: reduce) {
  .celebrate-box { animation: none; }
  .palette-btn, .cat-tab, .ctrl-btn, .gc-btn { transition: none; }
}
