:root {
  --bg: #071114;
  --panel: rgba(11, 18, 20, 0.88);
  --panel-soft: rgba(20, 31, 33, 0.76);
  --line: rgba(228, 238, 224, 0.18);
  --text: #edf3ec;
  --muted: #a9b4aa;
  --cyan: #78d6e6;
  --gold: #d9a441;
  --green: #50d37a;
  --red: #ef5959;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
a,
input {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.map-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 35% 30%, rgba(120, 214, 230, 0.12), transparent 28rem),
    linear-gradient(180deg, #0d2b35, #051014);
}

.world-canvas,
.marker-layer {
  position: absolute;
  inset: 0;
}

.world-canvas {
  cursor: grab;
}

.world-canvas.is-dragging {
  cursor: grabbing;
}

.marker-layer {
  pointer-events: none;
}

.map-topbar,
.map-toolbar,
.map-statusbar,
.inspector,
.town-detail {
  position: absolute;
  z-index: 10;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(18px);
}

.map-topbar {
  top: 1rem;
  right: 1rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  pointer-events: none;
}

.map-topbar .auth-pill {
  pointer-events: auto;
}

.brand-mark {
  display: none;
  align-items: center;
  gap: 0.62rem;
  min-width: 0;
  font-size: 0.95rem;
  font-weight: 860;
  letter-spacing: 0;
}

.brand-mark__sigil {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid rgba(217, 164, 65, 0.55);
  border-radius: 50%;
  color: #f2d89e;
  background: rgba(217, 164, 65, 0.14);
}

.map-nav {
  display: none;
  justify-content: center;
  gap: 0.85rem;
  min-width: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 740;
}

.map-nav a,
.auth-pill {
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.map-nav a:hover {
  color: var(--text);
}

.auth-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 6.6rem;
  max-width: min(18rem, calc(100vw - 2rem));
  min-height: 2.15rem;
  padding: 0 0.85rem;
  border: 1px solid rgba(80, 211, 122, 0.42);
  border-radius: 999px;
  color: #cff7dc;
  background: rgba(80, 211, 122, 0.15);
  font-size: 0.82rem;
  font-weight: 820;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.34);
}

.auth-pill[data-auth-state="in"] {
  border-color: rgba(80, 211, 122, 0.38);
  color: #cff7dc;
  background: rgba(80, 211, 122, 0.1);
}

.map-toolbar {
  top: 3.55rem;
  right: 1rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: auto;
  max-width: calc(100vw - 2rem);
  min-height: 2.45rem;
  padding: 0.35rem;
  border-radius: 8px;
  background: rgba(48, 55, 55, 0.72);
}

.icon-group,
.layer-switches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.icon-btn,
.text-btn,
.toggle-pill {
  min-height: 2rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: rgba(238, 244, 235, 0.08);
}

.icon-btn,
.text-btn {
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.icon-btn:hover,
.text-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(238, 244, 235, 0.34);
  background: rgba(238, 244, 235, 0.12);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  padding: 0;
  font-size: 1.05rem;
  font-weight: 860;
}

.text-btn {
  padding: 0 0.7rem;
  color: #f1d59c;
  font-size: 0.76rem;
  font-weight: 840;
}

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0 0.52rem;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 790;
  cursor: pointer;
}

.toggle-pill input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--cyan);
}

.toggle-pill--private {
  border-color: rgba(217, 164, 65, 0.32);
}

.map-statusbar {
  right: 1rem;
  bottom: 1rem;
  left: auto;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 0.75rem;
  width: max-content;
  max-width: calc(100vw - 2rem);
  min-height: 2.35rem;
  padding: 0.45rem 0.62rem;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 740;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
}

.session-state {
  padding-left: 0.75rem;
  border-left: 1px solid var(--line);
  white-space: nowrap;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-dot,
.legend-plus {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
}

.legend-dot {
  border-radius: 50%;
}

.legend-dot--alive {
  background: var(--green);
}

.legend-dot--dead {
  background: var(--red);
}

.legend-plus {
  position: relative;
}

.legend-plus::before,
.legend-plus::after {
  content: "";
  position: absolute;
  background: var(--gold);
}

.legend-plus::before {
  left: 0.32rem;
  top: 0;
  width: 0.12rem;
  height: 100%;
}

.legend-plus::after {
  left: 0;
  top: 0.32rem;
  width: 100%;
  height: 0.12rem;
}

.marker {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: auto;
  transform: translate(-50%, -50%);
}

.marker button {
  cursor: pointer;
}

.town-marker button,
.raid-marker button,
.character-marker button {
  border: 0;
  padding: 0;
  color: inherit;
  background: transparent;
}

.town-marker button {
  position: relative;
  width: 1.6rem;
  height: 1.6rem;
  border: 1px solid rgba(217, 164, 65, 0.82);
  border-radius: 50%;
  background: rgba(10, 16, 18, 0.76);
  box-shadow: 0 0 0 4px rgba(217, 164, 65, 0.12), 0 6px 18px rgba(0, 0, 0, 0.36);
}

.town-marker button::before,
.town-marker button::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  background: #f1d59c;
  transform: translate(-50%, -50%);
}

