:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  color: #eef5f7;
  background: #10191e;
  --surface: #142229;
  --line: #345059;
  --muted: #b0c1c7;
  --accent: #70ebd5;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: minmax(320px, 1fr);
}

h2, p { margin: 0; }

.panorama {
  position: relative;
  isolation: isolate;
  container-type: size;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 70% 30%, #28434a, transparent 63%),
    repeating-linear-gradient(45deg, #16262c 0 1px, transparent 1px 29px),
    #101b20;
}

#viewer { position: absolute; inset: 0; z-index: 0; }
#restart {
  position: absolute;
  bottom: .375rem;
  left: .75rem;
  z-index: 2;
  padding: 0;
}

#compass {
  position: absolute;
  bottom: .25rem;
  left: 4rem;
  z-index: 2;
  display: grid;
  width: 3rem;
  height: 3rem;
  pointer-events: none;
}
#compass circle { fill: #142229eb; stroke: var(--line); }
#compass text { fill: #fff; font: 700 9px system-ui, sans-serif; text-anchor: middle; }
.compass-north { fill: #ff757c; }
.compass-south { fill: #ebf1f3; }

#open-lobby, .round-hud {
  position: absolute;
  top: .75rem;
  z-index: 2;
}

#open-lobby { left: .75rem; }
.round-hud {
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .3rem .6rem;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
  background: var(--surface);
  font-size: .875rem;
  white-space: nowrap;
  z-index: 4;
  pointer-events: none;
}
.round-hud time {
  color: var(--accent);
  font-size: clamp(1.65rem, 3vw, 2.4rem);
  font-weight: 750;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.round-hud time.running-out { color: #ff757c; }
.round-clock-panel { display: flex; align-items: center; gap: .55rem; }
.team-round-hud {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content minmax(0, 1fr);
  width: min(26rem, calc(100% - 1.5rem));
  gap: clamp(.25rem, 1.5vw, .65rem);
  padding: .3rem;
  border: 0;
  background: transparent;
}
.team-round-hud .round-clock-panel,
.team-hud-panel {
  display: grid;
  justify-items: center;
  gap: .15rem;
  padding: .35rem .5rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
  background: var(--surface);
}
.team-round-hud .round-clock-panel { align-self: stretch; align-content: center; }
.team-hud-panel.is-own-team { border-color: currentColor; }
.team-hud-name { font-size: .75rem; }
.team-hud-you { margin-inline-start: .2em; font-weight: 750; }
.team-hud-panel strong { color: #eef5f7; font-variant-numeric: tabular-nums; }
.team-hud-damage { font-size: .75rem; font-variant-numeric: tabular-nums; }
.team-red { color: #ff9a9d; }
.team-blue { color: #9eb9ff; }

.lobby {
  z-index: 4;
  width: min(27rem, calc(100% - 1.5rem));
  max-height: calc(100dvh - 1.5rem);
  padding: 1.15rem;
  border: 1px solid var(--line);
  border-radius: .85rem;
  color: inherit;
  background: var(--surface);
}
.lobby::backdrop { background: #0b1117a6; }
.lobby form, #room-info { display: grid; gap: .65rem; }
.lobby-heading, .lobby-actions, #room-players li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
.lobby-heading { margin-bottom: .65rem; }
.lobby h2 { font-size: 1.25rem; }
#close-lobby { min-width: 2.75rem; font-size: 1.25rem; }
#room-code { text-transform: uppercase; }
#active-room-code { color: var(--accent); letter-spacing: .1em; }
#room-players { margin: 0; padding: 0; list-style: none; }
#room-players li { padding: .5rem 0; border-top: 1px solid var(--line); }
#room-phase, #lobby-message { color: var(--muted); overflow-wrap: anywhere; }
#lobby-message:not(:empty) { margin-top: .65rem; }
#room-phase:empty, #lobby-message:empty { display: none; }
.setting-toggle { display: flex; align-items: flex-start; gap: .55rem; }
.setting-toggle input { width: auto; min-height: auto; margin: .2em 0; accent-color: var(--accent); }
#shorten-timer-setting { display: grid; gap: .55rem; }
.team-setting { display: grid; gap: .4rem; }

@media (max-width: 550px) {
  .round-hud { top: 4rem; }
}

.setup {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: .75rem;
  z-index: 3;
  padding: 1rem;
  background: #101b2059;
}

#status, #navigation-error { color: var(--muted); font-size: .875rem; }
#status:empty { display: none; }
#navigation-error {
  position: absolute;
  z-index: 3;
  top: 4.5rem;
  left: 1rem;
  padding: .6rem .8rem;
  border-radius: .55rem;
  background: var(--surface);
}

input, select, button {
  font: inherit;
  min-height: 2.75rem;
  padding: .55rem .85rem;
  border-radius: .55rem;
}

input, select { width: 100%; color: inherit; background: #0e191f; border: 1px solid #5b7780; }
button { font-weight: 650; border: 1px solid transparent; cursor: pointer; }
button:disabled { cursor: default; opacity: .48; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.primary { color: #112923; background: var(--accent); }
.secondary { color: inherit; background: #20343c; border-color: var(--line); }
.secondary:hover:enabled { background: #2c4650; }
.icon-button {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
}

.icon-button svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#resize-map[aria-expanded="false"] .collapse-icon,
#resize-map[aria-expanded="true"] .expand-icon { display: none; }

.guess-panel {
  position: absolute;
  z-index: 2;
  right: .75rem;
  bottom: 3.25rem;
  width: min(21rem, calc(100% - 1.5rem));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: .8rem;
  background: var(--surface);
  box-shadow: 0 8px 26px #0007;
}

.guess-panel.expanded {
  inset-inline: .75rem;
  width: min(calc(100% - 1.5rem), calc((100cqh - 11rem) * 16 / 9 + 2px));
  margin-inline: auto;
}

.guess-header, .guess-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .4rem .55rem;
}

.guess-header h2, .guess-panel button { font-size: .875rem; }
.guess-panel button { min-height: 2.5rem; padding: .35rem .6rem; }
.guess-footer p { font-size: .875rem; color: var(--muted); }
.guess-footer { flex-wrap: wrap; }
.guess-footer #next-round-status { color: var(--accent); font-weight: 650; font-variant-numeric: tabular-nums; }
.guess-footer button { flex-shrink: 0; }
#guess-map { height: clamp(7rem, 24vh, 12rem); background: #d7e3e5; }
.expanded #guess-map { aspect-ratio: 16 / 9; height: auto; }
#guess-map.world-overview .leaflet-gl-layer {
  clip-path: inset(0 max(0px, calc((100% - var(--world-map-size)) / 2)));
}
#guess-map:focus-visible { outline-offset: -2px; }

.guess-panel.show-results.expanded {
  width: min(calc(100% - 1.5rem), calc((100cqh - 12rem) * 16 / 9 + 17rem + 2px));
  grid-template-columns: 17rem minmax(0, 1fr);
  grid-template-areas: "ranking heading" "ranking map" "ranking footer";
}

.guess-panel.final-results:not(.expanded) { grid-template-rows: auto auto minmax(0, 1fr) auto; }
.guess-panel.show-results.final-results.expanded {
  width: min(calc(100% - 1.5rem), calc((100cqh - 16rem) * 16 / 9 + 17rem + 2px));
  grid-template-areas: "summary summary" "ranking heading" "ranking map" "ranking footer";
}
.expanded #final-result { grid-area: summary; }
#final-result {
  padding: .65rem .85rem;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}
#final-result h2 { color: var(--accent); font-size: clamp(1.1rem, 3cqw, 1.55rem); }
#final-result p { margin-top: .2rem; color: var(--muted); font-size: .85rem; }

.show-results.expanded .guess-header { grid-area: heading; }
.show-results.expanded #guess-map { grid-area: map; }
.show-results.expanded .guess-footer { grid-area: footer; }
.show-results:not(.expanded) .guess-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "title size" "rounds rounds";
}
.show-results:not(.expanded) #guess-heading { grid-area: title; }
.show-results:not(.expanded) #resize-map { grid-area: size; }
.show-results:not(.expanded) #round-review { grid-area: rounds; justify-content: center; }
#round-review { display: flex; align-items: center; gap: .45rem; }
#round-review span { min-width: 6rem; text-align: center; font-variant-numeric: tabular-nums; }
#round-ranking {
  grid-area: ranking;
  contain: size;
  display: flex;
  flex-direction: column;
  gap: .7rem;
  min-width: 0;
  padding: .8rem;
  border-right: 1px solid var(--line);
}
#round-ranking h2 { font-size: 1.1rem; }
.ranking-heading { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.ranking-heading span, .round-points { color: var(--muted); font-size: .85rem; }
.round-points { margin-inline-start: .35rem; white-space: nowrap; }
.total-points { color: var(--accent); white-space: nowrap; }
.ranking-scroll { overflow: auto; flex: 1; min-height: 0; }
#round-standings { list-style: none; margin: 0; padding: 0; counter-reset: standing; }
#round-standings li {
  display: grid;
  position: relative;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .2rem .5rem;
  padding: .55rem .15rem .55rem 1.65rem;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
  counter-increment: standing;
}
#round-standings li::before {
  content: counter(standing) ".";
  position: absolute;
  inset: .55rem auto auto .2rem;
  color: var(--muted);
}
#ranking-status { font-size: .875rem; color: var(--muted); }
#ranking-status:empty { display: none; }
#team-results { display: grid; gap: .35rem; font-size: .85rem; }
#team-results p { margin: 0; }

.panorama:has(.guess-panel.expanded) .mapillary-direction-perspective,
.panorama:has(.guess-panel.expanded) .connections,
.panorama:has(.guess-panel.expanded) #sequence-navigation,
.panorama:has(.guess-panel.show-results.expanded) #compass,
.panorama:has(.guess-panel.show-results) #restart,
.panorama.no-movement :is(.mapillary-direction-perspective, .connections, #sequence-navigation, #restart) {
  display: none;
}

@media (max-width: 720px), (max-height: 480px) {
  .guess-panel.show-results.expanded {
    width: min(100% - 1.5rem, 34rem);
    max-height: calc(100cqh - 7rem);
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: repeat(4, max-content);
    grid-template-areas: "heading" "map" "footer" "ranking";
    overflow: auto;
  }
  .guess-panel.show-results.final-results.expanded {
    width: min(100% - 1.5rem, 34rem);
    grid-template-rows: repeat(5, max-content);
    grid-template-areas: "summary" "heading" "map" "footer" "ranking";
  }
  #round-ranking {
    contain: none;
    border-top: 1px solid var(--line);
    border-right: 0;
  }
  .ranking-scroll { max-height: 9rem; }
}

.map-ping { animation: ping-pulse .85s ease-in-out infinite alternate; }
@keyframes ping-pulse {
  from { opacity: .65; }
  to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .map-ping { animation: none; }
}

@media (max-width: 520px) {
  .guess-panel:not(.expanded) { width: min(17rem, calc(100% - 1.5rem)); }
}

@media (hover: hover) and (pointer: fine) {
  .guess-panel:not(.expanded, .show-results):is(.map-hovered, .map-held) {
    width: min(100% - 1.5rem, max(21rem, 50cqw));
  }
  .guess-panel:not(.expanded, .show-results):is(.map-hovered, .map-held) #guess-map {
    height: max(clamp(7rem, 24vh, 12rem), calc(50cqh - 7rem));
  }
}

#viewer :is(.mapillary-direction-circle, .mapillary-direction-turn-circle)[data-id] {
  background-color: var(--accent);
  outline: 1px solid #173e35;
}

#sequence-navigation {
  position: absolute;
  z-index: 1;
  left: .75rem;
  bottom: 3.25rem;
  display: flex;
  gap: .45rem;
}

#viewer:has(.mapillary-direction-perspective [data-id]:not([class*="circle-inactive"]))
  ~ #sequence-navigation { display: none; }

.connections {
  position: absolute;
  z-index: 1;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .5rem;
  width: max-content;
  max-width: calc(100% - 5rem);
}

.connection { color: #112923; background: var(--accent); }
.connection span { margin-right: .4rem; }
