/* Research Terrain design system layer.
   Loaded after each page's own styles, so it sets the shared look in one place:
   colour tokens that pass WCAG AA, one set of buttons and fields, a clear focus ring,
   44px touch targets, and consistent loading, empty and error states.
   Page files keep their layout; change shared looks here rather than in a page. */

/* ---------- Tokens ---------- */
:root {
  /* Text greys and the accent are darkened to reach 4.5:1 on every light surface. */
  --ink-3: #5b6c65;
  --accent: #047857;
  --accent-soft: rgba(4, 120, 87, .10);
  /* Recent-paper glow: yellow, so it never matches a keyword colour (orange is a keyword). */
  --glow: #eab308;
  /* Darker partners of the bright accent colours, for text and white-on-colour fills. */
  --g1-ink: #047857; --g2-ink: #1d4ed8; --g3-ink: #7e22ce; --g4-ink: #be123c; --g5-ink: #b45309;
  --primary-grad: #047857; /* one solid green for every main button (the name stays so pages keep working) */
  --danger: #b91c1c; --danger-soft: rgba(220, 38, 38, .10);
  --ok: #047857; --ok-soft: rgba(4, 120, 87, .10);
  /* Borders that show where a field or button is (3:1 against the page). */
  --field-border: #7f8f88;
  --focus: #1d4ed8;
  /* Shape and spacing scale */
  --ease-out: cubic-bezier(.23, 1, .32, 1); /* strong ease-out: things that open start fast */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-pill: 999px;
  --tap: 36px;              /* desktop control height */
  --shadow-1: 0 1px 2px rgba(15, 31, 26, .06), 0 2px 8px rgba(15, 31, 26, .06);
  --shadow-2: 0 8px 28px rgba(15, 31, 26, .14);
}
:root[data-theme="dark"] {
  --ink-3: #8d9c95;
  --accent: #5cc3a5; --accent-soft: rgba(92, 195, 165, .14);
  --glow: #facc15;
  --g1-ink: #34d399; --g2-ink: #93c5fd; --g3-ink: #d8b4fe; --g4-ink: #fda4af; --g5-ink: #fcd34d;
  --danger: #fca5a5; --danger-soft: rgba(248, 113, 113, .14);
  --ok: #6ee7b7; --ok-soft: rgba(110, 231, 183, .12);
  --field-border: #5f706a;
  --focus: #93c5fd;
}
/* Touch screens get 44px targets everywhere. */
@media (pointer: coarse) { :root { --tap: 44px; } }

/* ---------- Focus: one ring, everywhere ---------- */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--focus) !important; outline-offset: 2px;
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--panel) 85%, transparent);
}
canvas:focus-visible { outline-offset: -3px; }

/* ---------- Links: look like links ---------- */
.hint a, .paper a, .empty a, .foot a, .lfoot a, .sitelinks a, p a {
  color: var(--accent); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
}
.hint a:hover, .paper a:hover, p a:hover, .lfoot a:hover, .sitelinks a:hover { text-decoration-thickness: 2px; }
.linkish { color: var(--accent); text-underline-offset: 3px; min-height: 24px; }

/* ---------- Buttons ---------- */
button {
  min-height: var(--tap); border-radius: var(--r-sm);
  background: var(--panel); border-color: var(--field-border);
  transition: background-color .15s, border-color .15s, box-shadow .15s, transform .12s var(--ease-out);
}
button:hover { border-color: var(--ink-2); background: color-mix(in srgb, var(--accent) 6%, var(--panel)); }
button:active:not(:disabled) { transform: scale(.97); }
button:disabled, button[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }

