/* Here Be Dragons: a minimal look. White and light gray, black text, one red accent for the gaps.
   Layout: a top bar, a full-page map, and a gap panel docked at the right.
   Before the first search, the body has the class "landing": the search box sits in the middle of the page. */

/* Colors and sizes in one place.
   --map, --accent, and --text match MAP_BACKGROUND, ACCENT_COLOR, and INK_COLOR in config.js. */
:root {
  --map: #ffffff;
  --surface: #ffffff;      /* search box, panels, cards */
  --panel: #f5f5f6;        /* hover and quiet backgrounds */
  --text: #111111;
  --text-2: #3d3d3d;       /* body text */
  --muted: #6b6b6b;        /* labels and help text */
  --faint: #8f8f8f;        /* paper IDs, placeholder */
  --line: #e6e6e6;         /* hairline borders */
  --line-2: #d2d2d4;       /* stronger borders */
  --accent: #d03a2b;       /* the gaps */
  --accent-hover: #b32f21;
  --accent-tint: #fcf2f0;
  --bar-height: 56px;
  --ease: 0.35s cubic-bezier(0.2, 0.7, 0.2, 1);

  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;

  color-scheme: light;
}

* { box-sizing: border-box; }

/* An element with the hidden attribute always stays hidden */
[hidden] { display: none !important; }

body {
  margin: 0;
  height: 100vh;
  height: 100dvh; /* on a phone, 100vh also counts the part under the browser's bars */
  overflow: hidden;
  font: 14px/1.5 var(--sans);
  color: var(--text);
  background: var(--map);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

/* Text from the engine or the visitor may have a very long word. It wraps and does not widen the panel, the card, or the tooltip. */
#gap-panel, #paper-card, #tooltip { overflow-wrap: anywhere; }

/* Small labels in capitals, such as "Paper" */
.label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Top bar ---------- */

#top-bar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--bar-height);
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}

/* A small dashed circle, the brand mark */
.brand-mark {
  width: 16px;
  height: 16px;
  border: 2px dashed var(--accent);
  border-radius: 50%;
  transition: transform 0.6s ease;
}

.brand:hover .brand-mark { transform: rotate(90deg); }

.brand-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

/* The mode label: a colored dot and the mode name. main.js sets data-mode. */
#mode-label {
  --dot: var(--faint);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}

#mode-label::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dot);
}

#mode-label[data-mode="live"] { --dot: #1f9d55; }
#mode-label[data-mode="practice"] { --dot: #d99a00; }

/* ---------- Search box ---------- */

/* After a search, the box sits in the middle of the top bar. On the start page, it sits in the
   middle of the page (see "Start page" below). The change of place is animated. */
#search-form {
  position: fixed;
  top: 8px;
  left: 50%;
  z-index: 20;
  width: min(600px, calc(100vw - 470px));
  min-width: 320px;
  transform: translateX(-50%);
  transition: top var(--ease), left var(--ease), width var(--ease), transform var(--ease);
}

.search-box {
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 4px 0 14px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  transition: height var(--ease), border-color 0.15s;
}

.search-box:hover,
.search-box:focus-within { border-color: var(--muted); }

.search-icon {
  flex: none;
  width: 17px;
  height: 17px;
  color: var(--faint);
}

#query-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 10px;
  font: 15px var(--sans);
  color: var(--text);
  background: transparent;
  border: none;
  outline: none;
}

#query-input::placeholder { color: var(--faint); }

/* Method switch inside the box: two small joined buttons. The active one is white. */
#method-switch {
  flex: none;
  display: flex;
  gap: 2px;
  padding: 3px;
  margin-right: 6px;
  background: var(--panel);
  border-radius: 999px;
}

.method-button {
  height: 26px;
  padding: 0 10px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 999px;
  transition: background 0.12s, color 0.12s;
}

.method-button:hover { color: var(--text); }

.method-button.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line-2);
}

/* The round arrow button. Gray until the box has text. */
#search-button {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  transition: background 0.15s, width var(--ease), height var(--ease);
}

