/* 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-seats { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.vl-seats[hidden] { display: none; }
.vl-seats-text { flex: 1 1 auto; min-width: 0; }
.vl-seats-acts { display: inline-flex; gap: 6px; flex: none; }
.vl-seats-btn { font: inherit; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; border: 1px solid currentColor; background: #fff; color: inherit; cursor: pointer; }
.vl-seats-btn[hidden] { display: none; }
.vl-seats-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.vl-ticker { display: none; }
.vl-reopen { display: none; }
body.og .vl-reopen { display: none !important; }
@media (prefers-reduced-motion: reduce) { .vl, .vl.is-closed { transition: none !important; } }

.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-nature { --c: #4f8f3a; } .vl-ev.g-weather { --c: #3f7fb0; } .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-badge.is-hungry { color: #a0471f; border-color: #e0a27f; background: #fbeee4; }
.vl-hunger { display: grid; grid-template-columns: auto minmax(60px, 1fr) auto auto; align-items: center; gap: 8px; font-size: 13px; margin: 2px 0 8px; }
.vl-hunger-k { color: var(--muted); }
.vl-hunger-bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.vl-hunger-bar i { display: block; height: 100%; background: #7aa35a; border-radius: inherit; }
.vl-hunger.is-mid .vl-hunger-bar i { background: #d9a13b; }
.vl-hunger.is-high .vl-hunger-bar i { background: #c8643b; }
.vl-hunger.is-high .vl-hunger-word { color: #a0471f; }
.vl-hunger-n { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
.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: none;
    padding-bottom: env(safe-area-inset-bottom); transition: height .22s ease, transform .22s ease; }
  .vl.is-dragging { transition: none; }
  /* Closed: slid fully below the screen; only the reopen tab stays. */
  .vl.is-closed { transform: translateY(calc(100% + 8px)); visibility: hidden; transition: transform .22s ease, visibility 0s linear .22s; }
  /* The grip is the only drag handle: no page scroll or pinch while dragging it. */
  .vl-grip { display: block; flex: none; height: 24px; width: 100%; border: 0; background: none; position: relative; touch-action: none; cursor: grab; }
  .vl.is-dragging .vl-grip { cursor: grabbing; }
  .vl-grip::before { content: ""; position: absolute; left: 50%; top: 9px; width: 44px; height: 5px; margin-left: -22px; border-radius: 3px; background: var(--line); }
  .vl-grip:hover::before, .vl.is-dragging .vl-grip::before { background: var(--muted); }
  .vl-grip:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
  .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: var(--vl-open-h, 50vh); max-height: calc(var(--alal-vh, 100dvh) - var(--alal-top, 0px)); }
  .vl-reopen { position: fixed; left: 50%; bottom: calc(8px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 3;
    display: inline-flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 16px 7px; border-radius: 12px;
    background: var(--paper); color: var(--ink); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 12px; font-weight: 600; }
  .vl-reopen[hidden] { display: none; }
  .vl-reopen-bar { width: 32px; height: 4px; border-radius: 2px; background: var(--muted); }
  .vl-tab { padding: 8px 2px; }
  /* Other bottom things sit above the collapsed sheet. */
  /* Between the sheet and the measured top bar + chips (--alal-top), content height, scrolling inside. */
  body.has-village:not(.fp-touch) .info { bottom: calc(var(--vl-sheet-h) + 8px); max-height: calc(var(--alal-vh, 100dvh) - var(--vl-sheet-h) - 8px - var(--alal-top, 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, body.fp-touch .vl-reopen { display: none; }
}

/* Resident shortcut chips (top, always visible). `top` is set by village.js right under the top bar. */
.vl-chips { position: fixed; top: 60px; left: calc(var(--vl-w) + 32px); right: 372px; z-index: 3; display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none; padding: 2px; pointer-events: none; }
.vl-chips::-webkit-scrollbar { display: none; }
.vl-chip { pointer-events: auto; flex: none; display: inline-flex; align-items: center; gap: 6px; max-width: 160px; padding: 5px 12px 5px 10px; font-size: 13px; font-weight: 600;
  background: var(--paper); color: var(--ink); border: 1px solid var(--line); border-radius: 999px; box-shadow: 0 2px 8px rgba(20, 28, 30, .14); }
.vl-chip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vl-chip.is-asleep { color: var(--muted); font-weight: 500; }
.vl-chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.vl-chip.is-more { color: var(--muted); padding: 5px 10px; }
body.og .vl-chips, body.fp .vl-chips { display: none !important; }
/* Transient messages go below the chips row instead of on top of it. */
body.has-village .toast { top: calc(var(--vl-chips-bottom, 64px) + 8px); }
body.has-village .vl-flash { top: calc(var(--vl-chips-bottom, 64px) + 8px); }
@media (min-width: 721px) and (max-width: 1100px) { .vl-chips { right: 16px; } }
@media (max-width: 720px) {
  .vl-chips { left: 0; right: 0; padding: 2px 16px; }
  .vl-chip { padding: 6px 12px 6px 10px; }
  body.has-village .vl-flash { top: calc(var(--vl-chips-bottom, 100px) + 8px); }
}
