:root {
  color-scheme: dark;
  --bg: #101312;
  --panel: #171c1a;
  --panel-strong: #202721;
  --line: rgba(224, 231, 217, 0.16);
  --text: #edf4ea;
  --muted: #a8b5a9;
  --dim: #748174;
  --accent: #9bd15f;
  --accent-strong: #c6f47e;
  --danger: #ef5b64;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(91, 117, 74, 0.18), transparent 34%),
    radial-gradient(circle at 82% 12%, rgba(146, 190, 95, 0.12), transparent 28%),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  outline: none;
}

input:focus,
select:focus {
  border-color: rgba(198, 244, 126, 0.72);
  box-shadow: 0 0 0 3px rgba(198, 244, 126, 0.12);
}

label span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
}

.view {
  min-height: 100vh;
}

.login-view {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  background: rgba(23, 28, 26, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 1px solid rgba(198, 244, 126, 0.34);
  border-radius: var(--radius);
  margin-bottom: 22px;
  color: var(--accent-strong);
  background: rgba(155, 209, 95, 0.1);
  font-weight: 800;
  letter-spacing: 0;
}

h1,
p {
  margin: 0;
}

.login-panel h1,
.workspace-header h1,
.map-title h1 {
  letter-spacing: 0;
}

.login-panel h1 {
  margin-bottom: 22px;
  font-size: 28px;
}

.field-grid {
  display: grid;
  gap: 14px;
}

.primary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.primary-button {
  width: 100%;
  margin-top: 20px;
  color: #11160f;
  background: var(--accent-strong);
  font-weight: 800;
}

.ghost-button {
  border: 1px solid var(--line);
  padding: 0 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.ghost-button:hover,
.primary-button:hover {
  filter: brightness(1.05);
}

.status-line {
  min-height: 22px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 14px;
}

.status-line.error {
  color: var(--danger);
}

.games-view {
  padding: 28px;
}

.workspace-header,
.map-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.workspace-header {
  max-width: 1180px;
  margin: 0 auto 24px;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.workspace-header h1 {
  margin-top: 4px;
  font-size: clamp(26px, 3vw, 40px);
}

.header-actions,
.map-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.games-grid {
  display: grid;
  max-width: 1180px;
  grid-template-columns: repeat(auto-fit, minmax(238px, 1fr));
  gap: 14px;
  margin: 0 auto;
}

.game-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  color: var(--text);
  background: rgba(23, 28, 26, 0.84);
  text-align: left;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

.game-card strong {
  display: block;
  margin-bottom: 14px;
  font-size: 24px;
}

.game-card dl,
.party-item dl {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0;
}

.game-card dt,
.party-item dt {
  color: var(--dim);
  font-size: 11px;
  text-transform: uppercase;
}

.game-card dd,
.party-item dd {
  margin: 2px 0 0;
  color: var(--text);
  font-weight: 800;
}

.map-view {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.map-topbar {
  min-height: 76px;
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
  background: rgba(16, 19, 18, 0.94);
  backdrop-filter: blur(12px);
  z-index: 3;
}

.map-title {
  min-width: 180px;
  flex: 1;
}

.map-title h1 {
  margin-top: 2px;
  font-size: 22px;
}

.realtime-field {
  width: min(310px, 32vw);
}

.realtime-field input {
  min-height: 42px;
}

.map-layout {
  display: grid;
  min-height: 0;
  flex: 1;
  grid-template-columns: 330px minmax(0, 1fr) 300px;
}

.side-panel {
  min-height: 0;
  border-color: var(--line);
  background: rgba(23, 28, 26, 0.96);
  overflow: auto;
}

.parties-panel {
  border-right: 1px solid var(--line);
}

.activity-panel {
  border-left: 1px solid var(--line);
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
}

.metric-row div {
  padding: 14px 12px;
  border-right: 1px solid var(--line);
}

.metric-row div:last-child {
  border-right: 0;
}

.metric-row span {
  display: block;
  font-size: 23px;
  font-weight: 900;
}

.metric-row small {
  color: var(--muted);
}

.connection-status {
  margin: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  font-size: 13px;
}

.connection-status.online {
  border-color: rgba(155, 209, 95, 0.42);
  color: var(--accent-strong);
}

.connection-status.error {
  border-color: rgba(239, 91, 100, 0.55);
  color: #ff9aa1;
}

.party-list,
.live-list {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.party-item,
.live-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: rgba(255, 255, 255, 0.045);
}

.party-head,
.live-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.party-name,
.live-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 850;
}

.party-kind,
.live-age {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.swatch {
  width: 13px;
  height: 13px;
  flex: 0 0 13px;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  background: var(--party-color);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--party-color) 22%, transparent);
}

.party-title {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.map-stage {
  position: relative;
  min-height: 0;
}

#map {
  position: absolute;
  inset: 0;
  background: #20261f;
}

.panel-heading {
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 1px solid var(--line);
  padding: 14px 12px;
  background: rgba(23, 28, 26, 0.98);
}

.panel-heading strong {
  display: block;
  margin-top: 2px;
  font-size: 14px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--muted);
  text-align: center;
}

.party-marker,
.position-marker {
  width: max-content;
  transform: translate(-50%, -100%);
  pointer-events: none;
}

.party-pin,
.position-pin {
  position: relative;
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 50%;
  margin: 0 auto 4px;
  background: var(--party-color);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}

.party-pin::after {
  position: absolute;
  bottom: -7px;
  width: 9px;
  height: 9px;
  content: "";
  background: var(--party-color);
  transform: rotate(45deg);
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
}

.position-pin {
  width: 26px;
  height: 26px;
  border-color: rgba(255, 255, 255, 0.88);
}

.position-pin::before {
  width: 0;
  height: 0;
  border-right: 5px solid transparent;
  border-bottom: 11px solid #fff;
  border-left: 5px solid transparent;
  content: "";
  transform: translateY(-2px);
}

.pin-label {
  max-width: 160px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 6px;
  padding: 3px 7px;
  overflow: hidden;
  color: #11160f;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 7px 18px rgba(0, 0, 0, 0.25);
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  color: var(--text);
  background: #171c1a;
}

.popup-title {
  margin-bottom: 6px;
  font-weight: 900;
}

.popup-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

@media (max-width: 1100px) {
  .map-layout {
    grid-template-columns: 290px minmax(0, 1fr);
  }

  .activity-panel {
    display: none;
  }
}

@media (max-width: 780px) {
  .games-view {
    padding: 18px;
  }

  .workspace-header,
  .map-topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions,
  .map-actions {
    width: 100%;
    align-items: stretch;
    flex-wrap: wrap;
  }

  .header-actions > *,
  .map-actions > * {
    flex: 1 1 130px;
  }

  .realtime-field {
    width: 100%;
    flex-basis: 100%;
  }

  .map-layout {
    min-height: calc(100vh - 190px);
    grid-template-columns: 1fr;
    grid-template-rows: 220px minmax(420px, 1fr);
  }

  .parties-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .party-list {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }
}

@media (max-width: 480px) {
  .login-panel {
    padding: 22px;
  }

  .game-card dl,
  .party-item dl,
  .metric-row {
    grid-template-columns: 1fr;
  }

  .metric-row div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .metric-row div:last-child {
    border-bottom: 0;
  }
}