#search-button svg { width: 17px; height: 17px; }
#search-button:hover:not(:disabled) { background: var(--accent-hover); }
#search-button:disabled { color: #b5b5b8; background: var(--panel); }

/* Chips: small buttons that run an example search */
.chip {
  height: 30px;
  padding: 0 12px;
  font-size: 13px;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}

.chip:hover { color: var(--text); background: var(--panel); }

/* ---------- Start page ---------- */

/* A white layer over the map, and text above and below the search box.
   The search box center sits at 42% of the page height. Its height is 52 px, and the text
   keeps 24 px of space from it: 42vh + 26 px + 24 px = 42vh + 50 px. */
#landing-veil,
#landing-head,
#landing-foot {
  position: fixed;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--ease), visibility var(--ease), transform var(--ease);
}

#landing-veil {
  inset: var(--bar-height) 0 0 0;
  z-index: 15;
  background: rgba(255, 255, 255, 0.88);
}

#landing-head,
#landing-foot {
  left: 50%;
  z-index: 16;
  width: min(640px, calc(100vw - 32px));
  text-align: center;
  transform: translate(-50%, -12px);
}

/* A click on the empty part of the start page reaches the veil (main.js closes the start page then).
   Only the buttons and the links in the text take clicks themselves. */
#landing-head,
#landing-foot { pointer-events: none; }
#landing-foot .examples,
#landing-foot button { pointer-events: auto; }

#landing-head { bottom: calc(58vh + 50px); }
#landing-foot { top: calc(42vh + 50px); }

#landing-head h1 {
  margin: 0 0 8px;
  font-size: 30px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.025em;
}

#landing-head p {
  margin: 0;
  font-size: 15px;
  color: var(--muted);
}

.examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.examples-label { font-size: 13px; color: var(--muted); }
#examples { display: contents; } /* the chips sit in the same row as "Try" */

/* The quiet way past the search: a text button under the examples */
#explore-button {
  display: block;
  margin: 18px auto 0;
  padding: 4px 8px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
  border-radius: 6px;
}

#explore-button:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }

.landing-note {
  max-width: 520px;
  margin: 28px auto 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

.landing-note + .landing-note { margin-top: 8px; }
.landing-note.faint { color: var(--faint); }
.landing-note strong { font-weight: 600; color: var(--accent); }

/* The start page is on: show its parts and move the search box to the middle of the page */
.landing #landing-veil,
.landing #landing-head,
.landing #landing-foot {
  opacity: 1;
  visibility: visible;
}

.landing #landing-head,
.landing #landing-foot { transform: translate(-50%, 0); }

.landing #search-form {
  top: 42vh;
  width: min(640px, calc(100vw - 32px));
  transform: translate(-50%, -50%);
}

.landing .search-box { height: 52px; padding-left: 18px; }
.landing #query-input { font-size: 16px; }
.landing #search-button { width: 40px; height: 40px; }

/* The map's own overlays wait until there are results */
.landing #map-hint, .landing #map-status { visibility: hidden; }

/* ---------- Map ---------- */

#map-container {
  position: fixed;
  inset: var(--bar-height) 0 0 0;
  overflow: hidden;
  background: var(--map);
}

/* touch-action: none gives every touch on the map to the map: a pinch zooms the map, not the page */
#map-canvas { width: 100%; height: 100%; display: block; touch-action: none; }

/* The SVG layer that map.js draws over the dots: the selected gap (its lines and its pin marker), the star, and the papers of the gap.
   It ignores the pointer, so the map still pans under it. */
#shapes {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#shapes text { font: 600 11px var(--sans); }

/* Topic labels over the map. map.js places each one at its region and hides labels that would overlap.
   Clicks and hovers pass through the labels to the dots. */
#label-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
  transition: opacity var(--ease);
}

/* The start page has text over the map. The labels would show through its white layer and sit under that text. */
.landing #label-layer { opacity: 0; }

.map-label {
  position: absolute;
  top: 0;
  left: 0;
  padding: 1px 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.82);
  border-radius: 4px;
}

.map-label.level-1 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

