* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ── Welcome page ───────────────────────────────────────────────────────── */

body.welcome {
  background: #0a0a0f;
  color: #e0e0e0;
  font-family: system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
}
body.welcome h1 {
  font-size: 2.5rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 1rem;
  letter-spacing: 0.02em;
}
.subtitle {
  font-size: 1.1rem;
  color: #9ca3af;
  max-width: 480px;
  line-height: 1.6;
  margin-bottom: 0.6rem;
}
.play-btn {
  display: inline-block;
  margin-top: 2.5rem;
  padding: 0.9rem 3rem;
  background: #22c55e;
  color: #000;
  font-size: 1.25rem;
  font-weight: 700;
  border-radius: 8px;
  text-decoration: none;
  letter-spacing: 0.04em;
  transition:
    background 0.15s,
    transform 0.1s;
  box-shadow: 0 4px 20px rgba(34, 197, 94, 0.35);
}
.play-btn:hover {
  background: #16a34a;
  transform: translateY(-2px);
}
.play-btn:active {
  transform: translateY(0);
}

/* ── Game page ──────────────────────────────────────────────────────────── */

body.game {
  background: #000;
  overflow: hidden;
  font-family: "Segoe UI", sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
canvas {
  display: block;
  touch-action: none;
}

.hud {
  position: absolute;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 8px;
  padding: 10px 14px;
  pointer-events: none;
  user-select: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(4px);
}

#hud-left-col {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(300px, calc(100vw - 28px));
  pointer-events: none;
}
#hud-pos,
#hud-tile-detail {
  position: static;
  width: 100%;
}
#hud-pos {
  font-size: 13px;
  line-height: 1.7;
}
#hud-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  pointer-events: auto;
}
#hud-title-row strong {
  font-size: 15px;
  color: #a8d8ff;
}
#btn-world-info {
  background: none;
  border: none;
  cursor: pointer;
  color: #a8d8ff;
  font-size: 13px;
  padding: 0;
  pointer-events: auto;
}
#hud-editor-buttons {
  display: flex;
  gap: 4px;
  pointer-events: auto;
}
#hud-editor-buttons button {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  line-height: 1.3;
}
#hud-nick-row {
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
}
.hud-stat {
  pointer-events: auto;
}
#hud-hp {
  display: inline-block;
  min-width: 7ch;
}
#hud-ac,
#hud-wc,
#hud-fatigue {
  display: inline-block;
  min-width: 3ch;
}
#nick-display {
  display: inline;
}
#nick-edit-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #a8d8ff;
  font-size: 11px;
  padding: 0 0 0 4px;
  vertical-align: middle;
  pointer-events: auto;
}
#nick-edit-row {
  display: inline;
}
#nick-edit-row input {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  font-size: 12px;
  padding: 1px 4px;
  border-radius: 3px;
  width: 110px;
  pointer-events: auto;
}
#nick-edit-row button {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  cursor: pointer;
  font-size: 11px;
  padding: 1px 4px;
  border-radius: 3px;
  pointer-events: auto;
  margin-left: 2px;
}

#hud-toast {
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  min-width: 240px;
  max-width: min(460px, calc(100vw - 28px));
  text-align: center;
  font-size: 13px;
  line-height: 1.4;
  display: none;
  z-index: 1020;
  pointer-events: none;
  border-color: rgba(120, 220, 160, 0.6);
  background: rgba(18, 95, 55, 0.9);
}
#hud-toast.error {
  border-color: rgba(255, 150, 120, 0.6);
  background: rgba(120, 35, 25, 0.92);
}

#hud-active-actions {
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  font-size: 13px;
  pointer-events: auto;
  z-index: 1020;
}
.active-action-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.active-action-row button {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  background: rgba(150, 40, 40, 0.88);
}
.active-action-row button:hover {
  background: rgba(178, 50, 50, 1);
}

/* The aiming row in the active-actions panel is tinted to distinguish an
   armed-but-uncast action from ongoing follow/fight/approaches. */