.town-marker button::before {
  width: 0.14rem;
  height: 0.78rem;
}

.town-marker button::after {
  width: 0.78rem;
  height: 0.14rem;
}

.town-label {
  position: absolute;
  left: 1.1rem;
  top: 0.1rem;
  min-width: max-content;
  padding: 0.16rem 0.4rem;
  border: 1px solid rgba(217, 164, 65, 0.28);
  border-radius: 999px;
  color: #f0d393;
  background: rgba(7, 12, 14, 0.72);
  font-size: 0.68rem;
  font-weight: 820;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.raid-marker button {
  width: 1.05rem;
  height: 1.05rem;
  border: 2px solid rgba(8, 14, 16, 0.9);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.2), 0 0 18px rgba(0, 0, 0, 0.5);
}

.raid-marker[data-alive="true"] button {
  background: var(--green);
}

.raid-marker[data-alive="false"] button {
  background: var(--red);
}

.character-marker button {
  position: relative;
  display: grid;
  place-items: center;
  width: 1.95rem;
  height: 1.95rem;
  border: 2px solid rgba(238, 244, 235, 0.84);
  border-radius: 50%;
  background: #d9c3a0;
  box-shadow: 0 0 0 5px rgba(120, 214, 230, 0.18), 0 8px 22px rgba(0, 0, 0, 0.4);
}

.character-marker .face {
  position: relative;
  width: 0.86rem;
  height: 0.96rem;
  border-radius: 48% 48% 42% 42%;
  background: rgba(255, 247, 221, 0.92);
}

.character-marker .face::before,
.character-marker .face::after {
  content: "";
  position: absolute;
  top: 0.34rem;
  width: 0.12rem;
  height: 0.12rem;
  border-radius: 50%;
  background: #1b2324;
}

.character-marker .face::before {
  left: 0.23rem;
}

.character-marker .face::after {
  right: 0.23rem;
}

.character-marker[data-race="elf"] button {
  background: #78d6e6;
}

.character-marker[data-race="dark-elf"] button {
  background: #6f76d7;
}

.character-marker[data-race="orc"] button {
  background: #50d37a;
}

.character-marker[data-race="dwarf"] button {
  background: #d9a441;
}

.character-marker[data-race="kamael"] button {
  background: #d86f77;
}

.character-marker[data-race="elf"] .face,
.character-marker[data-race="dark-elf"] .face {
  border-radius: 44% 44% 38% 38%;
}

.character-marker[data-race="orc"] .face {
  width: 0.96rem;
  height: 0.9rem;
  border-radius: 42% 42% 50% 50%;
}

.character-marker[data-race="dwarf"] .face {
  width: 0.96rem;
  height: 0.78rem;
  border-radius: 48% 48% 46% 46%;
}

.character-marker[data-race="kamael"] button::after {
  content: "";
  position: absolute;
  top: -0.38rem;
  right: -0.2rem;
  width: 0.55rem;
  height: 0.85rem;
  border-radius: 50% 50% 20% 20%;
  border-right: 2px solid rgba(238, 244, 235, 0.8);
  transform: rotate(28deg);
}

.inspector {
  right: 1rem;
  top: 6.7rem;
  width: min(21rem, calc(100vw - 2rem));
  padding: 1rem;
  border-radius: 8px;
}

.town-detail {
  left: 1rem;
  top: 1rem;
  display: grid;
  gap: 0.85rem;
  width: min(47rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0.85rem;
  border-radius: 8px;
}

.town-detail[hidden] {
  display: none;
}

.town-detail__header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.town-detail__kicker {
  margin: 0 0 0.25rem;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 840;
  text-transform: uppercase;
}

.town-detail h1 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.15;
}

.town-detail__body {
  display: grid;
  grid-template-columns: minmax(20rem, 1fr) minmax(12rem, 15rem);
  gap: 0.8rem;
  min-height: 0;
}

