/* Village panel (village.js): intro, status, live log, residents + card, laws, seats. Uses the tokens from app.css. */
:root {
  --vl-w: 340px;
  --vl-life: #3d7f5a;
  --vl-work: #8a6a3c;
  --vl-find: #3d6fb8;
  --vl-mind: #7a5c9e;
  --vl-love: #c0507a;
  --vl-law: #1f2a2e;
  --vl-quiet: #a19d93;
  --vl-sheet-h: 0px;
}
/* The village panel replaces the old "지금 있는 몸" list (same data, richer). */
body.has-village .agents { display: none; }

.vl { word-break: keep-all; position: fixed; left: 16px; top: 70px; bottom: 16px; width: var(--vl-w); display: flex; flex-direction: column; min-height: 0;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; z-index: 2; }
.vl-grip { display: none; }
.vl-head { padding: 12px 14px 8px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.vl-intro { margin: 0; font-size: 13px; line-height: 1.45; color: var(--ink); }
.vl-status { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
.vl-awake { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vl-status .vl-muted { margin-left: auto; white-space: nowrap; }
.vl-muted { color: var(--muted); font-size: 13px; margin: 0; }
.vl-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--vl-quiet); }
.vl-dot.is-on { background: var(--vl-life); box-shadow: 0 0 0 3px rgba(61, 127, 90, .18); }

.vl-seats { text-align: left; font-size: 12px; padding: 6px 10px; border-radius: 8px; border: 1px dashed var(--line); background: var(--paper-2); color: var(--muted); }
.vl-seats.is-open { border: 1px solid var(--accent); background: #fbe9df; color: #8f3f1e; font-weight: 600; }
.vl-ticker { display: none; }

.vl-tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 6px; }
.vl-tab { flex: 1 1 0; background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 9px 4px; font-size: 14px; color: var(--muted); }
.vl-tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 700; }
.vl-tab[data-tab="dex"] { color: var(--ink); }
.vl-tab:hover { color: var(--ink); }
.vl-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 8px 10px 12px; overscroll-behavior: contain; }
.vl-hint { margin: 2px 4px 8px; font-size: 12px; color: var(--muted); line-height: 1.45; }
.vl-h { margin: 12px 4px 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.vl-empty { padding: 18px 8px; text-align: center; font-size: 14px; }
.vl-empty p { margin: 0 0 6px; }

/* Log */
.vl-log { list-style: none; margin: 0; padding: 0; }
.vl-ev { --c: var(--vl-quiet); }
.vl-ev.g-life { --c: var(--vl-life); } .vl-ev.g-work { --c: var(--vl-work); } .vl-ev.g-find { --c: var(--vl-find); }
.vl-ev.g-mind { --c: var(--vl-mind); } .vl-ev.g-love { --c: var(--vl-love); } .vl-ev.g-law { --c: var(--vl-law); } .vl-ev.g-birth { --c: var(--accent); }
.vl-ev-btn { width: 100%; display: grid; grid-template-columns: auto 1fr; grid-template-areas: "k t" ". w"; gap: 1px 8px; align-items: baseline;
  text-align: left; background: none; border: 0; border-radius: 8px; padding: 6px 6px; }
.vl-ev-btn:not(:disabled):hover { background: var(--paper-2); }
.vl-ev-btn:disabled { cursor: default; color: inherit; }
.vl-ev-kind { grid-area: k; font-size: 11px; color: var(--c); border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; white-space: nowrap; }
.vl-ev-text { grid-area: t; font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
.vl-ev-when { grid-area: w; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.vl-ev.g-quiet .vl-ev-text { color: var(--muted); }
.vl-ev.is-hot .vl-ev-btn { background: #fbf1e3; }
.vl-ev.g-birth .vl-ev-btn { background: #fbe9df; box-shadow: inset 3px 0 0 var(--accent); }
.vl-ev.g-birth .vl-ev-text { font-weight: 700; }
.vl-ev.is-new .vl-ev-btn { animation: vl-in .6s ease-out; }
@keyframes vl-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* Residents */
.vl-list { list-style: none; margin: 0; padding: 0; }
.vl-res { width: 100%; text-align: left; background: none; border: 0; border-radius: 8px; padding: 7px 6px; display: flex; flex-direction: column; gap: 2px; }
.vl-res:hover { background: var(--paper-2); }
.vl-res.is-following { background: #fbe9df; }
.vl-res-top { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 14px; }
.vl-res-top b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vl-res-state { margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }
.vl-res.is-asleep b { color: var(--muted); font-weight: 600; }
.vl-res-sub { font-size: 12px; color: var(--muted); padding-left: 14px; overflow-wrap: anywhere; }
.vl-badge { flex: none; font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }

/* Card */
.vl-card { padding: 2px 4px; }
.vl-card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.vl-back { background: none; border: 0; padding: 4px 2px; font-size: 13px; color: var(--muted); }
.vl-follow-btn { box-shadow: none; padding: 5px 12px; font-size: 13px; }
.vl-follow-btn.is-on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.vl-card-title { display: flex; align-items: center; gap: 8px; margin: 8px 0 4px; min-width: 0; }
.vl-card-title h3 { margin: 0; font-size: 22px; overflow-wrap: anywhere; min-width: 0; }
.vl-state { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.vl-state.is-on { color: var(--vl-life); font-weight: 600; }
.vl-facts { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 13px; margin: 6px 0; }
.vl-facts dt { color: var(--muted); }
.vl-facts dd { margin: 0; overflow-wrap: anywhere; }
.vl-card .vl-h { margin-left: 0; }
.vl-creed { margin: 0; padding: 8px 12px; background: var(--paper-2); border-left: 3px solid var(--vl-mind); border-radius: 0 8px 8px 0; font-size: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.vl-holds { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.vl-hold { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.vl-hold-bar { flex: none; display: flex; width: 56px; height: 12px; border: 1px solid var(--line); border-radius: 3px; overflow: hidden; background: #f4f2eb; }
.vl-hold-bar i { display: block; flex-basis: 0; min-width: 2px; }

/* Laws */
.vl-laws { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.vl-law { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fffdf8; }
.vl-law.is-law { border-color: var(--ink); box-shadow: inset 3px 0 0 var(--ink); }
.vl-law-text { margin: 0; font-size: 15px; font-weight: 700; line-height: 1.4; overflow-wrap: anywhere; }
.vl-law-why { margin: 6px 0 0; font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.vl-law-why-k { display: inline-block; margin-right: 6px; font-size: 11px; font-weight: 700; color: var(--accent); border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; vertical-align: 1px; }
.vl-law-meta { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.vl-law-stats { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.vl-pill { font-size: 12px; border-radius: 999px; padding: 2px 9px; background: var(--paper-2); font-variant-numeric: tabular-nums; }
.vl-pill.is-follow { background: var(--ink); color: var(--paper); }
.vl-pill.is-kept { color: var(--vl-life); }
.vl-pill.is-broken { color: #a3361a; }
.vl-law-who { margin: 6px 0 0; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.vl-law-recs { list-style: none; margin: 6px 0 0; padding: 6px 0 0; border-top: 1px dashed var(--line); font-size: 12px; display: grid; gap: 2px; }
.vl-law-recs .is-kept::before { content: "○ "; color: var(--vl-life); }
.vl-law-recs .is-broken::before { content: "× "; color: #a3361a; }

/* Follow bar and birth/law flash */
/* left/right 0 + auto margins: centred without the left:50% shrink-to-fit squeeze on narrow screens. */
.vl-follow { position: fixed; left: 0; right: 0; margin: 0 auto; width: max-content; bottom: 16px; display: flex; align-items: center; gap: 8px; max-width: calc(100% - 32px);
  background: var(--ink); color: var(--paper); border-radius: 999px; padding: 6px 6px 6px 16px; box-shadow: var(--shadow); font-size: 14px; z-index: 3; }
.vl-follow span { min-width: 4em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vl-follow button { flex: none; border: 0; border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.vl-follow-card { background: transparent; color: var(--paper); border: 1px solid rgba(246, 242, 234, .4) !important; }
.vl-follow-stop { background: var(--paper); color: var(--ink); font-weight: 600; }
body.playing .vl-follow { bottom: 190px; }
body.fp .vl-follow { display: none; }
.vl-flash { position: fixed; left: 50%; transform: translateX(-50%); top: 118px; max-width: calc(100% - 32px); background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: 15px; font-weight: 700; z-index: 4; animation: vl-in .5s ease-out; pointer-events: none; }

body.og .vl, body.og .vl-follow, body.og .vl-flash { display: none !important; }

/* Desktop: the info square stays on the right; the play panel is centred, clear of the left panel. */
@media (min-width: 721px) and (max-width: 1100px) {
  :root { --vl-w: 300px; }
  body.has-village .play { left: calc(var(--vl-w) + 32px); transform: none; width: min(560px, calc(100% - var(--vl-w) - 48px)); }
}

/* Phones: the panel is a bottom sheet. Collapsed = status, newest event, tabs. Open = 62% of the screen height. */
@media (max-width: 720px) {
  .vl { left: 0; right: 0; top: auto; bottom: 0; width: 100%; border-radius: 14px 14px 0 0; border-bottom: 0; max-height: 62vh;
    padding-bottom: env(safe-area-inset-bottom); }
  .vl-grip { display: block; flex: none; height: 18px; width: 100%; border: 0; background: none; position: relative; }
  .vl-grip::before { content: ""; position: absolute; left: 50%; top: 6px; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--line); }
  .vl-head { padding: 0 14px 6px; gap: 4px; }
  .vl-intro { font-size: 12px; }
  .vl:not(.is-open) .vl-seats:not(.is-open) { display: none; }
  .vl-ticker { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; background: var(--paper-2); border: 0; border-radius: 8px; padding: 6px 10px; font-size: 13px; min-width: 0; }
  .vl.is-open .vl-ticker { display: none; }
  .vl-live { flex: none; font-size: 11px; font-weight: 700; color: var(--accent); }
  .vl-ticker-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .vl-body { display: none; }
  .vl.is-open .vl-body { display: block; }
  .vl.is-open { height: 62vh; }
  .vl-tab { padding: 8px 2px; }
  /* Other bottom things sit above the collapsed sheet. */
  body.has-village .info { bottom: calc(var(--vl-sheet-h) + 8px); max-height: calc(100% - var(--vl-sheet-h) - 130px); }
  body.has-village.playing .play { bottom: calc(var(--vl-sheet-h) + 8px); }
  body.has-village.playing .info { top: 112px; bottom: auto; max-height: 34vh; }
  body.has-village .vl.is-open ~ .vl-follow, .vl-follow { bottom: calc(var(--vl-sheet-h) + 10px); }
  body.has-village.playing .vl-follow { display: none; }
  .vl-flash { top: 112px; font-size: 14px; }
  /* First person on a phone: the joystick owns the bottom-left, so the sheet steps aside. */
  body.fp-touch .vl { display: none; }
}