.active-action-aim {
  background: rgba(150, 90, 40, 0.55);
  border-radius: 6px;
  padding: 2px 6px;
}

#hud-world-info-panel {
  top: 14px;
  right: 14px;
  width: min(260px, calc(100vw - 28px));
  font-size: 12px;
  line-height: 1.9;
  display: none;
  pointer-events: auto;
  z-index: 1001;
}
.world-info-type {
  font-size: 13px;
  font-weight: 700;
  color: #a8d8ff;
  margin-bottom: 4px;
}
.world-info-desc {
  color: #d8e7c2;
  font-style: italic;
  line-height: 1.35;
  margin-bottom: 8px;
}
.world-info-legend-title {
  display: block;
  margin-bottom: 4px;
  color: #a8d8ff;
  font-size: 13px;
}
.leg {
  display: flex;
  align-items: center;
  gap: 8px;
}
.leg-box {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.25);
}
#legend-ground {
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
}
#legend-you {
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
}

#hud-keys {
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: #ccc;
  white-space: nowrap;
  text-align: center;
}
#hud-keys kbd {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: inherit;
}

#hud-auth-status {
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 280px;
  max-width: min(600px, calc(100vw - 28px));
  text-align: center;
  font-size: 12px;
  line-height: 1.5;
  display: none;
  z-index: 1010;
  pointer-events: auto;
  border-color: rgba(255, 196, 112, 0.6);
  background: rgba(120, 70, 10, 0.86);
}

#hud-tree-actions {
  bottom: 14px;
  right: 14px;
  pointer-events: auto;
  display: flex;
  gap: 8px;
}
#hud-tree-actions button {
  font-size: 13px;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
}
#btn-use {
  background: rgba(139, 69, 19, 0.85);
  border-color: rgba(160, 82, 45, 0.5);
}
#btn-use:hover {
  background: rgba(160, 82, 45, 1);
}
#btn-pick {
  background: rgba(25, 115, 72, 0.85);
  border-color: rgba(72, 190, 130, 0.55);
}
#btn-pick:hover {
  background: rgba(32, 145, 92, 1);
}
#btn-items {
  background: rgba(49, 76, 168, 0.88);
  border-color: rgba(130, 165, 255, 0.55);
}
#btn-items:hover {
  background: rgba(67, 100, 200, 1);
}
#btn-stats {
  background: rgba(150, 40, 40, 0.88);
  border-color: rgba(224, 122, 122, 0.55);
}
#btn-stats:hover {
  background: rgba(178, 50, 50, 1);
}

#hud-use-picker {
  right: 14px;
  bottom: 70px;
  width: min(260px, calc(100vw - 28px));
  display: none;
  pointer-events: auto;
  z-index: 1002;
  padding: 10px;
}
#use-picker-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: min(56vh, 460px);
  overflow-y: auto;
}
.use-picker-category {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.6;
  margin: 6px 2px 1px;
}
.use-picker-category:first-child {
  margin-top: 0;
}
#use-picker-actions button {
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
  font-family: inherit;
}
#use-picker-actions button:hover {
  background: rgba(255, 255, 255, 0.2);
}

