/* ==========================================================================
   World of Type — interactive map styles
   Assumes colors_and_type.css is loaded first (defines --ink, --paper, etc).
   ========================================================================== */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font-text);
  color: var(--ink);
  background: var(--paper);
}

/* Nav scrolls away with the page (not sticky), so the map section starts
   at the very top of the viewport when scrolled into view — no padding needed.
   .wot-root fills the full viewport height. */
.wot-root {
  position: relative;
  width: 100%;
  height: 100vh;
  min-height: 640px;
  background: var(--paper);
  overflow: hidden;
  user-select: none;
}
@media (max-width: 700px) {
  /* Mobile sizing: canvas below the 56px topbar is kept ~square so the
     constellation (which has roughly 1:1 aspect once leaks are excluded)
     fills the available pixels — no awkward white band above or below it.
     `100vw + 56px` matches the topbar+square layout naturally. Capped at
     `100svh` so it never exceeds the visible viewport on tall phones. */
  .wot-root {
    height: calc(100vw + 56px);
    min-height: 480px;
    max-height: 100svh;
    aspect-ratio: auto;
  }
  /* Match the canvas inset to the shorter mobile topbar height. */
  .wot-canvas { inset: 56px 0 0 0; }
}

/* ---------- Map toolbar (replaces old TopBar) ---------- */
.wot-topbar {
  position: absolute; top: 0; left: 0; right: 0;
  height: 64px;
  display: flex; align-items: center;
  padding: 0 clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--border-1);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 40;
  gap: 24px;
}
.wot-topbar-label {
  display: flex; align-items: center; gap: 14px;
}
.wot-topbar-kicker {
  font-family: var(--font-micro);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink);
}
.wot-topbar-sep {
  width: 1px;
  height: 14px;
  background: var(--border-2);
}
.wot-topbar-hint {
  font-family: var(--font-text);
  font-size: 12.5px;
  color: var(--fg-2);
  letter-spacing: -0.005em;
}
.wot-topbar-hint-mobile {
  /* Hidden on desktop — only shown on mobile in place of the long hint. */
  display: none;
  font-family: var(--font-text);
  font-size: 12px;
  color: var(--fg-2);
  letter-spacing: -0.005em;
}
@media (max-width: 720px) {
  .wot-topbar-sep, .wot-topbar-hint { display: none; }
  .wot-topbar-hint-mobile { display: inline; }
}
.wot-spacer { flex: 1; }

.wot-toolbar {
  display: flex; align-items: center; gap: 8px;
}
.wot-toolbtn {
  height: 36px;
  padding: 0 14px;
  font-family: var(--font-text);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: -0.005em;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--border-2);
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  transition: background var(--dur-fast) var(--ease-standard),
              color var(--dur-fast) var(--ease-standard),
              border-color var(--dur-fast) var(--ease-standard);
}
.wot-toolbtn:hover { background: var(--neutral-100); }
.wot-toolbtn.is-active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.wot-toolbtn .swatch {
  width: 8px; height: 8px; border-radius: 999px;
  background: var(--tokyo-red);
  box-shadow: 0 0 0 2px rgba(255,28,94,0.18);
}

/* Toolbar buttons can carry two labels — full text for desktop, short text
   for mobile. Default visibility is desktop; the mobile media query swaps. */
.wot-toolbtn-label-full   { display: inline; }
.wot-toolbtn-label-mobile { display: none; }

/* ---------- Legend (bottom-left) ---------- */
.wot-legend {
  position: absolute;
  left: clamp(16px, 3vw, 32px);
  bottom: 28px;
  z-index: 30;
  padding: 14px 16px;
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-1);
  border-radius: 6px;
  box-shadow: var(--shadow-1);
  max-width: 260px;
  pointer-events: auto;
}
.wot-legend h4 {
  font-family: var(--font-micro);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--fg-2);
  margin: 0 0 10px;
}
.wot-legend-row {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-text);
  font-size: 11.5px;
  color: var(--ink);
  margin-bottom: 6px;
  letter-spacing: -0.005em;
  line-height: 1.3;
}
.wot-legend-row:last-child { margin-bottom: 0; }
.wot-legend-swatch {
  width: 10px; height: 10px; border-radius: 2px;
  flex-shrink: 0;
}
.wot-legend-line {
  width: 18px; height: 2px;
  flex-shrink: 0;
}
.wot-legend-line.dashed {
  background: repeating-linear-gradient(to right, currentColor 0 3px, transparent 3px 6px);
  height: 2px;
}
.wot-legend-hint {
  font-family: var(--font-micro);
  font-size: 10px;
  color: var(--fg-3);
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border-1);
  letter-spacing: 0.01em;
  line-height: 1.4;
}

