/* OOPS Chiang Mai town (/chiangmai). Uses the oops. tokens from kp.css: paper panels, ink text,
   lantern as the one accent. Panels get a hard pixel shadow to match the art. */

html,
body.town-body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: oklch(0.62 0.09 140);
  overscroll-behavior: none;
}
.town {
  position: fixed;
  inset: 0;
  font-family: var(--font-body);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.town-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  image-rendering: pixelated;
  cursor: pointer;
  outline: none;
}
.town-noscript {
  position: absolute;
  inset: 40px 16px auto;
  background: var(--surface);
  padding: 16px;
  border-radius: var(--r-md);
}

.town-hud,
.town-panel,
.town-dialog,
.town-prompt button,
.town-log p {
  --px-shadow: 3px 3px 0 oklch(0.21 0.02 55 / 0.85);
}
.town button {
  font: inherit;
  color: inherit;
}
.town :focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--focus-halo);
}

/* Components set display, which would override the hidden attribute. */
.town [hidden] {
  display: none !important;
}

/* Top bar */
.town-top {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}
.town-top > * {
  pointer-events: auto;
}
.town-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 7px 14px 7px 10px;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  box-shadow: var(--px-shadow);
  text-decoration: none;
  color: var(--text);
}
.town-mark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: var(--tracking-display);
  line-height: 1;
}
.town-mark-lit {
  color: var(--lantern-ink);
}
.town-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}
.town-brand-text strong {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}
.town-brand-text small {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42vw;
}
.town-toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
}
.town-tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 12px;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  box-shadow: var(--px-shadow);
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}
.town-tool:hover {
  background: var(--lantern-soft);
}
.town-tool[aria-expanded="true"] {
  background: var(--ink);
  color: var(--paper);
}
.town-tool > span[aria-hidden] {
  font-family: var(--font-mono);
  font-weight: 600;
}
.town-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--line-strong);
}
.town-dot.is-on {
  background: var(--jungle);
}

/* Panels */
.town-panel {
  position: absolute;
  top: calc(max(12px, env(safe-area-inset-top)) + 58px);
  right: 12px;
  width: min(340px, calc(100vw - 24px));
  max-height: calc(100% - 200px);
  overflow: auto;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  box-shadow: var(--px-shadow);
  padding: 14px;
  box-sizing: border-box;
  z-index: 4; /* above the prompt and zoom buttons */
}
.town-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}
.town-panel h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}
.town-stamps {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent-text);
}
.town-minimap {
  width: 100%;
  aspect-ratio: 3 / 2;
  display: block;
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  image-rendering: pixelated;
  cursor: crosshair;
  background: var(--paper-2);
}
.town-npc-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 4px;
}
.town-npc-list button {
  width: 100%;
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  text-align: left;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.town-npc-list button:hover {
  background: var(--paper-2);
  border-color: var(--line);
}
.town-npc-list strong {
  display: block;
  font-size: 14px;
}
.town-npc-list small {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}
.town-npc-list .town-stamp {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-subtle);
}
.town-npc-list .town-stamp.is-done {
  color: var(--positive);
}
.town-npc-list canvas {
  width: 22px;
  height: 31px;
  image-rendering: pixelated;
}
.town-npc-list .town-place-icon {
  width: 22px;
  text-align: center;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-text);
}
.town-list-head {
  margin: 12px 0 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: var(--tracking-eyebrow);
  text-transform: uppercase;
  color: var(--text-subtle);
}

