:root {
  --paper: #f5f2e9;
  --ink: #191b19;
  --muted: #74766f;
  --line: rgba(25, 27, 25, 0.13);
  --glass: rgba(250, 249, 245, 0.88);
  --accent: #a74a36;
  --gold: #9a7b4f;
  --teal: #4f6f6a;
  --serif: "Playfair Display", Georgia, serif;
  --sans: "DM Sans", system-ui, sans-serif;
  --mono: "DM Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { color: inherit; }

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.12;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.16'/%3E%3C/svg%3E");
}

/*
 * Per-pixel negative contrast over the globe:
 * white ink + mix-blend-mode:difference → dark on cream, light on land.
 * Solid panels (search, info, modals) keep normal ink.
 */
.blend-fg {
  mix-blend-mode: difference;
  color: #ffffff;
}

header {
  position: absolute;
  z-index: 12;
  inset: 0 0 auto;
  height: 76px;
  padding: 0 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 0;
  pointer-events: none;
  /* Blend on the stacking-context root so ink inverts against the globe */
  mix-blend-mode: difference;
  color: #ffffff;
}

header > * {
  pointer-events: auto;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  font: 500 9px var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.header-nav a {
  color: #ffffff;
  text-decoration: none;
  opacity: 0.78;
}

.header-nav a:hover {
  opacity: 1;
  text-decoration: underline;
  text-underline-offset: 3px;
}

@media (max-width: 900px) {
  .header-nav { display: none; }
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font: 600 19px var(--serif);
  letter-spacing: -0.035em;
  color: #ffffff;
}

.brand-mark {
  width: 27px;
  height: 27px;
  border: 1px solid #ffffff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font: 11px var(--mono);
  background: transparent;
  color: #ffffff;
}

.brand small,
.eyebrow {
  font: 10px var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #ffffff;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 18px;
}

.status {
  font: 10px var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status::before {
  content: "";
  width: 6px;
  height: 6px;
  background: #ffffff;
  border-radius: 50%;
}

.status.offline::before { background: #ffb4a8; }

.source-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  font: 10px var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #ffffff;
  cursor: pointer;
  user-select: none;
}

.source-toggle input {
  accent-color: #ffffff;
  width: 13px;
  height: 13px;
  margin: 0;
  cursor: pointer;
}

.icon-btn {
  border: 1px solid #ffffff;
  background: transparent;
  color: #ffffff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
}

.kicker {
  position: absolute;
  z-index: 10;
  top: 96px;
  left: 50%;
  transform: translateX(-50%);
  width: min(570px, calc(100% - 32px));
  text-align: center;
  font: 10px var(--mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #ffffff;
  pointer-events: none;
  mix-blend-mode: difference;
}

.search-area {
  position: absolute;
  z-index: 12;
  top: 128px;
  left: 50%;
  transform: translateX(-50%);
  width: min(570px, calc(100% - 32px));
  text-align: center;
  pointer-events: auto;
}

.searchbox {
  position: relative;
  z-index: 10;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 0 19px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(25, 27, 25, 0.18);
  border-radius: 5px;
  box-shadow: 0 8px 30px rgba(36, 32, 22, 0.04);
  transition: 0.2s;
}

.searchbox:focus-within {
  border-color: var(--ink);
  box-shadow: 0 12px 36px rgba(36, 32, 22, 0.1);
  background: #fff;
}

.typeahead {
  position: relative;
  z-index: 10;
  margin-top: 6px;
  text-align: left;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(25, 27, 25, 0.14);
  border-radius: 5px;
  box-shadow: 0 10px 28px rgba(36, 32, 22, 0.08);
  overflow: hidden;
  max-height: 240px;
  overflow-y: auto;
}

.typeahead[hidden] { display: none; }

.typeahead-item {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 11px 16px;
  font: 15px var(--sans);
  color: var(--ink);
  cursor: pointer;
  border-bottom: 1px solid rgba(25, 27, 25, 0.06);
}

.typeahead-item:last-child { border-bottom: 0; }

.typeahead-item:hover,
.typeahead-item:focus-visible {
  background: rgba(79, 111, 106, 0.1);
  outline: none;
}

.searchbox svg {
  flex: none;
  color: #787970;
}

.searchbox input {
  border: 0;
  outline: 0;
  background: transparent;
  width: 100%;
  min-width: 0;
  font: 500 19px var(--serif);
  color: var(--ink);
}

.searchbox input::placeholder {
  color: #a1a096;
  font-style: italic;
}

.search-clear {
  flex: none;
  border: 0;
  background: transparent;
  color: #787970;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
}

.search-clear:hover {
  color: var(--ink);
  background: rgba(25, 27, 25, 0.06);
}

.enter-hint {
  font: 9px var(--mono);
  color: #929188;
  white-space: nowrap;
  border: 1px solid var(--line);
  padding: 4px 6px;
  border-radius: 3px;
}

.typeahead-heading {
  padding: 8px 16px 4px;
  font: 500 9px var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.search-message {
  position: relative;
  z-index: 12;
  min-height: 18px;
  margin-top: 8px;
  font-size: 12px;
  pointer-events: auto;
  /* White + difference → dark on cream, light on the globe */
  color: #ffffff;
  mix-blend-mode: difference;
}

.search-message .loading-state,
.search-message .loading-text {
  color: #ffffff;
}

.search-message .spinner {
  border-color: rgba(255, 255, 255, 0.28);
  border-top-color: #ffffff;
}

/* Solid chips sit above the blend so they stay clickable and readable */
.search-message .suggest-wrap {
  mix-blend-mode: normal;
  isolation: isolate;
  pointer-events: auto;
}

.search-message .suggest-intro {
  color: #ffffff;
  mix-blend-mode: difference;
}

.search-message .chip {
  margin: 0;
  border: 1px solid rgba(25, 27, 25, 0.18);
  border-radius: 3px;
  background: #ffffff;
  padding: 8px 12px;
  font: 11px var(--mono);
  letter-spacing: 0.015em;
  color: #191b19;
  cursor: pointer;
  pointer-events: auto;
  position: relative;
  z-index: 2;
  box-shadow: 0 2px 10px rgba(20, 22, 20, 0.16);
}

.search-message .chip:hover,
.search-message .chip:focus-visible {
  background: #191b19;
  border-color: #191b19;
  color: #ffffff;
  outline: 0;
}

.globe-wrap {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.globe-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: auto;
  touch-action: none;
  cursor: grab;
}

.globe-wrap canvas:active { cursor: grabbing; }

.globe-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.globe-label {
  position: absolute;
  transform: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  font: 400 10px var(--mono);
  color: #191b19;
  background: #ffffff;
  border: 1px solid rgba(25, 27, 25, 0.18);
  padding: 3px 7px 4px;
  border-radius: 2px;
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(20, 22, 20, 0.18);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  z-index: 1;
  margin: 0;
  font-family: inherit;
  text-align: left;
}

.globe-label:hover {
  border-color: rgba(25, 27, 25, 0.45);
  background: #ffffff;
}

.globe-label.selected { z-index: 3; }
.globe-label.hover { z-index: 2; }

.globe-label-stem {
  position: absolute;
  height: 1px;
  background: rgba(255, 255, 255, 0.7);
  pointer-events: none;
  transform-origin: 0 50%;
}

.globe-label-idx {
  font: 500 8px var(--mono);
  letter-spacing: 0.06em;
  color: rgba(25, 27, 25, 0.55);
}

.globe-label-form {
  font: 600 13px/1.15 var(--serif);
  letter-spacing: -0.02em;
  color: #191b19;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.globe-label-lang {
  font: 8px var(--mono);
  color: rgba(25, 27, 25, 0.55);
  letter-spacing: 0.02em;
}

.globe-label.selected {
  border-color: #191b19;
  border-width: 2px;
  z-index: 3;
}

.globe-label.selected .globe-label-form,
.globe-label.hover .globe-label-form,
.globe-label.selected .globe-label-idx {
  color: #191b19;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.globe-label.badge {
  padding: 2px 6px;
  min-width: 22px;
  align-items: center;
}

.globe-label.badge .globe-label-form,
.globe-label.badge .globe-label-lang {
  display: none;
}

.globe-label.badge .globe-label-idx {
  font-size: 10px;
  color: #191b19;
}

.canvas-hint {
  position: absolute;
  /* Sit above Journey + legend row so empty-state copy never collides */
  bottom: 108px;
  left: 50%;
  transform: translateX(-50%);
  font: 9px var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #ffffff;
  white-space: nowrap;
  pointer-events: none;
  z-index: 4;
  mix-blend-mode: difference;
}

.canvas-hint[hidden] {
  display: none !important;
}

/* Idle empty-state already covers onboarding — never stack a second hint on it */
body:not(:has(#infoPanel.visible)) .canvas-hint {
  display: none !important;
}

/* When a lineage legend is active, keep the explore hint off-screen */
body:has(#arcLegend:not([hidden])) .canvas-hint {
  display: none !important;
}

.empty-note {
  position: absolute;
  z-index: 4;
  left: 32px;
  /* Idle: Journey is hidden — clear the zoom cluster only */
  bottom: 72px;
  right: auto;
  top: auto;
  transform: none;
  width: 220px;
  /* White + difference → dark on cream, light on the globe (per-pixel) */
  color: #f0eee6;
  font: 11px/1.7 var(--mono);
  letter-spacing: 0.02em;
  pointer-events: none;
  mix-blend-mode: difference;
}

/* Journey only applies once a lineage is on the globe */
body:not(.panel-open):not(:has(#infoPanel.visible)) .timeline-bar {
  display: none !important;
}

.empty-note strong {
  display: block;
  color: #ffffff;
  font: 500 16px/1.35 var(--serif);
  margin-bottom: 8px;
}

.info-panel {
  position: absolute;
  z-index: 7;
  left: 28px;
  bottom: 27px;
  top: auto;
  width: 350px;
  max-height: min(58vh, 570px);
  overflow: auto;
  background: var(--glass);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 23px 24px 20px;
  box-shadow: 0 14px 50px rgba(39, 35, 24, 0.08);
  opacity: 0;
  transform: translateY(18px);
  pointer-events: none;
  transition: opacity 0.35s, transform 0.35s, max-height 0.3s, width 0.3s, padding 0.3s;
}

.info-panel.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Docked maximizable tab — keeps the active word while freeing the globe */
.info-panel.visible.minimized {
  width: min(168px, calc(42vw - 40px));
  max-height: 40px;
  overflow: hidden;
  padding: 7px 8px 7px 12px;
  cursor: pointer;
}

.info-panel.minimized .panel-top {
  margin: 0;
  gap: 8px;
}

.info-panel.minimized .panel-tab-title {
  display: block;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 500 14px/1.2 var(--serif);
  color: var(--ink);
}

.info-panel.minimized #panelEyebrow,
.info-panel.minimized .word-title,
.info-panel.minimized .definition,
.info-panel.minimized .etym-alts,
.info-panel.minimized #gapNote,
.info-panel.minimized .no-geo,
.info-panel.minimized .stats,
.info-panel.minimized .heartland-legend,
.info-panel.minimized .timeline-head,
.info-panel.minimized .timeline,
.info-panel.minimized .panel-section,
.info-panel.minimized .attrib,
.info-panel.minimized .panel-footer {
  display: none;
}

.panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-top .eyebrow { color: var(--accent); }

.panel-tab-title {
  display: none;
}

.panel-toggle {
  flex-shrink: 0;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 3px;
  font: 500 16px/1 var(--mono);
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
}

.panel-toggle:hover {
  color: var(--ink);
  border-color: var(--ink);
}

.info-panel.minimized .panel-toggle {
  width: 24px;
  height: 24px;
  font-size: 13px;
}

.lineage-summary {
  margin: 0 0 8px;
  font: 500 13px/1.45 var(--serif);
  color: #3a3c36;
}

.wiki-link {
  display: inline-block;
  margin-top: 8px;
  font: 500 11px var(--mono);
  color: var(--teal);
}

.heartland-legend {
  margin: 0 0 12px;
  font: 10px/1.45 var(--mono);
  color: var(--muted);
  letter-spacing: 0.02em;
}

.arc-legend {
  position: absolute;
  z-index: 8;
  /* Sit above Journey, clear zoom/reset cluster (~190px) on the right */
  right: 200px;
  left: auto;
  bottom: 66px;
  transform: none;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 6px 8px;
  max-width: min(420px, calc(100% - 240px));
  padding: 6px 0;
  font: 500 9px var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #ffffff;
  mix-blend-mode: difference;
  pointer-events: none;
  white-space: nowrap;
}

/* Author `display:flex` otherwise overrides the HTML hidden attribute */
.arc-legend[hidden] {
  display: none !important;
}

.arc-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.arc-legend-swatch.oldest { background: #e04530; }
.arc-legend-swatch.newest { background: #3b8fd9; }

.arc-legend-grad {
  width: 36px;
  height: 3px;
  border-radius: 2px;
  flex: none;
  background: linear-gradient(90deg, #e04530, #ef9a2e, #2fad8a, #3b8fd9);
}

.arc-legend-sep {
  opacity: 0.55;
}

.arc-legend-dash {
  opacity: 0.9;
  text-transform: none;
  letter-spacing: 0.02em;
}

.word-title {
  font: 600 35px/1.12 var(--serif);
  letter-spacing: -0.04em;
  margin: 13px 0 8px;
}

.word-roman,
.term-roman {
  font: 500 0.78em/1.2 var(--serif);
  font-style: italic;
  color: #5a5c54;
  letter-spacing: 0;
}

.term-roman {
  font-size: 15px;
}

.definition {
  font-size: 13px;
  line-height: 1.6;
  color: #565850;
  max-width: 290px;
}

.stats {
  display: flex;
  gap: 18px;
  margin: 19px 0 17px;
  padding: 13px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.stat strong {
  display: block;
  font: 500 17px var(--serif);
}

.stat span {
  display: block;
  margin-top: 3px;
  font: 9px var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.timeline-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.timeline-head span {
  font: 9px var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.timeline {
  position: relative;
  padding-left: 19px;
}

.timeline::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 5px;
  bottom: 10px;
  width: 1px;
  background: var(--line);
}

.timeline-item {
  position: relative;
  margin: 0 0 17px;
  cursor: pointer;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
  padding: 0;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: -19px;
  top: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--node);
  box-shadow: 0 0 0 3px var(--paper);
  transition: transform 0.2s;
}

.timeline-item:hover::before,
.timeline-item.selected::before {
  transform: scale(1.45);
}

.timeline-item.selected {
  margin-left: -8px;
  margin-right: -8px;
  padding: 8px 8px 10px;
  width: calc(100% + 16px);
  background: rgba(167, 74, 54, 0.08);
  border-radius: 4px;
  box-shadow: inset 3px 0 0 var(--accent);
}

.timeline-item.selected .term {
  color: var(--accent);
  font-weight: 600;
}

.timeline-item.selected .lang-era {
  color: var(--accent);
  opacity: 0.85;
}

.lang-era {
  font: 9px var(--mono);
  letter-spacing: 0.015em;
  color: var(--muted);
  margin-bottom: 3px;
}

.term {
  font: 500 17px var(--serif);
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.term .term-roman::before {
  content: "(";
  font-style: normal;
}

.term .term-roman::after {
  content: ")";
  font-style: normal;
}

.place {
  font-size: 11px;
  color: #55574f;
  margin-top: 3px;
}

.tag {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px 8px;
  margin-top: 6px;
  font: 9px var(--mono);
  color: #66675f;
}

.tag .st.geo-approximate,
.tag .st.geo-uncertain,
.tag .st.geo-period_only,
.tag .st.geo-unavailable {
  border: 1px solid var(--line);
  padding: 2px 6px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.45);
}

.tag .st.geo-uncertain {
  border-color: rgba(176, 120, 40, 0.45);
  color: #8a5a12;
}

.tag .st.geo-unavailable {
  opacity: 0.8;
}

.panel-footer {
  border-top: 1px solid var(--line);
  padding-top: 11px;
  margin-top: 3px;
  font: 9px/1.6 var(--mono);
  color: #85857c;
}

.bottom-left {
  position: absolute;
  z-index: 4;
  bottom: 28px;
  left: 32px;
  font: 9px var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #ffffff;
  mix-blend-mode: difference;
  transition: opacity 0.2s, left 0.3s ease, bottom 0.3s ease;
}

/* Expanded panel covers this corner — hide the status line */
body:has(#infoPanel.visible:not(.minimized)) .bottom-left {
  opacity: 0;
  pointer-events: none;
}

/* Minimized tab docks bottom-left — park status to its right */
body:has(#infoPanel.visible.minimized) .bottom-left {
  left: calc(28px + min(168px, 42vw - 40px) + 14px);
  bottom: 34px;
  max-width: min(280px, calc(100vw - 220px));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bottom-right {
  position: absolute;
  z-index: 9;
  bottom: 22px;
  right: 24px;
  display: flex;
  gap: 7px;
  align-items: center;
  /* Blend on the stacking-context root (child blend is clipped by z-index) */
  mix-blend-mode: difference;
  color: #ffffff;
}

.round-control {
  width: 35px;
  height: 35px;
  border: 1px solid #ffffff;
  background: transparent;
  color: #ffffff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 16px;
  transition: 0.2s;
}

.round-control:hover {
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
}

.zoom-label {
  font: 9px var(--mono);
  color: #ffffff;
  min-width: 34px;
  text-align: center;
}

.toast {
  position: absolute;
  z-index: 10;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  font: 11px var(--mono);
  border-radius: 3px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.st {
  display: inline-block;
  font: 9px var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 99px;
  border: 1px solid currentColor;
}

.st.attested { color: #4f7a5c; }
.st.reconstructed { color: #3d6178; }
.st.disputed { color: #a74a36; }
.st.unknown { color: #74766f; }

.note {
  font: 11px/1.55 var(--sans);
  color: var(--muted);
  margin: 5px 0 0;
}

.note:empty { display: none; }

.gloss {
  font: italic 12px var(--serif);
  color: var(--muted);
}

.attrib {
  font: 9px/1.6 var(--mono);
  color: var(--muted);
  margin-top: 10px;
}

.attrib a { color: inherit; }

.etym-alts {
  display: grid;
  gap: 4px;
  margin: 6px 0 8px;
}

.etym-alts[hidden] {
  display: none;
}

.etym-alts-intro {
  font: 9px var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.etym-alt {
  display: grid;
  gap: 2px;
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  padding: 5px 8px;
  border-radius: 3px;
  cursor: pointer;
  color: inherit;
  font: inherit;
  min-height: 0;
  overflow: hidden;
}

.etym-alt-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.etym-alt strong {
  font: 500 12px/1.25 var(--serif);
  color: var(--ink);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.etym-alt em {
  flex-shrink: 0;
  font: 500 8px/1.2 var(--mono);
  font-style: normal;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--teal);
}

/* One-line definition in the box; full text drops open on hover */
.etym-alt-gloss {
  font: 11px/1.3 var(--serif);
  color: #4a4c46;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-height: 1.3em;
  transition: max-height 0.15s ease;
}

@media (hover: hover) {
  .etym-alt:hover .etym-alt-gloss,
  .etym-alt:focus-visible .etym-alt-gloss {
    white-space: normal;
    text-overflow: clip;
    max-height: 5.2em;
  }
}

.etym-alt:hover:not(:disabled),
.etym-alt:focus-visible {
  border-color: var(--ink);
  z-index: 1;
}

.etym-alt.on,
.etym-alt:disabled {
  border-color: var(--ink);
  background: rgba(25, 27, 25, 0.06);
  cursor: default;
}

.others {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 8px 0;
}

.others:empty { display: none; }

.others button {
  font: 10px var(--mono);
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 99px;
  padding: 4px 9px;
  cursor: pointer;
}

.others button.on {
  background: var(--ink);
  color: var(--paper);
}

@media (max-width: 900px) {
  :root {
    /* Strict bottom stack (safe → journey → tools → content) */
    --m-safe: env(safe-area-inset-bottom, 0px);
    --m-pad: 10px;
    --m-journey: 56px;
    --m-tools: 44px;
    --m-meta: 20px; /* coords status line */
    --m-legend: 28px; /* oldest→newest strip */
    --m-stack-gap: 10px;
    --mobile-chrome: calc(var(--m-pad) + var(--m-safe) + var(--m-journey) + var(--m-stack-gap));
    --mobile-tools-row: calc(var(--mobile-chrome) + var(--m-tools) + var(--m-stack-gap));
    --mobile-meta-row: calc(var(--mobile-tools-row) + var(--m-meta) + 4px);
    --mobile-legend-row: calc(var(--mobile-meta-row) + var(--m-legend) + 4px);
    --mobile-panel-max: min(38vh, 300px);
  }

  header { height: 56px; padding: 0 14px; }
  .brand { font-size: 16px; gap: 7px; }
  .brand-mark { width: 24px; height: 24px; font-size: 10px; }
  .brand small, .status { display: none; }
  .header-right { gap: 10px; }
  .source-toggle { gap: 5px; font-size: 9px; letter-spacing: 0.04em; }
  .source-toggle span {
    max-width: 4.8em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .icon-btn { width: 36px; height: 36px; }

  .kicker { top: 64px; width: calc(100% - 28px); font-size: 9px; }
  .search-area { top: 86px; width: calc(100% - 28px); }
  .searchbox { height: 48px; padding: 0 12px; gap: 8px; }
  .searchbox input { font-size: 16px; } /* iOS: avoid focus zoom */
  .enter-hint { display: none; }
  .search-message { margin-top: 4px; font-size: 12px; }
  .typeahead {
    max-height: min(42vh, 280px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .typeahead-item { min-height: 44px; padding: 10px 12px; }

  /* Idle: one message — explore hint was stacking on the empty-state copy */
  .canvas-hint { display: none !important; }
  .empty-note {
    left: var(--m-pad);
    right: calc(var(--m-pad) + 160px);
    bottom: calc(var(--m-pad) + var(--m-safe) + var(--m-tools) + 12px);
    width: auto;
    max-width: none;
    font-size: 11px;
    line-height: 1.55;
  }
  .empty-note strong { font-size: 14px; }

  .info-panel {
    left: var(--m-pad);
    right: var(--m-pad);
    bottom: var(--mobile-chrome);
    width: auto;
    max-height: var(--mobile-panel-max);
    padding: 12px 14px 14px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }
  .info-panel .panel-top {
    position: sticky;
    top: -12px;
    margin: -12px -14px 0;
    padding: 12px 14px 8px;
    background: rgba(250, 249, 245, 0.94);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 2;
  }
  .panel-toggle {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }
  .info-panel.visible.minimized {
    /* Same row as zoom, above Journey — never share Journey's band */
    left: var(--m-pad);
    right: auto;
    width: min(150px, calc(100vw - 190px));
    max-height: 40px;
    padding: 7px 8px 7px 12px;
    bottom: calc(var(--mobile-chrome) + 0px);
    /* sit in tools row: above journey */
    margin: 0;
    touch-action: manipulation;
    z-index: 13;
  }
  body.panel-minimized .info-panel.visible.minimized,
  body:has(#infoPanel.visible.minimized) .info-panel {
    bottom: calc(var(--m-pad) + var(--m-safe) + var(--m-journey) + var(--m-stack-gap));
  }
  .info-panel.visible.minimized .panel-top {
    position: static;
    margin: 0;
    padding: 0;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .info-panel.minimized .panel-toggle {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }

  .word-title { font-size: 24px; margin: 6px 0 4px; }
  .definition { font-size: 12px; line-height: 1.45; max-width: none; }
  .lineage-summary { font-size: 12px; margin-bottom: 6px; }
  .wiki-link { margin-top: 6px; font-size: 10px; }
  .heartland-legend {
    font-size: 9px;
    line-height: 1.35;
    margin: 0 0 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .candidate { min-height: 44px; padding: 12px; }
  .retry-btn { min-height: 40px; padding: 10px 14px; }
  .etym-alts { margin: 4px 0 6px; gap: 3px; }
  .etym-alt { min-height: 40px; padding: 7px 8px; }
  .etym-alt:focus-visible .etym-alt-gloss,
  .etym-alt.on .etym-alt-gloss {
    white-space: normal;
    text-overflow: clip;
    max-height: 4em;
  }
  .stats { margin: 8px 0; padding: 8px 0; gap: 12px; }
  .stat strong { font-size: 14px; }
  .stat span { font-size: 8px; letter-spacing: 0.06em; }
  .timeline-head { margin-bottom: 8px; font-size: 9px; }
  .timeline-item { margin-bottom: 10px; }
  .term { font-size: 14px; }
  .term-roman { font-size: 13px; }
  .tag { margin-top: 3px; padding-bottom: 2px; font-size: 10px; }
  .panel-section { margin-top: 10px; padding-top: 8px; }
  .panel-section summary { min-height: 40px; padding: 8px 0; }
  .panel-footer { display: none; }

  .bottom-left {
    left: var(--m-pad);
    bottom: calc(var(--m-pad) + var(--m-safe));
    font-size: 8px;
    z-index: 11;
  }

  /* Expanded sheet: keep status/legend out of the way; zoom stays usable above the sheet */
  body.panel-expanded .bottom-left,
  body.panel-expanded .arc-legend,
  body:has(#infoPanel.visible:not(.minimized)) .bottom-left,
  body:has(#infoPanel.visible:not(.minimized)) .arc-legend {
    display: none !important;
  }

  /* Minimized: status above the tab/zoom row */
  body.panel-minimized .bottom-left,
  body:has(#infoPanel.visible.minimized) .bottom-left {
    display: block !important;
    left: var(--m-pad);
    right: var(--m-pad);
    bottom: var(--mobile-tools-row);
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    opacity: 0.9;
  }

  /* Zoom: tools row above Journey (or bottom when idle) */
  .bottom-right {
    right: var(--m-pad);
    bottom: calc(var(--m-pad) + var(--m-safe) + var(--m-journey) + var(--m-stack-gap));
    gap: 6px;
    z-index: 15;
  }
  body:not(.panel-open):not(:has(#infoPanel.visible)) .bottom-right {
    bottom: calc(var(--m-pad) + var(--m-safe));
  }
  /* Expanded: park zoom just above the sheet so reset/± stay reachable */
  body.panel-expanded .bottom-right,
  body:has(#infoPanel.visible:not(.minimized)) .bottom-right {
    display: flex !important;
    bottom: calc(var(--mobile-chrome) + var(--mobile-panel-max) + var(--m-stack-gap));
  }
  .round-control {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
  .zoom-label { font-size: 9px; min-width: 36px; }

  body.panel-expanded .empty-note,
  body:has(#infoPanel.visible:not(.minimized)) .empty-note { opacity: 0; }

  body.panel-expanded .info-panel,
  body:has(#infoPanel.visible:not(.minimized)) .info-panel {
    z-index: 14;
    max-height: var(--mobile-panel-max);
    bottom: var(--mobile-chrome);
  }

  .arc-legend {
    left: var(--m-pad);
    right: var(--m-pad);
    bottom: var(--mobile-meta-row);
    font-size: 8px;
    max-width: none;
    flex-wrap: wrap;
    justify-content: center;
    white-space: normal;
    row-gap: 4px;
    z-index: 11;
  }
  /* Minimized: keep oldest→newest strip above status */
  body.panel-minimized .arc-legend:not([hidden]),
  body:has(#infoPanel.visible.minimized) .arc-legend:not([hidden]) {
    display: flex !important;
    bottom: var(--mobile-meta-row);
  }

  .toast {
    bottom: var(--mobile-legend-row);
    max-width: calc(100% - 28px);
    white-space: nowrap;
  }
  .globe-label { padding: 2px 6px 3px; }
  .globe-label-form { font-size: 12px; max-width: 110px; }
  .globe-label-lang { font-size: 7px; }

  .modal { padding: 12px; align-items: flex-end; }
  .modal-card {
    width: 100%;
    max-height: min(88vh, 100%);
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
    border-radius: 12px 12px 5px 5px;
  }
}

@media (max-height: 650px) and (min-width: 901px) {
  .kicker { top: 70px; }
  .search-area { top: 98px; }
  .info-panel { max-height: 48vh; bottom: 15px; }
  .word-title { font-size: 29px; }
  .timeline-item { margin-bottom: 12px; }
}

.retry-btn {
  margin-top: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  padding: 6px 12px;
  font: 10px var(--mono);
  cursor: pointer;
  border-radius: 3px;
}

.candidate-list {
  text-align: left;
  margin-top: 10px;
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--ink);
}

.candidate-intro {
  font: 11px var(--mono);
  color: var(--muted);
  margin-bottom: 2px;
}

.candidate {
  display: grid;
  gap: 3px;
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  padding: 10px 12px;
  border-radius: 3px;
  cursor: pointer;
}

.candidate strong {
  font: 500 15px var(--serif);
  color: var(--ink);
}

.candidate em {
  font: 500 10px var(--mono);
  font-style: normal;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--teal);
}

.candidate span {
  font: 12px/1.35 var(--serif);
  color: #4a4c46;
}

.candidate:hover {
  border-color: var(--ink);
}

.no-geo {
  margin: 0 0 10px;
  font: 10px/1.45 var(--mono);
  color: var(--accent);
  background: rgba(224, 69, 48, 0.06);
  padding: 7px 9px;
  border: 1px solid rgba(224, 69, 48, 0.22);
  border-radius: 3px;
}

.no-geo[hidden] {
  display: none;
}

.timeline-bar {
  position: absolute;
  z-index: 8;
  /* Leave a clear gap before reset/zoom controls (cluster ≈ 190px wide) */
  right: 200px;
  left: auto;
  bottom: 22px;
  transform: none;
  display: flex;
  align-items: center;
  gap: 10px;
  font: 600 10px var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink);
  background: rgba(245, 242, 233, 0.96);
  border: 1px solid rgba(25, 27, 25, 0.22);
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: 0 6px 22px rgba(25, 27, 25, 0.14);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  max-width: min(280px, calc(100vw - 260px));
}

.timeline-bar label {
  color: var(--ink);
  opacity: 1;
  flex: none;
}

.timeline-bar input[type="range"] {
  width: min(140px, 18vw);
  min-width: 72px;
  flex: 1 1 auto;
  accent-color: var(--teal);
  height: 4px;
}

.panel-section {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.panel-section summary {
  font: 9px var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}

.lineage-graph {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.lineage-edge {
  display: grid;
  gap: 2px;
  font-size: 11px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(25, 27, 25, 0.06);
}

.le-from, .le-to {
  font: 500 14px var(--serif);
}

.le-rel {
  font: 9px var(--mono);
  color: var(--gold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sources-list {
  margin-top: 10px;
  display: grid;
  gap: 12px;
}

.source-item strong {
  display: block;
  font: 500 14px var(--serif);
}

.st.inferred_geo {
  color: var(--teal);
  margin-left: 4px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  width: min(100%, 100vw);
  max-width: 100%;
  height: min(100%, 100vh);
  max-height: 100%;
  margin: 0;
  background: rgba(25, 27, 25, 0.28);
  display: grid;
  place-items: center;
  padding: 24px;
  border: 0;
  color: inherit;
}

.modal:not([open]) { display: none !important; }

.modal::backdrop {
  background: rgba(25, 27, 25, 0.28);
}

.modal-card {
  width: min(520px, 100%);
  max-height: min(80vh, 720px);
  overflow: auto;
  background: var(--glass);
  backdrop-filter: blur(22px);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 22px 24px;
  box-shadow: 0 18px 60px rgba(39, 35, 24, 0.16);
}

.section-title {
  font: 9px var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 18px 0 8px;
}

.credits {
  margin: 0;
  padding-left: 18px;
  font: 12px/1.6 var(--sans);
  color: #565850;
}

.credits a { color: inherit; }

.cache-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.cache-actions .chip,
.file-chip {
  border: 1px solid var(--line);
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.42);
  padding: 7px 11px;
  font: 10px var(--mono);
  cursor: pointer;
}

.cache-actions .chip.danger { color: var(--accent); }

.search-area.loading .searchbox {
  border-color: var(--teal);
}

.loading-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 4px;
  color: var(--ink);
  font: 12px var(--sans);
}

.loading-text {
  color: var(--muted);
  font: 11px var(--mono);
  letter-spacing: 0.04em;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(25, 27, 25, 0.12);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: lx-spin 0.7s linear infinite;
  flex: none;
}

@keyframes lx-spin {
  to { transform: rotate(360deg); }
}

.suggest-wrap {
  margin-top: 6px;
  text-align: center;
  pointer-events: auto;
}

.suggest-intro {
  font-size: 12px;
  margin-bottom: 10px;
}

.suggest-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  pointer-events: auto;
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-top-color: var(--muted); }
}

@media (max-width: 900px) {
  /* Journey: exclusive full-width bottom band — never beside zoom */
  .timeline-bar {
    left: var(--m-pad, 10px);
    right: var(--m-pad, 10px);
    max-width: none;
    transform: none;
    bottom: calc(var(--m-pad, 10px) + var(--m-safe, env(safe-area-inset-bottom, 0px)));
    justify-content: space-between;
    z-index: 12;
    padding: 8px 14px;
    gap: 10px;
    min-height: 44px;
  }
  .timeline-bar input[type="range"] {
    width: auto;
    max-width: none;
    min-height: 28px;
    flex: 1 1 auto;
  }
}

/* Short phones / landscape: keep the globe dominant */
@media (max-width: 900px) and (max-height: 520px) {
  :root { --mobile-panel-max: 180px; }
  .kicker { display: none; }
  .search-area { top: 62px; }
  .word-title { font-size: 20px; }
  .stats { display: none; }
  .heartland-legend { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
