/* ===========================================================================
   Menu / home hub — the app's entrance hall: greeting, the main sections as
   illustrated cards over a topographic-map backdrop, and a small action bar.
   Kept separate from the tracker's style.css so it stays light.
   Also loaded by seff.html / trials.html for its tokens and .menu-btn rows.
   Palette matches the login page: night (dark) is the base, html.light overrides.
   =========================================================================== */
:root {
  --bg: #0f1613;
  --surface: #172019;
  --border: #2a3530;
  --text: #e7ece7;
  --muted: #9aa8a0;
  --faint: #6d7a73;
  --accent: #7cc49b;
  --accent-ink: #0f1613;
  --accent-stop: #f08a7e;
  --tile-neutral: rgba(231, 236, 231, 0.08);
  --contour: rgba(124, 196, 155, 0.09);
  --serif: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
/* Light theme — the default; toggled by the theme button (class on <html>). */
html.light {
  --bg: #f5f2ea;
  --surface: #fffdf8;
  --border: #e2ddd0;
  --text: #1d2621;
  --muted: #5d6a62;
  --faint: #8a948d;
  --accent: #2f6b4f;
  --accent-ink: #ffffff;
  --accent-stop: #b4382c;
  --tile-neutral: rgba(29, 38, 33, 0.06);
  --contour: rgba(47, 107, 79, 0.11);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;          /* the hub is a fixed page; only its card area scrolls */
  overscroll-behavior: none;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* Topographic backdrop. */
.topo {
  position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0;
  fill: none; stroke: var(--contour); stroke-width: 1.2;
  pointer-events: none;
}

/* Page: top row · scrolling greeting + cards · action bar + copyright. */
.menu {
  position: relative; z-index: 1;
  height: 100dvh;
  height: var(--app-h, 100dvh);     /* installed app: real visible height (deskfix.js) */
  display: flex;
  flex-direction: column;
  max-width: 980px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + var(--nav-pad, 0px) + 10px);
}

.menu-top {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 44px;
}
.menu-brand { font-size: 0.85rem; font-weight: 650; letter-spacing: 0.02em; color: var(--muted); }
.menu-top-r { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.menu-user {
  display: inline-flex; align-items: center; gap: 7px;
  max-width: 46vw; height: 40px; padding: 0 14px 0 11px;
  border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 0.88rem; font-weight: 600;
}
.menu-user .ico {
  width: 18px; height: 18px; flex-shrink: 0;
  fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.menu-user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Greeting + cards. Scrolls on its own if the cards outgrow the screen. */
.menu-main {
  flex: 1; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  margin: 0 -4px; padding: 0 4px 8px;
}
.menu-hello { padding: 18px 2px 18px; }
.menu-date {
  margin: 0; font-size: 0.74rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent);
}
.menu-title {
  margin: 6px 0 6px;
  font-family: var(--serif); font-weight: 600;
  font-size: clamp(1.6rem, 7vw, 2.1rem); line-height: 1.12; letter-spacing: -0.01em;
}
.menu-sub { margin: 0; color: var(--muted); font-size: 0.94rem; line-height: 1.45; max-width: 34em; }

/* ---- cards ---- */
.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.card {
  --tile-bg: var(--tile-neutral); --tile-fg: var(--text); --hole: var(--surface);
  display: flex; flex-direction: column;
  min-width: 0;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.card:active { transform: scale(0.985); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (hover: hover) {
  .card:hover { transform: translateY(-2px); border-color: var(--faint); box-shadow: 0 14px 30px -18px rgba(0, 0, 0, 0.35); }
}
.card-feature, .card-wide { grid-column: 1 / -1; }
.card { position: relative; }

/* The illustrated top of a card, drawn in the card's own colour. */
.card-art {
  position: relative; display: block; flex: none;
  height: 88px;
  background: var(--tile-bg);
  color: var(--tile-fg);
}
.card-art svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; fill: currentColor; }
.card-art .line, .card-art .ring, .card-art .trail {
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.card-art .trail { stroke-width: 2.4; stroke-dasharray: 0.5 7; opacity: 0.6; }
.card-art .pin-hole { fill: var(--hole); }
@media (prefers-reduced-motion: no-preference) {
  .rotor { animation: spin 12s linear infinite; }
  .rotor.slow { animation-duration: 17s; }
  @keyframes spin { to { transform: rotate(360deg); } }
}

.card-foot {
  flex: 1;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 10px;
  padding: 12px 14px 14px;
}
.card-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.card-lbl { font-size: 1rem; font-weight: 650; line-height: 1.25; }
.card-hint { font-size: 0.8rem; color: var(--muted); line-height: 1.35; }
.card-go {
  flex: none;
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--tile-fg);
  transition: background 0.15s ease;
}
.card:hover .card-go { background: var(--tile-bg); }
/* Smaller cards: the arrow sits in the picture's corner so the text keeps the width. */
.card:not(.card-feature) .card-go {
  position: absolute; top: 10px; right: 10px;
  width: 28px; height: 28px;
  background: var(--surface); border-color: transparent;
}
.card-go .ico { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Featured "Start registration": the one filled card. */
.card-feature { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.card-feature .card-art { height: 124px; background: transparent; color: var(--accent-ink); }
.card-feature .card-lbl { font-family: var(--serif); font-size: 1.35rem; font-weight: 600; }
.card-feature .card-hint { color: var(--accent-ink); opacity: 0.78; }
.card-feature .card-go { border-color: currentColor; color: var(--accent-ink); opacity: 0.85; width: 40px; height: 40px; }
.card-feature .card-go .ico { width: 18px; height: 18px; }
.card-feature .pin-hole { fill: var(--accent); }
.card-feature:hover .card-go { background: rgba(255, 255, 255, 0.12); }

/* Card colours (plain rgba, not color-mix, for older Android WebViews). */
.card.act-data     { --tile-bg: rgba(141, 184, 214, 0.12); --tile-fg: #8db8d6; }
.card.act-trials   { --tile-bg: rgba(195, 165, 209, 0.12); --tile-fg: #c3a5d1; }
.card.act-location { --tile-bg: rgba(224, 168, 107, 0.12); --tile-fg: #e0a86b; }
html.light .card.act-data     { --tile-bg: rgba(47, 95, 127, 0.08);  --tile-fg: #2f5f7f; }
html.light .card.act-trials   { --tile-bg: rgba(109, 79, 124, 0.08); --tile-fg: #6d4f7c; }
html.light .card.act-location { --tile-bg: rgba(154, 90, 31, 0.08);  --tile-fg: #9a5a1f; }
.card-wide .card-art { height: 76px; }

/* A menu option is a ROW: icon tile · label + hint · chevron. */
.menu-btn {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 74px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}
.menu-btn:hover { border-color: var(--muted); }
.menu-btn:active { transform: scale(0.985); }
.menu-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* The main action is the one filled row. */
.menu-btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.menu-btn.primary .menu-btn-hint,
.menu-btn.primary .menu-btn-go { color: var(--accent-ink); opacity: 0.75; }

/* Icon tile. Its colour is the option's identity. Plain rgba (not color-mix)
   so it renders the same on the older Android WebViews the field phones run. */
.menu-btn-ico {
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; flex: none;
  border-radius: 13px;
  background: var(--tile-bg, var(--tile-neutral));
  color: var(--tile-fg, var(--text));
}
.menu-btn-ico .ico {
  width: 24px; height: 24px;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.menu-btn.act-start   { --tile-bg: rgba(255, 255, 255, 0.16); --tile-fg: var(--accent-ink); }
.menu-btn.act-data    { --tile-bg: rgba(141, 184, 214, 0.13); --tile-fg: #8db8d6; }
.menu-btn.act-trials  { --tile-bg: rgba(195, 165, 209, 0.13); --tile-fg: #c3a5d1; }
.menu-btn.act-location{ --tile-bg: rgba(224, 168, 107, 0.13); --tile-fg: #e0a86b; }
html:not(.light) .menu-btn.act-start { --tile-bg: rgba(15, 22, 19, 0.12); }
html.light .menu-btn.act-data     { --tile-bg: rgba(47, 95, 127, 0.09);  --tile-fg: #2f5f7f; }
html.light .menu-btn.act-trials   { --tile-bg: rgba(109, 79, 124, 0.09); --tile-fg: #6d4f7c; }
html.light .menu-btn.act-location { --tile-bg: rgba(154, 90, 31, 0.09);  --tile-fg: #9a5a1f; }

.menu-btn-txt { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.menu-btn-lbl { font-size: 1.04rem; font-weight: 650; line-height: 1.25; }
.menu-btn-hint { font-size: 0.8rem; color: var(--muted); line-height: 1.35; }
.menu-btn-go { display: flex; font-size: 1.4rem; line-height: 1; color: var(--faint); }
.menu-btn-go .ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- bottom action bar: round icon buttons on phones, labelled pills wider ---- */
.menu-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 12px;
}
.menu-bar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 44px; height: 44px; padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease;
}
.menu-bar-btn:hover { border-color: var(--faint); }
.menu-bar-btn:active { transform: scale(0.95); }
.menu-bar-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.menu-bar-btn .menu-bar-lbl { display: none; }   /* icon-only on phones */
.menu-bar-btn.logout { color: var(--accent-stop); }
.menu-bar-btn .ico { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#btn-menu-theme { width: 40px; height: 40px; flex: none; }
#btn-menu-theme .ico-sun { display: none; }
html.light #btn-menu-theme .ico-moon { display: none; }
html.light #btn-menu-theme .ico-sun { display: block; }

.menu-copy {
  flex: none;
  margin-top: 8px;
  text-align: center;
  color: var(--faint);
  font-size: 0.72rem;
}

/* Bigger screens: the featured card tall on the left; Data, Trials and Location
   stacked on the right as picture-beside-text rows. Labelled pills in the bar. */
@media (min-width: 760px) {
  .menu { padding: calc(var(--safe-top) + 20px) 32px calc(var(--safe-bottom) + 14px); }
  .menu-main { display: flex; flex-direction: column; justify-content: center; justify-content: safe center; }
  .menu-hello { padding: 26px 2px 24px; }
  .menu-title { font-size: 2.5rem; }
  .menu-sub { font-size: 1rem; }
  .cards { grid-template-columns: 1.25fr 1fr; gap: 14px; }
  .card-feature { grid-column: 1; grid-row: span 3; }
  .card-feature .card-art { height: auto; flex: 1; min-height: 180px; }
  .card-feature .card-foot { flex: none; padding: 18px 20px 20px; }
  .card-feature .card-lbl { font-size: 1.65rem; }
  .card-wide { grid-column: 2; }
  .card:not(.card-feature) { flex-direction: row; min-height: 104px; }
  .card:not(.card-feature) .card-art { width: 128px; height: auto; }
  .card:not(.card-feature) .card-foot { align-items: center; padding: 14px 16px; }
  .card:not(.card-feature) .card-go { position: static; width: 32px; height: 32px; background: none; border-color: var(--border); }
  .card-lbl { font-size: 1.06rem; }
  .card-hint { font-size: 0.84rem; }
  .menu-bar-btn { width: auto; height: 36px; padding: 0 13px; border-radius: 999px; }
  .menu-bar-btn .menu-bar-lbl { display: inline; }
  #btn-menu-theme { width: 40px; height: 40px; padding: 0; border-radius: 50%; }
}

/* Short screens: slimmer pictures first, then drop the sub-line. */
@media (max-height: 760px) and (max-width: 759px) {
  .menu-hello { padding: 10px 2px 14px; }
  .card-art { height: 68px; }
  .card-feature .card-art { height: 96px; }
  .card-wide .card-art { height: 60px; }
}
@media (max-height: 760px) and (min-width: 760px) {
  .menu-hello { padding: 12px 2px 16px; }
  .menu-title { font-size: 2.1rem; }
  .card:not(.card-feature) { min-height: 92px; }
}
@media (max-height: 620px) and (max-width: 759px) {
  .menu-sub { display: none; }
  .card-art { height: 52px; }
  .card-feature .card-art { height: 76px; }
  .card-wide .card-art { display: none; }
  .menu-copy { display: none; }
}

/* Language: globe + code; a small list drops down under it. */
.lang-wrap { position: relative; display: inline-flex; }
#btn-menu-lang { width: auto; height: 40px; padding: 0 12px 0 10px; border-radius: 999px; gap: 6px; }
#btn-menu-lang .ico { width: 17px; height: 17px; }
.lang-code { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.04em; display: inline !important; }
.lang-pop { position: absolute; top: calc(100% + 8px); right: 0; z-index: 50; min-width: 168px; padding: 6px;
  display: flex; flex-direction: column; gap: 2px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.45); }
.lang-opt { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; font: inherit; font-size: 0.92rem;
  color: var(--text); background: none; border: 0; border-radius: 11px; padding: 9px 10px; cursor: pointer; }
.lang-opt:hover { background: var(--tile-neutral); }
.lang-opt b { font-size: 0.72rem; letter-spacing: 0.05em; color: var(--muted); width: 22px; }
.lang-opt.on { color: var(--accent); font-weight: 650; }
.lang-opt.on b { color: var(--accent); }

/* Guided tour styles live in /tour.js; only the "?" button is styled here. */
#btn-menu-help { width: 40px; height: 40px; flex: none; }

.hidden { display: none !important; }
/* Narrow phones: four controls in the header — drop the brand words and let a
   long username shorten itself so the theme button never falls off the edge. */
@media (max-width: 420px) {
  .menu-brand { display: none; }
  .menu-top { justify-content: flex-end; }
  .menu-top-r { gap: 6px; }
  .menu-user { max-width: 38vw; padding: 0 12px 0 9px; }
  #btn-menu-lang { padding: 0 10px 0 9px; gap: 4px; }
}

/* Phones: slightly larger text everywhere (all sizes are rem-based). */
@media (max-width: 480px) { html { font-size: 17px; } }

/* 📝 Report button: red count of new support reports (only for those who receive them). */
.menu-bar-btn.report { position: relative; }
.menu-badge { position: absolute; top: -5px; right: -5px; min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 999px; background: #d64545; color: #fff; font-size: 0.68rem; font-weight: 800; line-height: 19px;
  text-align: center; box-shadow: 0 0 0 2px var(--bg); }
.menu-badge.hidden { display: none; }
