/* Lichen v0.3 — visual substrate per biogame-fun-and-visual-meta
 * Okabe-Ito CVD-safe palette · system-ui (Atkinson recommended; CSP-compatible fallback)
 * Spring-feel easing · reduced-motion-first · WCAG 2.3.3 compliant
 *
 * Design principles applied (cycle-9 swarm synthesis):
 *   V1 vitality-as-organism-density (Suika principle) — see lichen.js renderOrganisms()
 *   V2 figure-ground separation (Gestalt) — alga=beads, fungus=filaments, distinct shape language
 *   V3 signifier-on-action-surface (Norman) — tap-organism IS the action
 *   V4 Okabe-Ito palette + spring easing + reduced-motion fallback
 */

:root {
  /* Okabe-Ito CVD-safe palette (Nature-adopted, 2008) */
  --bg-deep:    #1a1f1c;
  --bg-mid:     #242b27;
  --surface:    #2f3833;
  --ink:        #e8ebe6;
  --ink-mute:   #8a948c;
  --line:       #3a4540;

  --alga:       #56B4E9;   /* sky blue · autotroph · cool */
  --alga-low:   #2c5b75;
  --alga-halo:  rgba(86,180,233,0.08);

  --fungus:     #E69F00;   /* amber · heterotroph · warm */
  --fungus-low: #735030;
  --fungus-halo:rgba(230,159,0,0.07);

  --bond:       #009E73;   /* bluish-green, thriving cooperation */
  --warn:       #D55E00;   /* vermillion, crisis */
  --danger:     #b04a3a;

  /* Motion: spring-feel for organic, calm for chrome */
  --ease-organic: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-calm:    cubic-bezier(0.4, 0.0, 0.2, 1);
  --dur-breath:  4000ms;
  --dur-impact:   600ms;
  --dur-settle:  1200ms;

  /* Type — system-ui sans-serif, drop Georgia (signaled "blog post" not "game") */
  --font-system: system-ui, -apple-system, "Segoe UI", "Atkinson Hyperlegible", "Inter", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* WCAG 2.3.3 reduced-motion: degrade to opacity/saturation only */
@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-breath: 0ms;
    --dur-impact: 200ms;
    --dur-settle: 200ms;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 1rem 1rem 3rem;
  font-family: var(--font-system);
  background: radial-gradient(ellipse at 50% 30%, var(--bg-mid), var(--bg-deep) 70%);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  display: grid;
  gap: 1rem;
}

/* === Stage: the two organisms + bond arc === */
.stage {
  background: transparent;
  padding: 0.5rem 0 0;
  display: grid;
  place-items: center;
}

#organisms {
  width: 100%;
  height: auto;
  max-height: 60vh;
}

/* Idle "breathing" — the visual signature of two living beings phase-offset */
@keyframes breath-alga {
  0%, 100% { opacity: 0.92; transform: scale(1); }
  50%      { opacity: 1.00; transform: scale(1.02); }
}
@keyframes breath-fungus {
  0%, 100% { opacity: 0.94; transform: scale(0.98); }
  50%      { opacity: 1.00; transform: scale(1.015); }
}
@keyframes bond-flow {
  to { stroke-dashoffset: -28; }
}

#alga-beads {
  animation: breath-alga var(--dur-breath) ease-in-out infinite;
  transform-origin: center;
}
#fungus-filaments {
  animation: breath-fungus var(--dur-breath) ease-in-out infinite 1.3s;
  transform-origin: center;
}
#bond-arc {
  animation: bond-flow 3s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  #alga-beads, #fungus-filaments, #bond-arc {
    animation: none;
  }
}

/* Organism interactivity — tap is the action */
.organism {
  cursor: pointer;
  transition: filter 250ms var(--ease-calm);
}
.organism:focus-visible {
  outline: none;
}
.organism:focus-visible .halo {
  fill: rgba(255,255,255,0.06);
}
.organism:hover .halo {
  fill: rgba(255,255,255,0.04);
}

/* Tap response: anticipation → impact → settle, per Swink/Pichlmair */
.organism.tapped {
  animation: tap-pulse var(--dur-settle) var(--ease-organic);
}
@keyframes tap-pulse {
  0%   { transform: scale(1.00); }
  10%  { transform: scale(0.96); }   /* anticipation */
  25%  { transform: scale(1.08); }   /* impact */
  100% { transform: scale(1.00); }   /* spring settle */
}
@media (prefers-reduced-motion: reduce) {
  .organism.tapped {
    animation: none;
    filter: brightness(1.2);
  }
}

/* Concrete icons under each organism — universal-readable (☼ sun for alga, 💧 droplet for fungus) */
.org-glyph {
  font-size: 24px;
  fill: var(--ink-mute);
  pointer-events: none;
  user-select: none;
}