/* ---------- Info panel (right side, selection drawer) ---------- */
.wot-panel {
  position: absolute;
  top: 84px;
  right: clamp(16px, 3vw, 32px);
  bottom: 28px;
  width: 380px;
  max-width: calc(100vw - 32px);
  background: var(--paper);
  border: 1px solid var(--border-1);
  border-radius: 8px;
  box-shadow: var(--shadow-2);
  z-index: 35;
  display: flex; flex-direction: column;
  overflow: hidden;
  transform: translateX(420px);
  opacity: 0;
  transition: transform 400ms var(--ease-emphasis), opacity 300ms var(--ease-standard);
  pointer-events: none;
}
.wot-panel.is-open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}
.wot-panel-color { height: 6px; background: var(--ink); }
.wot-panel-header {
  padding: 28px 28px 20px;
  border-bottom: 1px solid var(--border-1);
}
.wot-panel-kind {
  font-family: var(--font-micro);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--fg-3);
  margin-bottom: 10px;
}
.wot-panel-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 36px;
  line-height: 1.02;
  letter-spacing: -0.025em;
  color: var(--ink);
  margin: 0;
}
.wot-panel-sub {
  font-family: var(--font-text);
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg-2);
  margin: 10px 0 0;
  letter-spacing: -0.005em;
}
.wot-panel-body {
  padding: 24px 28px;
  overflow-y: auto;
  flex: 1;
}
.wot-stat {
  padding: 16px 0;
  border-bottom: 1px solid var(--border-1);
  margin-bottom: 20px;
}
.wot-stat .val {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 44px;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--ink);
}
.wot-stat .lbl {
  font-family: var(--font-text);
  font-size: 13px;
  line-height: 1.45;
  color: var(--fg-2);
  margin-top: 8px;
  letter-spacing: -0.005em;
}
.wot-panel-section-label {
  font-family: var(--font-micro);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--fg-3);
  margin-bottom: 14px;
}
.wot-touchpoint-row {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  gap: 12px;
  align-items: baseline;
  padding: 12px 0;
  border-top: 1px solid var(--border-1);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard);
}
.wot-touchpoint-row:hover { background: var(--neutral-50); margin: 0 -12px; padding-left: 12px; padding-right: 12px; }
.wot-touchpoint-row:first-of-type { border-top: 0; }
.wot-touchpoint-dot {
  width: 10px; height: 10px; border-radius: 999px;
  align-self: center;
}
.wot-touchpoint-name {
  font-family: var(--font-text);
  font-weight: 500;
  font-size: 14px;
  color: var(--ink);
  letter-spacing: -0.005em;
}
.wot-touchpoint-note {
  font-family: var(--font-text);
  font-size: 12px;
  color: var(--fg-2);
  margin-top: 3px;
  line-height: 1.4;
}
.wot-touchpoint-risk {
  font-family: var(--font-micro);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-3);
  align-self: center;
  white-space: nowrap;
}

.wot-panel-close {
  position: absolute;
  top: 16px; right: 16px;
  width: 32px; height: 32px;
  background: transparent; border: 0;
  cursor: pointer;
  color: var(--fg-2);
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px;
}
.wot-panel-close:hover { background: var(--neutral-100); color: var(--ink); }

/* ---------- SVG map ----------
   Inset 64px from top so the canvas — and the constellation centered inside
   it — never renders behind the .wot-topbar (which sits absolute at top:0
   inside .wot-root, also 64px tall). Without this, the top of the Campaigns
   planet and its touchpoints end up hidden behind the toolbar. */
.wot-canvas {
  position: absolute;
  inset: 64px 0 0 0;
  cursor: default;
}
.wot-canvas.is-panning { cursor: default; }

/* Planet / node interactions */
.wot-node { cursor: pointer; }
.wot-node text {
  pointer-events: none;
  user-select: none;
}
.wot-planet-core {
  transition: transform 200ms var(--ease-standard);
  transform-box: fill-box;
  transform-origin: center;
}
.wot-planet-core:hover { transform: scale(1.06); }

/* Orbit rings — hairline */
.wot-orbit {
  fill: none;
  stroke: var(--neutral-200);
  stroke-width: 1;
  stroke-dasharray: 2 4;
  opacity: 0.7;
}
.wot-orbit-strong {
  fill: none;
  stroke: var(--neutral-300);
  stroke-width: 1;
  opacity: 0.85;
}

