/* Shared interface tokens and components. Loaded after page styles; chart geometry and exported artwork stay local. */
:root {
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --text-base: 1rem;
  --text-support: .875rem;
  --text-caption: .75rem;
  --text-control: .9375rem;
  --text-heading: 1.0625rem;
  --text-title: 1.5rem;
  --line-body: 1.55;
  --line-control: 1.25;
  --weight-body: 400;
  --weight-control: 500;
  --weight-heading: 600;
  --duration-control: 120ms;
  /* Light, quiet palette: one warm accent used sparingly, hairline borders, flat surfaces. */
  --ink: #2b2723;
  --ink-muted: #756e66;
  --hairline: #e9e3db;
  --hairline-strong: #d9d1c6;
  --surface: #ffffff;
  --canvas: #faf9f7;
  --accent: #7a5a36;
  --accent-hover: #664a2b;
  --accent-soft: #f4eee6;
  --hover-soft: #f7f4ef;
  /* 40px on a mouse, 44px under a finger (see the pointer query at the end). */
  --btn-h: 2.5rem;
  --btn-font: var(--text-control);
  --btn-pad: .45rem .875rem;
  --btn-form-h: 2.75rem;
  --btn-compact-h: 2rem;
  --field-font: var(--text-base);
  --field-min-h: var(--btn-h);
  --field-radius: .5rem;
  --field-border: 1px solid var(--hairline-strong);
  --field-ring: 0 0 0 3px rgba(122, 90, 54, .14);
  --radius-control: .5rem;
  --radius-card: .75rem;
  --radius-dialog: 1rem;
  --space-1: .25rem;
  --space-2: .5rem;
  --space-3: .75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --content-reading: 60rem;
  --content-wide: 80rem;
  --content-chart: 97.5rem;
  --page-pad: var(--space-6);
  --page-max: var(--content-wide);
  --ui-primary: var(--accent);
  --ui-primary-hover: var(--accent-hover);
  --ui-primary-text: #fff;
  --ui-danger: #a33a35;
  --ui-success: #2f704e;
  /* Page styles read these: map them onto the light palette so every page follows. */
  --text: var(--ink);
  --text-light: var(--ink-muted);
  --border: var(--hairline);
  --bg-light: var(--canvas);
  --bg-white: var(--surface);
  --primary: var(--accent);
  --primary-dark: var(--accent);
  --shadow: none;
  --shadow-lg: 0 12px 32px rgba(43, 39, 35, .12), 0 1px 3px rgba(43, 39, 35, .06);
}
html { font-family: var(--font-ui); }
body[class] [hidden] { display: none !important; }
body[class] { font-family: var(--font-ui); font-size: var(--text-base); line-height: var(--line-body); }
body[class] :is(button, input, select, textarea, h1, h2, h3, h4) { font-family: var(--font-ui); }
body.history-page { background: var(--bg-light); color: var(--text); }
body.rq-page, .auth-shell { background: var(--bg-light); }

