/* The "why did this move?" drawer, the shared tooltip and the glossary terms.
   Loaded after game.css and built only from the tokens in tokens.css, so it
   wears the same room: warm panels, cool instruments, brass for the one
   thing that matters. Kept in its own file because all three live outside any
   one screen. */

/* ---- Utility -------------------------------------------------------------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Glossary terms -------------------------------------------------------
   A dotted underline is the convention for "there is a definition here"; the
   colour stays the text's own so a paragraph does not turn into a row of
   links. */

.term {
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: var(--text-low);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  cursor: help;
  border-radius: 2px;
}
.term:hover { text-decoration-color: var(--accent); }
.term:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Tooltip -------------------------------------------------------------- */

.sc-tip {
  position: fixed;
  z-index: 90;
  left: 0;
  top: 0;
  max-width: min(320px, calc(100vw - 16px));
  padding: 8px 11px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background-color: var(--bg-3);
  background-image: linear-gradient(180deg, var(--bg-hover), var(--bg-3));
  box-shadow: var(--shadow-2), var(--shadow-inset);
  color: var(--text-mid);
  font-size: var(--fs-small);
  line-height: 1.45;
  pointer-events: none;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity var(--dur-1) var(--ease-out), transform var(--dur-1) var(--ease-out);
}
.sc-tip.on { opacity: 1; transform: none; }
.sc-tip[hidden] { display: none; }
.sc-tip-term { display: block; margin-bottom: 2px; color: var(--text-hi); font-weight: 600; }
.sc-tip-def { display: block; text-wrap: pretty; }
.sc-tip-basis {
  display: block;
  margin-top: 5px;
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.02em;
  color: var(--text-low);
}

/* A disabled button swallows pointer events in most engines, so its tip lives
   on a wrapper and the button lets the pointer through to it. */
.tip-wrap { display: inline-flex; border-radius: 6px; }
.tip-wrap > button:disabled { pointer-events: none; }

/* ---- Openers --------------------------------------------------------------- */

/* Topbar pills that open a drawer are buttons; they must still look like the
   readouts they are. */
button.pill {
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.pill[data-tip], .pill[data-why] { cursor: pointer; }
.pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.tile-why {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: var(--ls-caps);
  color: var(--text-low);
  transition: color var(--dur-1) var(--ease-out);
}
.tile:hover .tile-why,
.tile:focus-visible .tile-why { color: var(--accent); }

.why-open {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--text-mid);
  font: inherit;
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: var(--ls-caps);
  cursor: pointer;
  transition: border-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out);
}
.why-open:hover { border-color: var(--accent); color: var(--text-hi); }
.why-open:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* An Economy-screen figure that opens a drawer: the stat, made pressable. */
button.stat {
  font: inherit;
  color: inherit;
  text-align: left;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 3px;
  background: none;
  cursor: pointer;
  min-width: 0;
}
button.stat .stat-value { transition: color var(--dur-1) var(--ease-out); }
button.stat:hover .stat-value { color: var(--accent); }
button.stat:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.stat-why { color: var(--text-low); font-size: var(--fs-micro); letter-spacing: var(--ls-caps); text-transform: uppercase; }
button.stat:hover .stat-why { color: var(--accent); }

/* ---- The drawer ------------------------------------------------------------ */

.why-layer {
  position: fixed;
  inset: 0;
  z-index: 60;
}

.why-scrim {
  position: absolute;
  inset: 0;
  background: rgba(10, 6, 3, 0.55);
  animation: fadeIn var(--dur-2) var(--ease-out) both;
}

.why-drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(440px, 100vw);
  display: flex;
  flex-direction: column;
  background-color: var(--bg-1);
  background-image: linear-gradient(180deg, var(--bg-2), var(--bg-1) 240px);
  border-left: 1px solid var(--line-strong);
  box-shadow: var(--shadow-2), var(--shadow-inset);
  animation: whySlide var(--dur-2) var(--ease-out) both;
  outline: none;
}

@keyframes whySlide {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.why-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3) var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 238, 214, 0.018);
  flex: none;
}

.why-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.why-title-row { display: flex; align-items: center; gap: var(--sp-2); }
.why-glyph { color: var(--text-low); display: inline-flex; }
.why-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--fs-title);
  font-weight: 400;
  line-height: 1.1;
  color: var(--text-hi);
}

.why-now { display: flex; align-items: flex-end; gap: var(--sp-3); flex-wrap: wrap; }
.why-value { font-size: var(--fs-kpi); line-height: 1.05; color: var(--text-hi); }
.why-value.pos { color: var(--pos); }
.why-value.neg { color: var(--neg); }
.why-arrow { font-size: 22px; line-height: 1.2; color: var(--text-low); }
.why-arrow.pos { color: var(--pos); }
.why-arrow.neg { color: var(--neg); }

.why-heading { margin: 0; color: var(--text-mid); line-height: 1.5; text-wrap: pretty; }

