/* Village (M, village_sheet.rs, www/DESIGN.md, Village): the tab on the book (ui.css, "The book").
   The verso is the village from above, a plan in sumi on the page (village_picture.rs) with the
   places standing on it as their pictures; the recto the treasury (the coins and Build) over
   the residents, the jail and the library, ledgers on the paper. The marks keep their size
   (`.pin`); their cards and a resident's are the page's pops. */
.village-body {
  /* The plan needs no scrolling: its marks' cards may reach past the page's body. */
  .verso .page-body { position: relative; overflow: visible; }
  .plan { position: absolute; inset: 0; display: grid; place-items: center; container-type: size; }
  /* The coins are pictures of themselves (ui/icons/coin.svg, coins.svg), never runes. */
  .art {
    display: block; flex: none;
    &.coin { width: 18px; height: 18px; filter: drop-shadow(0 1px 1px var(--sumi-shade)); }
  }
  .glyph { position: relative; flex: none; display: grid; place-items: center; width: 34px; height: 34px; }
  .building {
    display: block; flex: none;
    img { display: block; width: 100%; height: 100%; }
  }
}

/* ---- The village from above ---------------------------------------------------------------------- */
.plan-stage { position: relative; width: min(100cqw, 100cqh); height: min(100cqw, 100cqh); }
/* The picture is ink on the page's own paper: it fades into the page at its edges. */
.plan-picture { display: block; width: 100%; height: 100%;
  mask: linear-gradient(90deg, transparent, var(--sumi) 9% 91%, transparent), linear-gradient(transparent, var(--sumi) 9% 91%, transparent);
  mask-composite: intersect; }
.plan-north {
  position: absolute; top: 4px; right: 4px; z-index: 2; display: grid; justify-items: center; gap: 3px;
  font: 700 12px/1 var(--face); letter-spacing: 0.1em; color: var(--sumi-soft);
  &::after { content: ""; width: 2px; height: 26px; background: var(--sumi-soft); mask: var(--brush-v) 0 0 / 100% 100% no-repeat; }
}
.plan-marks { position: absolute; inset: 0; z-index: 1; }
.plan-none { position: absolute; inset: 0; display: grid; place-items: center; padding: 30px; text-align: center;
  font: italic 400 15px/1.4 var(--face); color: var(--sumi-faint); }
