/* Dotstown (/town) — SPEC-TOWN.md §8. Same tokens as style.css. Linked site-wide, so it also
   carries the two cross-links: the feed hero's second button and the profile page's Dotstown card. */

/* ---------- layout: the town takes the whole column; its own panel replaces the rail ---------- */

.layout-town { max-width: 1200px; }
.layout-town .rail { display: none; }
/* The header lines up with the wider town layout while it is on the page. */
body:has(.layout-town) .header-in { max-width: 1200px; }
@media (min-width: 960px) {
  .layout-town { grid-template-columns: minmax(0, 1fr); }
}

.town { display: grid; gap: 14px; align-items: start; }
.town-head { display: grid; gap: 0; }
.town-head .page-h { margin: 4px 0 2px; }
.town-head p { margin: 0 0 6px; font-size: 14px; }

@media (min-width: 1100px) {
  .town { grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; }
  .town-head { grid-column: 1 / -1; }
  .town-panel { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow-y: auto; scrollbar-width: thin; }
}

/* ---------- map card ---------- */

.town-map-card { padding: 8px; overflow: hidden; }
.town-map-wrap { position: relative; }
.town-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  min-height: 260px;
  border-radius: 14px;
  background: var(--bg);
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.town-canvas.dragging { cursor: grabbing; }
.town-canvas.hover { cursor: pointer; }
.town-canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
/* Screen-reader-only announcement of the dot picked with the keyboard. */
.town-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.town-status, .town-recentre {
  position: absolute;
  top: 10px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.town-status { left: 10px; pointer-events: none; }
.town-status::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 6px 1px 0;
  border-radius: 50%;
  background: var(--muted);
}
.town-status[data-state="live"]::before, .town-status[data-state="polling"]::before { background: var(--ok); }
.town-status[data-state="offline"]::before { background: var(--red); }
.town-recentre { right: 10px; color: var(--ink); cursor: pointer; }
.town-recentre:hover { background: var(--chip-bg); }

.town-empty {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 12px 16px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 14px;
}
.town-empty p { margin: 0; }
.town-empty[hidden], .town-focus[hidden] { display: none; }

/* Avatar rings on the floating card, the journal and the rich list (same maths as style.css's
   --ring, with the same fallback where color-mix() is missing). */
.town-focus, .town-ev, .town-rich { --ring: color-mix(in srgb, var(--dot, var(--accent)) 60%, var(--tint-base)); }
@supports not (color: color-mix(in srgb, red, blue)) {
  .town-focus, .town-ev, .town-rich { --ring: var(--dot, var(--accent)); }
}

/* The selected resident's floating card: positioned by town.js with a transform. */
.town-focus {
  position: absolute;
  left: 0;
  top: 0;
  width: 224px;
  padding: 10px 12px 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 13px;
  z-index: 2;
}
.town-focus-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.town-focus-head > div { min-width: 0; overflow-wrap: anywhere; line-height: 1.3; }
.town-focus-head .avatar-img { width: 32px; height: 32px; box-shadow: 0 0 0 2px var(--ring); }
.town-focus-head .muted { font-size: 12px; }
.town-focus-act { margin-top: 6px; color: var(--ink); }
.town-focus .meta { margin-top: 2px; }
.town-focus > a { display: inline-block; margin-top: 6px; font-weight: 600; }

/* ---------- needs bars (floating card, rich list, profile card) ---------- */

.needs { display: grid; gap: 4px; margin: 6px 0 4px; }
.need { display: grid; grid-template-columns: 46px minmax(0, 1fr) 26px; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.need b { color: var(--ink); text-align: right; font-size: 12px; }
.need-bar { display: block; height: 7px; border-radius: 999px; background: var(--chip-bg); overflow: hidden; }
.need-bar i { display: block; height: 100%; border-radius: 999px; transition: width 0.6s ease; }
.need-energy i { background: var(--lime); }
.need-food i { background: var(--yellow); }
.need-social i { background: var(--pink); }

/* ---------- side panel ---------- */

.town-panel { display: grid; gap: 12px; align-content: start; min-width: 0; }
.town-panel .card { padding: 16px 18px; }
@media (min-width: 640px) and (max-width: 1099px) {
  .town-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .town-panel .town-card-journal { grid-column: 1 / -1; }
}

.town-clock { font-size: 20px; letter-spacing: -0.02em; }
.town-stats { gap: 20px; }
.town-stats .stat b { font-size: 26px; }

.town-journal { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; max-height: 440px; overflow-y: auto; scrollbar-width: thin; }
.town-ev { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; line-height: 1.4; min-width: 0; }
.town-ev > div { min-width: 0; }
.town-ev .avatar-img, .town-ev-dot { width: 24px; height: 24px; margin-top: 2px; flex: none; }
.town-ev .avatar-img { box-shadow: 0 0 0 2px var(--ring); }
.town-ev-dot { display: block; border-radius: 50%; background: var(--chip-bg); }
.town-ev-text { overflow-wrap: anywhere; }
.town-ev .meta { font-size: 12px; }

.town-place, .town-rich {
  display: flex;
  align-items: center;
  gap: 10px;
  width: calc(100% + 16px);
  margin: 0 -8px;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font-size: 14px;
}
.town-place:hover, .town-rich:hover { background: var(--chip-bg); }
.town-place-main, .town-rich-name { display: grid; min-width: 0; flex: 1; line-height: 1.3; }
.town-place-main .muted, .town-rich-name .muted { font-size: 12px; }
.town-here { flex: none; min-width: 26px; text-align: center; padding: 1px 8px; border-radius: 999px; background: var(--chip-bg); color: var(--muted-strong); font-size: 12px; }
.town-rank { flex: none; width: 18px; color: var(--muted); font-size: 12px; font-weight: 700; text-align: center; }
.town-rich .avatar-img { width: 28px; height: 28px; box-shadow: 0 0 0 2px var(--ring); }
.town-coins { flex: none; display: inline-flex; align-items: center; gap: 5px; font-size: 13px; }
/* 40% black over the yellow fill = color-mix(yellow 60%, black), without needing color-mix(). */
.town-coins::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--yellow); box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.4); }

.town-how { margin: 0; padding-left: 18px; font-size: 14px; }
.town-how li { margin-bottom: 4px; }
.town-panel .btn { margin-top: 4px; }

/* ---------- cross-links: hero button pair, profile card ---------- */

.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
/* The outline is an inset shadow, not a border, so .btn-soft stays exactly as tall as .btn. */
.btn-soft { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn-soft:hover { opacity: 1; background: var(--chip-bg); }

.town-card { margin-bottom: 14px; }
.town-card-line { font-size: 15px; }
.town-card .needs { max-width: 360px; }
.town-card > a { display: inline-block; margin-top: 4px; font-weight: 600; }

@media (max-width: 480px) {
  .town-map-card { padding: 6px; }
  .town-panel .card { padding: 14px 16px; }
  .town-focus { width: 200px; }
}