/* Primary: the one main action in each place. Same look on every page. */
.search .primary, .rbfoot .primary, .authform .primary, .hero .go, .primary {
  background: var(--primary-grad); color: #fff; border: 1px solid transparent; font-weight: 600;
  box-shadow: var(--shadow-1); padding-inline: 16px;
}
.search .primary:hover, .rbfoot .primary:hover, .authform .primary:hover, .hero .go:hover, .primary:hover {
  filter: brightness(1.08); background: var(--primary-grad); box-shadow: var(--shadow-2);
}
.primary-ghost { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* Icon-only buttons: square and the full target size. */
.iconbtn { width: var(--tap); height: var(--tap); min-height: var(--tap); }
.zoomctl button { width: var(--tap); height: var(--tap); background: var(--panel); box-shadow: var(--shadow-1); }
.zoomctl { gap: 6px; }

/* Quiet buttons inside lists keep their look but get a real target. */
.list li button, .gapcard ol button { min-height: var(--tap); }
.rlist .rx, .authhead button, .rbx, .exhead .iconbtn { min-width: var(--tap); min-height: var(--tap); border-radius: var(--r-sm); }
.rlist .rx:hover, .authhead button:hover, .rbx:hover { background: var(--accent-soft); }
.gapcard .gh button { min-height: 28px; text-decoration: underline; text-underline-offset: 3px; color: var(--ink-2); }

/* Segmented controls: the chosen option is filled, not only tinted. */
.seg { border-color: var(--field-border); border-radius: var(--r-sm); }
.seg button { min-height: var(--tap); background: var(--panel); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }
:root[data-theme="dark"] .seg button[aria-pressed="true"] { color: #0f1517; }
.seg button + button { border-left-color: var(--field-border); }

/* Pills: recent searches, paper links, star, authors. One shape, a real target. */
.recents button, .exitem .acts a, .plinks a, .star, .rbauthors button, .rbitem .onmap {
  min-height: 32px; display: inline-flex; align-items: center; border-radius: var(--r-pill);
  border: 1px solid var(--field-border); background: var(--panel); color: var(--ink-2); padding-inline: 12px;
}
@media (pointer: coarse) { .recents button, .exitem .acts a, .plinks a, .star, .rbauthors button { min-height: 44px; } }
.exitem .acts a:hover, .plinks a:hover, .recents button:hover { border-color: var(--accent); color: var(--ink); background: var(--accent-soft); }
.exitem .acts a.pdf, .plinks a.pdf { color: var(--accent); border-color: var(--accent); }
.exitem .acts a.pdf::before, .plinks a.pdf::before { content: "\2193"; margin-right: 5px; font-weight: 700; }
.star[aria-pressed="true"] { color: var(--g5-ink); border-color: var(--g5-ink); }

/* ---------- Fields ---------- */
input[type=text], input[type=email], input[type=password], input[type=search], select, textarea,
.search input[type=text], .search select, .search textarea, .authform input, .hero input, .exctl input[type=search], .exctl select {
  border: 1px solid var(--field-border); border-radius: var(--r-sm); background: var(--panel); color: var(--ink);
  min-height: var(--tap);
}
input::placeholder, textarea::placeholder { color: var(--ink-3); opacity: 1; }
input[type=text]:hover, input[type=email]:hover, input[type=password]:hover, input[type=search]:hover, select:hover, textarea:hover { border-color: var(--ink-2); }
input:user-invalid { border-color: var(--danger); }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; accent-color: var(--accent); }
.check { min-height: var(--tap); }
input[type=range] { min-height: 24px; accent-color: var(--accent); }

/* ---------- Hierarchy ---------- */
aside section > h2, .lsec .lh { color: var(--ink); }
aside section > h2 { font-size: 16px; font-weight: 600; }
aside section > h2 small { font-size: 12.5px; }
.search { gap: 10px; }
.search .primary { min-height: 40px; font-size: 15px; padding-inline: 20px; }
@media (pointer: coarse) { .search .primary { min-height: 44px; } }

/* ---------- Feedback: loading, empty, error, success ---------- */
@keyframes rt-spin { to { transform: rotate(360deg); } }
.loading { gap: 10px; grid-auto-flow: column; color: var(--ink-2); }
.loading::before { content: ""; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid color-mix(in srgb, var(--accent) 25%, transparent); border-top-color: var(--accent); animation: rt-spin .8s linear infinite; }
.progress .meter i { background: var(--primary-grad); }
.progress .box { border-radius: var(--r-md); box-shadow: var(--shadow-2); }
.progress .err, .err { display: flex; gap: 8px; align-items: flex-start; color: var(--ink);
  background: var(--danger-soft); border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent); border-left: 4px solid var(--danger);
  padding: 10px 12px; border-radius: var(--r-sm); font-size: 13.5px; line-height: 1.45; }