.plan-marks {
  .pin {
    position: absolute; display: grid; justify-items: center; transform: translate(-50%, -50%);
    &[tabindex] { cursor: pointer; outline: none; }
    > b { position: absolute; top: calc(100% + 2px); white-space: nowrap; font: 700 10.5px/1.2 var(--face); letter-spacing: 0.2em;
      text-transform: uppercase; color: var(--sumi); pointer-events: none; transition: opacity 0.15s;
      text-shadow: 0 0 2px var(--washi), 0 0 3px var(--washi), 0 0 6px var(--washi), 0 0 10px var(--washi), 0 0 14px var(--washi); }
    > i { display: block; rotate: 45deg; }
  }
  /* The buildings that matter, drawn as they stand (`ui/icons/place-*.svg`), their foot on where they are. */
  .place, .house { transform: translate(-50%, -84%); }
  .house .building { width: 24px; height: 24px; filter: drop-shadow(0 2px 2px var(--sumi-shade)); }
  .plaza > i { width: 12px; height: 12px; border: 1.5px solid var(--sumi-soft); background: var(--sumi-wash);
    box-shadow: 0 0 0 5px var(--sumi-wash); }
  .exit {
    width: 14px; height: 14px;
    &::before { content: ""; width: 9px; height: 9px; margin: 2px; rotate: 45deg; border: 1px dashed var(--sumi-soft); }
  }
  :is(.house, .exit, .plaza) > b { letter-spacing: 0.14em; }
  :is(.house, .exit, .you) > b { opacity: 0; }
  :is(.house, .exit, .plaza, .you):hover > b { opacity: 1; }
  .place {
    z-index: 1;
    .building { width: 64px; height: 64px; transform-origin: 50% 84%; transition: transform 0.15s, filter 0.15s;
      filter: drop-shadow(0 4px 3px var(--sumi-shade)); }
  }
  .yours .building { width: 46px; height: 46px; }
  .yours > b { color: var(--gold-ink); }
  /* Where you are and what the pointer is over glow in the accent on paper (it opens a card). */
  .place {
    &.here .building { filter: drop-shadow(0 0 1.5px var(--accent-on-paper)) drop-shadow(0 4px 3px var(--sumi-shade)); }
    &:is(:hover, :focus-within) .building { transform: scale(1.06);
      filter: drop-shadow(0 0 2px var(--accent-on-paper)) drop-shadow(0 6px 5px var(--sumi-shade)); }
    &:is(:hover, :focus-within) > b { color: var(--accent-on-paper); }
  }
  /* You: an ember diamond on the paper with a ring breathing round it. */
  .you {
    z-index: 2; width: 16px; height: 16px;
    > i { width: 10px; height: 10px; margin: 3px; background: var(--accent-on-paper); box-shadow: 0 0 0 2px var(--washi); }
    &::before { content: ""; position: absolute; inset: -9px; border-radius: 50%; border: 1.5px solid var(--accent-on-paper);
      animation: plan-you 2.2s ease-out infinite; }
    > b { color: var(--accent-on-paper); }
  }
  /* You and your home name themselves above their mark, the places below, so they cross less. */
  :is(.you, .yours) > b { top: auto; bottom: calc(100% + 3px); }
  .yours { z-index: 0; }
  /* A mark's card (village_sheet.rs, `card`): what is done there, a pop opened by pointing at the
     mark (or focusing it), kept open by a click (focus), away from the plan's nearer edges (east
     or west of the mark, below or above it). */
  .card {
    position: absolute; z-index: 6; width: 292px; padding: 14px 14px 12px 16px; cursor: default; display: none;
    &.east { left: calc(50% + 34px); }
    &.west { right: calc(50% + 34px); }
    &.down { top: -8px; --from: 6px; }
    &.up { bottom: -8px; --from: -6px; }
  }
  .pin {
    &:is(:hover, :focus-within) { z-index: 7; }
    &:is(:hover, :focus-within) > .card { display: block; animation: pop-in 0.16s ease-out; }
  }
  .card-head {
    display: flex; align-items: center; gap: 12px; padding: 0 2px 10px 6px; border-bottom: 1px solid var(--line);
    .building { width: 46px; height: 46px; filter: drop-shadow(0 3px 5px var(--shadow-soft)); }
    .glyph.dot { width: 46px; height: 46px; }
    .glyph.dot i { width: 14px; height: 14px; rotate: 45deg; border: 2px solid var(--paper); }
  }
  .card-title {
    display: flex; flex-direction: column; gap: 3px; min-width: 0;
    b { font: 600 19px/1.15 var(--face); color: var(--paper-bright); }
    small { font: 600 11px/1 var(--face); letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent-hi); }
  }
  .acts { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 4px; margin: 10px 0 0; padding: 0; list-style: none;
    &:has(> li:only-child) { grid-template-columns: 1fr; }
    > li:only-child .act { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 8px 10px; text-align: left; font-size: 14px; }
  }
  .act {
    display: flex; flex-direction: column; align-items: center; gap: 6px; width: 100%; height: 100%; padding: 9px 4px 8px;
    border: 1px solid transparent; border-radius: 3px; background: none; color: var(--paper); font: 500 13px/1.2 var(--face);
    text-align: center; transition: background 0.15s, border-color 0.15s, color 0.15s;
    .act-pic { width: 40px; height: 40px; filter: drop-shadow(0 3px 4px var(--shadow-soft)); transition: translate 0.18s var(--ease-spring), scale 0.18s var(--ease-spring); }
    &.go { cursor: pointer; }
    &.go:hover, &.go:focus-visible { border-color: var(--accent-rim); background: var(--accent-wash); color: var(--accent-hi); outline: none; }
    &.go:hover .act-pic { translate: 0 -2px; scale: 1.08; }
  }
}
@keyframes plan-you { from { opacity: 0.8; scale: 0.5; } to { opacity: 0; scale: 1.5; } }

/* ---- The recto: the treasury over the live page ------------------------------------------------ */
.village-body {
  .recto .page-body { display: flex; flex-direction: column; gap: 30px; padding-right: 6px; }
  .village-treasury { flex: none;
    > .note { margin: 0 0 12px; }
  }
  .village-live { display: grid; gap: 30px; }
}
/* The treasury: the hoard and the village's coins in gold, and Build beside them: the way into
   the Build view, open to the founder at the Elder Hall; faded with why under it otherwise. It
   beckons while the village can pay for something. */