/* One readable type scale for interface headings, labels and supporting text. */
body[class] :is(.stats-header h1, .auth-card h1, .history-intro h1, .rq-hero h1, .adm-bar h1) {
  font-family: var(--font-ui); font-size: var(--text-title); font-weight: var(--weight-heading);
  line-height: 1.25; letter-spacing: -.01em; color: var(--ink);
}
body[class] :is(.stat-chart h2, .prof-card h2, .net-box h3, .map-pop h3, .prof-name, .cal-subs h2, .cal-nav h2, .h-workbench-heading h2, .h-snapshot h2, .rq-side h2, .rq-card h2, .faq-h, .explore-guide h2) {
  font-family: var(--font-ui); font-size: var(--text-heading); font-weight: var(--weight-heading); line-height: 1.4; color: var(--ink);
}
body[class] :is(.prof-label, .tr-grid > label, .viz-field > label, .viz-field > legend, .cal-field > label, .cal-field > legend, .st-f, .rq-field, .h-focus-controls label, .auth-check, .viz-check, .cal-check) {
  font-size: var(--text-support); line-height: var(--line-body); font-weight: var(--weight-control); color: var(--ink);
}
body[class] :is(.auth-card p, .prof-card p:not(.prof-note), .rq-lead, .h-intro-copy, .faq-list p, .sug-kind-text strong):not(:where(.auth-note, .auth-status, .prof-note, .h-note)) { font-size: var(--text-base); line-height: var(--line-body); }
body[class] :is(.prof-note, .prof-years, .prof-count, .viz-hint, .cal-hint, .auth-note, .auth-status, .st-count, .h-note, .h-selection-meta, .h-chart-hint, .h-year-caption, #h-view-count, .rq-note, .rq-trust, .rq-steps, .rq-product, :where(.rq-cards li > span:last-child, .stat-card .l), .rq-field small, .rq-field em, .sug-kind-text small, .detail-years, .photo-view-caption) {
  font-size: var(--text-support); line-height: var(--line-body); color: var(--text-light);
}
body[class] :is(.h-eyebrow, .prof-h3, .cal-dow) { font-family: var(--font-ui); font-size: var(--text-caption); font-weight: var(--weight-control); letter-spacing: .06em; color: var(--ink-muted); }
body[class] :is(.h-counters .stat-card .v, #h-year-label) { font-family: var(--font-ui); font-weight: var(--weight-control); letter-spacing: -.01em; color: var(--ink); }
body[class] .stat-card .v { font-size: var(--text-title); }
body[class] #h-year-label { font-size: 2.25rem; }

body[class] .auth-status.error { color: var(--ui-danger); }
body[class] .auth-status.success { color: var(--ui-success); }

/* Aliases keep the same specificity so semantic and selected states can override the base. */
/* Standard controls. Photo handles, image tiles and the collapsed tree strip retain their own geometry. */
body[class] :is(button, .auth-submit, .nav-link, .nav-tree, .nav-invite, .prof-action, .detail-action, .cal-cta-btn, :where(.explore-views) a, .ui-button, :where(.prof-tabs, .ev-tabs) a):not(:where(.pho-ring, .pho-open, .gr-pick-btn, .jr-photo, .sug-kind, .stat-card, .detail-strip, .h-generation-title, .mem-photo-x, .gt-question-close, .gt-question-fold)) {
  min-height: var(--btn-h); padding: var(--btn-pad); border: 1px solid var(--hairline-strong); border-radius: var(--radius-control);
  font-family: var(--font-ui); font-size: var(--btn-font); font-weight: var(--weight-control); line-height: var(--line-control);
  color: var(--ink); background: var(--surface); box-shadow: none; text-decoration: none; vertical-align: middle; cursor: pointer; transform: none; transition: background-color var(--duration-control) ease, border-color var(--duration-control) ease, color var(--duration-control) ease, box-shadow var(--duration-control) ease;
}
body[class] :is(.auth-submit, .nav-link, .nav-tree, .nav-invite, .prof-action, .detail-action, .cal-cta-btn, :where(.explore-views) a, .ui-button, :where(.prof-tabs, .ev-tabs) a) { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); }
body[class] :is(.nav-group-items .nav-link, .nav-compact .nav-link, .prof-action, .detail-action) { justify-content: flex-start; }
body[class] :is(.auth-submit, .h-primary, .h-play-btn, .cal-btn-primary, .cal-cta-btn, .ui-button-primary) {
  background: var(--ui-primary); border-color: var(--ui-primary); color: var(--ui-primary-text);
}
body[class] :is(.auth-page .auth-submit, .rq-form .auth-submit, .inv-submit) { min-height: var(--btn-form-h); }
body[class] :is(button, .prof-action, .detail-action, .ui-button):hover:not(:disabled) { background: var(--hover-soft); border-color: var(--hairline-strong); }
body[class] :is(.auth-submit, .h-primary, .h-play-btn, .cal-btn-primary, .cal-cta-btn, .ui-button-primary):hover:not(:disabled) { background: var(--ui-primary-hover); border-color: var(--ui-primary-hover); transform: none; box-shadow: none; }

