/* ==========================================================================
   murmur — a living population feeling the arc market.
   Aesthetic: warm paper + ink, gallery / scientific-plot. Nothing neon, no
   glass cards, no tables. The artwork is the whole page; the UI floats on it.
   Palette tokens are live: app.js retints --paper / --accent with the market
   temperature, so the whole scene slowly warms (hot) or cools (cold).

   Performance note: the field canvas repaints every frame, so the floating UI
   deliberately avoids backdrop-filter and heavy blend modes (they would force a
   re-blur / re-composite of the whole scene each frame). Panels use a plain
   translucent fill; the grain overlay is static and normally composited.
   ========================================================================== */

:root {
  /* --- live palette (overridden by app.js from the market temperature) --- */
  --paper: #f2eee6;                 /* warm bone */
  --panel: rgba(242, 238, 230, 0.88);
  --ink: #1a1a18;
  --ink-rgb: 26, 26, 24;
  --accent: #9a8c6e;                /* regime accent (calm = taupe) */
  --accent-rgb: 154, 140, 110;
  --hair: rgba(26, 26, 24, 0.14);   /* hairline borders */
  --muted: rgba(26, 26, 24, 0.5);

  /* --- static behavioural-state palette (earth tones) --- */
  --agitate: #c05e3c;
  --explore: #c99a3f;
  --aggregate: #5b7c8d;
  --rest: #8b9a86;

  /* --- type --- */
  --display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --cjk: "PingFang SC", "Hiragino Sans", "Microsoft YaHei", "Yu Gothic", "Malgun Gothic", sans-serif;

  --pad: clamp(14px, 2.4vw, 28px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;                 /* the field is the page; no scroll */
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { transition: background 1.6s linear; }

::selection { background: rgba(var(--accent-rgb), 0.24); }

/* ============ the generative field ============ */
#field {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 0;
  cursor: crosshair;
}

/* printed-paper grain — static & normally composited so it can be cached
   instead of re-blended over the repainting canvas every frame */
.grain {
  position: fixed; inset: 0; z-index: 3; pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* soft vignette to focus the swarm */
.vignette {
  position: fixed; inset: 0; z-index: 2; pointer-events: none;
  background: radial-gradient(120% 90% at 50% 45%, transparent 40%, rgba(var(--ink-rgb), 0.07) 100%);
}

/* ============ top bar ============ */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--pad);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.wordmark { display: flex; align-items: baseline; gap: 9px; }
.wordmark .mark { fill: var(--accent); opacity: 0.9; transform: translateY(4px); transition: fill 1.6s linear; }
.wordmark .name {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(22px, 3vw, 30px);
  letter-spacing: 0.01em;
  font-variation-settings: "opsz" 40;
  color: var(--ink);
}

.topmeta {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; letter-spacing: 0.14em; text-transform: lowercase;
  color: var(--muted);
}
.topmeta .sep { opacity: 0.4; }
.link-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0.5);
  transition: background 0.6s ease;
}
.link-dot.live { background: var(--accent); animation: breathe 3.4s ease-in-out infinite; }
.link-dot.off  { background: rgba(var(--ink-rgb), 0.3); }
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0.45); }
  50%      { box-shadow: 0 0 0 6px rgba(var(--accent-rgb), 0); }
}

/* ============ floating panels ============ */
.panel {
  position: fixed; z-index: 10;
  background: var(--panel);
  border: 1px solid var(--hair);
  border-radius: 2px;
  padding: 14px 16px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.4) inset, 0 8px 30px rgba(var(--ink-rgb), 0.05);
  transition: background 1.6s linear, border-color 1.6s linear, opacity 0.45s ease;
}
.panel-title {
  font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 10px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
}