#legend {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.8;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
}

#legend::before {
  content: "Categories";
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

#legend span { border-radius: 50%; } /* round color dots; map.js sets their size and color */

#map-hint {
  position: absolute;
  bottom: 12px;
  left: calc((100% - var(--covered, 0px)) / 2);
  z-index: 2;
  margin: 0;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--faint);
  background: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  transform: translateX(-50%);
  white-space: nowrap;
  pointer-events: none;
}

/* The touch hint shows only on a touch screen (see "Touch screens" below) */
.hint-touch { display: none; }

/* The hint is for a visitor who has not opened a paper yet. The open paper card would cover half of it. */
#map-container:has(#paper-card.open) #map-hint { visibility: hidden; }

/* Top center of the free part of the map: the progress line and the error message.
   --covered is the width of the gap panel (main.js sets it). */
#map-status {
  position: absolute;
  top: 12px;
  left: calc((100% - var(--covered, 0px)) / 2);
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(900px, calc(100% - var(--covered, 0px) - 24px));
  transform: translateX(-50%);
  pointer-events: none;
}

#map-status > * { pointer-events: auto; }

/* The progress line: a red dot (or a spinner while the engine works) and the numbers of the search in bold. */
#progress {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  margin: 0;
  padding: 5px 14px;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#progress-text { overflow: hidden; text-overflow: ellipsis; }
#progress b { font-weight: 600; color: var(--text); }
.progress-separator { margin: 0 0.5em; color: #c4c4c8; }

.progress-mark {
  flex: none;
  width: 8px;
  height: 8px;
  margin: 0 1px; /* the dot and the spinner take the same width, so the text does not move when one becomes the other */
  background: var(--accent);
  border-radius: 50%;
}

#progress.busy .progress-mark {
  width: 10px;
  height: 10px;
  margin: 0;
  background: transparent;
  border: 1.5px solid var(--line-2);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

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

#error-notice {
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  color: #6b4b00;
  background: #fff8e6;
  border: 1px solid #f0dca8;
  border-radius: 10px;
}

#tooltip {
  position: absolute;
  z-index: 5;
  display: none;
  max-width: 260px;
  padding: 6px 9px;
  font-size: 12.5px;
  line-height: 1.4;
  color: #fff;
  background: var(--text);
  border-radius: 4px;
  pointer-events: none;
}

/* ---------- Gap panel (right) ---------- */

/* The panel is docked at the right edge of the map. It has no shadow: a hairline separates it from the map. */
#gap-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  width: min(440px, 100%);
  background: var(--surface);
  border-left: 1px solid var(--line);
  transition: transform var(--ease), opacity var(--ease), visibility var(--ease);
}

/* The panel slides out of view until main.js sets data-view (to "topic" or "gaps"). Its buttons are then out of the Tab order too. */
#gap-panel:not([data-view]) {
  transform: translateX(100%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.gap-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin: 0 20px;
  padding: 14px 4px 12px; /* the line is 20 px from the edge, the text 24 px, like the text of the cards below */
  border-bottom: 1px solid var(--line);
}

/* min-width 0 lets a long query wrap inside the header, so it does not push "Hide" out of the panel */
.gap-panel-head > div:first-child { min-width: 0; }

#gap-heading {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

#gap-subheading {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  overflow-wrap: anywhere; /* a long query without spaces still wraps */
}

.method-name { white-space: nowrap; }

#gap-toggle {
  flex: none;
  min-width: 54px; /* "Hide" and "Show" take the same width, so the button does not change size when it is clicked */
  height: 26px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  transition: background 0.12s;
}

#gap-toggle:hover { background: var(--panel); }

/* "Hide" shrinks the panel to its header */
#gap-panel.collapsed {
  bottom: auto;
  width: auto;
  border-bottom: 1px solid var(--line);
  border-bottom-left-radius: 12px;
}