/* Beads (alga) and filaments (fungus) styled in JS where possible; defaults here */
.bead {
  fill: var(--alga);
  filter: drop-shadow(0 0 2px rgba(86,180,233,0.4));
}
.bead.dim { fill: var(--alga-low); filter: none; }

.filament {
  stroke: var(--fungus);
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  filter: drop-shadow(0 0 1px rgba(230,159,0,0.4));
}
.filament.dim { stroke: var(--fungus-low); filter: none; }

/* Crisis state (vitality < 20%): rim warning, no blink */
.organism.crit .halo { fill: rgba(213,94,0,0.10); }

/* === Prompt: ambient state text === */
.prompt {
  margin: 0;
  text-align: center;
  font-size: 1rem;
  color: var(--ink-mute);
  min-height: 1.5em;
  font-style: italic;
  letter-spacing: 0.01em;
}

/* === Action surface — secondary only (primary is tap-organism) === */
.more {
  background: transparent;
}
.more summary {
  text-align: center;
  color: var(--ink-mute);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.5rem;
  list-style: none;
}
.more summary::-webkit-details-marker { display: none; }
.more summary::after { content: " ▾"; }
.more[open] summary::after { content: " ▴"; }

.actions {
  display: grid;
  gap: 0.5rem;
  padding: 0.5rem 0;
}

.action {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.7rem 1rem;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: 6px;
  text-align: left;
  transition: background 200ms var(--ease-calm), transform 100ms;
}
.action:hover { background: var(--bg-mid); border-color: var(--bond); }
.action:active { transform: translateY(1px); }
.action:disabled { opacity: 0.5; cursor: not-allowed; }
.action.ghost { background: transparent; border-color: var(--line); }
.action.compact { padding: 0.5rem 0.9rem; text-align: center; }

/* === Meta strip — minimized lineage chrome === */
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--ink-mute);
  padding: 0.5rem 0.25rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.meta strong { color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 500; }
.meta .health strong { color: var(--bond); }

/* === Cards (collapsible secondary panels) === */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
}
.card summary {
  cursor: pointer;
  font-weight: 500;
  list-style: none;
  user-select: none;
}
.card summary::-webkit-details-marker { display: none; }
.card summary::before { content: "› "; color: var(--ink-mute); transition: transform 200ms; }
.card[open] summary::before { content: "⌄ "; }

/* Pair connection */
.hidden { display: none !important; }

.conn-block {
  display: grid;
  gap: 0.5rem;
  padding: 0.5rem 0 0;
}
.conn-block p { margin: 0.25rem 0; }
.join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}
#join-code {
  font: inherit;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg-deep);
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-family: var(--font-mono);
}
#join-code:focus {
  outline: none;
  border-color: var(--bond);
  box-shadow: 0 0 0 2px rgba(0,158,115,0.25);
}

.hint { color: var(--ink-mute); font-size: 0.85rem; }
.hint.danger { color: var(--warn); }

/* Recent event log */
#log ul {
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
}
#log li {
  padding: 0.4rem 0;
  border-top: 1px dotted var(--line);
  color: var(--ink-mute);
}
#log li:first-child {
  border-top: none;
  color: var(--ink);
}

/* Footer */
footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--ink-mute);
  padding: 1rem 0.25rem 0;
}
.version { font-family: var(--font-mono); opacity: 0.6; }

.link {
  background: none;
  border: none;
  color: var(--bond);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  padding: 0;
}
.link.danger { color: var(--danger); }

code {
  background: var(--bg-deep);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.85em;
}

/* Micro-survey overlay (cycle 11) */
.micro-survey {
  position: fixed;
  inset: 0;
  background: rgba(26, 31, 28, 0.78);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 50;
  animation: fade-in 300ms var(--ease-calm);
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.micro-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.5rem 1.25rem;
  max-width: 360px;
  width: calc(100% - 2rem);
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.micro-q {
  margin: 0 0 1rem;
  font-size: 1rem;
  color: var(--ink);
}
.micro-scale {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.4rem;
  margin: 0.5rem 0;
}
.micro-btn {
  background: var(--bg-deep);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.6rem 0;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: 4px;
  transition: background 200ms, border-color 200ms;
}
.micro-btn:hover { background: var(--bond); border-color: var(--bond); color: var(--bg-deep); }
.micro-btn:active { transform: translateY(1px); }
.micro-hint {
  margin: 0.75rem 0 0.5rem;
  font-size: 0.8rem;
  color: var(--ink-mute);
}
.micro-skip {
  margin-top: 0.5rem;
  font-size: 0.85rem;
}
@media (prefers-reduced-motion: reduce) {
  .micro-survey { animation: none; }
}

@media (max-width: 480px) {
  body { padding: 0.5rem 0.5rem 3rem; }
  .meta { gap: 0.5rem 0.9rem; font-size: 0.8rem; }
  .micro-scale { gap: 0.25rem; }
  .micro-btn { padding: 0.5rem 0; font-size: 0.85rem; }
}