.why-strip {
  margin: 0;
  padding: var(--sp-2) var(--sp-3) var(--sp-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--bg-2);
  box-shadow: var(--shadow-inset);
}
.why-strip .trend-strip { display: block; width: 100%; height: auto; }
.why-strip figcaption { margin-top: 4px; font-size: var(--fs-micro); color: var(--text-low); }

.why-callout {
  margin: 0;
  padding: var(--sp-2) var(--sp-3);
  border-left: 2px solid var(--warn);
  background: var(--warn-dim);
  color: var(--text-mid);
  font-size: var(--fs-small);
  line-height: 1.5;
  border-radius: 0 4px 4px 0;
}

.why-section { display: flex; flex-direction: column; gap: var(--sp-2); }
.why-sec-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px var(--sp-3);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line-strong);
  font-size: var(--fs-caption);
}

.why-causes { display: flex; flex-direction: column; gap: var(--sp-3); margin: 0; padding: 0; list-style: none; }
.why-cause {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: riseIn var(--dur-2) var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 35ms);
}
.why-cause-head { display: flex; align-items: baseline; gap: var(--sp-2); min-width: 0; }
.why-rank {
  flex: none;
  width: 16px;
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  color: var(--text-low);
}
.why-cause-title {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--text-hi);
  font-size: var(--fs-body);
  line-height: 1.3;
}
button.why-link {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--text-hi);
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
}
button.why-link:hover { color: var(--accent); text-decoration-color: var(--accent); }
.why-amt { flex: none; font-size: var(--fs-small); }

.why-bar {
  display: block;
  height: 4px;
  margin-left: 24px;
  border-radius: 2px;
  background: var(--bg-3);
  box-shadow: var(--shadow-inset);
  overflow: hidden;
}
.why-bar > span { display: block; height: 100%; border-radius: 2px; background: var(--line-strong); opacity: 0.8; }
.why-bar > span.pos { background: var(--pos); }
.why-bar > span.neg { background: var(--neg); }

.why-sub, .why-note {
  margin: 0 0 0 24px;
  font-size: var(--fs-caption);
  line-height: 1.5;
  color: var(--text-mid);
  text-wrap: pretty;
}
.why-note { color: var(--text-low); font-style: italic; }
.why-section > .why-note { margin-left: 0; }

.why-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-left: 24px; }
.why-tags .chip { white-space: normal; text-transform: none; letter-spacing: 0.01em; font-size: var(--fs-micro); }

.why-other .why-cause-title { color: var(--text-mid); }

.why-total {
  margin: 0;
  padding-top: var(--sp-2);
  border-top: 1px dotted var(--line-strong);
  font-size: var(--fs-caption);
  color: var(--text-mid);
}

.why-standing {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-2);
}
.why-standing > summary {
  cursor: pointer;
  font-size: var(--fs-caption);
  text-transform: uppercase;
  letter-spacing: var(--ls-caps);
  color: var(--text-mid);
}
.why-standing > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.why-standing .why-note { margin: var(--sp-2) 0; }
.why-standing ul { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; font-size: var(--fs-small); }
.why-standing li { display: flex; justify-content: space-between; gap: var(--sp-3); color: var(--text-mid); }

.why-how {
  margin: 0;
  font-size: var(--fs-caption);
  line-height: 1.55;
  color: var(--text-low);
}
.why-how b { color: var(--text-mid); font-weight: 600; }

.why-foot {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-2);
  padding-top: var(--sp-2);
  border-top: 1px solid var(--line);
}

/* Phone: the whole screen. A bottom sheet of most of it left a strip of
   screen above that looked pressable and was not, and a chain of causes needs
   every line it can get. The header clears the notch, the list the home
   indicator, and the close button is a thumb's width. */
@media (max-width: 639.98px) {
  .why-drawer {
    inset: 0;
    width: 100%;
    max-height: none;
    border-left: 0;
    border-radius: 0;
    animation-name: whyRise;
  }
  .why-top {
    padding: calc(var(--sp-1) + var(--safe-t)) max(var(--sp-1), var(--safe-r)) var(--sp-1) max(var(--sp-4), var(--safe-l));
  }
  .why-top .btn { min-height: 44px; }
  .why-x { min-width: 44px; }
  .why-scroll {
    padding: var(--sp-4) max(var(--sp-4), var(--safe-r)) calc(var(--sp-4) + var(--safe-b)) max(var(--sp-4), var(--safe-l));
  }
}

@media (min-width: 1600px) {
  .why-drawer { width: min(480px, 100vw); }
}

/* The tip under a finger: wider type, the screen's own gutter, and below the
   trigger where it fits (ui/components/tooltip.js), so the thumb that opened
   it does not cover it. */
@media (max-width: 639.98px) {
  .sc-tip {
    max-width: min(320px, calc(100vw - 2 * var(--gutter)));
    font-size: var(--fs-small);
  }
}

@keyframes whyRise {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* base.css already shortens every animation to nothing; these entrances also
   lose their offset so nothing is left a few pixels out of place. */
@media (prefers-reduced-motion: reduce) {
  .why-drawer, .why-scrim, .why-cause { animation: none; }
  .sc-tip { transition: none; transform: none; }
}