#gap-panel.collapsed #gap-list,
#gap-panel.collapsed #topic-body,
#gap-panel.collapsed #topic-foot,
#gap-panel.collapsed #back-button,
#gap-panel.collapsed #gap-subheading { display: none; }
#gap-panel.collapsed .gap-panel-head { align-items: center; margin: 0; padding: 14px 24px 14px 14px; border-bottom: none; }

#gap-list,
#topic-body {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: none; /* A scrollbar that appears takes 10 px and re-wraps the text. The wheel, touch, and keys still scroll. */
  transition: opacity 0.15s;
}

/* Fade the old cards and the old topic panel while a search runs */
body.searching #gap-list,
body.searching #topic-body { opacity: 0.4; }

/* The panel shows the topic or the gaps, not both */
#gap-panel[data-view="topic"] #gap-list,
#gap-panel[data-view="gaps"] #topic-body,
#gap-panel[data-view="gaps"] #topic-foot { display: none; }

/* A small text button: "Back to topic" and "Copy link" */
.link-button,
.copy-link {
  padding: 0;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
}

.link-button { margin: 2px 0 0; font-size: 12px; }

.link-button:hover,
.copy-link:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Topic panel ---------- */

#topic-body { padding: 14px 24px; }

.topic-count {
  margin: 0 0 14px;
  font-size: 13.5px;
  color: var(--text-2);
}

.topic-count b { font-weight: 600; color: var(--text); }

/* Small headings in capitals, in the topic panel and in an expanded card */
#topic-body h4,
.gap-details h4 {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

#topic-body h4 { margin: 16px 0 6px; }

.topic-papers {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* A nearest-paper row: the title as a link, and the year at the right */
.topic-papers li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 4px 6px;
  margin: 0 -6px;
  font-size: 12.5px;
  line-height: 1.35;
  border-radius: 6px;
}

.topic-papers li:hover { background: var(--panel); }

.topic-paper {
  flex: 1;
  min-width: 0;
  color: var(--text-2);
  text-decoration: none;
}

.topic-paper:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.paper-year { flex: none; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }

/* The foot of the topic panel holds the one primary button */
#topic-foot {
  flex: none;
  padding: 12px 24px 16px;
  border-top: 1px solid var(--line);
}

#find-gaps {
  width: 100%;
  height: 40px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  transition: background 0.15s, opacity 0.15s;
}

#find-gaps:hover:not(:disabled) { background: var(--accent-hover); }
body.searching #find-gaps { opacity: 0.4; pointer-events: none; } /* the topic on screen is about to change */
#find-gaps:disabled { color: #b5b5b8; background: var(--panel); }

#topic-foot p {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

/* ---------- Gap cards ---------- */

/* A card runs from edge to edge of the panel, so a hover or a selection colors the full width.
   The hairline under a card is 20 px short of each edge, like the line under the panel's header. */
.gap-card {
  position: relative;
  display: flex;
  gap: 12px;
  padding: 14px 24px;
  border-top: 1px solid transparent; /* a selected card only changes color, so its text does not move */
  border-bottom: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s;
}

.gap-card::after {
  content: "";
  position: absolute;
  right: 20px;
  bottom: 0;
  left: 20px;
  border-bottom: 1px solid var(--line);
}

.gap-card:hover { background: var(--panel); }

/* The selected card (the gap on the map) has a red tint. The expanded card also shows everything. */
.gap-card.selected,
.gap-card.selected:hover {
  background: var(--accent-tint);
  border-color: #f1dcd8;
}

.gap-card.selected::after { display: none; }
.gap-card.expanded { cursor: default; }
.gap-card.expanded h3 { cursor: pointer; }

/* The number badge is a red circle with a white number, like the number in the gap's pin marker */
.gap-number {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-top: -1px; /* the middle of the badge sits on the middle of the first title line */
  font-size: 11.5px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border-radius: 50%;
}

.gap-body { flex: 1; min-width: 0; }

.gap-card h3 {
  margin: 0 0 3px;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.005em;
}

.gap-abstract {
  margin: 0 0 6px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-2);
}

