body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", sans-serif;
    background: #14161c;
    color: #e6e6e6;
    display: flex;
    height: 100vh;
    overflow: hidden;
}

#sidebar {
    width: 380px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #2a2d36;
    padding: 12px;
    box-sizing: border-box;
    overflow-y: auto;
}

#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

h1 { font-size: 16px; margin: 0 0 8px 0; }
h2 { font-size: 13px; margin: 16px 0 6px 0; color: #9aa0ac; text-transform: uppercase; letter-spacing: 0.05em; }

#canvas {
    border: 1px solid #3a3e4a;
    border-radius: 8px;
    background: #1c1f27;
    image-rendering: pixelated;
    box-shadow: 0 8px 28px rgba(0,0,0,0.45);
}

#controls {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 640px;
}

#controls button {
    background: #2a2d36;
    color: #e6e6e6;
    border: 1px solid #3a3e4a;
    border-radius: 4px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 14px;
}
#controls button:hover { background: #3a3e4a; }

#scrub { flex: 1; }
#tickLabel { font-variant-numeric: tabular-nums; min-width: 90px; text-align: right; font-size: 12px; color: #9aa0ac; }

#fileInput { margin-bottom: 8px; }

#log {
    flex: 1;
    overflow-y: auto;
    font-size: 12px;
    line-height: 1.4;
    border: 1px solid #2a2d36;
    border-radius: 4px;
    padding: 6px;
    min-height: 120px;
}