#hud-inventory-panel {
  right: 14px;
  bottom: 70px;
  width: min(340px, calc(100vw - 28px));
  max-height: min(52vh, 460px);
  overflow: hidden;
  display: none;
  pointer-events: auto;
  padding: 10px;
  z-index: 1001;
}
#hud-statistics-panel {
  right: 14px;
  bottom: 70px;
  width: min(340px, calc(100vw - 28px));
  max-height: min(52vh, 460px);
  overflow: hidden;
  display: none;
  pointer-events: auto;
  padding: 10px;
  z-index: 1001;
}
#hud-container-panel {
  /* Opposite corner from #hud-inventory-panel: the container panel is shown
     alongside the inventory panel (see openContainer() in
     client-container-panel.js), so it needs a non-overlapping anchor
     instead of the shared right:14px/bottom:70px spot every other
     (mutually-exclusive) side panel uses. */
  left: 14px;
  bottom: 70px;
  width: min(340px, calc(100vw - 28px));
  max-height: min(52vh, 460px);
  overflow: hidden;
  display: none;
  pointer-events: auto;
  padding: 10px;
  z-index: 1002;
}
.inv-slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}
.inv-slot {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  padding: 6px;
  font-size: 12px;
  line-height: 1.5;
}
.inv-slot .name {
  font-weight: 700;
  color: #d2e8ff;
}
.inv-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.inv-actions button,
.inv-row button {
  font-size: 11px;
  line-height: 1.2;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
  font-family: inherit;
}
.inv-actions button:hover,
.inv-row button:hover {
  background: rgba(255, 255, 255, 0.2);
}
#inv-bag-list,
#stats-list,
#container-list {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  max-height: min(32vh, 250px);
  overflow-y: scroll;
  padding: 4px 6px;
  display: grid;
  grid-template-columns: minmax(33%, 1fr) auto;
  align-items: start;
  column-gap: 8px;
  font-size: 12px;
}
.inv-row {
  display: contents;
}
.inv-row .label {
  color: #e6f3ff;
  word-break: break-word;
  padding: 5px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.inv-row-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-start;
  padding: 5px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
#inv-footer {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: #cfdde7;
}
.living-value-meter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.living-value-meter-track {
  width: 60px;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}
.living-value-meter-fill {
  height: 100%;
  background: #7dd3fc;
  border-radius: 3px;
}
.living-value-meter-text {
  font-size: 11px;
  color: #cfdde7;
  white-space: nowrap;
}

#hud-tile-detail {
  max-height: min(52vh, 400px);
  overflow-y: auto;
  display: none;
  pointer-events: auto;
  padding: 10px;
  z-index: 1001;
}
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.panel-title {
  font-size: 13px;
  font-weight: 700;
  color: #a8d8ff;
}
.panel-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  opacity: 0.7;
  font-family: inherit;
}
.panel-close:hover {
  opacity: 1;
}
#hud-tile-detail .tile-section {
  margin-bottom: 8px;
}
#hud-tile-detail .tile-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #88bbdd;
  margin-bottom: 4px;
}
#hud-tile-detail .tile-row {
  font-size: 12px;
  color: #ddeeff;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  word-break: break-all;
}
#hud-tile-detail .tile-row:last-child {
  border-bottom: 0;
}
#hud-tile-detail .tile-living-entry {
  padding-top: 6px;
  margin-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}
#hud-tile-detail .tile-living-entry:first-child {
  padding-top: 0;
  margin-top: 0;
  border-top: 0;
}
#hud-tile-detail .tile-living-name {
  font-size: 12px;
  font-weight: 700;
  color: #a8d8ff;
  padding: 3px 0;
}
#hud-tile-detail .tile-living-description {
  font-size: 11px;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.72);
  font-style: italic;
  padding: 0 0 3px;
}
#hud-tile-detail .tile-empty {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.4);
  font-style: italic;
}
#hud-tile-detail .tile-you {
  color: #7dd3fc;
  font-weight: 700;
}

/* Speech bubbles: an overlay above the canvas, positioned per frame from the
   speaker's avatar. The layer never takes pointer events — a bubble must not
   swallow a tap meant for the world (or the NPC) underneath it. */
#speech-bubbles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 900;
  overflow: hidden;
}
#speech-bubbles .speech-bubble {
  position: absolute;
  /* left/top from the projection mark the speaker's head, so the bubble is
     centred on it and sits fully above it. */
  transform: translate(-50%, -100%);
  max-width: 220px;
  padding: 6px 9px;
  border-radius: 10px;
  background: rgba(12, 18, 28, 0.88);
  border: 1px solid rgba(168, 216, 255, 0.35);
  color: #eaf3ff;
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  animation: speech-bubble-in 140ms ease-out;
}
/* Matches the chat panel's NPC colour, so the same voice reads the same in
   both places. */