/* A card shows two lines of the abstract. The expanded card shows all of it. */
.gap-card:not(.expanded) .gap-abstract {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* The check line under the reason: small gray text. The closest paper in it is a link that opens the paper card. */
.gap-check {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.check-link {
  padding: 0;
  text-align: left;
  color: var(--text-2);
  background: none;
  border: none;
  text-decoration: underline;
  text-decoration-color: var(--line-2);
  text-underline-offset: 2px;
}

.check-link:hover { color: var(--text); text-decoration-color: var(--muted); }

/* A card whose write-up is not ready. It shows a thin gray bar that moves. */
.gap-card.drafting h3 {
  margin: 2px 0 8px;
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
}

/* Three dots after "Drafting the idea". The box grows from 0 to 3 dots in 4 steps, then starts again. */
.dots {
  display: inline-block;
  width: 1.1em;
  overflow: hidden;
  vertical-align: bottom;
  white-space: nowrap;
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots { from { width: 0; } to { width: 1.1em; } }

.gap-bar {
  position: relative;
  height: 2px;
  margin: 0 0 10px;
  overflow: hidden;
  background: var(--line);
}

.gap-bar::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 30%;
  background: var(--line-2);
  animation: bar 1.4s ease-in-out infinite;
}

@keyframes bar { from { left: -30%; } to { left: 100%; } }

/* The details of the expanded card: why the idea does not exist yet, the check, and the papers */
.gap-card:not(.expanded) .gap-details { display: none; }

.gap-details {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #f1dcd8;
}

.gap-details h4 { margin: 8px 0 5px; }

.gap-reason {
  margin: 0 0 6px;
  padding-left: 10px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-2);
  border-left: 2px solid var(--line-2);
}

/* Paper rows: the title opens the paper card. A "builds on" tag marks the papers that the idea builds on. */
.paper-list {
  margin: 0 0 6px;
  padding: 0;
  list-style: none;
}

.paper-list li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 2.5px 0;
  line-height: 1.35;
}

.paper-open {
  flex: 1;
  padding: 0;
  font-size: 12px;
  line-height: 1.35;
  text-align: left;
  color: var(--text-2);
  background: none;
  border: none;
}

.paper-open:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }

.paper-tag {
  flex: none;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
}

.copy-link {
  display: block;
  margin: 0 0 8px;
  font-size: 12px;
}

/* ---------- Paper card (bottom left) ---------- */

#paper-card {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  width: 360px;
  max-width: calc(100% - var(--covered, 0px) - 24px); /* stays left of the gap panel */
  max-height: 50%;
  padding: 12px 14px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity 0.2s, visibility 0.2s, transform 0.2s;
}

#paper-card.open {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

#paper-id {
  font: 11.5px var(--mono);
  color: var(--faint);
}

#paper-close {
  width: 24px;
  height: 24px;
  margin: 0 -6px 0 auto;
  font-size: 18px;
  line-height: 1;
  color: var(--faint);
  background: transparent;
  border: none;
  border-radius: 4px;
}

#paper-close:hover { color: var(--text); background: var(--panel); }

#paper-title {
  margin: 6px 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

/* A long abstract scrolls by itself. The title and the link stay in place, and a scrollbar does not narrow the title. */
#paper-card > * { flex: none; }

#paper-link { align-self: flex-start; }

#paper-abstract {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-2);
}

#paper-abstract:empty { display: none; }
#paper-abstract.loading { color: var(--faint); }

#paper-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--line-2);
  text-underline-offset: 3px;
}

#paper-link::after { content: " \2197"; }
#paper-link:hover { text-decoration-color: var(--text); }

/* ---------- Touch screens ---------- */

/* A finger needs larger targets than a mouse: approximately 32 px or more for each button */
@media (pointer: coarse) {
  .chip { height: 36px; padding: 0 14px; }
  .method-button { height: 30px; }
  #gap-toggle { height: 32px; }
  #explore-button { padding: 8px 12px; }
  .link-button { padding: 4px 0; }
  .copy-link { padding: 4px 0; }
  .paper-list li { padding: 5px 0; }
  .topic-papers li { padding: 7px 6px; }
}

