/* Bite context: era chip, map strip and the Context panel (handoff 26 Part B). Colours are tokens only, so every theme works. */

.cx {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.cx[hidden] {
  display: none;
}

.cx-top-slot:empty {
  display: none;
}

.cx-when {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-2);
  font: 600 var(--text-sm) var(--font-ui);
}

.cx-chip {
  padding: 0.1rem 0.6rem;
  color: var(--color-ink-soft);
  font: inherit;
  background: color-mix(in srgb, var(--color-accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-accent) 40%, var(--color-line));
  border-radius: var(--radius-pill);
  cursor: pointer;
}

.cx-chip:focus-visible,
.cx-map:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

.cx-approx {
  color: var(--color-muted);
  font-weight: 400;
}

.cx-written,
.cx-says {
  color: var(--color-muted);
  font-weight: 400;
}

.cx-explain,
.cx-note,
.cx-hint,
.cx-gap {
  margin: var(--space-1) 0 0;
  color: var(--color-muted);
  font: var(--text-sm) / 1.4 var(--font-ui);
}

.cx-explain[hidden] {
  display: none;
}

.cx-unknown {
  margin: 0;
  color: var(--color-faint);
  font: italic var(--text-xs, 0.78rem) var(--font-ui);
}

/* The map: an SVG scaled to the card's width. */
.cx-map {
  display: block;
  width: 100%;
  max-width: 30rem;
  padding: 0;
  overflow: hidden;
  background: none;
  border: 1px solid var(--color-line-soft);
  border-radius: var(--radius-md);
  cursor: zoom-in;
}

.cx-enlarged .cx-map {
  max-width: 100%;
  cursor: zoom-out;
}

.cm-map {
  display: block;
  width: 100%;
  height: auto;
  touch-action: pan-y;
}

.cx-map-large .cm-map {
  touch-action: none;
  border-radius: var(--radius-md);
}

.cm-map.cm-zoomed {
  cursor: grab;
}

.cm-sea {
  fill: color-mix(in srgb, var(--color-note) 16%, var(--color-paper));
}

.cm-land {
  fill: var(--color-surface-raised);
  stroke: var(--color-line);
  stroke-width: 0.6;
  vector-effect: non-scaling-stroke;
}

.cm-lake {
  fill: color-mix(in srgb, var(--color-note) 16%, var(--color-paper));
  stroke: var(--color-line-soft);
  stroke-width: 0.5;
  vector-effect: non-scaling-stroke;
}

.cm-border {
  fill: none;
  stroke: var(--color-line);
  stroke-width: 0.5;
  stroke-dasharray: 2 2;
  opacity: 0.7;
  vector-effect: non-scaling-stroke;
}

.cm-river {
  fill: none;
  stroke: color-mix(in srgb, var(--color-note) 55%, transparent);
  stroke-width: 0.6;
  vector-effect: non-scaling-stroke;
}

.cm-pin {
  stroke: var(--color-surface-raised);
  stroke-width: 1.4;
}

.cm-c0 { fill: var(--color-accent); }
.cm-c1 { fill: var(--color-note); }
.cm-c2 { fill: var(--color-positive); }
.cm-c3 { fill: var(--color-caution); }
.cm-c4 { fill: var(--color-warning); }
.cm-c5 { fill: var(--color-focus); }

.cm-label,
.cm-area-label,
.cm-ref {
  font-family: var(--font-ui);
  paint-order: stroke;
  stroke: var(--color-surface-raised);
  stroke-width: 2.4px;
  stroke-linejoin: round;
}

.cm-label {
  fill: var(--color-ink);
  font-weight: 600;
}

.cm-area-label {
  fill: var(--color-ink-soft);
  font-style: italic;
  letter-spacing: 0.04em;
}

.cm-ref {
  fill: var(--color-faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.cm-ref-sea {
  font-style: italic;
  text-transform: none;
}

/* Atlas: a plain text link, beside Shelf's own map. */
.cx-atlas {
  color: var(--color-accent);
  font: 600 var(--text-sm) var(--font-ui);
}

.cx-atlas-slot:empty {
  display: none;
}

.cx-atlas-row {
  margin: 0;
}

/* Go deeper: the Context pill and panel. */
.reader-context-pill {
  position: absolute;
  z-index: 25;
  bottom: calc(var(--space-6) + 3.25rem);
  left: 50%;
  min-height: 2.25rem;
  padding: 0 var(--space-4);
  color: var(--color-ink);
  font: 600 var(--text-sm) var(--font-ui);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-cover);
  cursor: pointer;
  transform: translateX(-50%);
}

.reader-context-pill[hidden] {
  display: none;
}

/* The pill's phone position lives in reader-prefs.css, next to the bottom bar it sits above (handoff 31). */

.cx-panel {
  position: absolute;
  z-index: 40;
  inset: auto 0 0 0;
  box-sizing: border-box;
  max-height: min(80%, 40rem);
  overflow-y: auto;
  padding: var(--space-4) var(--space-4) calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
  color: var(--color-ink);
  background: var(--color-surface);
  border-top: 1px solid var(--color-line);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-sheet);
}

.cx-panel[hidden] {
  display: none;
}

@media (min-width: 701px) {
  .cx-panel {
    inset: auto auto var(--space-6) 50%;
    width: min(34rem, calc(100% - 2rem));
    border: 1px solid var(--color-line);
    border-radius: var(--radius-lg);
    transform: translateX(-50%);
  }
}

.cx-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cx-panel-head h2 {
  margin: 0;
  font: 700 var(--text-sm) var(--font-ui);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.cx-panel-close {
  width: 2.5rem;
  height: 2.5rem;
  color: var(--color-ink);
  font-size: 1.5rem;
  background: none;
  border: 0;
  cursor: pointer;
}

.cx-panel-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.cx-era-line {
  margin: 0;
}

.cx-timeline {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.cx-line {
  position: relative;
  height: 1.25rem;
  border-bottom: 2px solid var(--color-line);
}

.cx-band {
  position: absolute;
  bottom: -2px;
  height: 0.7rem;
  background: var(--color-accent);
  border-radius: 2px;
}

.cx-tick {
  position: absolute;
  bottom: -2px;
  width: 2px;
  height: 1.25rem;
  background: var(--color-note);
}

.cx-axis {
  display: flex;
  justify-content: space-between;
  color: var(--color-faint);
  font: var(--text-sm) var(--font-ui);
}

.cx-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  font: var(--text-sm) var(--font-ui);
}

.cx-key::before {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  margin-right: 0.35rem;
  vertical-align: -0.05rem;
  content: "";
  border-radius: 2px;
}

.cx-key-band::before {
  background: var(--color-accent);
}

.cx-key-tick::before {
  width: 2px;
  background: var(--color-note);
}

.cx-place-list {
  margin: 0;
  padding-left: var(--space-5);
  font: var(--text-sm) / 1.5 var(--font-ui);
}

@media (prefers-reduced-motion: no-preference) {
  .cx-panel {
    animation: cx-rise 160ms ease-out;
  }
}

@keyframes cx-rise {
  from {
    opacity: 0;
    transform: translateY(0.5rem);
  }
}

@media (min-width: 701px) {
  @media (prefers-reduced-motion: no-preference) {
    .cx-panel {
      animation-name: cx-rise-wide;
    }
  }
}

@keyframes cx-rise-wide {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(0.5rem);
  }
}