/* --- temperature panel (bottom-left) --- */
.panel-temp { left: var(--pad); bottom: var(--pad); width: clamp(250px, 28vw, 340px); }
.regime-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.regime {
  font-family: var(--display); font-weight: 600;
  font-size: clamp(20px, 2.6vw, 26px);
  letter-spacing: 0.02em; text-transform: lowercase;
  color: var(--accent); transition: color 1.2s linear;
  font-variation-settings: "opsz" 60;
}
.temp-value {
  font-family: var(--display); font-weight: 300; font-style: italic;
  font-size: clamp(20px, 2.6vw, 26px);
  color: var(--ink); opacity: 0.82; font-variant-numeric: tabular-nums;
}
.meter {
  position: relative; height: 3px; margin: 12px 0 6px;
  background: rgba(var(--ink-rgb), 0.1); border-radius: 2px; overflow: visible;
}
.meter-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 50%;
  background: var(--accent); border-radius: 2px;
  transition: width 1.1s cubic-bezier(0.22, 1, 0.36, 1), background 1.2s linear;
}
.meter-tick { position: absolute; top: -3px; width: 1px; height: 9px; background: rgba(var(--ink-rgb), 0.28); }
.meter-scale {
  display: flex; justify-content: space-between;
  font-size: 9px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); opacity: 0.7;
}
.micro {
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--hair);
  display: grid; grid-template-columns: 1fr 1fr; gap: 7px 14px;
}
.micro > div { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.micro dt { font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.micro dd { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--ink); opacity: 0.85; }

/* temperature history ribbon (client-side rolling record of the market temperature) */
.temp-history { display: block; width: 100%; height: 40px; margin-top: 12px; opacity: 0.95; }

/* --- population panel (top-right) --- */
.panel-pop { right: var(--pad); top: calc(var(--pad) + 46px); width: clamp(232px, 26vw, 300px); }
.pop-size { font-family: var(--display); font-size: 13px; font-style: italic; color: var(--accent); opacity: 0.9; }
.dist { display: flex; height: 8px; gap: 2px; margin-bottom: 10px; }
.dist-seg { height: 100%; border-radius: 1px; transition: flex-grow 1s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.4s; min-width: 0; }
.dist-seg.agitate   { background: var(--agitate); }
.dist-seg.explore   { background: var(--explore); }
.dist-seg.aggregate { background: var(--aggregate); }
.dist-seg.rest      { background: var(--rest); }
.dist-seg.zero { opacity: 0.14; }
.dist-legend { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 5px 12px; }
.dist-legend li { display: flex; align-items: center; gap: 6px; font-size: 9.5px; letter-spacing: 0.06em; color: var(--muted); text-transform: uppercase; }
.dist-legend .sw { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.dist-legend b { margin-left: auto; font-weight: 500; color: var(--ink); font-variant-numeric: tabular-nums; }

/* --- about panel (bottom-right): the project note in four languages --- */
.panel-about { right: var(--pad); bottom: var(--pad); width: clamp(250px, 28vw, 344px); }
.about-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.about-head .panel-title { margin-bottom: 0; }
.lang-switch { display: flex; gap: 3px; }
.lang {
  font-family: var(--mono), var(--cjk);
  font-size: 9px; letter-spacing: 0.04em; line-height: 1;
  color: var(--muted); background: transparent;
  border: 1px solid var(--hair); border-radius: 2px;
  padding: 3px 5px; cursor: pointer;
  transition: background 0.25s, border-color 0.25s, color 0.25s;
}
.lang:hover { border-color: rgba(var(--accent-rgb), 0.55); color: var(--ink); }
.lang.active { background: rgba(var(--accent-rgb), 0.16); border-color: rgba(var(--accent-rgb), 0.5); color: var(--ink); }
.about-title {
  font-family: var(--display); font-weight: 400; font-style: italic;
  font-size: clamp(19px, 2.5vw, 25px); letter-spacing: 0.01em;
  color: var(--ink); margin-bottom: 6px;
}
.about-body {
  font-family: var(--mono), var(--cjk);
  font-size: 10.5px; line-height: 1.72; color: var(--ink); opacity: 0.82;
  margin-bottom: 10px;
}
.about-points {
  list-style: none; display: flex; flex-direction: column; gap: 5px;
  border-top: 1px solid var(--hair); padding-top: 10px;
}
.about-points li {
  font-family: var(--mono), var(--cjk);
  font-size: 9.5px; line-height: 1.55; color: var(--muted);
  padding-left: 12px; position: relative;
}
.about-points li::before {
  content: ""; position: absolute; left: 2px; top: 6px;
  width: 3px; height: 3px; border-radius: 50%; background: var(--accent); opacity: 0.8;
}

/* ============ fly inspector ============ */
.inspector {
  position: fixed; z-index: 12;
  right: var(--pad); top: 50%; transform: translateY(-50%) translateX(14px);
  width: clamp(250px, 27vw, 300px);
  max-height: 84vh; overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--hair); border-radius: 2px;
  padding: 16px;
  box-shadow: 0 14px 50px rgba(var(--ink-rgb), 0.1);
  opacity: 0; pointer-events: none;
  transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.22, 1, 0.36, 1), background 1.6s linear;
}
.inspector.open { opacity: 1; pointer-events: auto; transform: translateY(-50%) translateX(0); }
/* when a fly is selected, recede the other floating panels so the inspector is the focus */
body.ins-open .panel-pop, body.ins-open .panel-about, body.ins-open .panel-econ { opacity: 0.1; pointer-events: none; }
.ins-close {
  position: absolute; top: 8px; right: 10px;
  background: none; border: none; cursor: pointer;
  font-size: 20px; line-height: 1; color: var(--muted);
  transition: color 0.2s, transform 0.2s;
}
.ins-close:hover { color: var(--ink); transform: rotate(90deg); }
.ins-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.ins-id { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.ins-id b { font-family: var(--display); font-size: 17px; font-weight: 600; color: var(--ink); letter-spacing: 0; }
.ins-state {
  font-family: var(--display); font-weight: 600; font-size: 14px; letter-spacing: 0.02em; text-transform: lowercase;
  padding: 2px 9px; border-radius: 2px; color: var(--paper);
  background: var(--accent); transition: background 0.6s;
}
.bloom-wrap { display: flex; justify-content: center; margin: 2px 0 8px; }
#bloom { width: 156px; height: 156px; opacity: 0.95; }

/* live spike raster — scrolls as fresh /snapshot frames arrive */
.raster-wrap { margin: 0 0 12px; }
.raster-label {
  font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted);
  margin-bottom: 4px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.raster-label span { letter-spacing: 0.04em; opacity: 0.72; text-transform: none; }
#raster {
  display: block; width: 100%; height: 58px;
  background: rgba(var(--ink-rgb), 0.035);
  border: 1px solid var(--hair); border-radius: 2px;
}