.event {
    padding: 6px 8px;
    margin-bottom: 6px;
    border-radius: 8px;
    border-left: 3px solid #555;
}
.event.EXPERIENCE { border-left-color: #5fb878; background: rgba(95,184,120,0.08); }
.event.HEARSAY    { border-left-color: #5b9bd5; background: rgba(91,155,213,0.08); }
.event.DREAM      { border-left-color: #b07cd6; background: rgba(176,124,214,0.08); }
.event.current { outline: 1px solid #ffd166; }

/* Chat-message shape: avatar dot + name + type badge on one line, message bubble below.
   Raw engine metrics (tick/importance/hop depth) live in the title tooltip, not printed --
   a spectator reads "who said what," not a salience score. */
.eventHead { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; flex-wrap: wrap; }
.avatar { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 0 1px rgba(255,255,255,0.15); }
.name { font-weight: 600; font-size: 12px; }
.badge {
    font-size: 9px; text-transform: uppercase; letter-spacing: 0.04em;
    padding: 1px 6px; border-radius: 10px; color: #14161c; font-weight: 700;
}
.badge.EXPERIENCE { background: #5fb878; }
.badge.HEARSAY    { background: #5b9bd5; }
.badge.DREAM      { background: #b07cd6; }
.via { font-size: 10px; color: #9aa0ac; font-style: italic; }
.bubble { font-size: 12.5px; line-height: 1.45; color: #dfe2e8; }
/* live mode: new entries fade in rather than popping in instantly, and a fresh backup of
   many-at-once (fold-back catch-up) reads as a gentle wave, not a flood */
.event.new { animation: eventFadeIn 0.5s ease; }
@keyframes eventFadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

#liveUrl { width: 100%; box-sizing: border-box; margin-bottom: 6px; font-size: 11px; padding: 4px; }
#liveBtn { width: 100%; margin-bottom: 4px; }
#liveStatus { font-size: 11px; color: #9aa0ac; }

#coinList {
    font-size: 12px;
    max-height: 160px;
    overflow-y: auto;
    border: 1px solid #2a2d36;
    border-radius: 4px;
    padding: 6px;
}
#coinList .coin { padding: 2px 0; border-bottom: 1px solid #2a2d36; }
#coinList .coin .term { color: #ffd166; font-weight: 600; }
#coinList .coin.spread { color: #5fb878; }

#speedLabel { font-size: 12px; color: #9aa0ac; min-width: 60px; }

.hidden { display: none !important; }

/* ---- served-mode identity: tagline + connection dot, dev controls hidden ---- */
#tagline { font-size: 12px; color: #9aa0ac; margin: -4px 0 10px 0; }
#connDot {
    display: inline-block; width: 8px; height: 8px; border-radius: 50%;
    background: #f0ad4e; margin-right: 6px; vertical-align: baseline;
    transition: background 0.3s ease;
}
#connDot.connected { background: #5fb878; }

/* ---- village pulse (session stats) ---- */
#pulse { margin-bottom: 4px; }
#pulseCounts { display: flex; gap: 6px; flex-wrap: wrap; }
.pulseStat {
    flex: 1; min-width: 70px; text-align: center;
    background: #1c1f27; border: 1px solid #2a2d36; border-radius: 8px;
    padding: 6px 4px;
}
.pulseStat .num { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; display: block; }
.pulseStat .lbl { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.05em; color: #9aa0ac; }
.pulseStat.MOMENT .num { color: #5fb878; }
.pulseStat.GOSSIP .num { color: #5b9bd5; }
.pulseStat.DREAM .num { color: #b07cd6; }
.pulseStat.COINED .num { color: #ffd166; }
#pulseTop { font-size: 11.5px; color: #9aa0ac; margin-top: 6px; }
#pulseTop .avatar { width: 9px; height: 9px; display: inline-block; margin-right: 4px; }

/* ---- experiment status strip (live mode only) ---- */
#statusBar {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: #c9cdd6;
    background: #1c1f27;
    border: 1px solid #2a2d36;
    border-radius: 8px;
    padding: 7px 14px;
    font-variant-numeric: tabular-nums;
}
#helpBtn {
    background: #2a2d36; color: #e6e6e6; border: 1px solid #3a3e4a;
    border-radius: 50%; width: 22px; height: 22px; cursor: pointer;
    font-size: 12px; line-height: 1; flex-shrink: 0;
}
#helpBtn:hover { background: #3a3e4a; }

/* ---- villager focus card ---- */
#focusCard {
    margin-top: 10px;
    border: 1px solid #3a3e4a;
    border-radius: 8px;
    padding: 8px 10px;
    background: #1c1f27;
}
#focusHead { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
#focusName { font-weight: 600; font-size: 13px; flex: 1; }
#focusClose {
    background: none; border: none; color: #9aa0ac; cursor: pointer; font-size: 12px;
}
#focusClose:hover { color: #e6e6e6; }
.needRow { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.needLabel { font-size: 11px; color: #9aa0ac; width: 82px; flex-shrink: 0; }
.bar {
    flex: 1; height: 8px; background: #2a2d36; border-radius: 4px; overflow: hidden;
}
.bar .fill {
    height: 100%; border-radius: 4px; background: #5fb878;
    transition: width 0.6s ease, background 0.6s ease;
}
#focusLast { font-size: 11.5px; color: #b8bdc7; margin-top: 6px; font-style: italic; line-height: 1.4; }
.event.filtered { display: none; }

/* ---- first-visit intro overlay ---- */
#introOverlay {
    position: fixed; inset: 0; z-index: 10;
    background: rgba(10, 12, 16, 0.72);
    display: flex; align-items: center; justify-content: center;
}
#introCard {
    max-width: 460px; max-height: 85vh; margin: 20px;
    background: #1c1f27; border: 1px solid #3a3e4a; border-radius: 12px;
    padding: 22px 26px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.6);
    overflow-y: auto;
}
#introCard h1 { font-size: 18px; margin: 0 0 10px 0; }
#introCard p { font-size: 13px; line-height: 1.55; color: #c9cdd6; margin: 0 0 10px 0; }
#introCard .legend { line-height: 2; }
#introDismiss {
    background: #5fb878; color: #14161c; border: none; border-radius: 6px;
    padding: 8px 16px; font-size: 13px; font-weight: 700; cursor: pointer; margin-top: 4px;
}
#introDismiss:hover { filter: brightness(1.1); }