.progress .err::before, .err::before { content: "!"; flex: none; width: 18px; height: 18px; border-radius: 50%; background: var(--danger); color: var(--panel);
  font-weight: 700; font-size: 12px; display: grid; place-items: center; margin-top: 1px; }
.empty, .exempty { display: flex; gap: 8px; align-items: flex-start; color: var(--ink-2); }
.empty::before, .exempty::before { content: "i"; flex: none; width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--ink-3); color: var(--ink-3);
  font: italic 600 11px/15px Georgia, serif; text-align: center; box-sizing: border-box; margin-top: 1px; }
.toast { border-radius: var(--r-md); padding: 10px 16px; box-shadow: var(--shadow-2); display: flex; gap: 8px; align-items: center; z-index: 60; }
.toast:not([hidden])::before { content: "\2713"; font-weight: 700; color: color-mix(in srgb, var(--g1) 80%, var(--ground)); }
.hero .msg:not(:empty) { padding: 8px 10px; border-radius: var(--r-sm); background: var(--accent-soft); color: var(--ink); }

/* ---------- Colour never carries meaning alone ---------- */
.legend { border-radius: var(--r-sm); }
.legend i { box-shadow: 0 0 0 1px color-mix(in srgb, var(--ink) 25%, transparent); }
.gapcard .gh strong i { box-shadow: 0 0 0 4px color-mix(in srgb, var(--glow) 35%, transparent); }
.gap-tag::before { content: "\25B3 "; }

/* ---------- Panels and cards ---------- */
.gapcard, .explorer, .tip, dialog { border-radius: var(--r-md); }
.explorer, dialog { box-shadow: var(--shadow-2); }
dialog { border-color: var(--field-border); }
.card { border-radius: var(--r-md); }
/* Card call-to-action: dark partner of the card colour, with an arrow. */
.card .go { color: var(--c-ink, var(--accent)); text-decoration: underline; text-underline-offset: 3px; }
.card .go::after { content: " \2192"; }
.lsec .more { color: var(--accent); text-underline-offset: 3px; }

/* ---------- Landing: sign-in card beside a real map ---------- */
.hero form { border-radius: var(--r-md); box-shadow: var(--shadow-1); }
.hero form h2 { font-size: 15px; font-weight: 600; }
.hero .go { min-height: 40px; }
.lnav a:not(.brand) { min-height: var(--tap); display: inline-flex; align-items: center; color: var(--ink-2); }
/* Keep the phone menu on one line: this file loads last, so the page's hide rule has to be repeated here */
@media (max-width: 760px) { .lnav a.hide-sm { display: none; } }
.scrollcue { color: var(--ink-2); min-height: var(--tap); }

@media (prefers-reduced-motion: reduce) { .loading::before { animation: none; } button:active:not(:disabled) { transform: none; } }

/* Text-style buttons (paper titles, breadcrumbs) read as text, so they keep a smaller height. */
.exitem .ttl, .rlist .rt, .rbitem .ttl, .rbitem .rm, .rbtrail button { min-height: 24px; background: none; }