#speech-bubbles .speech-bubble.is-npc {
  border-color: rgba(232, 192, 122, 0.55);
  color: #f6e6c8;
}
@keyframes speech-bubble-in {
  from {
    opacity: 0;
    transform: translate(-50%, -92%);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -100%);
  }
}

/* Dialogue: a panel the conversation lives in, above the HUD but below the
   editors. Wide enough for a paragraph, and the choices read as a list of
   things you could say rather than as toolbar buttons. */
#hud-dialogue {
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  width: min(520px, calc(100vw - 28px));
  pointer-events: auto;
  z-index: 1015;
  border-color: rgba(232, 192, 122, 0.45);
}
#dialogue-speaker {
  font-size: 13px;
  font-weight: 700;
  color: #e8c07a;
  margin-bottom: 4px;
}
#dialogue-text {
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: 10px;
}
#dialogue-choices {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dialogue-choice {
  text-align: left;
  font-family: inherit;
  font-size: 12px;
  line-height: 1.35;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: #eaf3ff;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.22);
}
.dialogue-choice:hover {
  background: rgba(255, 255, 255, 0.14);
}
#dialogue-close {
  margin-top: 10px;
  font-family: inherit;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 5px;
  cursor: pointer;
  color: #fff;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.25);
}
#hud-tile-detail .tile-talk-btn {
  font-family: inherit;
  font-size: 11px;
  padding: 3px 9px;
  margin: 2px 0 4px;
  border-radius: 5px;
  cursor: pointer;
  color: #f6e6c8;
  background: rgba(232, 192, 122, 0.16);
  border: 1px solid rgba(232, 192, 122, 0.45);
  pointer-events: auto;
}

#joystick-container {
  position: absolute;
  bottom: 14px;
  left: 14px;
  width: 140px;
  height: 140px;
  pointer-events: auto;
  touch-action: auto;
  display: block; /* Always visible for debugging */
  z-index: 1000;
}
#joystick-base {
  position: absolute;
  width: 140px;
  height: 140px;
  background: rgba(0, 0, 0, 0.4);
  border: 3px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  backdrop-filter: blur(4px);
  touch-action: auto;
}
#joystick-stick {
  position: absolute;
  width: 50px;
  height: 50px;
  background: rgba(255, 255, 255, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: all 0.1s ease-out;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
#joystick-stick.active {
  background: rgba(41, 128, 185, 0.8);
  border-color: rgba(41, 128, 185, 1);
}

/* Joystick always visible, can hide keyboard hints on touch devices */
@media (hover: none) and (pointer: coarse) {
  #hud-keys {
    display: none;
  }
}

/* ── Players panel ──────────────────────────────────────────────────── */
#hud-players-panel {
  right: 14px;
  bottom: 70px;
  width: min(380px, calc(100vw - 28px));
  max-height: min(55vh, 480px);
  overflow: hidden;
  display: none;
  pointer-events: auto;
  padding: 10px;
  z-index: 1001;
}
#players-list-wrap {
  max-height: min(44vh, 380px);
  overflow-y: auto;
  margin-top: 6px;
}
.players-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.players-table th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #88bbdd;
  text-align: left;
  padding: 4px 6px 6px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}
.players-table td {
  padding: 5px 6px;
  color: #ddeeff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  vertical-align: middle;
}
.players-table tr:last-child td {
  border-bottom: 0;
}
.players-table .you-badge {
  font-size: 10px;
  color: #7dd3fc;
  font-weight: 700;
  margin-left: 4px;
}
.players-table .world-badge {
  font-size: 10px;
  color: #aaa;
}
.players-table .time-cell {
  font-size: 11px;
  color: #99aacc;
  white-space: nowrap;
}
.btn-dm {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  color: #fff;
  background: rgba(49, 76, 168, 0.75);
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.btn-dm:hover {
  background: rgba(67, 100, 200, 1);
}
#btn-players {
  background: rgba(80, 50, 140, 0.88);
  border-color: rgba(180, 140, 255, 0.55);
}
#btn-players:hover {
  background: rgba(100, 65, 180, 1);
}
#btn-players.has-activity {
  background: rgba(100, 65, 180, 1);
}