.village-body .treasury {
  .treasury-head { display: flex; align-items: center; gap: 16px; }
  .art.hoard { width: 72px; height: 72px; margin: -6px 0 -6px -8px; filter: drop-shadow(0 4px 4px var(--sumi-shade)); }
  .sum {
    display: flex; flex-direction: column; gap: 7px; min-width: 0;
    b { font: 500 42px/1 var(--face); font-variant-numeric: tabular-nums; color: var(--gold-ink); }
    span { font: 600 10.5px/1 var(--face); letter-spacing: 0.22em; text-transform: uppercase; color: var(--sumi-faint); }
  }
  .build-call {
    display: flex; flex-direction: column; align-items: flex-end; gap: 7px; margin-left: auto;
    .why { max-width: 230px; font: italic 400 13px/1.3 var(--face); text-align: right; color: var(--sumi-faint); }
  }
}
.cta.build.ready::before { animation: raise-beckon 2.4s ease-in-out infinite; }
@keyframes raise-beckon { 50% { filter: url(#ink-brush) drop-shadow(0 0 18px var(--accent-rim)); } }

/* A ledger's head: its name in the serif, its count, and what its right column holds in small
   capitals. */
.village-body .people-head {
  display: flex; align-items: baseline; gap: 10px; padding: 0 4px 10px;
  .count { font: 500 15px/1 var(--face); font-variant-numeric: tabular-nums; color: var(--sumi-soft); }
  .given-head { margin-left: auto; font: 600 10.5px/1 var(--face); letter-spacing: 0.2em; text-transform: uppercase; color: var(--sumi-faint); }
}
.village-body .sex { flex: none; width: 14px; height: 14px; color: var(--sumi-faint); }
/* The residents, those here first, then by what they gave today; pointing at one opens their
   card; your own line is picked out. */
.village-body .people-list > .person {
  position: relative; grid-template-columns: 14px minmax(0, 1fr) auto minmax(72px, auto); gap: 14px; cursor: default; outline: none;
  &:is(:hover, :focus):not(.on) { background: var(--sumi-wash); }
  .presence { width: 8px; height: 8px; margin-left: 3px; rotate: 45deg; border: 1.5px solid var(--sumi-faint); }
  &.online .presence { border-color: var(--jade-ink); background: var(--jade-ink); }
  .who {
    display: flex; align-items: center; gap: 8px; min-width: 0;
    b { font: 600 16px/1.2 var(--face); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    small { font: 700 9.5px/1 var(--face); letter-spacing: 0.2em; text-transform: uppercase; color: var(--accent-on-paper); }
  }
  .level { font: 400 14px/1 var(--face); color: var(--sumi-faint); font-variant-numeric: tabular-nums; }
  .given {
    display: inline-flex; align-items: center; justify-content: flex-end; gap: 7px; font-variant-numeric: tabular-nums;
    b { font: 600 17px/1 var(--face); color: var(--gold-ink); }
    &.none .art { filter: grayscale(1); opacity: 0.45; }
    &.none b { color: var(--sumi-faint); font-weight: 400; }
  }
  &:not(.online) .who b { color: var(--sumi-soft); font-weight: 500; }
}
/* A resident's card: a pop, fixed with no offsets, so it stands where the row starts and is
   moved out to its left, over the plan, and the page's scrolling never clips it. */
.village-body .person-card { position: fixed; z-index: 8; display: none; gap: 14px; align-items: stretch; width: 300px; padding: 12px 12px 12px 14px;
  transform: translate(calc(-100% - 46px), -38%); pointer-events: none; color: var(--paper);
  .portrait {
    position: relative; flex: none; width: 120px; height: 144px; overflow: hidden; border-radius: 2px;
    background: radial-gradient(90% 70% at 50% 35%, var(--plate-lit), var(--ink)); box-shadow: inset 0 0 0 1px var(--line);
    img { display: block; width: 100%; height: 100%; object-fit: cover; }
    &::after { content: ""; position: absolute; inset: 0; box-shadow: inset 0 -30px 30px -18px var(--veil); }
    &.unseen::before { content: ""; position: absolute; left: 50%; top: 26%; width: 46px; height: 54px; margin-left: -23px;
      border-radius: 50% 50% 46% 46%; background: var(--paper-fill); box-shadow: 0 64px 0 18px var(--paper-fill); }
  }
  .facts {
    display: flex; flex-direction: column; gap: 8px; min-width: 0; padding-top: 4px;
    > b { font: 600 20px/1.15 var(--face); color: var(--paper-bright); overflow-wrap: anywhere; }
  }
  .line { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
  .sex { width: 16px; height: 16px; color: var(--muted); }
  .state { font: 600 11px/1 var(--face); letter-spacing: 0.16em; text-transform: uppercase; color: var(--faint); }
}
.village-body .person:is(:hover, :focus) .person-card { display: flex; animation: pop-in 0.12s ease-out; }
.village-body .person.online .person-card .state { color: var(--jade-hi); }

/* The jail: the village's own held elsewhere, each with where, until when, the ransom and Pay
   ransom (faded with why when it cannot be paid); then whom its own jail holds, and to a
   prisoner's ally, Break the jail open, or how far along it is. */
.village-body .jail-list > .held {
  grid-template-columns: minmax(0, 1fr) auto; gap: 6px 14px;
  .who {
    display: flex; flex-direction: column; gap: 4px; min-width: 0;
    b { font: 600 16px/1.2 var(--face); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    small { font: italic 400 13.5px/1.3 var(--face); color: var(--sumi-faint); }
    .tag { font: 700 9.5px/1 var(--face); font-style: normal; letter-spacing: 0.2em; text-transform: uppercase; color: var(--jade-ink); }
  }
  .price {
    display: inline-flex; align-items: center; justify-content: flex-end; gap: 7px; font-variant-numeric: tabular-nums;
    b { font: 600 17px/1 var(--face); color: var(--gold-ink); }
  }
  .pay {
    grid-column: 1 / -1; display: flex; align-items: center; justify-content: flex-end; gap: 12px;
    .why { font: italic 400 13px/1.3 var(--face); text-align: right; color: var(--sumi-faint); }
  }
  &.paid .price b { color: var(--sumi-faint); font-weight: 400; }
}
.village-body .jail.away .held .who small { color: var(--vermilion-ink); }
.village-body .breakout {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 14px 4px 0;
  .problem { margin: 0; }
  &.under-way span:first-child { font: 400 15px/1.4 var(--face); color: var(--sumi-soft); }
  .bar { position: relative; width: 100%; height: 5px; background: var(--sumi-line); overflow: hidden; }
  .bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent-on-paper); transition: width 0.1s linear; }
}

/* The storehouse, under the coins: the materials the residents brought home, each its name, the
   territory it was gathered in, how far from the village that is and how much (village_sheet.rs). */
.village-body .storehouse {
  margin-top: 22px;
  > .muted { margin: 12px 4px 0; font: italic 400 14.5px/1.4 var(--face); }
  .stored {
    grid-template-columns: minmax(0, 1fr) auto minmax(48px, auto); gap: 16px; padding-block: 8px;
    .who { display: flex; flex-direction: column; gap: 5px; min-width: 0;
      b { font: 600 16px/1.2 var(--face); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
      small { font: italic 400 13px/1.3 var(--face); color: var(--sumi-faint); } }
    .far { font: 400 13.5px/1 var(--face); color: var(--sumi-faint); white-space: nowrap;
      b { font-weight: 600; color: var(--sumi-soft); font-variant-numeric: tabular-nums; }
      &.unknown { font-style: italic; } }
    .amount { text-align: right; }
    .amount b { font: 400 20px/1 var(--face); font-variant-numeric: tabular-nums; color: var(--sumi); }
  }
}

/* The library: the scrolls the residents found again and gave the village, each its picture, its
   name in its rarity's ink, and how many copies it holds (village_sheet.rs). */
.village-body .library {
  > .muted { margin: 12px 4px 0; font: italic 400 14.5px/1.4 var(--face); }
  .copy {
    grid-template-columns: auto minmax(0, 1fr) auto; gap: 16px; padding-block: 8px;
    .pic { width: 54px; height: 37px; }
    .who { display: flex; flex-direction: column; gap: 5px; min-width: 0;
      b { font: 600 16px/1.2 var(--face); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: currentColor; }
      small { font: 600 9.5px/1 var(--face); letter-spacing: 0.2em; text-transform: uppercase; color: var(--sumi-faint); } }
    .copies b { font: 400 20px/1 var(--face); font-variant-numeric: tabular-nums; color: var(--sumi); }
  }
}
@media (max-height: 800px) {
  .village-body {
    .recto .page-body, .village-live { gap: 22px; }
    .treasury .sum b { font-size: 34px; }
    .treasury .art.hoard { width: 60px; height: 60px; }
  }
}
@media (prefers-reduced-motion: reduce) { .plan-marks .you::before { animation: none; } }