/* Gravity lines (source -> dept).
   Governed flows are quietly present at all times. Leak flows are hidden
   by default — they only appear when the user clicks a leak source
   (Inherited estates, Shadow IT, Satellite licenses) or a department
   that has incoming leaks. The 200ms transition makes them fade in/out. */
.wot-gravity {
  fill: none;
  stroke: var(--neutral-500);
  stroke-width: 1.25;
  opacity: 0.55;
  transition: opacity 200ms var(--ease-standard),
              stroke 200ms var(--ease-standard),
              stroke-width 200ms var(--ease-standard);
}
.wot-gravity.leak {
  stroke: var(--tokyo-red);
  stroke-width: 1.5;
  stroke-dasharray: 4 5;
  opacity: 0;
}
.wot-gravity.is-highlighted {
  opacity: 1;
  stroke-width: 2;
}
.wot-gravity.leak.is-highlighted {
  opacity: 1;
  stroke-width: 2.25;
}

/* Internal inter-departmental flow arrows — hidden because they crowded
   the constellation visually. Layer kept in the DOM so toggling back on
   later is a one-line CSS change. */
.wot-internal-layer { display: none; }
.wot-internal {
  fill: none;
  stroke: var(--neutral-400);
  stroke-width: 1.25;
  stroke-dasharray: 1 4;
  opacity: 0.7;
}
.wot-particle { fill: var(--ink); }

.wot-risk-halo {
  opacity: 0;
  transition: opacity 500ms var(--ease-standard);
  pointer-events: none;
}
.wot-root.risk-on .wot-risk-halo { opacity: 0.7; }

/* Risk overlay also reveals the leak paths (otherwise hidden) — they're
   the structural counterpart to the per-touchpoint risk halos. Visible at
   moderate opacity by default; non-highlighted ones dim further when
   something is selected; the selected/related leak path stays at full. */
.wot-root.risk-on .wot-gravity.leak { opacity: 0.7; }
.wot-root.risk-on.has-selection .wot-gravity.leak:not(.is-highlighted) { opacity: 0.35; }
.wot-root.risk-on .wot-gravity.leak.is-highlighted { opacity: 1; }

/* Typography inside SVG */
.wot-svg-label {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.02em;
  fill: var(--ink);
}
.wot-svg-label.inverse { fill: var(--paper); }
.wot-svg-sub {
  font-family: var(--font-micro);
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  fill: rgba(255,255,255,0.7);
}
.wot-svg-outer-label {
  font-family: var(--font-micro);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  fill: var(--fg-2);
}

.wot-sun text { fill: var(--paper); }

.wot-moon-ring {
  fill: var(--paper);
  stroke: currentColor;
  stroke-width: 1.5;
  transition: fill 200ms var(--ease-standard),
              stroke-width 200ms var(--ease-standard);
}
.wot-moon.is-hover .wot-moon-ring,
.wot-moon:hover .wot-moon-ring {
  fill: currentColor;
  stroke-width: 2;
}
/* This rule wins over the SVG fontSize/fontFamily attributes in map.jsx
   (CSS beats presentation attributes), so the source of truth lives here. */
.wot-moon-label {
  font-family: var(--font-text);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.005em;
  fill: var(--ink);
}
.wot-root.risk-on .wot-moon-ring { stroke-width: 0; }

/* Dim non-highlighted when something is selected */
.wot-root.has-selection .wot-department:not(.is-selected):not(.is-related) { opacity: 0.28; }
.wot-root.has-selection .wot-outer:not(.is-selected):not(.is-related) { opacity: 0.35; }
.wot-root.has-selection .wot-gravity:not(.is-highlighted) { opacity: 0.18; }
.wot-root.has-selection .wot-gravity.leak:not(.is-highlighted) { opacity: 0; }
.wot-department, .wot-outer, .wot-gravity, .wot-internal {
  transition: opacity 300ms var(--ease-standard);
}

.wot-outer-dot {
  fill: var(--paper);
  stroke: var(--ink);
  stroke-width: 1.25;
}
.wot-outer-dot.leak {
  stroke: var(--tokyo-red);
  stroke-dasharray: 2 2;
}

/* ==========================================================================
   Mobile (<= 700px) — collapses chrome, info panel becomes a bottom sheet.
   ========================================================================== */