/* ── Chat panel ─────────────────────────────────────────────────────── */
#hud-chat-panel {
  right: 14px;
  bottom: 70px;
  width: min(400px, calc(100vw - 28px));
  height: min(60vh, 520px);
  display: none;
  flex-direction: column;
  pointer-events: auto;
  padding: 10px;
  z-index: 1001;
}
#hud-chat-panel.visible {
  display: flex;
}
.chat-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}
.chat-tab {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  font-family: inherit;
  position: relative;
}
.chat-tab.active {
  background: rgba(49, 76, 168, 0.85);
  border-color: rgba(130, 165, 255, 0.55);
  color: #fff;
}
.chat-tab .unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #e74c3c;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  border-radius: 8px;
  padding: 1px 4px;
  line-height: 1.4;
  display: none;
}
.chat-tab .unread-badge.visible {
  display: block;
}
.chat-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.chat-content.hidden {
  display: none;
}
.chat-msgs {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 2px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chat-msg {
  font-size: 12px;
  line-height: 1.4;
  color: #ddeeff;
}
.chat-msg .msg-nick {
  font-weight: 700;
  color: #a8d8ff;
  margin-right: 4px;
}
.chat-msg .msg-nick.is-me {
  color: #7dd3fc;
}
/* A living that is not a person talking: warmer than the player blues, so a
   line from the world reads as such at a glance. */
.chat-msg .msg-nick.is-npc {
  color: #e8c07a;
}
.chat-msg .msg-ts {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.35);
  margin-left: 4px;
}
.chat-input-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.chat-input-row input {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
  padding: 6px 8px;
  font-family: inherit;
  outline: none;
}
.chat-input-row input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}
.chat-input-row input:focus {
  border-color: rgba(130, 165, 255, 0.7);
}
.chat-input-row button {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid rgba(130, 165, 255, 0.55);
  color: #fff;
  background: rgba(49, 76, 168, 0.85);
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.chat-input-row button:hover {
  background: rgba(67, 100, 200, 1);
}
.dm-convos {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.dm-convo-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  font-size: 12px;
  color: #ddeeff;
}
.dm-convo-item:hover {
  background: rgba(255, 255, 255, 0.12);
}
.dm-convo-item .convo-nick {
  font-weight: 600;
}
.dm-back {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ddeeff;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font-family: inherit;
  margin-bottom: 6px;
  display: inline-block;
}
.dm-back:hover {
  background: rgba(255, 255, 255, 0.16);
}
#btn-chat {
  background: rgba(14, 100, 80, 0.88);
  border-color: rgba(60, 200, 160, 0.55);
  position: relative;
}
#btn-chat:hover {
  background: rgba(20, 130, 100, 1);
}
#btn-chat .unread-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #e74c3c;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 5px;
  line-height: 1.4;
  display: none;
}
#btn-chat .unread-badge.visible {
  display: block;
}

/* ── Item / action / living class panels ────────────────────────────────── */
#btn-item-classes {
  background: rgba(30, 90, 60, 0.85);
  border-color: rgba(80, 200, 130, 0.55);
}
#btn-item-classes:hover {
  background: rgba(40, 120, 80, 1);
}
#btn-action-classes {
  background: rgba(90, 30, 90, 0.85);
  border-color: rgba(200, 80, 200, 0.55);
}
#btn-action-classes:hover {
  background: rgba(120, 40, 120, 1);
}
#btn-living-classes {
  background: rgba(30, 70, 110, 0.85);
  border-color: rgba(80, 150, 220, 0.55);
}
#btn-living-classes:hover {
  background: rgba(40, 95, 145, 1);
}
#btn-world-classes {
  background: rgba(110, 80, 30, 0.85);
  border-color: rgba(220, 170, 80, 0.55);
}
#btn-world-classes:hover {
  background: rgba(145, 105, 40, 1);
}