/* Forms inside the town */
.town-form {
  display: grid;
  gap: 10px;
}
.town-form label {
  font-size: 13px;
  color: var(--text-muted);
}
.town-form input,
.town-ask input {
  width: 100%;
  box-sizing: border-box;
  min-height: 44px;
  padding: 0 12px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-sm);
}
.town-form .town-row {
  display: flex;
  gap: 8px;
}
.town-form .town-row input {
  flex: 1;
  min-width: 0;
}
.town-note {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
}
.town-error {
  margin: 0;
  font-size: 13px;
  color: var(--danger);
}
.town-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  margin: 12px 0 6px;
}
.town-switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--ink);
}
/* Account panel, signed in: identity, look editor (folds), menu rows, settings, footer. */
.town-acct-id { display: grid; grid-template-columns: 44px 1fr; gap: 12px; align-items: center; margin-bottom: 10px; }
.town-acct-id canvas { width: 44px; height: 44px; image-rendering: pixelated; background: var(--paper-2); border: 2px solid var(--ink); border-radius: var(--r-sm); }
.town-acct-id strong { display: block; font-size: 16px; }
.town-acct-id small { display: block; font-size: 12px; color: var(--text-muted); word-break: break-all; }
.town-acct-badge { display: inline-block; margin-top: 4px; padding: 0 8px; border-radius: 999px; background: var(--ink); color: var(--paper); font-size: 11px; font-weight: 600; }
.town-acct-look { border: 1.5px solid var(--line); border-radius: var(--r-sm); padding: 0 10px; margin-bottom: 10px; }
.town-acct-look summary { cursor: pointer; padding: 8px 0; font-size: 14px; font-weight: 600; }
.town-acct-look[open] summary { border-bottom: 1.5px solid var(--line); margin-bottom: 10px; }
.town-acct-menu { display: grid; border: 1.5px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.town-acct-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 9px 12px; background: var(--surface); border: 0; border-top: 1.5px solid var(--line); color: var(--text); font: inherit; font-size: 14px; text-align: left; text-decoration: none; cursor: pointer; }
.town-acct-row:first-child { border-top: 0; }
.town-acct-row:hover { background: var(--lantern-soft); }
.town-acct-row small { display: block; font-size: 12px; color: var(--text-muted); }
.town-acct-row i { font-style: normal; font-size: 18px; color: var(--text-muted); }
.town-acct-foot { border-top: 1.5px solid var(--line); margin-top: 8px; padding-top: 6px; }

/* Prompt above the player */
.town-prompt {
  position: absolute;
  left: 50%;
  bottom: 168px;
  transform: translateX(-50%);
}
.town-prompt button {
  padding: 8px 14px;
  background: var(--ink);
  color: var(--paper);
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  box-shadow: var(--px-shadow);
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}
.town-prompt kbd {
  font-family: var(--font-mono);
  background: var(--lantern);
  color: var(--ink);
  border-radius: 4px;
  padding: 0 6px;
  margin-right: 6px;
}

/* Journal */
.town-log {
  position: absolute;
  left: 12px;
  top: calc(max(12px, env(safe-area-inset-top)) + 58px);
  display: grid;
  gap: 4px;
  max-width: min(360px, calc(100vw - 24px));
  pointer-events: none;
}
.town-log p {
  margin: 0;
  padding: 5px 10px;
  background: oklch(0.99 0.006 80 / 0.92);
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.4;
  animation: town-fade 7s forwards;
}
.town-log time {
  font-family: var(--font-mono);
  color: var(--text-subtle);
  margin-right: 6px;
}
@keyframes town-fade {
  0%,
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* Hotbar */
.town-hotbar {
  position: absolute;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 6px;
  max-width: calc(100vw - 24px);
  box-sizing: border-box;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  box-shadow: var(--px-shadow);
}
.town-hotbar::-webkit-scrollbar {
  display: none;
}
.town-slot {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 60px;
  height: 56px;
  background: var(--paper-2);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-sm);
  cursor: pointer;
  padding: 0;
}
.town-slot:hover {
  background: var(--lantern-soft);
  border-color: var(--ink);
}
.town-slot.is-campus {
  background: var(--lantern-soft);
}
.town-slot {
  position: relative;
  width: 64px;
  height: 64px;
  gap: 1px;
}
.town-slot kbd {
  position: absolute;
  top: 3px;
  left: 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-subtle);
}
.town-slot span {
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.town-slot canvas {
  width: 18px;
  height: 25px;
  image-rendering: pixelated;
  margin-top: 6px;
}
.town-slot-door {
  width: 14px;
  height: 20px;
  margin-top: 9px;
  margin-bottom: 2px;
  border: 2px solid var(--ink);
  border-bottom: 0;
  border-radius: 7px 7px 0 0;
  background: linear-gradient(var(--lantern), var(--lantern) 60%, var(--ink) 60%);
  box-sizing: border-box;
}

/* Clock in the brand line, and the time-of-day switch in the map panel. */
.town-clock {
  margin-left: 6px;
  color: var(--text);
}
.town-clock:empty {
  display: none;
}
.town-time {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}
.town-seg {
  display: inline-flex;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-pill);
  overflow: hidden;
  background: var(--paper-2);
}
.town-seg button {
  border: 0;
  background: none;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.town-seg button + button {
  border-left: 1.5px solid var(--line-strong);
}
.town-seg button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

/* Opening title card: fades over the flyover and takes no clicks. */
.town-intro {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 4px;
  pointer-events: none;
  color: var(--paper);
  text-shadow:
    0 2px 0 oklch(0.21 0.02 55),
    0 0 24px oklch(0.21 0.02 55 / 0.6);
  animation: town-intro 3.4s ease-in-out forwards;
  z-index: 6;
}
.town-intro .town-mark {
  font-size: 28px;
}
.town-intro strong {
  font-size: clamp(32px, 7vw, 56px);
  letter-spacing: 0.04em;
  line-height: 1.1;
}
.town-intro small {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.18em;
}
@keyframes town-intro {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(1.04);
  }
  18% {
    opacity: 1;
    transform: none;
  }
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-6px);
  }
}

