@layer components {
  .places-main {
    gap: 14px;
    grid-auto-rows: max-content;
  }

  .places-intro {
    max-width: 75ch;
    color: var(--text-secondary);
    line-height: 1.6;
  }

  .places-sidebar > .side-link {
    margin-bottom: 16px;
  }

  .places-tree {
    gap: 4px;
  }

  .places-nav-group > summary {
    display: flex;
    align-items: center;
    padding: 0;
  }

  .places-nav-group > summary::before {
    flex: 0 0 16px;
    text-align: center;
  }

  .places-nav-group:not([open]) > summary::before {
    content: "+";
  }

  .places-nav-group[open] > summary::before {
    content: "−";
  }

  .places-nav-group > summary > .side-link {
    flex: 1;
    min-width: 0;
    text-decoration: none;
  }

  .places-nav-children {
    display: grid;
    gap: 3px;
    margin: 3px 0 6px 12px;
    border-left: 1px solid var(--border-subtle);
    padding-left: 6px;
  }

  .places-tree .side-link {
    overflow-wrap: anywhere;
  }

  .places-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr));
    gap: 18px;
  }

  .place-card {
    display: grid;
    grid-template-rows: auto 1fr;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    background: var(--surface-raised);
    color: var(--text);
    text-decoration: none;
  }

  .place-card:hover {
    border-color: var(--border-focus);
    background: var(--surface-muted);
  }

  .place-card-image {
    position: relative;
    display: grid;
    place-items: center;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    background: #eae5d8;
    padding: 10px;
  }

  .place-card-image img {
    position: absolute;
    top: 10px;
    left: 10px;
    display: block;
    width: calc(100% - 20px);
    height: calc(100% - 20px);
    object-fit: contain;
  }

  .place-card-copy {
    display: grid;
    align-content: start;
    gap: 6px;
    padding: 16px;
  }

  .place-card-copy h2 {
    color: var(--text-strong);
    font-size: 1.18rem;
  }

  .place-card-copy p {
    color: var(--text-secondary);
    font-size: 0.88rem;
    line-height: 1.5;
  }

  .places-map-label {
    margin: 0;
    color: var(--text-strong);
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.4;
  }

  .places-map {
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    background: var(--surface-raised);
  }

  .places-map-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border-bottom: 1px solid var(--border-subtle);
    padding: 10px;
  }

  .places-map-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }

  .places-map-controls output {
    min-width: 48px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-align: center;
  }

  .places-map-viewport {
    position: relative;
    height: clamp(360px, 65vh, 850px);
    overflow: hidden;
    background: #eae5d8;
    cursor: grab;
    touch-action: none;
  }

  .places-map-viewport:active {
    cursor: grabbing;
  }

  .places-map-image {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: contain;
    transform-origin: 0 0;
    user-select: none;
    pointer-events: none;
  }

  .places-map-help {
    padding: 9px 12px;
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.5;
  }

  .places-map:fullscreen {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    border: 0;
    border-radius: 0;
  }

  .places-map:fullscreen .places-map-viewport {
    height: 100%;
  }

  /* Layered bundle viewer (public/scripts/places-bundle.js) */
  .places-bundle-kind {
    margin-left: 6px;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 400;
  }

  /* the layered map fills the main panel */
  .places-main.places-main-map {
    grid-template-rows: minmax(0, 1fr);
    grid-auto-rows: auto;
  }

  .places-bundle {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 0;
  }

  .places-bundle-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 260px;
    min-height: 0;
  }

  .places-bundle-viewport {
    height: auto;
    min-height: 0;
    background: #f2ede0;
  }

  .places-bundle-tip {
    position: absolute;
    z-index: 3;
    display: grid;
    gap: 2px;
    max-width: 260px;
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    background: var(--surface-raised);
    box-shadow: 0 4px 14px rgb(0 0 0 / 18%);
    padding: 6px 9px;
    color: var(--text);
    font-size: 0.8rem;
    line-height: 1.35;
    pointer-events: none;
  }

  .places-bundle-tip strong {
    color: var(--text-strong);
  }

  .places-bundle-tip span,
  .places-bundle-tip em {
    color: var(--text-secondary);
  }

  .places-bundle-tip .pb-tip-people {
    color: #b23a48;
  }

  .places-bundle-card {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 4;
    width: min(340px, calc(100% - 24px));
    max-height: calc(100% - 24px);
    overflow: auto;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    background: var(--surface-raised);
    box-shadow: 0 6px 20px rgb(0 0 0 / 20%);
    padding: 12px 14px;
    font-size: 0.84rem;
    cursor: auto;
  }

  .places-bundle-close {
    float: right;
    border: 0;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
  }

  .places-bundle-world,
  .places-bundle-labels {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    user-select: none;
  }

  .places-bundle-labels {
    pointer-events: none;
  }

  .places-bundle-viewport .token-layer {
    z-index: 2;
  }

  .places-bundle-tip.has-portrait {
    grid-template-columns: 44px 1fr;
    column-gap: 9px;
  }

  .places-bundle-tip.has-portrait > :not(.pb-tip-portrait) {
    grid-column: 2;
  }

  .pb-tip-portrait,
  .pb-card-portrait,
  .pb-list-portrait {
    border-radius: 50%;
    object-fit: cover;
    background: var(--surface);
  }

  .pb-tip-portrait {
    grid-row: 1 / span 6;
    width: 44px;
    height: 44px;
    align-self: start;
  }

  .pb-card-portrait {
    float: left;
    width: 64px;
    height: 64px;
    margin: 0 12px 6px 0;
    box-shadow: 0 0 0 2px var(--border-subtle);
  }

  .pb-list-portrait {
    width: 20px;
    height: 20px;
    margin-right: 6px;
    vertical-align: -5px;
  }

  .pb-tip-portrait.is-emblem,
  .pb-card-portrait.is-emblem,
  .pb-list-portrait.is-emblem {
    border-radius: 22%;
    object-fit: contain;
  }

  .places-bundle-card dl,
  .places-bundle-card h4 {
    clear: both;
  }

  .pb-far .pb-art-fine,
  .pb-mid .pb-art-near {
    display: none;
  }
  .pb-far .pb-lod-parcels {
    display: none;
  }

  /* While the map moves, the tree patterns over woods and parks are left out
     (slow to draw in Firefox); the green underneath stays. See LIGHTEN_WHILE_MOVING. */
  .pb-moving [fill="url(#pb-trees)"],
  .pb-moving [fill="url(#pb-park)"] {
    display: none;
  }

  .places-bundle-status {
    position: absolute;
    inset: auto 0 45% 0;
    color: #5d6652;
    text-align: center;
  }

  .places-bundle-panel {
    display: grid;
    align-content: start;
    gap: 10px;
    min-height: 0;
    overflow: auto;
    border-left: 1px solid var(--border-subtle);
    padding: 10px 12px;
    font-size: 0.84rem;
  }

  .places-bundle-search {
    position: relative;
    display: grid;
    gap: 4px;
    color: var(--text-secondary);
  }

  .places-bundle-search input {
    width: 100%;
  }

  .places-bundle-results {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    z-index: 5;
    display: grid;
    gap: 2px;
    max-height: 320px;
    overflow: auto;
    margin: 4px 0 0;
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    background: var(--surface-raised);
    box-shadow: 0 6px 18px rgb(0 0 0 / 18%);
    padding: 6px 8px;
    list-style: none;
  }

  .places-bundle-results[hidden],
  .places-bundle-tip[hidden],
  .places-bundle-card[hidden] {
    display: none;
  }

  .places-bundle-none {
    color: var(--text-muted);
  }

  .places-bundle-results button,
  .places-bundle-chain button {
    border: 0;
    background: none;
    color: var(--link, var(--text));
    cursor: pointer;
    padding: 2px 0;
    text-align: left;
    text-decoration: underline;
    text-decoration-color: var(--border-subtle);
  }

  .places-bundle-results span,
  .places-bundle-people span {
    color: var(--text-muted);
    font-size: 0.76rem;
  }

  .places-bundle-card h3 {
    margin: 0;
    color: var(--text-strong);
    font-size: 1.02rem;
  }

  .places-bundle-card h4 {
    margin: 10px 0 4px;
    color: var(--text-secondary);
    font-size: 0.8rem;
  }

  .places-bundle-card dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 3px 10px;
    margin: 8px 0 0;
  }

  .places-bundle-card dt {
    color: var(--text-muted);
  }

  .places-bundle-card dd {
    margin: 0;
  }

  .places-bundle-kind,
  .places-bundle-hint,
  .places-bundle-contains {
    color: var(--text-muted);
  }

  .places-bundle-people {
    display: grid;
    gap: 4px;
    margin: 0;
    padding-left: 0;
    list-style: none;
  }

  .places-bundle-section summary {
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 600;
  }

  .places-bundle-section label,
  .places-bundle-layers label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 5px;
  }

  .places-bundle-layers {
    display: grid;
  }

  .places-bundle:fullscreen {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .places-child-section {
    display: grid;
    gap: 12px;
    margin-top: 10px;
  }
}

@layer responsive {
  @media (max-width: 640px) {
    .places-nav-children {
      margin-left: 4px;
      padding-left: 3px;
    }

    .places-map-viewport {
      height: 60vh;
      min-height: 280px;
    }

    .places-bundle-body {
      grid-template-columns: 1fr;
      grid-template-rows: minmax(300px, 1fr) auto;
    }

    .places-bundle-panel {
      max-height: 40vh;
      border-top: 1px solid var(--border-subtle);
      border-left: 0;
    }

    .places-map-controls .button {
      padding: 5px 7px;
      font-size: 0.76rem;
    }

    .places-grid {
      gap: 12px;
    }
  }

  /* Player view: the map without its controls (pv-hide) takes the full width. */
  html.pv-present .places-bundle-body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }
}