#hud-item-class-panel,
#hud-action-class-panel,
#hud-living-class-panel,
#hud-world-class-panel,
#hud-tile-class-panel {
  right: 14px;
  bottom: 90px;
  width: min(400px, calc(100vw - 28px));
  max-height: min(85vh, 700px);
  overflow-y: auto;
  display: none;
  pointer-events: auto;
  padding: 10px;
  z-index: 1001;
}
.class-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 144px;
  overflow-y: scroll;
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  padding-bottom: 8px;
}
.class-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 5px;
  font-size: 12px;
}
.class-row-id {
  font-weight: 700;
  color: #a8d8ff;
  flex: 0 0 auto;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.class-row-label {
  flex: 1;
  color: #ddeeff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}
.class-row-btns {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
}
.class-row-btns button {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.12);
}
.class-row-btns button:hover {
  background: rgba(255, 255, 255, 0.22);
}
.class-form-title {
  font-weight: 700;
  color: #a8d8ff;
  font-size: 12px;
  margin-bottom: 8px;
}
.class-form-fields {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.class-form-fields label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: #cfdde7;
}
.class-form-fields input[type="text"],
.class-form-fields select,
.class-form-fields textarea {
  font-size: 12px;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 5px;
  color: #fff;
  padding: 4px 7px;
}
.class-form-fields input[type="text"]:disabled {
  opacity: 0.5;
}
.class-form-fields textarea {
  resize: vertical;
  min-height: 52px;
}
.class-form-fields input[type="checkbox"] {
  width: auto;
  margin-right: 4px;
}
/* Hex field + swatch picker + "Auto" reset, on one row (living class color). */
.class-form-color {
  display: flex;
  gap: 4px;
  align-items: center;
}
.class-form-color input[type="text"] {
  flex: 1;
  min-width: 0;
}
.class-form-color input[type="color"] {
  width: 28px;
  height: 24px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
}
.class-form-color button {
  font-size: 11px;
  font-family: inherit;
  padding: 4px 8px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(70, 70, 80, 0.8);
  color: #fff;
  cursor: pointer;
}
.class-form-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}
.class-form-actions button {
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  background: rgba(140, 91, 31, 0.9);
}
.class-form-actions button:hover {
  background: rgba(168, 110, 38, 1);
}
.class-form-actions button:last-child {
  background: rgba(70, 70, 80, 0.8);
}
.class-form-actions button:last-child:hover {
  background: rgba(95, 95, 110, 1);
}

/* World-class placement editor (see client-editors.js). Compact rows: a class
   can carry a dozen placements and the panel shares the HUD's screen. */
.wc-placements-block {
  border-top: 1px solid #3a4a3a;
  margin-top: 8px;
  padding-top: 8px;
}
.wc-placements-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.wc-placement {
  border: 1px solid #3a4a3a;
  border-radius: 4px;
  margin-bottom: 6px;
  padding: 4px;
}
.wc-placement-main,
.wc-placement-sub {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.wc-placement-sub {
  margin-top: 4px;
  font-size: 11px;
}
.wc-p-id {
  width: 110px;
}
.wc-p-num {
  width: 56px;
}
.wc-rule {
  white-space: nowrap;
}
.wc-preview-wrap {
  margin-top: 8px;
}
#wc-preview {
  border: 1px solid #3a4a3a;
  background: #101810;
  image-rendering: pixelated;
}
.wc-preview-legend {
  font-size: 11px;
  opacity: 0.75;
}
.wc-reconcile-row {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}
.wc-placement-errors {
  color: #ff9a9a;
  font-size: 11px;
  white-space: pre-wrap;
  margin-top: 6px;
}