/* ---------- Beta notice (js/beta.js) ---------- */
/* One thin strip above everything. --beta-h lets full-height layouts (the app, the landing) leave room for it. */
:root { --beta-h: 30px; }
:root.beta-off { --beta-h: 0px; }
.beta-off .betabar { display: none; }
.betabar { position: relative; z-index: 60; display: flex; align-items: center; justify-content: center; gap: 4px 10px;
  min-height: var(--beta-h); box-sizing: border-box; padding: 4px 40px 4px 12px; margin: 0;
  font: 500 12.5px/1.3 var(--body, system-ui, sans-serif); color: var(--ink-2); text-align: center;
  background: var(--panel, #fff); border-bottom: 1px solid var(--rule, #dde6e2); }
.betabar .betatag { flex: none; padding: 1px 7px; border-radius: var(--r-pill); font-size: 11px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--g5-ink); background: rgba(245, 158, 11, .14); }
.betabar a { color: var(--accent); font-weight: 600; text-underline-offset: 3px; white-space: nowrap; }
.betabar .betax { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; min-height: 0; padding: 0;
  display: grid; place-items: center; border: 0; border-radius: 50%; background: none; color: var(--ink-3); cursor: pointer; font-size: 16px; line-height: 1; }
.betabar .betax::before { content: ""; position: absolute; inset: -9px; } /* 44px touch target without a taller strip */
.betabar .betax:hover { color: var(--ink); background: var(--accent-soft); }
@media (max-width: 560px) { .betabar .betamore { display: none; } }
/* Full-height app and landing on the map page sit below the strip instead of being pushed off the screen. */
.betabar ~ .app { height: calc(100% - var(--beta-h)); }
.betabar ~ .landing { top: var(--beta-h); }
@media (max-width: 760px) { .betabar ~ .app { height: auto; } .betabar ~ .app.shell { height: calc(100dvh - var(--beta-h)); } }
/* "Signed in on another device" notice (js/single-session.js): one account, one signed-in device at a time. */
.session-ended { position: fixed; left: 50%; top: calc(16px + var(--beta-h, 0px)); transform: translateX(-50%); z-index: 80;
  width: min(560px, calc(100% - 32px)); display: flex; gap: 12px; align-items: center; padding: 12px 14px;
  background: var(--ground); color: var(--ink); border: 1px solid var(--field-border); border-radius: var(--r-md);
  box-shadow: var(--shadow-2); font-size: 14px; line-height: 1.45; }
.session-ended span { flex: 1; }
.session-ended button { flex: none; min-height: 36px; padding: 0 14px; border-radius: var(--r-sm); border: 1px solid currentColor;
  background: transparent; color: inherit; font: inherit; font-weight: 600; cursor: pointer; }
/* "Private beta" screen (js/members.js): shown over the app to a signed-in account not on the founders' list. */
.private-beta { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 20px;
  background: color-mix(in srgb, var(--ground) 92%, transparent); backdrop-filter: blur(6px); }
.private-beta > div { width: min(440px, 100%); padding: 24px; background: var(--panel, var(--ground)); color: var(--ink);
  border: 1px solid var(--field-border); border-radius: var(--r-md); box-shadow: var(--shadow-2); }
.private-beta h2 { margin: 0 0 8px; font-size: 20px; }
.private-beta p { margin: 0 0 18px; color: var(--ink-2); line-height: 1.5; }
.private-beta div div { display: flex; gap: 16px; align-items: center; }
.private-beta button { min-height: 40px; padding: 0 18px; border-radius: var(--r-sm); border: 0; background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }

/* ---------- Motion: panels and dialogs open with a short fade + lift, so they don't pop in ---------- */
@keyframes rt-in { from { opacity: 0; transform: translateY(6px) scale(.98); } }
@keyframes rt-up { from { transform: translateY(100%); } }
@keyframes rt-fade { from { opacity: 0; } }
.shell .searchopts, .pcard, .gapcard, .explorer, .kwpanel, .drawer, .emailbox { animation: rt-in .2s var(--ease-out); }
.searchopts { transform-origin: top left; } .kwpanel, .pcard { transform-origin: top right; }
dialog[open] { animation: rt-in .24s var(--ease-out); }
dialog[open]::backdrop { animation: rt-fade .24s var(--ease-out); }
.tourbody, .tourdlg img { animation: rt-fade .2s var(--ease-out); }
@media (max-width: 760px) { .drawer { animation: rt-up .3s var(--ease-out); } }
@media (prefers-reduced-motion: reduce) {
  .shell .searchopts, .pcard, .gapcard, .explorer, .kwpanel, .drawer, .emailbox, dialog[open], dialog[open]::backdrop, .tourbody, .tourdlg img { animation: none; }
}