.ins-drives { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.drive { display: grid; grid-template-columns: 62px 1fr 30px; align-items: center; gap: 8px; }
.drive .d-name { font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.drive .d-bar { height: 2px; background: rgba(var(--ink-rgb), 0.1); border-radius: 2px; position: relative; overflow: hidden; }
.drive .d-fill { position: absolute; inset: 0 auto 0 0; width: 0%; background: var(--ink); opacity: 0.7; border-radius: 2px; transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1); }
.drive.turn .d-bar::before { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: rgba(var(--ink-rgb), 0.2); }
.drive.turn .d-fill { left: 50%; }
.drive .d-val { font-size: 10px; text-align: right; color: var(--ink); opacity: 0.8; font-variant-numeric: tabular-nums; }

.ins-meta { padding-top: 12px; border-top: 1px solid var(--hair); display: flex; flex-direction: column; gap: 6px; }
.ins-meta > div { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.ins-meta dt { font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.ins-meta dd { font-size: 10.5px; color: var(--ink); opacity: 0.85; }
.ins-meta .fp { font-size: 9.5px; letter-spacing: 0.02em; opacity: 0.6; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ins-foot { margin-top: 12px; font-size: 9px; letter-spacing: 0.08em; color: var(--muted); opacity: 0.7; text-align: center; }

/* ============ select hint + footer ============ */
.hint-select {
  position: fixed; z-index: 9; left: 50%; bottom: calc(var(--pad) + 6px); transform: translateX(-50%);
  font-size: 10px; letter-spacing: 0.16em; text-transform: lowercase; color: var(--muted);
  opacity: 0.55; pointer-events: none; transition: opacity 0.8s; text-align: center;
}
.hint-select.hide { opacity: 0; }

/* --- agent economy panel (top-left): the x402 swarm ledger --- */
.panel-econ { left: var(--pad); top: calc(var(--pad) + 44px); width: clamp(300px, 32vw, 420px); }
.econ-mode {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.08em; text-transform: lowercase;
  color: var(--accent); border: 1px solid rgba(var(--accent-rgb), 0.4);
  border-radius: 2px; padding: 2px 6px; white-space: nowrap;
}
.econ-hero { display: flex; align-items: baseline; gap: 8px; margin: 4px 0 2px; flex-wrap: wrap; }
.econ-vol {
  font-family: var(--display); font-weight: 300; font-style: italic;
  font-size: clamp(30px, 4vw, 44px); color: var(--ink); line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: 0.01em;
}
.econ-unit { font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.econ-grid { margin-top: 12px; padding-top: 11px; }
.panel-econ .micro dt { font-size: 10px; }
.panel-econ .micro dd { font-size: 13px; }
.econ-feed {
  margin-top: 12px; padding-top: 9px; border-top: 1px solid var(--hair);
  display: flex; flex-direction: column; gap: 5px;
}
.econ-line {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.02em;
  color: var(--muted); font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  animation: econ-in 0.45s ease;
}
.econ-line:first-child { color: var(--ink); opacity: 0.85; }
@keyframes econ-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
.econ-foot {
  margin-top: 11px; font-size: 9px; letter-spacing: 0.08em; text-transform: lowercase;
  color: var(--muted); opacity: 0.6;
}

/* --- inspector: this fly's x402 agent wallet --- */
.ins-wallet {
  margin: 0 0 14px; padding: 11px 12px;
  border: 1px solid var(--hair); border-radius: 2px;
  background: rgba(var(--accent-rgb), 0.05);
}
.wallet-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted);
  margin-bottom: 6px;
}
.wallet-scheme { letter-spacing: 0.04em; text-transform: none; color: var(--accent); opacity: 0.9; }
.wallet-bal { display: flex; align-items: baseline; gap: 5px; }
.wallet-bal b {
  font-family: var(--display); font-weight: 400; font-size: 22px;
  color: var(--ink); font-variant-numeric: tabular-nums;
}
.wallet-bal em { font-style: normal; font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.wallet-addr { margin: 3px 0 8px; }
.wallet-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding-top: 8px; border-top: 1px solid var(--hair); }
.wallet-stats > div { display: flex; flex-direction: column; gap: 1px; }
.wallet-stats dt { font-size: 8px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.wallet-stats dd { font-size: 10px; color: var(--ink); opacity: 0.85; font-variant-numeric: tabular-nums; }

/* ============ responsive ============ */
@media (max-width: 820px) {
  .panel-pop { width: clamp(150px, 40vw, 200px); }
  .panel-temp { width: clamp(180px, 46vw, 240px); }
  .panel-about { width: clamp(184px, 48vw, 250px); }
  .about-body { font-size: 10px; }
  .panel-econ { width: clamp(150px, 40vw, 200px); }
  .econ-feed { display: none; }
  .inspector {
    right: var(--pad); left: var(--pad); width: auto; top: auto; bottom: var(--pad);
    transform: translateY(14px); max-height: 62vh; overflow-y: auto;
  }
  .inspector.open { transform: translateY(0); }
  .bloom-wrap { display: none; }
  .hint-select { display: none; }
}
@media (max-height: 560px) {
  .micro { display: none; }
  .about-points { display: none; }
  .panel-pop { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.08s !important; }
}
