/* Town Map "Tsui" exploration: name-tag cards + first-visit guide.
   Loaded only by index.html. Palette follows styles.css:
   paper #f3ecd9 / ink #28322d / accent #876f4c on map section #d8d2c3. */

/* ---------- Guide banner ---------- */
.tsui-guide {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 14px;
  padding: 12px 16px;
  background: #f3ecd9;
  border: 1px solid #876f4c40;
  color: #28322d;
  opacity: 1;
  transition: opacity .35s ease;
}
.tsui-guide.is-leaving { opacity: 0; }
.tsui-guide-text {
  margin: 0;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: 13px;
  letter-spacing: .06em;
  line-height: 1.8;
}
.tsui-guide-skip {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 6px 4px;
  border-bottom: 1px solid #28322d66;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: 11px;
  letter-spacing: .1em;
  color: #28322d;
  white-space: nowrap;
}
.tsui-guide-skip:hover { color: #876f4c; }

/* ---------- Guide highlight (first visit) ---------- */
@keyframes tsui-breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231, 214, 173, .6), 0 5px 18px #17201c55; }
  50% { box-shadow: 0 0 0 14px rgba(231, 214, 173, 0), 0 5px 18px #17201c55; }
}
.map-hotspot.tsui-target .map-marker {
  background: #795f3f;
  animation: tsui-breathe 2.6s ease-in-out infinite;
}
.map-hotspot.tsui-quiet .map-marker { opacity: .45; }

/* ---------- Name-tag card ---------- */
.tsui-card {
  position: absolute;
  z-index: 30;
  width: min(290px, 76%);
  background: #f3ecd9;
  color: #28322d;
  border: 1px solid #876f4c59;
  box-shadow: 0 18px 44px rgba(23, 32, 28, .38);
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  opacity: 0;
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;
}
.tsui-card.is-open { opacity: 1; pointer-events: auto; }

/* Measurement pose for the clamp pass in townmap-tsui.js: the card is
   rendered once in its settled open geometry, invisible and with
   transitions off, so its rect can be measured and left/top corrected
   before the entrance animation replays from the closed pose. */
.tsui-card--measure { visibility: hidden !important; transition: none !important; }

/* Placement variants: the card sits beside the tapped spot.
   --above (default): above the spot; --below: below the spot.
   These pick the preferred side only; JS then measures the card
   against the canvas and shifts left/top so it never clips. */
.tsui-card { transform: translate(-50%, calc(-100% - 20px)) translateY(8px); }
.tsui-card.is-open { transform: translate(-50%, calc(-100% - 20px)) translateY(0); }
.tsui-card--below { transform: translate(-50%, 20px) translateY(-8px); }
.tsui-card--below.is-open { transform: translate(-50%, 20px) translateY(0); }
.tsui-card--align-left { transform: translate(-14px, calc(-100% - 20px)) translateY(8px); }
.tsui-card--align-left.is-open { transform: translate(-14px, calc(-100% - 20px)) translateY(0); }
.tsui-card--align-left.tsui-card--below { transform: translate(-14px, 20px) translateY(-8px); }
.tsui-card--align-left.tsui-card--below.is-open { transform: translate(-14px, 20px) translateY(0); }
.tsui-card--align-right { transform: translate(calc(-100% + 14px), calc(-100% - 20px)) translateY(8px); }
.tsui-card--align-right.is-open { transform: translate(calc(-100% + 14px), calc(-100% - 20px)) translateY(0); }
.tsui-card--align-right.tsui-card--below { transform: translate(calc(-100% + 14px), 20px) translateY(-8px); }
.tsui-card--align-right.tsui-card--below.is-open { transform: translate(calc(-100% + 14px), 20px) translateY(0); }

.tsui-card-media {
  position: relative;
  height: 148px;
  overflow: hidden;
  background: #27392e;
}
.tsui-card-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.tsui-card-body { padding: 14px 16px 14px; }
.tsui-card-code {
  margin: 0 0 6px;
  font-size: 10px;
  letter-spacing: .2em;
  color: #876f4c;
}
.tsui-card-name {
  margin: 0 0 10px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: .05em;
  line-height: 1.4;
}
.tsui-card-copy {
  margin: 0;
  font-size: 12px;
  line-height: 1.8;
  color: #59615d;
}
.tsui-card-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-top: 6px;
  padding: 8px 0 4px;
  border-bottom: 1px solid #28322d66;
  font-size: 12px;
  letter-spacing: .11em;
  color: #28322d;
}
.tsui-card-link span { display: inline-block; transition: transform .25s; }
.tsui-card-link:hover span, .tsui-card-link:focus-visible span { transform: translate(3px, -3px); }
.tsui-card-link:focus-visible { outline: 1px solid #6f5a39; outline-offset: 4px; }
.tsui-card-close {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: #17201cd9;
  color: #f3ecd9;
  border: 1px solid #f3ecd938;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
}
.tsui-card-close:hover { color: #fff; }
.tsui-card-close:focus-visible { outline: 1px solid #f8efcf; outline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  .tsui-card, .tsui-guide, .tsui-card-link span { transition: none; }
  .map-hotspot.tsui-target .map-marker { animation: none; }
}

/* ---------- Small screens (<=640px): bottom-sheet card ---------- */
/* On phones the floating card did not fit inside the map frame and the
   photo was squeezed away. The card becomes a bottom sheet instead:
   JS moves it to <body> and adds .tsui-card--sheet (a transform on
   .town-map-canvas would trap position:fixed inside the canvas).
   The map frame also goes full-bleed so the map itself reads larger.
   The canvas inside is height-driven with its own aspect ratio, so
   widening the frame never shifts the hotspot % coordinates. */
@media (max-width: 640px) {
  .town-map-frame {
    width: 100vw;
    margin-inline: calc(50% - 50vw);
  }

  .tsui-card.tsui-card--sheet {
    position: fixed;
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 90;
    width: auto;
    max-height: 45vh;
    max-height: 45svh;
    overflow: hidden;
    transform: translateY(16px);
  }
  .tsui-card.tsui-card--sheet.is-open { transform: translateY(0); }

  /* Height hugs the content: banner + name row + copy (<=2 lines) + CTA,
     roughly 290px in total, no empty paper below the text. */
  .tsui-card--sheet .tsui-card-media {
    height: clamp(140px, 38vw, 160px);
  }
  .tsui-card--sheet .tsui-card-body {
    padding: 10px 16px 12px;
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 10px;
    align-items: baseline;
  }
  .tsui-card--sheet .tsui-card-code { margin: 0; }
  .tsui-card--sheet .tsui-card-name { margin: 0; font-size: 17px; }
  .tsui-card--sheet .tsui-card-copy {
    grid-column: 1 / -1;
    margin-top: 6px;
    line-height: 1.75;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .tsui-card--sheet .tsui-card-link {
    grid-column: 1 / -1;
    margin-top: 2px;
    padding: 6px 0 2px;
  }
}
