/* ---------- Avatar renderer (cutout rig) ---------- */
.avatar { overflow: visible; display: block; }
.avatar .av-root { transform-box: view-box; transform-origin: 0 0; transform: var(--b-root, none); }
.avatar .av-b { transform-box: view-box; transform-origin: 0 0; }
.avatar .av-b-torso { transform: var(--b-torso, none); }
.avatar .av-b-head { transform: var(--b-head, none); }
.avatar .av-b-arm_l { transform: var(--b-arm_l, none); }
.avatar .av-b-arm_r { transform: var(--b-arm_r, none); }
.avatar .av-b-leg_l { transform: var(--b-leg_l, none); }
.avatar .av-b-leg_r { transform: var(--b-leg_r, none); }
.avatar .av-l { transform-box: view-box; }
.avatar .av-l-eyes { transform-origin: 120px 90px; translate: var(--look-x, 0) var(--look-y, 0); transition: translate .2s steps(3), scale .15s steps(2); animation: av-blink 4.6s steps(1) infinite; }
.avatar .av-l-brows { transform-origin: 120px 62px; transition: translate .2s steps(3), rotate .2s steps(3); }
.avatar .av-l-mouth { transform-origin: 120px 124px; transition: scale .2s steps(3), translate .2s steps(3); }
@keyframes av-blink { 0%, 93%, 100% { transform: scaleY(1); } 94% { transform: scaleY(.08); } }
.avatar.static .av-l-eyes { animation: none; }
.avatar.paper { filter: url(#paper); }

.avatar.mood-happy .av-l-eyes { scale: 1 .6; }
.avatar.mood-happy .av-l-mouth { scale: 1.3; }
.avatar.mood-happy .av-l-brows { translate: 0 -5px; }
.avatar.mood-sad .av-l-brows { translate: 0 3px; rotate: 6deg; }
.avatar.mood-sad .av-l-mouth { scale: 1 -1; translate: 0 4px; }
.avatar.mood-surprised .av-l-eyes { scale: 1.12; }
.avatar.mood-surprised .av-l-brows { translate: 0 -8px; }
.avatar.mood-surprised .av-l-mouth { scale: .8 1.3; }
.avatar.mood-focus .av-l-brows { translate: 0 3px; }
.avatar.talking .av-l-mouth { animation: av-talk .9s steps(1) infinite; }
@keyframes av-talk { 0%, 40%, 75% { transform: scale(1.04, 1.55); } 20%, 55%, 100% { transform: scale(1, .7); } 88% { transform: scale(1.08, 1.25); } }
@media (prefers-reduced-motion: reduce) { .avatar.talking .av-l-mouth { animation: none; } }

/* ---------- Map profile button ---------- */
.hud-profile { position: absolute; right: 80px; top: 14px; height: 54px; display: flex; align-items: center; gap: 8px; padding: 0 16px 0 3px; border-radius: 999px; cursor: pointer;
  border: 3px solid #23263a; background: linear-gradient(#7fd3ff, #3aa6f0); box-shadow: 0 5px 0 #2f8fe0, 0 10px 18px rgba(0,0,0,.25); color: #10223d; font: inherit;
  transition: transform .15s, box-shadow .15s; }
.hud-profile .hp-face { width: 44px; height: 44px; border-radius: 50%; overflow: hidden; background: radial-gradient(circle at 50% 35%, #e9f7ff, #9bd8ff); display: grid; place-items: center; font-size: 24px; border: 2px solid #23263a; }
.hud-profile .hp-face .avatar { width: 100%; height: 100%; }
.hud-profile b { font-size: 14px; font-weight: 900; white-space: nowrap; }
.hud-profile:hover { transform: translateY(-2px) scale(1.04); }
.hud-profile:active { transform: translateY(4px); box-shadow: 0 1px 0 #2f8fe0; }
[data-theme=night] .hud-profile { background: radial-gradient(circle at 50% 35%, #3a4a8a, #1b2550); box-shadow: 0 5px 0 #0f1838, 0 0 16px rgba(90,200,250,.35); }

/* ---------- Editor ---------- */
.dialog.avatar-editor { width: min(1040px, 96vw); max-height: 94vh; }
.ae-body { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 18px; min-height: 0; }
.ae-stage { position: relative; border-radius: 14px; border: 1.5px dashed rgba(255,255,255,.35); overflow: hidden;
  background: radial-gradient(ellipse at 50% 30%, rgba(255,255,255,.18), transparent 60%), linear-gradient(#2a62a8, #173e72); min-height: 440px; }
.ae-spot { position: absolute; left: 50%; top: -20%; width: 120%; height: 120%; transform: translateX(-50%); background: radial-gradient(ellipse at 50% 0, rgba(255,230,160,.35), transparent 60%); pointer-events: none; }
.ae-preview { position: absolute; inset: 18px 18px 46px; display: flex; align-items: flex-end; justify-content: center; }
.ae-preview .avatar { height: 100%; max-width: 100%; filter: drop-shadow(0 12px 10px rgba(0,0,0,.35)); }
.ae-pedestal { position: absolute; left: 50%; bottom: 22px; width: 200px; height: 34px; transform: translateX(-50%); border-radius: 50%;
  background: radial-gradient(ellipse, #ffc83d 0, #e0a312 60%, #9c6a10 100%); box-shadow: 0 8px 0 #7a520c, 0 16px 20px rgba(0,0,0,.35); }
.ae-panel { min-width: 0; display: flex; flex-direction: column; }
.ae-content { overflow-y: auto; max-height: 56vh; padding-right: 4px; }
.ae-group { margin-bottom: 14px; }
.ae-group h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: #bcd7ff; }
.ae-swatches { display: flex; flex-wrap: wrap; gap: 7px; }
.ae-swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255,255,255,.5); cursor: pointer; transition: transform .15s; }
.ae-swatch:hover { transform: scale(1.12); }
.ae-swatch.on { border-color: #fff; box-shadow: 0 0 0 3px #ffc83d; transform: scale(1.12); }
.ae-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.ae-tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 4px 7px; border-radius: 12px; cursor: pointer;
  border: 1.5px dashed rgba(255,255,255,.35); background: rgba(255,255,255,.07); color: #eaf3ff; font: inherit; font-size: 11px; transition: transform .15s, background .15s; }
.ae-tile:hover { transform: translateY(-2px); background: rgba(255,255,255,.14); }
.ae-tile.on { border: 2px solid #ffc83d; background: rgba(255,200,61,.18); }
.ae-tile b { font-weight: 700; line-height: 1.15; text-align: center; font-family: var(--font); }
.ae-thumb { width: 76px; height: 76px; border-radius: 10px; background: radial-gradient(circle at 50% 30%, #5d8fd6, #23467e); display: grid; place-items: center; overflow: hidden;
  font-size: 30px; color: rgba(255,255,255,.6); }
.ae-thumb .avatar { width: 100%; height: 100%; }
.ae-pack { position: absolute; top: 4px; left: 4px; font-style: normal; font-size: 9px; font-weight: 800; background: #8e5cf7; color: #fff; padding: 1px 5px; border-radius: 6px; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ae-rarity { font-style: normal; font-size: 9px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.ae-tile.rarity-rare .ae-rarity { color: #7fd3ff; }
.ae-tile.rarity-epic .ae-rarity { color: #d1a6ff; }
.ae-tile.rarity-legendary .ae-rarity { color: #ffd34d; }
.ae-tile.rarity-legendary .ae-thumb { box-shadow: inset 0 0 0 2px #ffd34d, 0 0 12px rgba(255,211,77,.5); }
.ae-warn { margin: 10px 0; font-size: 12px; color: #ffd9a0; }
.ae-warn summary { cursor: pointer; font-weight: 700; }
.ae-warn ul { margin: 6px 0; padding-left: 18px; max-height: 120px; overflow-y: auto; }
[data-theme=night] .ae-stage { background: radial-gradient(ellipse at 50% 30%, rgba(140,170,255,.16), transparent 60%), linear-gradient(#142a52, #0a1730); }
[data-theme=night] .ae-thumb { background: radial-gradient(circle at 50% 30%, #2c4a80, #0f2142); }
@media (max-width: 760px) { .ae-body { grid-template-columns: 1fr; } .ae-stage { min-height: 300px; } }

/* ---------- Factory worker ---------- */
.walker-layer { pointer-events: none; }
.worker { position: absolute; left: 0; top: 0; width: 124px; height: 124px; transform-origin: 0 0; pointer-events: auto; cursor: pointer; will-change: transform; }
.worker .avatar { width: 100%; height: 100%; pointer-events: none; }
.worker::after { content: ''; position: absolute; left: 26%; right: 26%; bottom: 2px; height: 10px; border-radius: 50%; background: rgba(0,0,0,.28); z-index: -1; }
.layer.walker-layer.behind .worker::after { display: none; }
.wk-stamp-base { fill: #22b866; stroke: #1f1a24; stroke-width: 2; }
.shop-door .door-frame { fill: #23263a; }
.shop-door .door-dark { fill: #121420; }
.shop-door .door-leaf { fill: #8a5a44; stroke: #23263a; stroke-width: 2; }
.shop-door .door-sign { fill: #22b866; }
.shop-door .door-text { font-size: 10px; font-weight: 900; fill: #fff; text-anchor: middle; font-family: var(--font); }
.op-bubble { position: absolute; transform: translate(-50%, -100%); background: #fffdf7; color: #23263a; font-weight: 800; font-size: 14px; padding: 7px 12px;
  border-radius: 14px; box-shadow: 0 4px 0 rgba(0,0,0,.2); white-space: nowrap; pointer-events: none; z-index: 20; }
.op-bubble::after { content: ''; position: absolute; left: 50%; bottom: -8px; margin-left: -8px; border: 8px solid transparent; border-top-color: #fffdf7; border-bottom: 0; }
[data-theme=night] .worker { filter: drop-shadow(0 0 14px rgba(255,214,120,.45)); }
[data-theme=night] .op-bubble { background: #e6e9ff; }
[data-theme=night] .op-bubble::after { border-top-color: #e6e9ff; }

/* ---------- Slack visitors (factory) ---------- */
.visitor-layer { pointer-events: none; }
.visitor { position: absolute; left: 0; top: 0; width: 104px; height: 104px; will-change: transform; }
.visitor .vs-body { position: absolute; inset: 0; pointer-events: auto; cursor: pointer; }
.visitor .vs-body::after { content: ''; position: absolute; left: 26%; right: 26%; bottom: 0; height: 9px; border-radius: 50%; background: rgba(0,0,0,.28); z-index: -1; }
.visitor .avatar { width: 100%; height: 100%; pointer-events: none; }
.visitor .vs-body:hover .avatar { filter: url(#paper) drop-shadow(0 0 6px rgba(255,255,255,.7)); }
.vs-tag { position: absolute; left: 50%; bottom: calc(100% - 2px); transform: translateX(-50%); max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 2px 9px 2px 22px; border-radius: 999px; background: #4a154b; color: #fff; font-size: 12px; font-weight: 800; border: 2px solid #23263a; box-shadow: 0 3px 0 rgba(0,0,0,.25);
  pointer-events: auto; cursor: pointer; }
.vs-tag::before { content: '#'; position: absolute; left: 3px; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 4px; background: #ecb22e; color: #4a154b;
  font-size: 11px; line-height: 14px; text-align: center; font-weight: 900; }
.vs-stack { position: absolute; left: 50%; bottom: calc(100% + 26px); transform: translateX(-50%); width: 236px; display: flex; flex-direction: column; align-items: center; gap: 7px; pointer-events: none; }
.vs-bubble { position: relative; max-width: 236px; padding: 6px 11px; border-radius: 13px; background: #fffdf7; color: #23263a; font-size: 13px; font-weight: 700; line-height: 1.3;
  box-shadow: 0 4px 0 rgba(0,0,0,.2); pointer-events: auto; cursor: pointer; display: flex; gap: 5px; overflow-wrap: anywhere; transition: transform .12s, box-shadow .12s; }
.vs-bubble:hover { transform: translateY(-2px); box-shadow: 0 6px 0 rgba(0,0,0,.2), 0 0 0 2px #ffc83d; }
.vs-bubble span { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.vs-bubble.reply { background: #f3ecff; }
.vs-reply { color: #8e5cf7; font-weight: 900; }
.vs-bubble:last-child::after { content: ''; position: absolute; left: 50%; bottom: -8px; margin-left: -8px; border: 8px solid transparent; border-top-color: #fffdf7; border-bottom: 0; }
.vs-bubble.reply:last-child::after { border-top-color: #f3ecff; }
.vs-more { padding: 1px 9px; border-radius: 999px; background: rgba(35,38,58,.82); color: #fff; font-size: 11px; font-weight: 800; pointer-events: auto; cursor: pointer; }
.visitor.entering .vs-stack { visibility: hidden; }
.visitor.leaving .vs-body, .visitor.leaving .vs-tag, .visitor.leaving .vs-bubble { pointer-events: none; }
/* waiting for Claude: old bubbles fade, a "thinking" one with a spinner sits closest to the head */
.visitor.forming .vs-bubble:not(.think), .visitor.forming .vs-more { opacity: .5; }
.vs-bubble.think { background: #ffe9a8; align-items: center; cursor: default; }
.vs-bubble.think:hover { transform: none; box-shadow: 0 4px 0 rgba(0,0,0,.2); }
.vs-bubble.think:last-child::after { border-top-color: #ffe9a8; }
.vs-spin { flex: none; width: 13px; height: 13px; border-radius: 50%; border: 2.5px solid rgba(35,38,58,.25); border-top-color: #23263a; animation: vs-spin .8s linear infinite; }
@keyframes vs-spin { to { transform: rotate(360deg); } }
.visitor.forming .vs-body { cursor: progress; }
/* bubbles breaking into boxes on their way to the feed pipe (stage coordinates) */
.vs-ghost { position: absolute; left: 0; top: 0; max-width: none; pointer-events: none; z-index: 5; }
.vs-ghost::after { display: none; }
.vs-chunk { position: absolute; left: 0; top: 0; width: 36px; height: 30px; pointer-events: none; z-index: 6; will-change: transform; }
.vs-chunk i { position: absolute; inset: 0; border-radius: 4px;
  background: linear-gradient(180deg, var(--cardboard-light, #f0c690) 0, var(--cardboard, #d9a061) 25%, #c68a4d 100%);
  box-shadow: inset 0 -3px 0 rgba(90,50,10,.18), 0 0 0 1.5px rgba(60,35,10,.55), 0 3px 0 rgba(0,0,0,.18); }
.vs-chunk i::before { content: ''; position: absolute; left: 50%; top: 0; width: 9px; height: 10px; margin-left: -4.5px; background: rgba(245,222,170,.95); }
[data-theme=night] .visitor .vs-body { filter: drop-shadow(0 0 10px rgba(180,140,255,.4)); }
[data-theme=night] .vs-bubble { background: #e6e9ff; }
[data-theme=night] .vs-bubble:last-child::after { border-top-color: #e6e9ff; }
[data-theme=night] .vs-bubble.reply { background: #e3d9ff; }
[data-theme=night] .vs-bubble.reply:last-child::after { border-top-color: #e3d9ff; }
[data-theme=night] .vs-bubble.think { background: #ffe9a8; }
[data-theme=night] .vs-bubble.think:last-child::after { border-top-color: #ffe9a8; }

/* ---------- Visitor dialog ---------- */
.visitor-dialog { width: min(1100px, 96vw); height: 92vh; max-height: 92vh; flex-direction: column; }
.visitor-dialog[open] { display: flex; }
.visitor-dialog form { display: flex; flex-direction: column; min-height: 0; gap: 12px; }
#visitorView { display: flex; flex-direction: column; min-height: 0; overflow: auto; }
.vd-head { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.vd-head h3 { margin: 0 0 2px; }
.vd-face { flex: none; width: 72px; height: 72px; border-radius: 50%; overflow: hidden; background: #4a154b; box-shadow: 0 0 0 3px #ecb22e; }
.vd-face .avatar { width: 120%; height: 120%; margin: -6% 0 0 -10%; }
.vd-hint { margin: 4px 0 10px; font-size: 13px; }
.vd-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.vd-msg { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; background: #fffdf7; border: 1.5px solid var(--border); cursor: pointer; }
.vd-msg.reply { background: #f6f0ff; border-color: #d9c8ff; }
.vd-msg:has(input:not(:checked)) { opacity: .55; }
.vd-msg input { margin-top: 3px; width: 17px; height: 17px; accent-color: var(--primary); flex: none; }
.vd-main { flex: 1; min-width: 0; }
.vd-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted, #7a7f95); margin-bottom: 4px; }
.vd-meta .spacer { flex: 1; }
.vd-meta a { font-weight: 700; }
.vd-thread { color: #8e5cf7; font-weight: 800; }
.vd-text { color: #23263a; overflow-wrap: anywhere; line-height: 1.45; }
.vd-text p { margin: 0 0 6px; }
.vd-text :last-child { margin-bottom: 0; }
.vd-busy { display: flex; align-items: center; gap: 8px; margin: 10px 0 0; font-weight: 700; }
#visitorView { flex: 1; min-height: 0; overflow-y: auto; padding-right: 4px; }
.vd-text { font-size: 15px; }
/* editable proposal */
.vd-tasks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.vd-task { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: 14px; background: #fff7ea; border: 2px solid #f0dcb8; box-shadow: 0 3px 0 #e6c99a; }
.vd-task:focus-within { border-color: #ff7a2f; }
.vd-task-head { display: flex; align-items: center; gap: 8px; }
.vd-num { flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: #d29a5a; color: #fff; font-size: 14px; box-shadow: inset 0 -3px 0 rgba(0,0,0,.15); }
.vd-title { flex: 1; font-weight: 800; font-size: 16px; }
.vd-del { margin-left: 0; }
.vd-desc { resize: vertical; font-size: 14px; line-height: 1.45; min-height: 64px; }
.vd-srcs { display: flex; flex-wrap: wrap; gap: 5px; }
.vd-src { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: #f6f0ff; color: #6b3fd4; border: 1px solid #d9c8ff; cursor: help; }
.vd-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.vd-empty { padding: 14px; border-radius: 12px; border: 2px dashed #e6c99a; background: #fffdf7; color: #5a3412; margin: 0; }
.vd-dups { margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: #f3f4f8; font-size: 13px; }
.vd-dups ul { margin: 6px 0 0; padding-left: 18px; }
.vd-dups a { cursor: pointer; font-weight: 800; }
@media (max-width: 640px) { .visitor-dialog { height: 96vh; max-height: 96vh; width: 100vw; } }

/* ---------- Map walker ---------- */
.walker { cursor: pointer; }
.walker-shadow { fill: #000; opacity: .22; }
.walker-glow { fill: #ffe38a; opacity: 0; filter: blur(8px); transition: opacity .8s; pointer-events: none; }
[data-theme=night] .walker-glow { opacity: .45; }
.walker .walker-body { transform-box: fill-box; transform-origin: 50% 100%; }

/* ---------- Editor moves ---------- */
.ae-moves { position: absolute; left: 10px; right: 10px; top: 10px; display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; z-index: 2; }
.ae-moves button { border: 1.5px dashed rgba(255,255,255,.5); background: rgba(0,0,0,.25); color: #fff; border-radius: 999px; padding: 3px 9px; font: inherit; font-size: 11px; font-weight: 800; cursor: pointer; }
.ae-moves button.on { background: #ffc83d; color: #23263a; border: 1.5px solid #ffc83d; }
.ae-preview { top: 44px !important; }

/* ---------- Player name ---------- */
.ae-nick { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 0 0; }
.ae-nick small { text-transform: none; letter-spacing: 0; color: #9fc2ef; }
.ae-nick input { flex: 1 1 200px; max-width: 320px; margin: 0; font-size: 15px; font-weight: 700; font-family: var(--font); }