@media (max-width: 700px) {
  /* Hide legend on small screens; the How-to-read section below the map
     covers the same content, and the legend would crowd a 380px viewport. */
  .wot-legend { display: none; }

  /* Toolbar — replace the long desktop hint with a short mobile-only one
     ("Tap a planet to explore"). To keep the row on a single line at 375px,
     we also drop the THE MAP kicker — the page heading already names the
     section and the hint reads as a self-contained instruction. */
  .wot-topbar-hint { display: none; }
  .wot-topbar-kicker { display: none; }
  .wot-topbar { padding: 0 12px; gap: 8px; height: 56px; }
  .wot-topbar-label { gap: 8px; flex: 0 1 auto; min-width: 0; }
  .wot-topbar-hint-mobile { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .wot-toolbar { gap: 4px; flex: 0 0 auto; }
  .wot-toolbtn {
    /* tighter buttons so all three fit on a phone, with single-line labels */
    padding: 0 10px;
    font-size: 12px;
    height: 32px;
    white-space: nowrap;
  }
  .wot-toolbtn-label-full   { display: none; }
  .wot-toolbtn-label-mobile { display: inline; }

  /* Info panel — bottom sheet, full width, slides up from below.
     position: fixed (overrides the desktop `absolute`) so the panel is
     positioned relative to the viewport, NOT to .wot-root. Without this,
     .wot-root has aspect-ratio:1/1 + overflow:hidden, which clips the
     top of any panel taller than wot-root (the previous symptom: the
     header of the info card was cut off on mobile).
     Capped at 55vh so ~45vh of map stays visible above. */
  .wot-panel {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: none;
    max-height: 55vh;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    /* Tweak shadow direction for an upward-cast lift */
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
  }

  /* Bigger touch hit-target for moon dots on mobile so taps land cleanly.
     CSS `r` overrides the SVG attribute. ~36 world units gives ~12px hit
     radius at home zoom (0.34) and ~22px when a planet is zoomed-in (planet
     zoom mult 1.8 × home 0.34 ≈ 0.61), close to the 44px guideline at
     planet-zoom and still tappable at home. */
  .wot-moon-hit { r: 36; }

  /* Inflate SVG labels on mobile so they render at a legible viewport size
     at home zoom (~0.27 scale on a 375px phone). CSS font-size on SVG <text>
     wins over the presentation attribute, so this is also what scales the
     planet/sun labels — the JSX-set sizes only apply on desktop. */
  .wot-moon-label { font-size: 36px; letter-spacing: -0.01em; }
  .wot-svg-outer-label { font-size: 28px; }
  .wot-department .wot-planet-core text:first-of-type {
    /* Department short-name (e.g. "Brand", "Procurement"). Capped at 26 so
       the longest label ("Procurement", 11 chars) still fits inside the
       smallest planet (r=72, diameter 144 world units). Going larger
       overflows the colored fill and the white text becomes invisible
       against the white page background. */
    font-size: 26px !important;
  }
  .wot-department .wot-planet-core text:last-of-type {
    /* "N TOUCHPOINTS" subline — 12 chars at ~6 world units each = 72 world
       units, comfortably fits inside any planet at this size. */
    font-size: 11px !important;
  }
  .wot-sun text { font-size: 36px; }
  .wot-sun text:last-of-type { font-size: 13px; }

  /* HOME-VIEW DECLUTTER: at home zoom on a phone, the inner-orbit moon labels
     (touchpoints) clip against the screen edges and crowd each other beyond
     legibility — there are 30+ of them spread across 6 planets. We hide
     them at home and reveal only the labels for the planet the user has
     tapped into; the planet-zoom view (1.9× home) gives those labels
     plenty of room to breathe. The connector lines, halos, and dots are
     unaffected, so the constellation's structure is still visible. */
  .wot-root:not(.has-selection) .wot-moon-label { opacity: 0; }
  .wot-root.has-selection .wot-department:not(.is-selected):not(.is-related) .wot-moon-label { opacity: 0; }
  .wot-moon-label { transition: opacity 250ms var(--ease-standard); }
  .wot-panel.is-open { transform: translateY(0); }
  .wot-panel-close {
    /* Bigger tap target for the close button on touch devices */
    width: 40px;
    height: 40px;
    top: 12px;
    right: 12px;
  }
  .wot-panel-header { padding: 24px 20px 16px; }
  .wot-panel-title  { font-size: 28px; }
  .wot-panel-body   { padding: 18px 20px; }
}