.town-map {
  position: relative;
  min-height: 26rem;
  overflow: hidden;
  border: 1px solid rgba(238, 244, 235, 0.16);
  border-radius: 6px;
  background:
    linear-gradient(90deg, rgba(238, 244, 235, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(238, 244, 235, 0.04) 1px, transparent 1px),
    #10191b;
  background-size: 42px 42px;
}

.town-canvas,
.town-marker-layer {
  position: absolute;
  inset: 0;
}

.town-canvas {
  width: 100%;
  height: 100%;
}

.town-marker-layer {
  pointer-events: none;
}

.town-point {
  position: absolute;
  left: 0;
  top: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transform: translate(-50%, -50%);
  pointer-events: auto;
}

.town-point button {
  display: inline-grid;
  place-items: center;
  width: 1.65rem;
  height: 1.65rem;
  padding: 0;
  border: 2px solid rgba(9, 13, 14, 0.78);
  border-radius: 50%;
  color: #081012;
  background: #f0d393;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 900;
  box-shadow: 0 0 0 4px rgba(217, 164, 65, 0.14), 0 8px 20px rgba(0, 0, 0, 0.42);
}

.town-point[data-kind="teleport"] button {
  background: #78d6e6;
}

.town-point[data-kind="warehouse"] button {
  background: #d9a441;
}

.town-point[data-kind="blacksmith"] button {
  background: #efb06d;
}

.town-point[data-kind="shop"] button {
  background: #50d37a;
}

.town-point[data-kind="character"] button {
  background: #d86f77;
  color: #fff;
}

.town-point__label {
  max-width: 9.5rem;
  padding: 0.15rem 0.38rem;
  border: 1px solid rgba(238, 244, 235, 0.18);
  border-radius: 999px;
  color: var(--text);
  background: rgba(7, 12, 14, 0.72);
  font-size: 0.68rem;
  font-weight: 820;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  transform: translateX(-0.18rem);
  transition: opacity 120ms ease, transform 120ms ease;
  white-space: nowrap;
}

.town-point:hover .town-point__label,
.town-point:focus-within .town-point__label {
  opacity: 1;
  transform: translateX(0);
}

.town-detail__list {
  display: grid;
  align-content: start;
  gap: 0.45rem;
  max-height: min(26rem, calc(100vh - 9rem));
  overflow: auto;
  padding-right: 0.2rem;
}

.town-list-item {
  display: grid;
  gap: 0.12rem;
  padding: 0.48rem 0.55rem;
  border: 1px solid rgba(238, 244, 235, 0.14);
  border-radius: 6px;
  background: rgba(238, 244, 235, 0.06);
}

.town-list-item strong {
  color: var(--text);
  font-size: 0.78rem;
}

.town-list-item span {
  color: var(--muted);
  font-size: 0.72rem;
}

.inspector-close {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  width: 2rem;
  min-height: 2rem;
  font-size: 0.86rem;
}

.inspector-kicker {
  margin: 0 2.25rem 0.35rem 0;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 840;
  text-transform: uppercase;
}

.inspector h1 {
  margin: 0 2.25rem 0.75rem 0;
  font-size: 1.15rem;
  line-height: 1.15;
}

.inspector dl {
  display: grid;
  grid-template-columns: minmax(5rem, auto) 1fr;
  gap: 0.35rem 0.75rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.inspector dt {
  color: rgba(237, 243, 236, 0.72);
  font-weight: 800;
}

.inspector dd {
  min-width: 0;
  margin: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

@media (max-width: 860px) {
  .auth-pill {
    justify-self: end;
    max-width: 11rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .map-toolbar {
    top: 3.5rem;
    left: 0.65rem;
    right: 0.65rem;
    justify-content: flex-end;
  }

  .inspector {
    top: auto;
    left: 1rem;
    right: 1rem;
    bottom: 4.2rem;
    width: auto;
  }

  .town-detail {
    left: 0.65rem;
    right: 0.65rem;
    width: auto;
  }

  .town-detail__body {
    grid-template-columns: 1fr;
  }

  .town-map {
    min-height: min(62vh, 25rem);
  }

  .town-label {
    display: none;
  }
}

@media (max-width: 560px) {
  .map-topbar,
  .map-toolbar {
    left: 0.65rem;
    right: 0.65rem;
  }

  .map-toolbar {
    width: auto;
    align-items: flex-start;
    flex-direction: column;
  }

  .map-statusbar {
    right: 0.65rem;
    left: auto;
    width: max-content;
    max-width: calc(100vw - 1.3rem);
    align-items: flex-start;
    flex-direction: column;
    gap: 0.4rem;
  }

  .session-state {
    padding-left: 0;
    border-left: 0;
  }

  .town-detail {
    top: 0.65rem;
    max-height: calc(100vh - 1.3rem);
  }

  .town-point__label {
    display: none;
  }
}
