/* Civication city layer
   Levende byverden: fasepunkter (steder) + simulerte venner som figurer.
   Ligger over kartmotoren (canvas/3D) og vises kun i kartmodus.

   Kartforankret (følger kartets zoom/pan/resize – posisjon settes i px fra JS
   via CanvasMap-projeksjonen): .civi-city-markers, .civi-city-place,
   .civi-city-friend.
   Ikke kartforankret (vanlige UI-paneler over kartet): .civi-city-self,
   .civi-city-detail og lukkeknapp/detaljpanel – disse panoreres/zoomes aldri
   med kartet. */

.civi-city-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  display: none;
  color: #fff;
  font-family: var(--civi-font-sans);
}

body.civi-mapmode .civi-city-layer {
  display: block;
}

/* Dekker kartflaten. Markørene inni får left/top i px fra JS (kartprojeksjon),
   ikke egne overlay-prosenter, så de følger kartets eget koordinatsystem. */
.civi-city-markers {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* ---- Stedsmarkører ---- */
/* left/top settes i px fra kartprojeksjonen; translate(-50%,-50%) sentrerer
   markøren på punktet. will-change holder pan/zoom jevn. */
.civi-city-place {
  position: absolute;
  transform: translate(-50%, -50%);
  will-change: left, top;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  pointer-events: auto;
  opacity: 0.62;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.civi-city-place:hover,
.civi-city-place.is-selected {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.06);
}

.civi-city-place.is-active {
  opacity: 1;
}

.civi-city-place-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  font-size: var(--civi-text-lg);
  line-height: 1;
  border-radius: 12px;
  background: rgba(18, 26, 36, 0.76);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.civi-city-place.is-active .civi-city-place-icon {
  border-color: rgba(255, 224, 150, 0.7);
  box-shadow: 0 0 0 2px rgba(255, 224, 150, 0.28), 0 6px 16px rgba(0, 0, 0, 0.45);
}

.civi-city-place.is-friend-home .civi-city-place-icon {
  background: rgba(20, 24, 34, 0.72);
  border-style: dashed;
}

/* ---- Vennefigurer ---- */
/* left/top settes i px fra kartprojeksjonen + liten deterministisk
   skjermpiksel-offset rundt stedet (flere venner på samme sted). */
.civi-city-friend {
  position: absolute;
  transform: translate(-50%, -50%);
  will-change: left, top;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  pointer-events: auto;
  z-index: 2;
}

.civi-city-friend-figure {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  font-size: var(--civi-text-xs);
  font-weight: 700;
  color: #11151c;
  border-radius: 50%;
  background: var(--friend-color, #cfd6e0);
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  transition: transform 0.16s ease;
}

.civi-city-friend:hover .civi-city-friend-figure,
.civi-city-friend.is-selected .civi-city-friend-figure {
  transform: scale(1.12);
}

/* Tilstand: på vei / trener / besøker gir en liten visuell forskjell. */
.civi-city-friend.is-travelling .civi-city-friend-figure,
.civi-city-friend.is-walking_in_city .civi-city-friend-figure {
  border-style: dashed;
}

.civi-city-friend.is-visiting_player .civi-city-friend-figure {
  box-shadow: 0 0 0 3px rgba(120, 220, 160, 0.4), 0 4px 12px rgba(0, 0, 0, 0.45);
}

/* Byens skikkelser – samlede History Go-personer (CivicationHistoryFigures).
   Gullring skiller dem fra venner; samme grunnfigur ellers. */
.civi-city-figure .civi-city-figure-avatar {
  background: #2a2418;
  color: #ffd479;
  border-color: #ffd479;
  box-shadow: 0 0 0 3px rgba(255, 212, 121, 0.35), 0 4px 12px rgba(0, 0, 0, 0.45);
}

/* Markører uten kartanker (CanvasMap aktiv, men stedet kan ikke projiseres)
   skjules – de skal aldri plasseres tilfeldig midt på kartet. Klassen settes
   av JS i positionMarker(); en egen regel trengs fordi .civi-city-place/.friend
   setter egen display-verdi og ville ellers overstyre [hidden]. */
.civi-city-place.is-unanchored,
.civi-city-friend.is-unanchored {
  display: none;
}

/* ---- Spillerens eget fase-minne (diskret status) ---- */
.civi-city-self {
  position: absolute;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  transform: translateX(-50%);
  max-width: min(380px, calc(100vw - 28px));
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border-radius: 999px;
  font-size: var(--civi-text-xs);
  line-height: 1.3;
  background: rgba(18, 26, 36, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  pointer-events: none;
  z-index: 3;
}

.civi-city-self[hidden] {
  display: none;
}

.civi-city-self-icon {
  font-size: var(--civi-text-xs);
  line-height: 1;
}

.civi-city-self-text {
  opacity: 0.92;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.civi-city-self-text strong {
  font-weight: 700;
}

/* ---- Detaljpanel ---- */
.civi-city-detail {
  position: absolute;
  left: 50%;
  bottom: calc(var(--footer-h, 64px) + 14px);
  transform: translateX(-50%);
  width: min(420px, calc(100vw - 28px));
  max-height: 56vh;
  overflow-y: auto;
  padding: 16px 16px 18px;
  border-radius: 18px;
  background: rgba(20, 28, 38, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  pointer-events: auto;
}

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

.civi-city-detail-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}

.civi-city-detail-kicker {
  font-size: var(--civi-text-xs);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  opacity: 0.75;
}

.civi-city-detail h3 {
  margin: 4px 0 6px;
  font-size: 20px;
}

.civi-city-detail h4 {
  margin: 0 0 6px;
  font-size: var(--civi-text-sm);
  opacity: 0.85;
}

.civi-city-detail-desc {
  margin: 0 0 10px;
  font-size: var(--civi-text-sm);
  line-height: var(--civi-leading-base);
  opacity: 0.9;
}

.civi-city-detail-status {
  display: inline-block;
  font-size: var(--civi-text-xs);
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  margin-bottom: 10px;
}

.civi-city-detail-status.is-active {
  background: rgba(255, 224, 150, 0.16);
  border-color: rgba(255, 224, 150, 0.5);
  color: #ffe9b8;
}

.civi-city-detail-section {
  margin-top: 12px;
}

/* Profilkort-seksjoner (Livstegn/Figur/Relasjon) deler kompakt rutenett. */
.civi-city-detail-section .civi-city-detail-grid {
  margin: 6px 0 0;
}

.civi-friend-relation .civi-city-detail-status {
  margin-bottom: 6px;
}

.civi-friend-relation-blurb {
  margin: 0;
  font-size: var(--civi-text-sm);
  line-height: 1.45;
  opacity: 0.88;
}

/* Levende relasjonsstatus (relasjonsmotoren): diskret, vises kun etter at en
   sosial henvendelse er besvart (Svar/Ignorer/Avvis). */
.civi-friend-relation-live {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.civi-friend-relation-stage {
  font-size: var(--civi-text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0.95;
}

.civi-friend-relation-live-blurb {
  margin: 4px 0 0;
  font-size: var(--civi-text-sm);
  line-height: 1.45;
  opacity: 0.88;
}

.civi-friend-relation-meta {
  margin: 4px 0 0;
  font-size: var(--civi-text-xs);
  line-height: 1.35;
  opacity: 0.75;
}

.civi-city-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.civi-city-chip {
  font-size: var(--civi-text-xs);
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.civi-city-detail-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: var(--civi-text-sm);
}

.civi-city-detail-list .muted {
  opacity: 0.68;
}

.civi-city-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0;
}

.civi-city-detail-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.civi-city-detail-cell span {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  opacity: 0.7;
}

.civi-city-detail-cell strong {
  font-size: var(--civi-text-sm);
  font-weight: 600;
}

.civi-city-detail-hint {
  margin: 10px 0 0;
  font-size: var(--civi-text-xs);
  opacity: 0.82;
  line-height: 1.45;
}

.civi-city-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.civi-city-detail-actions .civi-btn {
  flex: 1 1 auto;
  min-width: 120px;
}

.civi-city-detail-feedback {
  margin: 10px 0 0;
  font-size: var(--civi-text-xs);
  line-height: 1.45;
  color: #bfe6c9;
}

.civi-city-detail-feedback[hidden] {
  display: none;
}

/* Sosiale møter på et sted: personer som også sist valgte stedet i samme fase. */
.civi-city-encounters .civi-city-encounter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.civi-city-encounters .civi-city-encounter-line {
  font-size: var(--civi-text-sm);
  line-height: var(--civi-leading-base);
}

.civi-city-encounters .civi-city-approach {
  flex: 0 0 auto;
  min-width: 104px;
}

/* ---------------------------------------------------------------------------
   Node-roller (Del B)
   Systemfunksjoner, ekte steder og personer skal leses som forskjellige ting:
   - systemnoder  -> diskrete portal/funksjonsnoder (sirkel + halo)
   - ekte steder  -> konkrete møteplasser (pin-aktig, tydeligere)
   - venners hjem -> spillanker/hjemmepunkt (stiplet, diskret – ikke GPS)
   - fallback     -> kategoriinnganger (nedtonet/stiplet, aldri konkurrent)
   --------------------------------------------------------------------------- */

/* Systemnoder (Hjem/Arbeidsplass/NAV/Psykologirommet): Civication-funksjoner/
   portaler, ikke konkrete steder. Sirkulær ramme + halo som leses som
   funksjonsnode; tydelig ikon, men dominerer ikke kartet. */
.civi-city-place.is-role-system-node .civi-city-place-icon,
.civi-city-place.is-role-player-home .civi-city-place-icon,
.civi-city-place.is-role-work-node .civi-city-place-icon,
.civi-city-place.is-role-insight-node .civi-city-place-icon {
  border-radius: 50%;
  background: rgba(14, 20, 30, 0.78);
  border-color: rgba(150, 190, 255, 0.45);
  box-shadow: 0 0 0 3px rgba(120, 160, 230, 0.18), 0 6px 16px rgba(0, 0, 0, 0.4);
}

/* Innsiktsnoden (Psykologirommet) får et eget psykologi-/AHA-preg. */
.civi-city-place.is-role-insight-node .civi-city-place-icon {
  border-color: rgba(190, 160, 255, 0.52);
  box-shadow: 0 0 0 3px rgba(170, 130, 240, 0.2), 0 6px 16px rgba(0, 0, 0, 0.4);
}

/* Ekte sosiale steder (Fuglen/Tim Wendelboe/St. Hanshaugen park …): konkrete
   møteplasser. Pin-aktig markørstil, sterkere/tydeligere enn fallback. */
.civi-city-place.is-role-social-place {
  opacity: 0.92;
}
.civi-city-place.is-role-social-place .civi-city-place-icon {
  border-radius: 14px 14px 14px 4px;
  background: rgba(16, 22, 18, 0.78);
  border-color: rgba(150, 220, 170, 0.55);
}
/* Venners hjem: spillanker/hjemmepunkt, ikke ekte adresse/GPS. Diskret, stiplet
   ramme – tydelig som "hjem i spillet". (is-friend-home beholdes for
   bakoverkompat; rollen styrer den samme stilen.) */
.civi-city-place.is-role-friend-home .civi-city-place-icon {
  border-radius: 50%;
  border-style: dashed;
  background: rgba(20, 24, 34, 0.7);
}
/* Generiske sosiale fallback-noder (Kafé/Park/Fotballbane/Kultursted …): tones
   ned og får stiplet ramme slik at de leses som kategoriinnganger
   og aldri konkurrerer visuelt med ekte sosiale steder (social_place). */
.civi-city-place.is-role-social-fallback {
  opacity: 0.6;
}
.civi-city-place.is-role-social-fallback.is-active {
  opacity: 0.78;
}
.civi-city-place.is-role-social-fallback .civi-city-place-icon {
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.26);
  box-shadow: none;
}
/* Spillerens lagrede fasevalg ("hvor valgte jeg å gå"): grønn ring rundt
   markøren. Fase-minne, ikke live-posisjon – skilles bevisst fra gull-haloen
   til is-active (aktiv i fasen) og fra is-selected (åpnet i detaljpanelet). */
.civi-city-place.is-player-choice {
  opacity: 1;
}
.civi-city-place.is-player-choice .civi-city-place-icon {
  border-color: rgba(143, 238, 172, 0.7);
  box-shadow: 0 0 0 3px rgba(118, 214, 148, 0.26), 0 6px 16px rgba(0, 0, 0, 0.45);
}

/* Del C/E: en generisk fallback fremstår som en inngang/kategori som leder til
   konkrete ekte sosiale steder. Gjenbruker detalj-panelets eksisterende stil. */
.civi-city-fallback-choices .civi-city-fallback-choice {
  list-style: none;
}
.civi-city-fallback-choices .civi-city-fallback-choice .civi-btn {
  width: 100%;
  text-align: left;
}
.civi-city-fallback-choices .civi-city-fallback-choice small {
  opacity: 0.7;
  font-weight: 400;
}

/* ---------------------------------------------------------------------------
   Konkrete fasevalg for spilleren ("Hvor vil du gå i denne fasen?")
   Grupperte, kompakte rader i stedskortet: konkrete steder leses som steder,
   systemvalg som funksjoner, fallback som nedtonede kategoriinnganger, og
   spillerens lagrede valg får tydelig valgt-status.
   --------------------------------------------------------------------------- */
.civi-city-phase-choices {
  display: grid;
  gap: 10px;
}

.civi-city-phase-choice-group {
  display: grid;
  gap: 6px;
}

.civi-city-phase-choice-group h5 {
  margin: 2px 0 0;
  font-size: var(--civi-text-xs);
  line-height: 1.2;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: rgba(238, 246, 255, 0.78);
}

.civi-city-phase-choice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
}

/* Konkrete steder (ekte socialPlaces): grønnlig stedstone. */
.civi-city-phase-choice.is-kind-social-place {
  background: rgba(76, 175, 115, 0.08);
  border-color: rgba(137, 220, 166, 0.24);
}

/* Systemvalg + hjem/arbeid: blålig funksjonstone, skilt fra ekte steder. */
.civi-city-phase-choice.is-kind-system-node,
.civi-city-phase-choice.is-kind-home-work {
  background: rgba(111, 155, 255, 0.07);
  border-color: rgba(150, 190, 255, 0.2);
}

/* Fallback/kategoriinnganger: nedtonet + stiplet, aldri som konkret sted. */
.civi-city-phase-choice.is-kind-social-fallback,
.civi-city-fallback-choice {
  opacity: 0.78;
  background: rgba(255, 255, 255, 0.025);
  border-style: dashed;
}

/* Spillerens lagrede valg for fasen (fase-minne, ikke live-posisjon). */
.civi-city-phase-choice.is-selected-choice {
  background: rgba(118, 214, 148, 0.14);
  border-color: rgba(143, 238, 172, 0.52);
  box-shadow: 0 0 0 1px rgba(143, 238, 172, 0.12) inset;
}

.civi-city-phase-choice-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.civi-city-phase-choice-copy strong {
  font-size: var(--civi-text-sm);
  line-height: 1.3;
}

.civi-city-phase-choice-copy small,
.civi-city-fallback-choice small {
  font-size: var(--civi-text-xs);
  opacity: 0.76;
}

.civi-city-phase-choice .civi-btn {
  flex: 0 0 auto;
}

.civi-city-phase-choice.is-selected-choice .civi-btn {
  color: #d9ffe6;
  border-color: rgba(143, 238, 172, 0.45);
  background: rgba(76, 175, 115, 0.2);
}

/* "Henvend deg" (person-/møteknapp) skilles fra "Gå hit" (stedsvalg). */
.civi-city-approach {
  border-color: rgba(255, 214, 112, 0.38);
  background: rgba(255, 214, 112, 0.1);
}

.civi-city-phase-choice-more {
  margin: 0;
  font-size: var(--civi-text-xs);
}

/* Status-chip i stedskortet: dette stedet er spillerens lagrede fasevalg. */
.civi-city-detail-status.is-player-choice {
  background: rgba(118, 214, 148, 0.16);
  border-color: rgba(143, 238, 172, 0.5);
  color: #d9ffe6;
  margin-left: 6px;
}

@media (max-width: 520px) {
  .civi-city-detail-grid {
    grid-template-columns: 1fr;
  }
}
