/* Dark theme only. Layout: full-bleed word clouds on the left, fixed control panel on the right; stacks on phones. */
:root {
  --ocean: #11191d;
  --land: #222c31;
  --coast: #3b4b52;
  --panel: #171f23;
  --ink: #e4ecee;
  --muted: #93a5ab;
  --rule: #2a363b;
  --chip: #222c31;
  --font-body: "DM Sans", var(--font-fallback), system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "DM Mono", ui-monospace, Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--panel); color: var(--ink); font: 12px/1.45 var(--font-body); }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* The panel comes first in the page, for screen readers and tabbing, but sits on the right. */
/* The panel is as wide as its widest fixed-width content (the title or the
   feeling buttons); text and word chips wrap to that width (see .fit). */
.app { display: grid; grid-template-columns: 1fr auto; grid-template-rows: 100%; height: 100%; }
.app > .panel { grid-column: 2; grid-row: 1; }
.app > .map-wrap { grid-column: 1; grid-row: 1; }

.panel {
  display: flex; flex-direction: column; gap: 20px;
  padding: 24px 20px 20px; overflow-y: auto; min-width: 0; /* the logo, last, sits level with the info button */
  border-left: 1px solid var(--rule); background: var(--panel);
}
.masthead h1 {
  font: 400 30px/var(--feeling-line) var(--font-title, var(--font-body)); margin: 0 0 12px;
  white-space: nowrap;
}
.lede { margin: 0; color: var(--muted); }
/* Takes the panel's width without setting it, so it wraps instead of widening the panel. */
.fit { width: 0; min-width: 100%; }