/* Quiet controls: navigation, toolbars, row actions and close buttons carry no border until hovered or selected. */
body[class] :is(.nav-link, .nav-group-toggle, .nav-tree, .nav-invite, .graph-zoom-btn, .h-icon-btn, .detail-close, .about-close, .adm-icon, .gt-question-close, .gt-question-fold, :where(.stats-header, .adm-bar, .chart-toolbar) :is(.logout-btn, [data-lang-toggle]), .adm-tab, .ev-tabs a, .prof-tabs a, .h-view-tabs button, .ui-button-quiet):not(:where(.pho-ring, .pho-open)) {
  border-color: transparent; background: transparent; box-shadow: none;
}
body[class] :is(.nav-link, .nav-group-toggle, .nav-tree, .nav-invite, .graph-zoom-btn, .h-icon-btn, .detail-close, .about-close, .adm-icon, .gt-question-close, .gt-question-fold, :where(.stats-header, .adm-bar, .chart-toolbar) :is(.logout-btn, [data-lang-toggle]), .adm-tab, .ev-tabs a, .prof-tabs a, .h-view-tabs button, .ui-button-quiet):hover:not(:disabled) {
  background: var(--hover-soft); border-color: transparent; color: var(--ink);
}
/* The compact (burger) menu is a list: its rows keep a full 44px whatever the pointer. */
body[class] .nav-compact .nav-link { min-height: 2.75rem; }
body[class] .nav-group.open > .nav-group-toggle { background: var(--hover-soft); border-color: transparent; }
body[class] :is(.prof-danger, .cal-danger, .sug-del, .photo-delete, .ui-button-danger) { color: var(--ui-danger); border-color: var(--hairline-strong); background: var(--surface); }
body[class] .adm-icon.danger { color: var(--ui-danger); border-color: transparent; }
body[class] :is(.prof-danger, .cal-danger, .sug-del, .photo-delete, .ui-button-danger, .adm-icon.danger):hover:not(:disabled) { background: #fdf4f3; border-color: #ecc9c6; }
body[class] :is(.zoom-toggle[aria-pressed="true"], .adm-tab[aria-selected="true"], .prop-chip.on, .prof-bday-tabs .logout-btn.active, .prof-tabs a.active, .ev-tabs a[aria-current="page"], .nav-link[aria-current="page"], .nav-tree[aria-current="page"], .explore-views a[aria-current="page"], .st-chip[aria-pressed="true"], .jr-type[aria-pressed="true"], .prop-chip[aria-pressed="true"], .h-view-tabs button[aria-selected="true"]) {
  background: var(--accent-soft); border-color: transparent; color: var(--accent);
}
body[class] :is(.jr-type, .st-chip, .prop-chip, .prof-tabs a, .ev-tabs a, .adm-tab, .h-view-tabs button):is([aria-pressed="true"], [aria-selected="true"], [aria-current="page"], .active, .on) { border-color: transparent; }
body[class] :is(.graph-zoom-btn, .h-icon-btn, .detail-close, .about-close) { min-width: var(--btn-h); width: var(--btn-h); min-height: var(--btn-h); height: var(--btn-h); padding: 0; font-size: 1.125rem; }
body[class] :is(.jr-type, .st-chip, .prop-chip, .cal-chipcheck > span, .prof-tabs a, .ev-tabs a, .gt-question-pill) { border-radius: 999px; }
body[class] :is(.ui-button-compact, .prof-table .logout-btn, .lk-small, .cal-card-btn, .prop-toggle, .h-generation-title, .mem-photo-x) {
  min-height: var(--btn-compact-h); font-size: var(--text-support); line-height: var(--line-control);
}
body[class] :is(button, input, select, textarea, h1, h2, h3, h4):disabled { cursor: not-allowed; }
body[class] button:disabled { opacity: .55; }

/* Inputs use the existing shared field tokens; 16px avoids involuntary zoom on iPhones. */
body[class] :is(.auth-input, .nav-search-input, .chart-search, .cal-sub-url, .viz-field input, .viz-field select, .cal-field input, .cal-field select, .st-f input, .st-f select, .tr-grid input, .tr-grid select, .tr-grid textarea):not(:where([type="checkbox"], [type="radio"], [type="range"], [type="hidden"], [type="file"])) {
  font-family: var(--font-ui); font-size: var(--field-font); font-weight: var(--weight-body); line-height: var(--line-control);
  min-height: var(--field-min-h); border: var(--field-border); border-radius: var(--field-radius); padding: var(--field-pad); color: var(--ink); background: var(--surface); box-shadow: none;
}
body[class] :is(.auth-input, .nav-search-input, .chart-search, .cal-sub-url, .viz-field input, .viz-field select, .cal-field input, .cal-field select, .st-f input, .st-f select, .tr-grid input, .tr-grid select, .tr-grid textarea):focus { border-color: var(--accent); box-shadow: var(--field-ring); outline: none; }
body[class] ::placeholder { color: #a39b92; }
body[class] :is(.viz-check, .cal-check, .auth-check, .h-smart) { min-height: var(--btn-h); align-items: center; }
body[class] :is(input[type="checkbox"], input[type="radio"]) { accent-color: var(--primary); }
body :is(a, button, summary, [tabindex]):focus-visible { outline: 2px solid var(--accent) !important; outline-offset: 2px; }
body[class] :is(.faq-list summary, .explore-guide > summary, .map-more > summary, .rq-more > summary, .prof-card > summary) { min-height: var(--btn-h); font-size: var(--text-base); line-height: var(--line-body); }

/* Shared card surfaces and spacing; reading forms and large charts have deliberate width roles. */
body[class] :is(.auth-card, .stat-chart, .stat-card, .net-box:where(:not(:empty)), .cal-board, .cal-subs, .rq-card, .h-focus-controls, .history-workbench, .h-summary-card, .h-snapshot, .h-moments-card, .map-selection, .explore-guide, .map-more, .cal-toolbar, .st-filters) {
  border: 1px solid var(--hairline); border-radius: var(--radius-card); background: var(--surface); box-shadow: none;
}
body[class] :is(.stat-chart, .stat-card, .net-box:where(:not(:empty)), .cal-board, .cal-subs, .rq-card, .h-focus-controls, .h-summary-card, .h-snapshot, .h-moments-card, .map-selection, .cal-toolbar, .st-filters) { padding: var(--space-6); }
body[class] .h-counters .stat-card { border: 0; padding: 0; background: transparent; box-shadow: none; }
body[class] .auth-card { padding: var(--space-8); max-width: 28rem; }
body[class] :is(.stats-main, .viz-main, .cal-main, .rq-main) { max-width: var(--content-wide); padding-left: var(--space-6); padding-right: var(--space-6); }
body[class] .ev-tabs-narrow { max-width: var(--content-reading); }
body[class] .prof-main { max-width: var(--content-reading); }
body[class] .history-main { max-width: var(--content-chart); padding-left: var(--space-6); padding-right: var(--space-6); }
body[class] :is(.stats-header, .chart-toolbar) { padding-left: var(--space-6); padding-right: var(--space-6); }
body[class] .ev-tabs { flex-wrap: wrap; }
body[class] dialog { border: 1px solid var(--border); border-radius: var(--radius-dialog); background: var(--bg-white); color: var(--text); box-shadow: var(--shadow-lg); max-width: calc(100vw - 2rem); max-height: calc(100dvh - 2rem); }
body[class] .leaflet-container { font-family: var(--font-ui); }
body[class] :is(.leaflet-control-zoom-in, .leaflet-control-zoom-out) { width: var(--btn-h); height: var(--btn-h); line-height: var(--btn-h); }
body[class] .leaflet-popup-close-button { width: var(--btn-h); height: var(--btn-h); line-height: var(--btn-h); font-size: 1.25rem; }
body[class] .nav-group-current > .nav-group-toggle { background: transparent; border-color: transparent; color: var(--accent); }
body[class] .nav-group-heading, body[class] .nav-account-heading { font-size: var(--text-base); }
body[class] .gt-question-close { width: var(--btn-h); height: var(--btn-h); top: .25rem; right: .25rem; }
body[class] .gt-question-fold { width: var(--btn-h); height: var(--btn-h); top: .25rem; right: 3.25rem; }
body[class] .gt-question-bubble .gt-question-title { padding-right: 6.25rem; }

/* Telegram's colours remain bound to its light/dark theme; type and control geometry are shared. */
body.tg-page { --border: var(--sep); --bg-white: var(--bg); --bg-light: var(--bg2); --primary: var(--link); --primary-dark: var(--link); --text-light: var(--hint); --ui-primary: var(--btn); --ui-primary-text: var(--btn-text); }
body.tg-page button { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
body.tg-page button.ghost { background: transparent; color: var(--link); border-color: var(--sep); }
@media (max-width: 600px) {
  body[class] :is(.stats-main, .viz-main, .cal-main, .history-main, .rq-main, .stats-header, .chart-toolbar) { padding-left: var(--space-3); padding-right: var(--space-3); }
  :root { --page-pad: var(--space-3); }
  body[class] .auth-card { padding: var(--space-6); }
  body[class] .h-focus-controls { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  body[class] :is(button, a, input, select, textarea) { transition: none !important; }
}

body[class] :is(.prof-dl, .prof-event, .prof-person, .rq-cards strong) { font-size: var(--text-base); line-height: var(--line-body); }
body[class] :is(.prof-table th, .prof-table td, .st-table, .stats-footer) { font-size: var(--text-support); }
body[class] .ui-button:hover:not(:disabled) { border-color: var(--primary); }
@media (max-width: 768px) {
  /* The fixed question clears the 44px details strip and the footer's standard control plus padding. */
  body.tree-page .gt-question-bubble { bottom: calc(44px + var(--btn-h) + var(--space-2) + var(--space-4) + 1px + env(safe-area-inset-bottom, 0px)); }
  body.tree-page .gt-question-bubble.gt-question-folded { bottom: calc(44px + var(--btn-h) + var(--space-2) + var(--space-3) + 1px + env(safe-area-inset-bottom, 0px)); }
  body.tree-page .detail-panel.collapsed .detail-close { top: 0; }
}
/* Long translated menu labels wrap inside their grid cell instead of widening the phone menu. */
body[class] .nav-group-items .nav-link { min-width: 0; }
body[class] .nav-group-items .nav-link > span:not([aria-hidden]) { min-width: 0; overflow-wrap: anywhere; }

body[class] .copy-link-btn.copied { color: var(--ui-success); border-color: var(--ui-success); }
body[class] :is(.inv-chip, .pho-open, .jr-photo, .gr-pick-btn) { border-radius: var(--radius-card); }
body[class] .inv-chip b { font-size: var(--text-base); }
body[class] .inv-chip span { font-size: var(--text-support); }
body[class] :is(.jr-name, .rq-book strong) { font-family: var(--font-ui); }

body[class] .net-box { font-size: var(--text-base); line-height: var(--line-body); }
body[class] :is(.map-canvas, .net-canvas, .cal-sub, .gt-photo-dialog) { border-radius: var(--radius-card); }
body[class] .gt-photo-dialog p { font-size: var(--text-support); line-height: var(--line-body); }

/* Tables read as lists: muted small headers, hairline rows, no boxes. */
body[class] :is(table) th { font-size: var(--text-support); font-weight: var(--weight-control); color: var(--ink-muted); border-bottom: 1px solid var(--hairline); }
body[class] :is(table) td { border-color: var(--hairline); }
body[class] :is(.adm-tabs, .ev-tabs, .prof-tabs) { gap: var(--space-1); }
body[class] :is(.stats-header, .chart-toolbar, .adm-bar) { background: var(--surface); border-bottom: 1px solid var(--hairline); box-shadow: none; }
/* The request page's closing band: a quiet tint instead of a dark block. */
body.rq-page .rq-heritage { background: var(--accent-soft); color: var(--ink); box-shadow: none; border-radius: var(--radius-card); }
body.rq-page .rq-heritage :is(h2, .rq-her-text, .rq-book, .rq-book strong) { color: var(--ink); }
body.rq-page .rq-heritage .rq-her-text { color: var(--ink-muted); }
body.rq-page .rq-chips li { background: var(--surface); border-color: var(--hairline); color: var(--ink); }

/* Under a finger every control and field grows to a 44px target; a mouse keeps the lighter 40px. */
@media (pointer: coarse), (max-width: 600px) {
  :root { --btn-h: 2.75rem; --btn-form-h: 3rem; --btn-compact-h: 2.25rem; }
}

/* Small cards inside a page stay flat like the large ones. */
body[class] :is(.rq-cards li, .rq-card, .prof-card, .inv-composer, .stat-card) { box-shadow: none; }

/* Interface icons: one set of line icons (icons/ui/*.svg, 24px grid, 2px stroke) drawn in the text colour. Emojis stay for content (announcement types, cards), never on controls. */
.gt-ico { display: inline-block; flex: none; width: 1.15em; height: 1.15em; vertical-align: -.2em; background: currentColor; -webkit-mask: center / contain no-repeat; mask: center / contain no-repeat; }
.gt-ico-ban { -webkit-mask-image: url('/icons/ui/ban.svg'); mask-image: url('/icons/ui/ban.svg'); }
.gt-ico-calendar { -webkit-mask-image: url('/icons/ui/calendar.svg'); mask-image: url('/icons/ui/calendar.svg'); }
.gt-ico-camera { -webkit-mask-image: url('/icons/ui/camera.svg'); mask-image: url('/icons/ui/camera.svg'); }
.gt-ico-copy { -webkit-mask-image: url('/icons/ui/copy.svg'); mask-image: url('/icons/ui/copy.svg'); }
.gt-ico-eye { -webkit-mask-image: url('/icons/ui/eye.svg'); mask-image: url('/icons/ui/eye.svg'); }
.gt-ico-key { -webkit-mask-image: url('/icons/ui/key.svg'); mask-image: url('/icons/ui/key.svg'); }
.gt-ico-link { -webkit-mask-image: url('/icons/ui/link.svg'); mask-image: url('/icons/ui/link.svg'); }
.gt-ico-lock { -webkit-mask-image: url('/icons/ui/lock.svg'); mask-image: url('/icons/ui/lock.svg'); }
.gt-ico-menu { -webkit-mask-image: url('/icons/ui/menu.svg'); mask-image: url('/icons/ui/menu.svg'); }
.gt-ico-pause { -webkit-mask-image: url('/icons/ui/pause.svg'); mask-image: url('/icons/ui/pause.svg'); }
.gt-ico-play { -webkit-mask-image: url('/icons/ui/play.svg'); mask-image: url('/icons/ui/play.svg'); }
.gt-ico-refresh { -webkit-mask-image: url('/icons/ui/refresh.svg'); mask-image: url('/icons/ui/refresh.svg'); }
.gt-ico-trash { -webkit-mask-image: url('/icons/ui/trash.svg'); mask-image: url('/icons/ui/trash.svg'); }
.gt-ico-tree { -webkit-mask-image: url('/icons/ui/tree.svg'); mask-image: url('/icons/ui/tree.svg'); }
.gt-ico-user { -webkit-mask-image: url('/icons/ui/user.svg'); mask-image: url('/icons/ui/user.svg'); }
.gt-ico-user-plus { -webkit-mask-image: url('/icons/ui/user-plus.svg'); mask-image: url('/icons/ui/user-plus.svg'); }
.gt-ico-users { -webkit-mask-image: url('/icons/ui/users.svg'); mask-image: url('/icons/ui/users.svg'); }
body[class] .adm-icon .gt-ico { width: 1.1rem; height: 1.1rem; }
.gt-ico-mail { -webkit-mask-image: url('/icons/mail.svg'); mask-image: url('/icons/mail.svg'); }
.gt-ico-share { -webkit-mask-image: url('/icons/share.svg'); mask-image: url('/icons/share.svg'); }
.gt-ico-check { -webkit-mask-image: url('/icons/ui/check.svg'); mask-image: url('/icons/ui/check.svg'); }
.gt-ico-x { -webkit-mask-image: url('/icons/ui/x.svg'); mask-image: url('/icons/ui/x.svg'); }
.gt-ico-undo { -webkit-mask-image: url('/icons/ui/undo.svg'); mask-image: url('/icons/ui/undo.svg'); }
body[class] .adm-icon.adm-ok { color: var(--ui-success); }