/* Screen-reader text for a line while it is typed out. */
.town-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.town-portrait.is-talking {
  animation: town-talk 0.36s ease-in-out infinite alternate;
}
@keyframes town-talk {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-2px);
  }
}

.town-zoom {
  position: absolute;
  right: 12px;
  bottom: 96px;
  display: grid;
  gap: 6px;
}
.town-zoom button {
  width: 40px;
  height: 40px;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  box-shadow: var(--px-shadow);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

/* NPC dialog */
.town-dialog {
  position: absolute;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 24px));
  --dialog-max: min(62vh, 560px);
  max-height: var(--dialog-max);
  box-sizing: border-box;
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 14px;
  padding: 14px;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  box-shadow: var(--px-shadow);
  z-index: 5;
}
.town-portrait {
  width: 64px;
  height: 91px;
  image-rendering: pixelated;
  background: var(--paper-2);
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
}
.town-dialog-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  /* Cap the column (dialog max minus padding and border) so a long chat
     scrolls inside .town-chat instead of pushing the input off screen. */
  max-height: calc(var(--dialog-max) - 2 * var(--dialog-pad, 14px) - 4px);
}
.town-dialog-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  padding-right: 36px;
  position: relative;
}
.town-dialog-head h2 {
  margin: 0;
  font-size: 17px;
}
.town-dialog-head h2 small {
  font-weight: 500;
  font-size: 13px;
  color: var(--text-muted);
  margin-left: 6px;
}
.town-theme {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--lantern-soft);
  color: var(--accent-text);
}
.town-close {
  position: absolute;
  top: -4px;
  right: -2px;
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  font-size: 24px;
  cursor: pointer;
  border-radius: var(--r-sm);
}
.town-close:hover {
  background: var(--paper-2);
}
.town-chat {
  flex: 1 1 auto;
  min-height: 60px;
  overscroll-behavior: contain;
  overflow-y: auto;
  /* Inner room so focus rings on answer buttons are not clipped. */
  margin: 6px -6px;
  padding: 4px 6px;
  display: grid;
  gap: 8px;
  align-content: start;
}
.town-msg {
  margin: 0;
  font-size: 15px;
  line-height: 1.7;
}
.town-msg.is-you {
  justify-self: end;
  max-width: 85%;
  padding: 6px 12px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 12px 12px 2px 12px;
  font-size: 14px;
}
.town-msg.is-npc {
  max-width: 100%;
  position: relative;
}
.town-msg .town-msg-who {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-subtle);
  margin-bottom: 2px;
}
.town-msg .town-cta {
  margin-top: 6px;
}
.town-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  flex: none;
}
.town-ask {
  flex: none;
}

/* Always-visible map thumbnail under the toolbar; click to walk there. */
.town-corner-map {
  position: absolute;
  left: 12px;
  bottom: 96px;
  width: 240px;
  height: 160px;
  box-sizing: border-box;
  display: block;
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  box-shadow: var(--px-shadow);
  background: var(--paper-2);
  image-rendering: pixelated;
  cursor: crosshair;
  z-index: 3;
}
.town-chip {
  padding: 6px 12px;
  font-size: 13px;
  background: var(--paper-2);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-pill);
  cursor: pointer;
  text-align: left;
}
.town-chip:hover {
  border-color: var(--ink);
  background: var(--lantern-soft);
}
.town-ask {
  display: flex;
  gap: 8px;
}
.town-ask input {
  flex: 1;
  min-width: 0;
}
.town-source {
  font-size: 11px;
  color: var(--text-subtle);
  margin: 4px 0 0;
}