.block { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.label {
  margin: 0; font: 600 11px/1 var(--font-body); text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--muted);
}
.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.label-actions { display: flex; gap: 10px; }
.link { background: none; border: 0; padding: 0; color: var(--muted); font-size: 12px; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link:hover { color: var(--ink); }

/* One column, ordered most positive to most negative. */
.feelings { display: grid; grid-template-columns: 1fr; gap: 4px; }
.feeling {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px; border: 1px solid var(--rule); border-radius: 6px;
  background: transparent; cursor: pointer; text-align: left;
}
.feeling .name {
  font: 400 15px/var(--feeling-line) var(--font-body); flex: none; white-space: nowrap;
  /* Moves the name down so the band from its capitals' tops to its baseline is
     centred in the button: Playwrite sits that band 0.09em above the middle of
     its line. Tuned to Playwrite's measurements; recheck with another font. */
  position: relative; top: 0.09em;
}
/* Bars share one left edge so lengths compare directly, and the name follows
   the end of its bar. --p is the bar's share of the longest bar, and --bar the
   longest bar's length, set by app.js so the longest bar and its name fill the
   button. Rounded at the data end (right) only. */
.feeling .fill {
  flex: none; height: 8px; min-width: 3px; width: calc(var(--bar, 180px) * var(--p));
  background: var(--c); border-radius: 0 4px 4px 0;
}
.feeling:hover { border-color: var(--c); }
.feeling[aria-pressed="true"] { background: var(--c); border-color: var(--c); color: var(--c-ink, #fff); }
/* The bar takes the text color, so it shows on pale feelings too. */
.feeling[aria-pressed="true"] .fill { background: var(--c-ink, #fff); }

.words { display: flex; flex-wrap: wrap; gap: 5px; }
.word {
  display: inline-flex; align-items: baseline; gap: 5px;
  padding: 0 8px 3px; border-radius: 999px; border: 1px solid transparent;
  background: var(--chip); cursor: pointer; font-size: 13px;
}
.word .w { line-height: var(--feeling-line); }
.word .n { font: 10.5px var(--font-mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.word[aria-pressed="true"] { border-color: var(--c); }
.word[aria-pressed="false"] { opacity: 0.45; text-decoration: line-through; }
/* Words with no matching places: plain text under the chips. */
.words-empty { margin: 10px 0 0; font-size: 12px; line-height: 1.5; color: var(--muted); }
.words-empty .label-inline { font: 10.5px var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; }

.classes { display: flex; flex-direction: column; gap: 4px; }
.classes label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.classes .n { margin-left: auto; font: 11px var(--font-mono); color: var(--muted); font-variant-numeric: tabular-nums; }

/* Sources: a round button in the bottom right corner opens them just above it. */
.info-button {
  position: fixed; right: 12px; bottom: 12px; z-index: 5;
  width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--rule);
  background: var(--panel); color: var(--muted); cursor: pointer;
  font: italic 600 14px/1 Georgia, serif;
}
.info-button:hover { color: var(--ink); border-color: var(--muted); }
.credit {
  inset: auto 12px 48px auto; margin: 0; width: min(280px, calc(100vw - 24px));
  padding: 10px 12px; border: 1px solid var(--rule); border-radius: 8px;
  background: var(--panel); color: var(--muted); font-size: 12px; line-height: 1.5;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
.credit a { color: var(--ink); }
.credit p { margin: 0; }

/* Logo at the bottom of the panel, below everything else. */
.logo { margin-top: auto; padding-top: 8px; }
/* The logo is a mask over the link's background, so CSS sets its color:
   white, and a bright yellow on hover. */
.logo a {
  display: block; width: 74px; height: 16px; background: #fff;
  -webkit-mask: url(assets/stamen-logo.svg) no-repeat left center / contain;
  mask: url(assets/stamen-logo.svg) no-repeat left center / contain;
  transition: background-color 0.15s;
}
.logo a:hover, .logo a:focus-visible { background: yellow; }
/* On phones, the rest of the intro, above the sources. */
.credits-more { color: var(--ink); margin-bottom: 10px !important; }

.map-wrap { position: relative; min-width: 0; background: var(--ocean); overflow: hidden; }

.tip {
  position: absolute; pointer-events: none; z-index: 2;
  background: var(--panel); color: var(--ink); border: 1px solid var(--rule);
  border-radius: 6px; padding: 8px 10px; max-width: 260px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}
.tip .t-name { font: 700 16px/var(--feeling-line) var(--font-body); }
.tip .t-meta { margin-top: 4px; font: 11px/1.4 var(--font-mono); color: var(--muted); }


/* Word-cloud cartogram. */
.cloud-view { position: absolute; inset: 0; background: var(--map-sea, var(--panel)); transition: background-color 0.4s; }
#cloud { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
#cloud.on-dot { cursor: pointer; }
#cloud:active { cursor: grabbing; }
/* The map's sea and land take the shown feelings' hue: --map-sea and
   --map-land, set by app.js (see MAP there). */
.cloud-land { fill: var(--map-land, var(--chip)); transition: fill 0.4s; }
.cloud-dots path { pointer-events: none; }
.cloud-dots.has-selected path.all { opacity: 0.2; }
.cloud .w { text-anchor: middle; font-weight: 400; cursor: pointer; }
/* A hovered word glows in its own color (color is set to the feeling's color,
   like fill). In ems, so the glow scales with the word. */
.cloud .w:hover, .cloud .w.lit { text-shadow: 0 0 0.12em currentColor, 0 0 0.35em currentColor; }
.clouds.has-selected .w:not(.selected) { opacity: 0.3; }
.clouds.has-lit .w:not(.lit) { opacity: 0.3; }

/* Card for one word's places. */
.inset {
  position: absolute; left: 16px; bottom: 16px; z-index: 4; width: min(380px, calc(100% - 32px));
  padding: 12px; background: var(--panel); border: 1px solid var(--rule); border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
}
.i-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.i-name { font-weight: 700; font-size: 20px; line-height: var(--feeling-line); }
.i-meta { margin-top: 3px; font: 11px/1.4 var(--font-mono); color: var(--muted); }
.i-close { border: 0; background: none; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 2px; }
.i-names { margin: 8px 0 0; font-size: 12px; line-height: 1.45; color: var(--muted); }

.map-controls { position: absolute; top: 12px; right: 12px; display: flex; flex-direction: column; gap: 4px; }
.map-controls button {
  width: 32px; height: 32px; border-radius: 6px; border: 1px solid var(--rule);
  background: var(--panel); cursor: pointer; font-size: 16px; line-height: 1;
}
.loading {
  position: absolute; inset: 0; display: grid; place-items: center;
  font: 600 13px var(--font-body); color: var(--muted); letter-spacing: 0.04em;
}

/* Phones: the map fills the top half of the screen and stays put; the panel
   fills the bottom half and scrolls on its own. dvh follows the browser's
   toolbars as they show and hide; vh is for browsers without it. */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; height: 100vh; height: 100dvh; }
  .app > .map-wrap { grid-column: 1; grid-row: 1; min-height: 0; }
  .app > .panel {
    grid-column: 1; grid-row: 2; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
    border-left: 0; border-top: 1px solid var(--rule); padding: 16px 16px 20px;
  }
}