@media (hover: none) and (pointer: coarse) {
  .hint-pointer { display: none; }
  .hint-touch { display: inline; }
}

/* ---------- Phones ---------- */

/* PHONE_LAYOUT_QUERY in config.js uses the same width. Change both together.
   The top bar holds the brand mark and the search box. The panel is a sheet over the bottom half of the map,
   and main.js tells map.js how much of the map it covers (--covered-bottom), so the camera centers the results above it.
   The paper card is a sheet over the panel. */
@media (max-width: 700px) {
  :root { --bar-height: 52px; }

  #top-bar { padding: 0 14px; }

  /* After a search, the search box needs the full width of the bar: only the brand mark stays */
  body:not(.landing) .brand-name,
  body:not(.landing) #mode-label { display: none; }

  /* The box starts right of the brand mark (14 px + 16 px + 10 px = 40 px) and ends 10 px from the right edge.
     So its width is 100vw - 50 px and its center is at 40 px + (100vw - 50 px) / 2 = 50% + 15 px. */
  #search-form {
    top: 6px;
    left: calc(50% + 15px);
    width: calc(100vw - 50px);
    min-width: 0;
  }

  .search-box { padding-left: 12px; }
  body:not(.landing) .search-icon { display: none; }
  /* 16 px or more: a phone browser zooms into a text box with smaller text when it gets the focus */
  #query-input,
  .landing #query-input { padding: 0 8px; font-size: 16px; }
  #method-switch { margin-right: 4px; }
  .method-button { padding: 0 8px; font-size: 11px; }

  /* The start page: the search box sits higher, so the text under it fits on a small screen.
     The box center is at 34% of the small viewport height (svh: the height while the browser's bars show).
     The text keeps 20 px of space from the 52 px box: 34svh + 26 px + 20 px = 34svh + 46 px. */
  .landing #search-form {
    top: 34svh;
    left: 50%;
    width: calc(100vw - 24px);
  }

  #landing-head { bottom: calc(66svh + 46px); }
  #landing-foot { top: calc(34svh + 46px); }
  #landing-head h1 { font-size: 24px; }
  #landing-head p { font-size: 14px; }
  #explore-button { margin-top: 12px; }
  .landing-note { margin-top: 16px; font-size: 12.5px; line-height: 1.55; }
  .landing-note.faint { display: none; }

  /* The progress line can wrap, so its numbers stay readable on a narrow screen */
  #map-status { width: calc(100% - 24px); }
  #progress { white-space: normal; text-align: center; border-radius: 12px; }

  /* The map hint sits above the panel */
  #map-hint {
    bottom: calc(var(--covered-bottom, 0px) + 10px);
    left: 50%;
    max-width: calc(100% - 24px);
    white-space: normal;
    text-align: center;
  }

  /* The panel: a sheet over the bottom half of the map */
  #gap-panel {
    top: auto;
    left: 0;
    width: auto;
    height: 50%;
    border-top: 1px solid var(--line);
    border-left: none;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
  }

  #gap-panel:not([data-view]) { transform: translateY(100%); }

  .gap-panel-head { margin: 0 16px; padding: 12px 0 10px; }
  #topic-body { padding: 12px 16px; }
  #topic-foot { padding: 10px 16px 12px; }
  .gap-card { padding: 12px 16px; }
  .gap-card::after { right: 16px; left: 16px; }

  /* "Hide" shrinks the sheet to its header, at the bottom of the map */
  #gap-panel.collapsed {
    top: auto;
    bottom: 0;
    width: auto;
    height: auto;
    border-bottom: none;
    border-radius: 14px 14px 0 0;
  }

  #gap-panel.collapsed .gap-panel-head { padding: 10px 16px; }

  /* The paper card: a sheet at the bottom, over the panel */
  #paper-card {
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 6;
    width: auto;
    max-width: none;
    max-height: 60%;
    padding: 10px 16px 16px;
    border-bottom: none;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
  }

  #paper-close { width: 36px; height: 36px; margin-right: -10px; font-size: 22px; }
}

/* No motion for visitors who ask for less of it */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