/* Rooms (interiors) */
.town-room {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.town-room-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  border-bottom: 2px solid var(--ink);
  background: var(--surface);
  position: relative;
}
.town-room-head h1 {
  margin: 0;
  font-size: 18px;
  outline: none;
}
.town-room-head .town-close {
  position: static;
}
.town-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: var(--tracking-eyebrow);
  text-transform: uppercase;
  color: var(--text-subtle);
}
.town-back {
  padding: 8px 12px;
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  background: var(--paper-2);
  cursor: pointer;
  white-space: nowrap;
  font-size: 14px;
}
.town-room-body {
  flex: 1;
  overflow: auto;
}
.town-room-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  display: grid;
  gap: 16px;
}
.town-room-inner h2 {
  margin: 0;
  font-size: 20px;
}
.town-room-inner p {
  margin: 0;
  line-height: 1.8;
}
.town-card {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px;
  display: grid;
  gap: 12px;
}
.town-card.is-ink {
  background: var(--night);
  color: var(--on-night);
  border-color: var(--night);
}
.town-card.is-ink .town-note {
  color: var(--on-night-2);
}
.town-steps {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 6px;
  line-height: 1.7;
}
.town-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.town-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
}
.town-status::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--lantern);
}
.town-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: var(--bg);
}

@media (max-width: 640px) {
  .town-tool-label {
    display: none;
  }
  .town-tool {
    padding: 0 11px;
  }
  .town-brand-text small {
    max-width: 34vw;
  }
  /* The area name may be long; give the clock its own line. */
  .town-clock {
    display: block;
    margin-left: 0;
  }
  .town-slot {
    width: 54px;
    height: 58px;
  }
  .town-slot canvas {
    width: 15px;
    height: 21px;
  }
  .town-corner-map {
    width: 132px;
    height: 88px;
  }
  .town-dialog {
    grid-template-columns: 1fr;
    --dialog-max: 70vh;
    --dialog-pad: 12px;
    padding: 12px;
  }
  .town-portrait {
    display: none;
  }
  .town-prompt {
    bottom: 240px;
  }
  .town-corner-map {
    bottom: 140px;
  }
  .town-zoom {
    bottom: 140px;
  }
  .town-room-head .town-back span {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .town-log p {
    animation: none;
  }
  .town-intro {
    display: none;
  }
  .town-portrait.is-talking {
    animation: none;
  }
}

/* The room title is focused only so screen readers announce it; no ring. */
.town .town-room-head h1:focus-visible { outline: none; box-shadow: none; }


/* --- people layer: tabs, passport, board, chat, avatar, say bar, xp, quiz --- */
.town-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  border-bottom: 1.5px solid var(--line);
}
.town-tabs button {
  border: 0;
  background: none;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1.5px;
  cursor: pointer;
}
.town-tabs button[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--ink);
}
.town-time-extra {
  margin-top: 8px;
  justify-content: flex-start;
}
.town-pill {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  background: var(--paper-2);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-pill);
  cursor: pointer;
}
.town-pill[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.town-pass-sum {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.town-pass-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.town-pass {
  position: relative;
  width: 100%;
  display: grid;
  grid-template-columns: 20px 1fr;
  column-gap: 8px;
  align-items: center;
  padding: 8px;
  text-align: left;
  background: var(--paper-2);
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.town-pass canvas {
  grid-row: span 2;
  width: 18px;
  height: 25px;
  image-rendering: pixelated;
  filter: grayscale(1) opacity(0.55);
}
.town-pass.is-done canvas,
.town-pass.is-gold canvas {
  filter: none;
}
.town-pass.is-done {
  border-color: var(--line-strong);
  background: var(--surface);
}
.town-pass.is-gold {
  border-color: var(--lantern);
  background: var(--lantern-soft);
}
.town-pass strong {
  font-size: 12px;
  line-height: 1.3;
}
.town-pass small {
  font-size: 11px;
  color: var(--text-muted);
}
.town-pass-state {
  position: absolute;
  top: 4px;
  right: 7px;
  font-size: 12px;
  color: var(--text-subtle);
}
.town-pass.is-gold .town-pass-state {
  color: var(--accent-text);
}
.town-pass-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.town-board,
.town-chatlog {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}
.town-board li {
  display: grid;
  grid-template-columns: 20px 18px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  background: var(--paper-2);
}
.town-board li.is-me {
  outline: 1.5px solid var(--lantern);
}
.town-board canvas {
  width: 18px;
  height: 25px;
  image-rendering: pixelated;
}
.town-board strong {
  display: block;
  font-size: 13px;
}
.town-board small {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
}
.town-board b {
  font-family: var(--font-mono);
  font-size: 12px;
}
.town-rank {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-subtle);
}
.town-chatlog li {
  font-size: 13px;
  line-height: 1.5;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  background: var(--paper-2);
}
.town-chatlog time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-subtle);
  margin-right: 6px;
}
.town-chatlog strong {
  margin-right: 4px;
}
.town-hr {
  border: 0;
  border-top: 1.5px solid var(--line);
  margin: 12px 0;
}
.town-avatar {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 12px;
  align-items: start;
  margin-bottom: 8px;
}
.town-avatar > canvas {
  width: 48px;
  height: 68px;
  image-rendering: pixelated;
  background: var(--paper-2);
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
}
.town-avatar-form label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}
.town-avatar-form input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-top: 2px;
  padding: 6px 8px;
  font: inherit;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
}
.town-avatar-parts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 8px;
  align-items: center;
  margin: 8px 0;
  font-size: 12px;
  color: var(--text-muted);
}
.town-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.town-swatches button {
  width: 20px;
  height: 20px;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
}
.town-swatches button[aria-pressed="true"] {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--ink);
}
.town-avatar .town-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.town-say {
  position: absolute;
  left: 50%;
  bottom: 104px;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 24px));
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  box-shadow: var(--px-shadow);
  z-index: 5;
}
.town-say .town-chips {
  margin: 0;
}
.town-say .town-source {
  margin: 0;
}
.town-xp {
  position: absolute;
  left: 12px;
  bottom: calc(96px + 160px + 8px);
  width: 240px;
  box-sizing: border-box;
  padding: 5px 8px 6px;
  display: grid;
  grid-template-columns: 1fr auto;
  row-gap: 4px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  box-shadow: var(--px-shadow);
  z-index: 3;
}
.town-xp #xp-num {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text-muted);
}
.town-xp-bar {
  grid-column: 1 / -1;
  display: block;
  height: 6px;
  background: var(--paper-2);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  overflow: hidden;
}
.town-xp-bar b {
  display: block;
  height: 100%;
  width: 0;
  background: var(--lantern);
  transition: width 0.4s ease;
}
.town-chip.is-quiz {
  background: var(--lantern-soft);
  border-color: var(--lantern);
  font-weight: 700;
}
.town-choices {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}
.town-choice {
  text-align: left;
  padding: 8px 12px;
  font-size: 14px;
  background: var(--paper-2);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.town-choice:hover:not(:disabled) {
  border-color: var(--ink);
  background: var(--lantern-soft);
}
.town-choice:disabled {
  cursor: default;
  opacity: 0.75;
}
.town-choice.is-right {
  border-color: #4f8a45;
  background: #e4f1dc;
  opacity: 1;
}
.town-choice.is-wrong {
  border-color: #c94c4c;
  background: #f6dede;
}
.town-slot.is-say {
  background: var(--surface);
  border-style: dashed;
}
.town-slot-emoji {
  font-size: 18px;
  margin-top: 6px;
  line-height: 1;
}
@media (max-width: 640px) {
  .town-xp {
    bottom: calc(140px + 88px + 6px);
    width: 132px;
    padding: 4px 6px 5px;
    font-size: 10px;
  }
  .town-say {
    bottom: 96px;
  }
  .town-pass-grid {
    grid-template-columns: 1fr;
  }
}

/* --- living town: board range, question book, mute, rooms, sources --- */
.town-board-range { margin: 0 0 8px; }
.town-sub { margin: 10px 0 4px; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--kp-muted, #6b5a48); }
.town-asks { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.town-asks li { padding: 4px 0; border-bottom: 1px dashed rgba(43, 33, 24, 0.14); }
.town-asks b { color: #c05a2c; margin-right: 4px; }
.town-asks small { color: var(--kp-muted, #6b5a48); }
.town-mute { border: 0; background: none; cursor: pointer; font-size: 13px; padding: 0 4px; opacity: 0.7; }
.town-mute:hover, .town-mute:focus-visible { opacity: 1; }
.town-mentors { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 6px; }
.town-mentors details { background: #fffdf7; border: 1.5px solid #2b2118; border-radius: 10px; padding: 8px 12px; }
.town-mentors summary { cursor: pointer; font-weight: 700; }
.town-mentors p { margin: 6px 0 0; font-size: 14px; line-height: 1.55; }
.town-degree li { margin-bottom: 10px; }
.town-degree li p { margin: 2px 0 0; font-size: 14px; line-height: 1.55; }
.town-msg .town-source { margin-top: 6px; }
.town-msg .town-source a { color: #c05a2c; }

/* ==========================================================================
   HUD layout. One grid for every screen element so edges and baselines line up.
   Top band:    brand (left) · toolbar (right), same height. The level sits in
                the toolbar, joined to the account button as one profile chip.
   Under the brand card, left edge: the map card (minimap, then the zoom buttons).
   Bottom band: log (left) · hotbar (center), one baseline.
   Below 1100px the hotbar takes the bottom row and the log sits above it.
   ========================================================================== */
.town {
  --m: 12px;
  --gap: 8px;
  --bar-h: 44px;
  --top: max(var(--m), env(safe-area-inset-top));
  --base: max(var(--m), env(safe-area-inset-bottom));
  --map-w: 240px;
  --map-h: 160px;
  --zoom-w: 40px;
  --card-w: var(--map-w);
  --card-h: var(--map-h);
  --hotbar-h: 80px;
  /* where the log's bottom edge sits (wide: on the baseline) */
  --log-b: var(--base);
}

/* Top band: equal heights. */
.town-brand,
.town-tool {
  min-height: var(--bar-h);
  box-sizing: border-box;
}
.town-brand {
  padding-top: 4px;
  padding-bottom: 4px;
}

/* Profile chip: level + account in one bordered box, split by a rule. */
.town-profile {
  display: flex;
  align-items: stretch;
  min-height: var(--bar-h);
  box-sizing: border-box;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  box-shadow: var(--px-shadow);
  overflow: hidden;
}
.town-profile .town-tool {
  min-height: 0;
  border: 0;
  border-left: 2px solid var(--ink);
  border-radius: 0;
  box-shadow: none;
}
.town-profile .town-xp {
  position: static;
  width: auto;
  box-sizing: border-box;
  padding: 0 5px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 8px;
}
/* Level ring: the arc fills with progress to the next level; the number sits inside. */
.xp-ring {
  --p: 0;
  --ring: calc(var(--bar-h) - 10px);
  flex: none;
  width: var(--ring);
  height: var(--ring);
  border-radius: 50%;
  display: grid;
  place-content: center;
  text-align: center;
  line-height: 1;
  background:
    radial-gradient(closest-side, var(--surface) 72%, transparent 74%),
    conic-gradient(var(--lantern) calc(var(--p) * 1%), var(--paper-2) 0);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
.xp-ring small {
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 600;
  color: var(--text-muted);
}
.xp-ring b {
  font-size: 14px;
  font-weight: 800;
}
/* Only the ring shows; the title and points live in the tooltip and aria-label. */
.xp-text {
  display: none;
}

/* Map card: top left, under the brand card. The zoom buttons sit right
   beside the minimap, on its inner side, top-aligned. */
.town-mapcard {
  position: absolute;
  left: var(--m);
  top: calc(var(--top) + var(--bar-h) + var(--gap));
  display: flex;
  align-items: flex-start;
  gap: 6px;
  z-index: 3;
}
.town-mapcard .town-corner-map {
  position: static;
  width: var(--map-w);
  height: var(--map-h);
  box-sizing: border-box;
}
.town-mapcard .town-zoom {
  position: static;
}

/* Hotbar: centered on the screen, on the baseline, never under the log. */
.town-hotbar {
  bottom: var(--base);
  max-width: calc(100vw - 2 * (var(--m) + var(--card-w) + var(--m)));
}

/* Log: bottom left, on the baseline (stacked: above the hotbar). */
.town-log {
  top: auto;
  left: var(--m);
  bottom: var(--log-b);
  width: var(--card-w);
  max-width: var(--card-w);
}

/* Prompt and say box: centered, just above the hotbar. */
.town-prompt {
  bottom: calc(var(--base) + var(--hotbar-h) + var(--gap));
}
.town-say {
  bottom: calc(var(--base) + var(--hotbar-h) + var(--gap));
}

/* Stacked: the hotbar owns the bottom row; the log sits above it. */
@media (max-width: 1099px) {
  .town {
    --map-w: 200px;
    --map-h: 133px;
    --log-b: calc(var(--base) + var(--hotbar-h) + var(--gap));
  }
  .town-hotbar {
    max-width: calc(100vw - 2 * var(--m));
  }
}

@media (max-width: 640px) {
  .town {
    --bar-h: 40px;
    --map-w: 132px;
    --map-h: 88px;
    --hotbar-h: 74px;
  }
  .town-tool {
    min-height: var(--bar-h);
  }
  .town-toolbar {
    gap: 4px;
  }
  .town-tool {
    padding: 0 9px;
  }
  /* Brand: two tight lines; the clock stays on the area line. */
  .town-brand {
    padding: 3px 10px 3px 8px;
    gap: 8px;
  }
  .town-mark {
    font-size: 19px;
  }
  .town-brand-text strong {
    font-size: 13px;
  }
  /* The area name gives way; the clock always shows. */
  .town-brand-text small {
    display: flex;
    max-width: 44vw;
  }
  #town-area {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .town-clock {
    display: inline;
    flex: none;
    margin-left: 6px;
  }
  /* The log shows only its latest line, one prompt-row above the hotbar. */
  .town-log {
    left: var(--m);
    right: var(--m);
    width: auto;
    max-width: none;
    /* one prompt-row (46px) plus a gap higher, so a prompt and a log line never overlap */
    bottom: calc(var(--log-b) + 46px + var(--gap));
  }
  .town-log p:not(:last-child) {
    display: none;
  }
  /* A dialog or the say box covers this band; the log steps aside. */
  .town:has(#town-say:not([hidden])) .town-log,
  .town:has(#town-dialog:not([hidden])) .town-log {
    display: none;
  }
  .town-say {
    bottom: calc(var(--base) + var(--hotbar-h) + var(--gap));
  }
}

/* --------------------------------------------------------------------------
   Icons (Lucide, see js/town/icons.js). Line icons that take the text color.
   -------------------------------------------------------------------------- */
.town-icon {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  vertical-align: -0.2em;
}
.town-tool-icon {
  display: inline-flex;
  font-style: normal;
}
.town-tool-icon .town-icon {
  width: 18px;
  height: 18px;
  vertical-align: 0;
}
.town-pill .town-icon {
  width: 15px;
  height: 15px;
  margin-right: 2px;
}
.town-chip-icon {
  display: inline-grid;
  place-items: center;
  min-width: 40px;
}
.town-chip-icon .town-icon {
  width: 18px;
  height: 18px;
  vertical-align: 0;
}
.town-chip.is-quiz .town-icon {
  width: 15px;
  height: 15px;
}
.town-icon.is-emote {
  width: 20px;
  height: 20px;
  vertical-align: -0.3em;
}
.town-slot-emoji .town-icon {
  width: 18px;
  height: 18px;
}
.town-slot kbd .town-icon {
  width: 10px;
  height: 10px;
  vertical-align: 0;
}
.town-clock .town-icon {
  width: 11px;
  height: 11px;
  margin-right: 3px;
  vertical-align: -0.1em;
}
.town-pass-state .town-icon {
  width: 16px;
  height: 16px;
  vertical-align: 0;
}
.town-pass.is-gold .town-pass-state,
.town-count .town-icon[fill="currentColor"] {
  color: var(--lantern-ink);
}
.town-count {
  white-space: nowrap;
}
.town-count .town-icon {
  width: 12px;
  height: 12px;
  margin-right: 1px;
  vertical-align: -0.1em;
}
.town-place-icon .town-icon,
.town-stamp .town-icon {
  width: 14px;
  height: 14px;
  vertical-align: 0;
}
.town-mute .town-icon {
  width: 14px;
  height: 14px;
}
.town-asks small .town-icon {
  width: 11px;
  height: 11px;
}

/* Staff-bound NPCs (PRD F1.4, F1.6, F1.27): the badge, message labels, sources, Replies. */
.town-npc-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  padding: 1px 8px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.6;
  color: #fffdf7;
  background: #8a8178;
  vertical-align: 2px;
  white-space: nowrap;
}
.town-npc-badge.is-live { background: #2e7d4f; }
.town-npc-badge.is-away { background: #b07a1a; }
.town-npc-badge.is-agent { background: #5f574f; }
.town-npc-badge.is-static { background: #5f574f; white-space: normal; }
.town-human-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.town-human-actions[hidden] { display: none; }
.town-human-actions button { min-height: 40px; }
.town-human-actions button:disabled { opacity: .55; cursor: default; }
.town-account-delete { display: flex; flex-wrap: wrap; gap: 8px; border-top: 1px solid var(--line); margin-top: 16px; padding-top: 12px; }
.town-npc-badge .town-icon,
.town-msg-label .town-icon,
.town-npc-sources .town-icon,
.town-npc-leave .town-icon {
  width: 13px;
  height: 13px;
  vertical-align: -0.15em;
}
.town-msg-meta {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: 4px;
  vertical-align: 1px;
}
.town-msg-label,
.town-msg-flag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0 6px;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.6;
}
.town-msg-label.is-staff { background: #2e7d4f; color: #fffdf7; }
.town-msg-label.is-agent { background: #5f574f; color: #fffdf7; }
.town-msg-flag { border: 1px solid var(--ink); color: var(--ink); }
.town-msg.is-note {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-subtle);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}
.town-msg.is-wait { font-style: italic; }
.town-npc-notify { font-size: 13px; }
.town-unread {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #c05a2c;
  color: #fffdf7;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  box-sizing: border-box;
}
#btn-replies { position: relative; }
#btn-replies .town-unread { margin-left: 2px; }
@media (max-width: 640px) {
  #btn-replies .town-unread {
    position: absolute;
    top: -6px;
    right: -6px;
    margin: 0;
  }
}
.town-replies {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.town-reply {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 8px 10px;
  text-align: left;
  font: inherit;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.town-reply:hover { background: var(--lantern-soft); }
.town-reply.is-unread { border-color: #c05a2c; }
.town-reply-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.town-reply-status { font-size: 12px; color: var(--text-subtle); }
.town-reply-q {
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* A phone with the Replies or desk button: the toolbar needs the brand's text room. */
@media (max-width: 420px) {
  .town:has(#btn-replies:not([hidden])) .town-brand-text,
  .town:has(#btn-staff:not([hidden])) .town-brand-text {
    display: none;
  }
}

/* P6: native modal focus boundaries; compact conversations, large tasks, focus views. */
.town dialog:not([open]) { display: none; }
.town dialog { color: var(--text); font-family: var(--font-body); }
.town dialog::backdrop { background: oklch(0.21 0.02 55 / 0.35); }
dialog.town-room {
  position: fixed;
  inset: 0;
  margin: auto;
  padding: 0;
  width: min(960px, 94vw);
  height: min(800px, 88dvh);
  max-width: none;
  max-height: none;
  box-sizing: border-box;
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  overflow: hidden;
}
dialog.town-room[data-size="compact"] { width: min(640px, 94vw); height: min(560px, 80dvh); }
dialog.town-room[data-size="full"] { width: 100vw; height: 100dvh; border: 0; border-radius: 0; }
dialog.town-room .town-room-body { min-height: 0; }
dialog.town-dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  transform: none;
  width: min(640px, calc(100vw - 24px));
  --dialog-max: min(80dvh, 560px);
}
#town-replies-panel {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(880px, 94vw);
  height: min(720px, 88dvh);
  max-width: none;
  max-height: none;
  box-sizing: border-box;
  overflow: hidden;
}
#town-replies-panel[open] { display: flex; flex-direction: column; }
#replies-body { overflow: auto; min-height: 0; }
.town-tasks-panel {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 20px;
  box-sizing: border-box;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
}
.town-tasks-panel h2 { margin: 0; font-size: 18px; }
.town-tasks-panel .town-close, #town-replies-panel .town-close { position: static; margin-left: auto; }
.town-task-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.town-task-links button {
  min-height: 48px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--paper-2);
  text-align: left;
  cursor: pointer;
}
.town-task-links button:hover { border-color: var(--ink); }
.town-roles { margin: 0 0 14px; }
.town-roles h3 { margin: 0 0 8px; font-size: 13px; color: var(--ink-3, #8A7B6E); }
.town-roles > div { display: flex; flex-wrap: wrap; gap: 8px; }
.town-role { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper-2); color: inherit; font: inherit; font-size: 14px; text-decoration: none; cursor: pointer; }
.town-role:hover { border-color: var(--ink); }
.town-role b { padding: 0 7px; border-radius: 999px; background: var(--accent, #D9653B); color: #fff; font-size: 12px; font-weight: 600; }
@media (max-width: 700px) {
  dialog.town-room, #town-replies-panel {
    width: 100vw;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }
  dialog.town-room[data-size="compact"] { width: calc(100vw - 24px); height: min(560px, 80dvh); border: 2px solid var(--ink); border-radius: var(--r-md); }
  .town-room-head h1 { font-size: 16px; overflow-wrap: anywhere; }
  .town-room-head { padding-bottom: 10px; }
  .town-room-body { padding-bottom: env(safe-area-inset-bottom); }
}

.town-room-head:has(.town-task-switch) { grid-template-columns: auto minmax(0, 1fr) auto auto; }
.town-task-switch {
  flex: none;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--paper-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.town-task-switch:hover { border-color: var(--ink); }
@media (max-width: 700px) {
  .town-task-switch { padding: 8px; font-size: 12px; }
  .library-task-head:has(.town-task-switch) { gap: 8px; }
}
