:root {
  --surface-page: #edf8f5;
  --surface-app: #f8fbf9;
  --surface-raised: #ffffff;
  --surface-soft: #eff8f5;
  --surface-glass: rgba(249, 252, 250, .94);
  --app-safe-top: max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px));
  --app-safe-right: max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px), var(--tg-content-safe-area-inset-right, 0px));
  --app-safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px), var(--tg-content-safe-area-inset-bottom, 0px));
  --app-safe-left: max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px), var(--tg-content-safe-area-inset-left, 0px));
}

html[data-theme="dark"] {
  --ink: #e8fbf8;
  --ink-soft: #b7d5d1;
  --muted: #8fb2ae;
  --line: rgba(175, 230, 223, .15);
  --line-strong: rgba(175, 230, 223, .25);
  --gold-light: #f7dfa0;
  --surface-page: #050d0f;
  --surface-app: #081719;
  --surface-raised: #10282a;
  --surface-soft: #0e2325;
  --surface-glass: rgba(8, 26, 28, .96);
}

html,
body {
  width: 100%;
  max-width: 100%;
  min-height: var(--app-viewport-height, 100dvh);
  overflow-x: hidden;
  background: var(--surface-page);
}

.app-stage {
  min-height: var(--app-viewport-height, 100dvh);
  padding-top: max(16px, var(--app-safe-top));
  padding-right: max(16px, var(--app-safe-right));
  padding-bottom: max(16px, var(--app-safe-bottom));
  padding-left: max(16px, var(--app-safe-left));
}

.app-frame {
  max-width: 100%;
  height: min(940px, calc(var(--app-viewport-height, 100dvh) - max(32px, var(--app-safe-top)) - max(32px, var(--app-safe-bottom))));
  background: var(--surface-app);
}

/* Telegram already provides the outer window: the product must fill it. */
html[data-telegram-entry="complete"] body:not(.web-mode):not(.demo-mode) .app-stage {
  min-height: var(--app-viewport-height, 100dvh);
  padding: 0;
  place-items: stretch;
}

html[data-telegram-entry="complete"] body:not(.web-mode):not(.demo-mode) .app-frame {
  width: 100%;
  max-width: none;
  height: var(--app-viewport-height, 100dvh);
  max-height: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.app-view,
.app-view > *,
.section-band,
.bottom-sheet,
.bottom-sheet > * {
  min-width: 0;
  max-width: 100%;
}

img,
svg,
canvas,
video {
  max-width: 100%;
}

.topbar,
.view-topbar {
  padding-top: max(18px, var(--app-safe-top));
  padding-right: max(22px, var(--app-safe-right));
  padding-left: max(22px, var(--app-safe-left));
}

.bottom-nav {
  padding-right: max(8px, var(--app-safe-right));
  padding-bottom: max(9px, var(--app-safe-bottom));
  padding-left: max(8px, var(--app-safe-left));
  background: var(--surface-glass);
}

.ai-fab {
  right: max(18px, var(--app-safe-right), calc((100vw - 480px) / 2 + 18px));
  bottom: calc(93px + var(--app-safe-bottom));
}

.bottom-sheet {
  width: min(480px, 100vw);
  max-height: calc(var(--app-viewport-height, 100dvh) - var(--app-safe-top));
  padding-right: max(22px, var(--app-safe-right));
  padding-bottom: max(20px, var(--app-safe-bottom));
  padding-left: max(22px, var(--app-safe-left));
}

body.keyboard-open .bottom-sheet.active {
  max-height: var(--app-viewport-height, 100dvh);
}

html[data-theme="dark"] body,
html[data-theme="dark"] .app-stage {
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -8%, rgba(41, 160, 153, .18), transparent 38%),
    linear-gradient(180deg, #0a1d20, #061214);
}

html[data-theme="dark"] .startup-shell {
  color: #dffcf8;
  background: #041719;
}

html[data-theme="dark"] .startup-shell__veil {
  background:
    linear-gradient(180deg, rgba(2, 14, 16, .08), rgba(2, 14, 16, .25) 42%, rgba(1, 10, 12, .96) 100%),
    linear-gradient(90deg, rgba(2, 17, 19, .7), rgba(2, 18, 20, .12) 76%);
}

html[data-theme="dark"] :is(
  .app-frame,
  .app-view,
  .section-band,
  .profile-actions,
  .personal-route,
  .display-settings,
  .body-lab,
  .avatar-capture,
  .avatar-route,
  .analysis-workspace,
  .web-access__panel
) {
  color: var(--ink);
  border-color: var(--line);
  background-color: var(--surface-raised);
}

html[data-theme="dark"] .living-hero {
  color: var(--ink);
  background: #071416;
}

html[data-profile-gender="unknown"] .living-hero__image,
html[data-profile-gender="unknown"] .profile-visual > img {
  display: block;
  object-fit: cover;
  object-position: 50% center;
  opacity: .96;
  filter: saturate(.9) contrast(1.08) drop-shadow(0 28px 60px rgba(10, 92, 91, .26));
}

html[data-profile-gender="unknown"] .living-hero__image {
  object-position: 58% center;
  opacity: .84;
}

html[data-profile-gender="unknown"] .profile-visual > img {
  opacity: .94;
}

html[data-profile-gender="unknown"] .living-hero {
  background:
    linear-gradient(90deg, rgba(250,255,253,.98), rgba(240,253,249,.72) 38%, rgba(5,63,65,.04) 70%),
    url("./assets/myepigen-day-morning.webp") 58% center / cover no-repeat,
    #dff5f1;
}

html[data-profile-gender="unknown"] .living-hero__veil {
  background:
    linear-gradient(90deg, rgba(249, 255, 253, .97) 0%, rgba(246, 255, 252, .76) 31%, rgba(221, 248, 243, .08) 67%),
    radial-gradient(circle at 69% 36%, rgba(116, 234, 220, .1), rgba(7, 82, 83, .24) 72%),
    linear-gradient(180deg, rgba(245, 255, 251, .04), rgba(227, 250, 246, .68));
}

html[data-profile-gender="unknown"] .profile-visual {
  background:
    linear-gradient(90deg, rgba(3,45,49,.9), rgba(5,77,76,.28) 68%, rgba(4,45,48,.06)),
    linear-gradient(0deg, rgba(2,31,35,.84), transparent 58%),
    url("./assets/startup-atlas-dna.webp") 58% center / cover no-repeat,
    #063638;
}

html[data-profile-state="empty"] .profile-visual {
  box-shadow: inset 0 -120px 140px rgba(2, 31, 35, .42);
}

html[data-profile-gender="unknown"] .profile-visual::before {
  content: "";
  position: absolute;
  z-index: 2;
  inset: 0;
  background:
    repeating-linear-gradient(180deg, transparent 0 15px, rgba(197, 255, 245, .035) 16px),
    radial-gradient(ellipse at 50% 42%, rgba(87, 230, 214, .12), transparent 54%);
  mix-blend-mode: screen;
  pointer-events: none;
}

/* First-run entry is driven by the shared Bot/Mini App questionnaire state. */
html[data-onboarding-state="required"] #profile > :not(.profile-onboarding) { display: none; }

.profile-onboarding[hidden] { display: none; }

.profile-onboarding {
  position: relative;
  display: flex;
  min-height: calc(var(--app-viewport-height, 100dvh) - 96px);
  padding: 28px 28px max(34px, var(--app-safe-bottom));
  flex-direction: column;
  overflow: hidden;
  color: #eefcf9;
  background: #063b3e;
}

.profile-onboarding::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(3,43,46,.08), rgba(3,38,41,.2) 42%, rgba(2,29,32,.94) 100%),
    linear-gradient(90deg, rgba(2,37,40,.68), rgba(2,37,40,.04) 78%);
}

.profile-onboarding > * { position: relative; z-index: 2; }
.profile-onboarding__art { position: absolute; z-index: 0; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 58% center; }
.profile-onboarding__brand { display: flex; align-items: center; gap: 10px; font: 800 0.875rem/1 system-ui, sans-serif; letter-spacing: .08em; }
.profile-onboarding__brand .brand__mark { width: 32px; height: 32px; }
.profile-onboarding > .eyebrow { margin-top: auto; color: #8ee8dd; }
.profile-onboarding h1 { max-width: 390px; margin: 12px 0 0; font: 750 clamp(3rem, calc(13vw * var(--app-font-scale)), 4.5rem)/.9 system-ui, sans-serif; letter-spacing: -.055em; }
.profile-onboarding > p { max-width: 390px; margin: 22px 0 0; color: rgba(231,250,246,.78); font: 500 1rem/1.5 system-ui, sans-serif; }
.profile-onboarding__hold { display: grid; max-width: 420px; margin-top: 18px; padding: 14px 15px; gap: 7px; border: 1px solid rgba(238,210,124,.3); border-radius: 15px; background: rgba(2,31,33,.68); box-shadow: 0 16px 34px rgba(0,18,20,.2); }
.profile-onboarding__hold[hidden] { display: none; }
.profile-onboarding__hold strong { color: #f1dda0; font: 750 0.875rem/1.25 system-ui, sans-serif; }
.profile-onboarding__hold span { color: rgba(235,251,248,.78); font: 500 0.75rem/1.45 system-ui, sans-serif; }
.profile-onboarding__hold a { width: fit-content; color: #9de9df; font: 700 0.75rem/1.3 system-ui, sans-serif; text-underline-offset: 3px; }
.profile-onboarding > small { display: flex; margin-top: 16px; align-items: center; gap: 8px; color: rgba(225,247,243,.64); font: 500 0.6875rem/1.4 system-ui, sans-serif; }
.profile-onboarding > small svg { width: 15px; }

.profile-onboarding__visual {
  position: absolute;
  z-index: 1;
  top: 68px;
  right: -65px;
  width: 310px;
  aspect-ratio: 1;
  opacity: .62;
}
.profile-onboarding__visual > i { position: absolute; inset: 14%; border: 1px solid rgba(174,248,238,.28); border-radius: 50%; animation: profile-orbit 12s linear infinite; }
.profile-onboarding__visual > i:nth-child(2) { inset: 25% 4%; transform: rotate(58deg); animation-duration: 16s; }
.profile-onboarding__visual > i:nth-child(3) { inset: 4% 29%; transform: rotate(-44deg); animation-duration: 20s; }
.profile-onboarding__visual > b { position: absolute; inset: 39%; border: 1px solid rgba(241,205,111,.6); border-radius: 50%; box-shadow: 0 0 52px rgba(101,230,214,.28); }
.profile-onboarding__visual span { position: absolute; inset: 0; }
.profile-onboarding__visual u { position: absolute; width: 7px; height: 7px; border-radius: 50%; background: #a6f1e8; box-shadow: 0 0 14px rgba(166,241,232,.8); }
.profile-onboarding__visual u:nth-child(1) { top: 17%; left: 32%; }.profile-onboarding__visual u:nth-child(2) { top: 38%; right: 12%; }.profile-onboarding__visual u:nth-child(3) { bottom: 20%; right: 29%; }.profile-onboarding__visual u:nth-child(4) { bottom: 12%; left: 27%; }.profile-onboarding__visual u:nth-child(5) { top: 44%; left: 7%; }.profile-onboarding__visual u:nth-child(6) { top: 28%; left: 56%; }.profile-onboarding__visual u:nth-child(7) { bottom: 35%; left: 49%; background: #eed27c; }
@keyframes profile-orbit { to { rotate: 360deg; } }

.profile-onboarding__steps { display: grid; margin-top: 24px; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.profile-onboarding__steps span { display: grid; min-height: 55px; padding: 9px 10px; align-content: space-between; border: 1px solid rgba(189,239,233,.2); border-radius: 12px; color: rgba(235,251,248,.82); background: rgba(7,45,48,.24); font: 650 0.6875rem/1 system-ui, sans-serif; }
.profile-onboarding__steps b { color: #e4c76e; font-size: 0.5625rem; letter-spacing: .09em; }
.profile-onboarding__action { display: flex; min-height: 56px; margin-top: 12px; padding: 0 18px; align-items: center; justify-content: space-between; border: 0; border-radius: 14px; color: #082d30; background: linear-gradient(110deg, #b6f3eb, #6bdad0); box-shadow: 0 18px 42px rgba(0,20,22,.25); font: 750 0.9375rem/1 system-ui, sans-serif; }
.profile-onboarding__action svg { width: 19px; }
.profile-onboarding__action:disabled { cursor: not-allowed; opacity: .66; filter: saturate(.45); box-shadow: none; }

.profile-health-hold {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: start;
  gap: 5px 11px;
  color: #604c1d;
  border-top: 1px solid rgba(179, 138, 61, .2);
  border-bottom: 1px solid rgba(179, 138, 61, .2);
  background: linear-gradient(115deg, rgba(255, 250, 231, .96), rgba(244, 250, 246, .94));
}
.profile-health-hold[hidden] { display: none; }
.profile-health-hold > svg { width: 21px; color: #9b752d; }
.profile-health-hold > span { display: grid; gap: 4px; }
.profile-health-hold strong { font: 750 0.875rem/1.25 var(--font-display); }
.profile-health-hold small { color: var(--ink-soft); font: 550 0.6875rem/1.45 var(--font-ui); }
.profile-health-hold a { grid-column: 2; width: fit-content; color: var(--aqua-deep); font: 700 0.6875rem/1.3 var(--font-ui); text-underline-offset: 3px; }
[data-health-questionnaire-locked="true"] { cursor: not-allowed !important; opacity: .52; filter: saturate(.45); }

html[data-theme="dark"] .profile-health-hold {
  color: #f0dda1;
  border-color: rgba(225, 194, 110, .2);
  background: linear-gradient(115deg, rgba(49, 42, 22, .92), rgba(13, 40, 40, .94));
}

.profile-start-blocks__grid { display: grid; gap: 9px; }
.profile-start-block { display: grid; width: 100%; min-height: 70px; padding: 13px 14px; gap: 11px; border: 1px solid rgba(29,125,120,.13); border-radius: 15px; color: var(--ink); background: linear-gradient(115deg, rgba(255,255,255,.96), rgba(235,248,244,.86)); text-align: left; }
.profile-start-block > span { display: grid; grid-template-columns: 28px minmax(0,1fr) auto; align-items: center; gap: 8px; }
.profile-start-block b { color: #b38a3d; font: 800 0.625rem/1 system-ui, sans-serif; }
.profile-start-block strong { overflow: hidden; font: 700 0.875rem/1.25 system-ui, sans-serif; text-overflow: ellipsis; white-space: nowrap; }
.profile-start-block small { color: #54726d; font: 700 0.6875rem/1 system-ui, sans-serif; }
.profile-start-block > i { height: 4px; overflow: hidden; border-radius: 999px; background: rgba(17,110,105,.1); }
.profile-start-block > i u { display: block; width: var(--progress); height: 100%; border-radius: inherit; background: linear-gradient(90deg, #178e86, #65d9cc); }
.profile-start-block.is-complete { border-color: rgba(27,151,142,.24); }

/* A single, always tappable mode selector in the conversation itself. */
.assistant-mode-dock > div:first-child { display: grid; grid-template-columns: auto minmax(0,1fr); align-items: baseline; column-gap: 8px; }
.assistant-mode-dock > div:first-child > span { color: #9a7432; font: 800 0.5625rem/1 system-ui, sans-serif; letter-spacing: .08em; text-transform: uppercase; }
.assistant-mode-dock > div:first-child > strong { color: #193c3b; font: 750 0.8125rem/1.2 system-ui, sans-serif; }
.assistant-mode-dock > div:first-child > small { grid-column: 1 / -1; margin-top: 3px; color: #71827b; font: 500 0.625rem/1.3 system-ui, sans-serif; }
.assistant-mode-dock__buttons { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 5px; padding: 4px; border: 1px solid rgba(64,86,76,.1); border-radius: 15px; background: rgba(235,241,237,.82); }
.assistant-mode-dock__buttons button { position: relative; display: flex; min-width: 0; min-height: 44px; padding: 0 11px; align-items: center; justify-content: center; gap: 7px; border: 0; border-radius: 11px; color: #63736b; background: transparent; font: 750 0.75rem/1 system-ui, sans-serif; }
.assistant-mode-dock__buttons button svg { width: 16px; height: 16px; }
.assistant-mode-dock__buttons button.active,
.assistant-mode-dock__buttons button[aria-pressed="true"] { color: #f7fffd; background: linear-gradient(135deg, #197b74, #105955); box-shadow: 0 7px 18px rgba(17,89,85,.2); }
.assistant-mode-dock__buttons button em { position: absolute; top: -4px; right: 4px; padding: 2px 5px; border: 1px solid rgba(183,141,65,.42); border-radius: 999px; color: #765a26; background: #f4e7c7; font: 800 0.4375rem/1 system-ui, sans-serif; font-style: normal; letter-spacing: .05em; text-transform: uppercase; }
.assistant-mode-dock__buttons button[aria-pressed="true"] em { color: #fff4d4; background: rgba(53,35,4,.3); }

html[data-theme="dark"] .profile-start-block { color: var(--ink); border-color: var(--line); background: rgba(17,43,45,.92); }
html[data-theme="dark"] .assistant-mode-dock > div:first-child > strong { color: var(--ink); }
html[data-theme="dark"] .assistant-mode-dock__buttons { border-color: var(--line); background: rgba(8,29,31,.9); }

@media (min-width: 720px) {
  body.web-mode .app-frame,
  body.demo-mode .app-frame {
    width: min(820px, calc(100vw - 40px));
  }

  .profile-onboarding { min-height: 760px; padding: 42px 48px; }
  .profile-onboarding__visual { width: 430px; right: -20px; }
  .profile-start-blocks__grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

/* Telegram Desktop may expose a very wide viewport. Keep the product at a
   readable app width while preserving the native full-height container. */
@media (min-width: 900px) {
  html[data-telegram-entry="complete"] body:not(.web-mode):not(.demo-mode) .app-stage {
    padding: 12px max(18px, var(--app-safe-right)) max(12px, var(--app-safe-bottom)) max(18px, var(--app-safe-left));
    place-items: center;
    background:
      radial-gradient(circle at 50% 0%, rgba(111, 224, 211, .16), transparent 42%),
      var(--surface-page);
  }

  html[data-telegram-entry="complete"] body:not(.web-mode):not(.demo-mode) .app-frame {
    width: min(820px, calc(100vw - 36px));
    max-width: 820px;
    height: calc(var(--app-viewport-height, 100dvh) - 24px);
    max-height: calc(var(--app-viewport-height, 100dvh) - 24px);
    border: 1px solid rgba(255,255,255,.82);
    border-radius: 26px;
    box-shadow: 0 28px 90px rgba(19,72,72,.18);
  }

  html[data-theme="dark"][data-telegram-entry="complete"] body:not(.web-mode):not(.demo-mode) .app-frame {
    border-color: rgba(133,225,214,.14);
    box-shadow: 0 30px 100px rgba(0,0,0,.48);
  }
}

html[data-font-preset="large"] .bottom-nav span,
html[data-font-preset="maximum"] .bottom-nav span {
  display: -webkit-box;
  max-width: 100%;
  min-height: 2.1em;
  overflow: hidden;
  overflow-wrap: anywhere;
  line-height: 1.05;
  text-overflow: clip;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

@media (max-width: 520px) {
  .bottom-nav {
    align-items: stretch;
  }

  .bottom-nav button {
    height: auto;
    min-width: 0;
    overflow: hidden;
    padding-inline: 0;
  }

  .bottom-nav span,
  html[data-font-preset="large"] .bottom-nav span,
  html[data-font-preset="maximum"] .bottom-nav span {
    display: block;
    width: 100%;
    min-height: 0;
    overflow: visible;
    overflow-wrap: anywhere;
    line-height: 1.05;
    text-align: center;
    text-overflow: clip;
    white-space: normal;
    -webkit-box-orient: initial;
    -webkit-line-clamp: unset;
  }
}

@media (prefers-reduced-motion: reduce) {
  .profile-onboarding__visual > i { animation: none; }
}

:is(
  .profile-onboarding,
  .profile-start-block,
  .assistant-mode-dock,
  .assistant-mode-dock button
) {
  font-family: var(--font-ui) !important;
}

:is(
  .profile-onboarding__brand,
  .profile-onboarding h1,
  .profile-start-block strong,
  .assistant-mode-dock > div:first-child > strong
) {
  font-family: var(--font-display) !important;
}

html[data-profile-gender="unknown"] .profile-visual__veil {
  z-index: 2;
  background:
    linear-gradient(180deg, rgba(3, 36, 39, .04) 12%, rgba(3, 35, 38, .18) 55%, rgba(2, 29, 32, .86)),
    radial-gradient(circle at 50% 36%, transparent 0 30%, rgba(3, 43, 46, .2) 72%);
}

html[data-theme="light"] .living-hero__image,
html[data-theme="light"] .profile-visual > img {
  filter: saturate(.9) brightness(1.02) contrast(1.02);
}

html[data-theme="dark"] .living-hero__image,
html[data-theme="dark"] .profile-visual > img {
  filter: saturate(.86) brightness(.72) contrast(1.02);
}

html[data-theme="dark"] .living-hero,
html[data-theme="dark"][data-profile-gender="unknown"] .living-hero {
  background:
    linear-gradient(90deg, rgba(4, 15, 18, .98) 0%, rgba(5, 24, 29, .82) 38%, rgba(4, 29, 39, .08) 72%),
    url("./assets/myepigen-day-night.webp") 58% center / cover no-repeat,
    #06171d;
}

html[data-theme="dark"] .living-hero__veil {
  background:
    linear-gradient(90deg, rgba(5, 18, 20, .9) 0%, rgba(7, 24, 26, .62) 38%, rgba(7, 20, 22, .08) 74%),
    linear-gradient(180deg, rgba(6, 20, 22, .1), rgba(5, 16, 18, .72));
}

html[data-theme="dark"] .living-hero::after {
  background: linear-gradient(transparent, rgba(8, 23, 25, .84) 72%, var(--surface-app));
}

html[data-theme="dark"] :is(.simple-header, .analysis-header) {
  color: var(--ink);
  border-color: var(--line);
  background:
    linear-gradient(155deg, rgba(7, 24, 26, .96), rgba(12, 39, 40, .9)),
    url("./assets/myepigen-atlas-hero.png") center / cover;
  background-blend-mode: normal, soft-light;
}

html[data-theme="dark"] :is(.calendar-band, .mode-switch, .training-card, .profile-fact-grid article) {
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface-raised);
}

.profile-fact-grid .profile-fact-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(15, 121, 115, .12);
  border-radius: 22px;
  background: linear-gradient(145deg, rgba(255, 255, 255, .98), rgba(239, 250, 247, .92));
  box-shadow: 0 16px 36px rgba(24, 78, 74, .07);
}
.profile-fact-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: #16a39a;
}
.profile-fact-card--lime::before { background: #9dbf43; }
.profile-fact-card--violet::before { background: #8a78c7; }
.profile-fact-card--sun::before { background: #e2af3d; }
.profile-fact-card--coral::before { background: #dd8068; }
.profile-fact-card > summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: center;
  gap: 14px;
  min-height: 88px;
  padding: 18px 18px 18px 22px;
  cursor: pointer;
  list-style: none;
}
.profile-fact-card > summary::-webkit-details-marker { display: none; }
.profile-fact-card > summary > span:first-child { display: grid; min-width: 0; gap: 5px; }
.profile-fact-card > summary small { color: #168f88; font-size: .68rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.profile-fact-card > summary strong { min-width: 0; color: #143f3c; font-size: 1rem; line-height: 1.25; overflow-wrap: break-word; }
.profile-fact-card__chevron {
  position: relative;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(20, 120, 113, .16);
  border-radius: 50%;
  background: rgba(229, 248, 244, .86);
}
.profile-fact-card__chevron::before {
  content: "";
  position: absolute;
  top: 9px;
  left: 10px;
  width: 8px;
  height: 8px;
  border-right: 2px solid #168f88;
  border-bottom: 2px solid #168f88;
  transform: rotate(45deg);
  transition: transform .22s ease, top .22s ease;
}
.profile-fact-card[open] .profile-fact-card__chevron::before { top: 12px; transform: rotate(225deg); }
.profile-fact-card dl { display: grid; gap: 8px; margin: 0; padding: 0 18px 12px 22px; }
.profile-fact-card dl > div { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding-top: 8px; border-top: 1px solid rgba(20, 63, 60, .08); }
.profile-fact-card dt { color: #748481; font-size: .78rem; }
.profile-fact-card dd { margin: 0; color: #173f3c; font-size: .82rem; font-weight: 750; text-align: right; }
.profile-card-collapse,
.profile-collapse-action {
  width: 44px;
  height: 36px;
  display: grid;
  place-items: center;
  margin: 4px auto 14px;
  color: #168f88;
  border: 1px solid rgba(20, 120, 113, .14);
  border-radius: 999px;
  background: rgba(230, 248, 245, .9);
}
.profile-card-collapse::before,
.profile-collapse-action::before {
  content: "";
  width: 9px;
  height: 9px;
  border-top: 2px solid currentColor;
  border-left: 2px solid currentColor;
  transform: translateY(2px) rotate(45deg);
}
.profile-collapse-action > svg { display: none; }
.profile-facts.is-empty .profile-fact-card:not(:first-child) { opacity: .72; }

.profile-section-disclosure {
  overflow: hidden;
}
.profile-section-disclosure > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 74px;
  cursor: pointer;
  list-style: none;
}
.profile-section-disclosure > summary::-webkit-details-marker { display: none; }
.profile-section-disclosure__summary > span:first-child { display: grid; min-width: 0; gap: 5px; }
.profile-section-disclosure__summary > span:first-child > strong { color: var(--ink); font-family: var(--font-display); font-size: 1.35rem; line-height: 1.12; }
.profile-section-disclosure__summary > svg,
.profile-section-disclosure__score > svg { width: 22px; height: 22px; flex: 0 0 auto; color: var(--aqua-deep); transition: transform .22s ease; }
.profile-section-disclosure[open] > summary > svg,
.profile-section-disclosure[open] .profile-section-disclosure__score > svg { transform: rotate(180deg); }
.profile-section-disclosure__score { display: flex; align-items: center; gap: 12px; }
.profile-section-disclosure__body { padding-top: 4px; }
.profile-section-link {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  padding: 12px 0;
  color: var(--aqua-deep);
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  font: inherit;
  font-weight: 750;
}
.profile-section-link > svg { width: 18px; height: 18px; }

.epigen-feature-settings > p {
  margin: 0 0 16px;
  color: var(--ink-soft);
  line-height: 1.55;
}
.epigen-feature-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 0;
  border-top: 1px solid var(--line);
}
.epigen-feature-setting > span { min-width: 0; display: grid; grid-template-columns: 34px minmax(0, 1fr); column-gap: 11px; align-items: center; }
.epigen-feature-setting > span > svg { grid-row: 1 / 3; width: 34px; height: 34px; padding: 8px; color: var(--aqua-deep); border-radius: 50%; background: var(--aqua-pale); }
.epigen-feature-setting b { color: var(--ink); font-size: .92rem; }
.epigen-feature-setting small { color: var(--ink-soft); font-size: .7rem; line-height: 1.35; }
.profile-settings-actions { margin-top: 0; }

html[data-theme="dark"] .profile-fact-card__chevron,
html[data-theme="dark"] :is(.profile-card-collapse, .profile-collapse-action) {
  color: #72ddd1;
  border-color: rgba(114, 221, 209, .2);
  background: rgba(24, 71, 70, .72);
}
html[data-theme="dark"] .profile-fact-grid .profile-fact-card { background: var(--surface-raised); }
html[data-theme="dark"] .profile-fact-card > summary small { color: #72ddd1; }
html[data-theme="dark"] .profile-fact-card > summary strong,
html[data-theme="dark"] .profile-fact-card dd { color: var(--ink); }
html[data-theme="dark"] .profile-fact-card dt { color: var(--ink-soft); }

@media (max-width: 720px) {
  .profile-fact-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; border: 0; background: transparent; }
  .profile-fact-grid .profile-fact-card { width: 100%; }
}

html[data-theme="dark"] .training-card.featured {
  border-color: rgba(67, 217, 206, .3);
  background: linear-gradient(135deg, #123032, #0b2426);
}

html[data-theme="dark"] .mode-switch button.active {
  color: #05201f;
  background: var(--aqua);
}

html[data-theme="dark"] :is(
  .tracker,
  .vital-item,
  .day,
  .profile-fact-grid > *,
  .library-result-card,
  .food-result,
  .nutrient-result,
  .gene-card,
  .upload-action,
  .device-import,
  .questionnaire-form,
  .avatar-profile-fields > label,
  .avatar-gender,
  .analysis-field
) {
  color: var(--ink);
  border-color: var(--line);
  background-color: rgba(18, 43, 45, .9);
}

html[data-theme="dark"] .questionnaire-field {
  color: var(--ink);
  border-color: rgba(126, 221, 211, .18);
  background: rgba(10, 31, 33, .96);
}

html[data-theme="dark"] .questionnaire-choice-grid label > span {
  color: #d8e8e5;
  border-color: rgba(126, 221, 211, .22);
  background: #102b2d;
  font-size: max(0.625rem, .72em);
}

html[data-theme="dark"] .questionnaire-choice-grid input:checked + span {
  color: #f5fffd;
  border-color: rgba(67, 217, 206, .68);
  background: #174446;
  box-shadow: inset 3px 0 #43d9ce;
}

html[data-theme="dark"] .questionnaire-value-field {
  color: var(--ink);
  border-color: rgba(126, 221, 211, .24);
  background: #0d1e20;
}

html[data-theme="dark"] .questionnaire-value-field :is(input, textarea),
html[data-theme="dark"] .questionnaire-value-field b {
  color: var(--ink);
}

html[data-theme="dark"] .questionnaire-safety {
  color: #ffd8cf;
  border-color: rgba(255, 146, 123, .3);
  background: rgba(104, 43, 36, .44);
}

html[data-theme="dark"] .tracker.done {
  border-color: rgba(67, 217, 206, .32);
  background-color: rgba(17, 53, 54, .94);
  background-image: none;
}

html[data-theme="dark"] :is(.avatar-studio-view, .avatar-studio-hero) {
  --avatar-stage-bg: #081719;
  color: var(--ink);
  background: linear-gradient(180deg, #0b1d1f 0%, #10282a 62%, #081719 100%);
}

html[data-theme="dark"] .avatar-body-stage {
  background: #071416;
}

html[data-theme="dark"] .avatar-body-stage::before {
  background:
    linear-gradient(90deg, rgba(5, 16, 18, .72), transparent 20%, transparent 80%, rgba(5, 16, 18, .72)),
    linear-gradient(180deg, rgba(5, 16, 18, .08) 48%, rgba(2, 12, 14, .74));
}

html[data-theme="dark"] :is(
  .bottom-nav,
  .bottom-sheet,
  .assistant-composer,
  .assistant-discussions,
  .chat-input,
  .library-module-search,
  .library-module-filters select
) {
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface-glass);
}

html[data-theme="dark"] :is(.assistant-message, .assistant-mode-dock, .assistant-mode-tabs, .assistant-empty-prompts button, .assistant-input-tools button) {
  color: var(--ink);
  border-color: var(--line);
  background: rgba(19, 45, 47, .88);
}

html[data-theme="dark"] :is(.assistant-empty-state strong, .assistant-empty-state p) { color: var(--ink-soft); }
html[data-theme="dark"] .user-message { color: #effffd; background: linear-gradient(135deg, #145d5a, #0d4443); }
html[data-theme="dark"] .analysis-field svg { background: #102b2d; }
html[data-theme="dark"] .avatar-gender button.active { color: #05201f; background: var(--aqua); }
html[data-theme="dark"] .sheet-handle { background: rgba(126, 221, 211, .25); }
html[data-theme="dark"] .bottom-nav { box-shadow: 0 -16px 36px rgba(0, 0, 0, .32); }
html[data-theme="dark"] .ai-nav__mark {
  color: #effffd;
  background:
    radial-gradient(circle at 32% 27%, rgba(255,255,255,.92) 0 5%, transparent 19%),
    radial-gradient(circle at 68% 69%, rgba(82,222,211,.94), transparent 38%),
    conic-gradient(from 210deg, #071f25, #229f9d, #75e6db, #6653bb, #071f25);
}

@media (max-width: 720px) {
  #miniapp-hero-avatar {
    right: -14%;
    width: 86%;
    opacity: .82;
  }
}

html[data-theme="dark"] :is(.topbar__action.icon-button, .twin-status, .hero-score) {
  color: var(--ink);
  border-color: rgba(90, 213, 202, .24);
  background: rgba(10, 32, 34, .84);
  box-shadow: 0 16px 42px rgba(0, 0, 0, .28);
}

html[data-theme="dark"] :is(.hero-score__ring, .focus-orbit, .profile-score-ring)::before {
  background: #102123;
}

html[data-theme="dark"] :is(.health-wheel__center, .audit-wheel-compact__center) {
  color: var(--ink);
  border-color: rgba(90, 213, 202, .2);
  background: rgba(10, 31, 33, .96);
}

html[data-theme="dark"] .goal-date {
  color: #f0d681;
  border-color: rgba(224, 185, 83, .28);
  background: rgba(91, 68, 20, .42);
}

html[data-theme="dark"] .micro-rating { color: #70ddd3; }

html[data-theme="dark"] .library-search {
  color: var(--ink);
  border-color: var(--line);
  background: rgba(15, 39, 41, .94);
}

html[data-theme="dark"] .library-search input { background: transparent; }

html[data-theme="dark"] .atlas-grid { background: #071416; }
html[data-theme="dark"] .atlas-tile { background: #10292b; }

html[data-theme="dark"] .library-category-list > button {
  color: var(--ink-soft);
  border-color: var(--line);
  background: rgba(17, 42, 44, .9);
}

html[data-theme="dark"] .library-category-list > button.active {
  color: #05201f;
  border-color: rgba(85, 224, 213, .78);
  background: #55e0d5;
}

html[data-theme="dark"] :is(.library-result-card > svg, .library-empty > svg) {
  color: #71e2d8;
  background: rgba(44, 169, 159, .18);
}

html[data-theme="dark"] .library-result-card > b {
  color: #8ce8df;
  border-color: rgba(85, 224, 213, .24);
  background: rgba(32, 116, 111, .24);
}

html[data-theme="dark"] .library-detail-summary {
  color: var(--ink);
  background: rgba(104, 77, 20, .34);
}

html[data-theme="dark"] :is(.profile-visual, .movement-hero, .system-hero) {
  background-color: #071416;
}

.food-input-tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.food-input-tool {
  min-width: 0;
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--ink);
  background: rgba(255, 255, 255, .78);
  cursor: pointer;
}

.food-input-tool > input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.food-input-tool > svg { width: 22px; color: var(--aqua-deep); flex: 0 0 auto; }
.food-input-tool > span { min-width: 0; display: grid; gap: 3px; text-align: left; }
.food-input-tool b { font: 750 0.8125rem/1.2 var(--font-display); }
.food-input-tool small { color: var(--ink-soft); font: 600 0.6875rem/1.25 var(--font-ui); }
.food-input-tool.is-recording { border-color: #e16d67; box-shadow: 0 0 0 3px rgba(225, 109, 103, .12); }

.food-photo-preview {
  min-width: 0;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--white);
}

.food-photo-preview[hidden] { display: none; }
.food-photo-preview img { width: 54px; height: 54px; object-fit: cover; border-radius: 10px; }
.food-photo-preview > span { min-width: 0; display: grid; gap: 3px; }
.food-photo-preview b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.food-photo-preview small { color: var(--ink-soft); }
.food-photo-preview button { width: 36px; height: 36px; border: 0; border-radius: 50%; color: var(--ink); background: var(--aqua-pale); }

.food-recognize-text {
  width: 100%; min-height: 54px; display: flex; align-items: center; gap: 12px;
  margin-top: 10px; padding: 11px 14px; color: var(--ink); text-align: left;
  border: 1px solid rgba(18, 167, 158, .26); border-radius: 14px;
  background: linear-gradient(135deg, rgba(229, 249, 246, .96), rgba(255, 255, 255, .95));
}
.food-recognize-text > svg { width: 22px; color: var(--aqua-deep); flex: 0 0 auto; }
.food-recognize-text > span { display: grid; gap: 2px; }
.food-recognize-text b { font: 750 0.8125rem/1.2 var(--font-display); }
.food-recognize-text small { color: var(--ink-soft); font: 600 0.6875rem/1.3 var(--font-ui); }
.food-log-form.is-recognizing .food-recognize-text > svg { animation: food-recognition-pulse 1s ease-in-out infinite; }
.food-log-form.is-health-data-locked :is(.food-input-tool, .food-recognize-text, .form-grid, .primary-action) {
  opacity: .58;
  filter: saturate(.5);
}
.food-log-form.is-health-data-locked :is(button, input, textarea):disabled { cursor: not-allowed; }

.food-recognition-review {
  margin-top: 12px; padding: 14px; border: 1px solid rgba(18, 167, 158, .22);
  border-radius: 16px; background: rgba(242, 251, 249, .94);
  box-shadow: 0 14px 36px rgba(5, 68, 65, .07);
}
.food-recognition-review[hidden] { display: none; }
.food-recognition-review > header { display: grid; gap: 3px; margin-bottom: 10px; }
.food-recognition-review > header span { color: var(--aqua-deep); font: 800 0.75rem/1.2 var(--font-display); text-transform: uppercase; letter-spacing: .05em; }
.food-recognition-review > header small { color: var(--ink-soft); font: 600 0.625rem/1.35 var(--font-ui); }
.food-recognition-review > p { display: flex; gap: 7px; margin: 10px 0 0; color: var(--ink-soft); font: 600 0.5625rem/1.45 var(--font-ui); }
.food-recognition-review > p svg { width: 15px; color: var(--aqua-deep); flex: 0 0 auto; }
.food-recognition-item {
  display: grid; grid-template-columns: minmax(0, 1fr) 82px 32px; align-items: end; gap: 8px;
  padding: 10px 0; border-top: 1px solid rgba(5, 68, 65, .09);
}
.food-recognition-item > label:first-child { min-width: 0; display: grid; gap: 3px; }
.food-recognition-item small { color: var(--aqua-deep); font: 700 0.5625rem/1.2 var(--font-ui); }
.food-recognition-item.is-uncertain small { color: #a16b14; }
.food-recognition-item input { min-width: 0; width: 100%; padding: 8px 9px; color: var(--ink); border: 1px solid var(--line); border-radius: 9px; outline: 0; background: rgba(255,255,255,.92); font: 700 0.75rem/1.2 var(--font-ui); }
.food-recognition-item input:focus { border-color: var(--aqua); box-shadow: 0 0 0 3px rgba(18,167,158,.1); }
.food-recognition-amount { display: flex; align-items: center; gap: 4px; }
.food-recognition-amount span { color: var(--ink-soft); font: 700 0.625rem/1 var(--font-ui); }
.food-recognition-item > button { width: 32px; height: 34px; border: 0; border-radius: 9px; color: var(--ink-soft); background: rgba(5,68,65,.07); font-size: 20px; line-height: 1; }

@keyframes food-recognition-pulse { 50% { transform: scale(.86); opacity: .55; } }

html[data-theme="dark"] :is(.food-input-tool, .food-photo-preview, .food-recognize-text, .food-recognition-review) {
  color: var(--ink);
  border-color: var(--line);
  background: rgba(15, 39, 41, .92);
}

html[data-theme="dark"] .food-macro-grid label {
  color: var(--ink);
  border-color: var(--line);
  background: rgba(15, 39, 41, .92);
}

html[data-theme="dark"] .food-macro-grid input {
  border-color: transparent;
  background: transparent;
}

html[data-theme="dark"] .quick-log-submit {
  color: #042426;
  background: #63ded5;
}

@media (max-width: 360px) {
  .food-input-tools { grid-template-columns: 1fr; }
}

html[data-theme="dark"] input,
html[data-theme="dark"] textarea,
html[data-theme="dark"] select {
  color: var(--ink);
  border-color: var(--line-strong);
  background-color: var(--surface-soft);
}

html[data-theme="dark"] .myepigen-pilot-gate,
html[data-theme="dark"] .myepigen-pilot-gate__panel {
  color: var(--ink) !important;
  border-color: var(--line) !important;
  background: #081719 !important;
}

@media (max-width: 560px) {
  .app-stage { padding: 0; }

  .app-frame {
    width: 100%;
    height: var(--app-viewport-height, 100dvh);
    max-height: var(--app-viewport-height, 100dvh);
    border: 0;
    border-radius: 0;
  }

  .app-view {
    padding-right: var(--app-safe-right);
    padding-left: var(--app-safe-left);
  }

  .living-hero,
  .simple-header,
  .avatar-studio-hero,
  .movement-hero,
  .system-hero {
    margin-right: calc(var(--app-safe-right) * -1);
    margin-left: calc(var(--app-safe-left) * -1);
  }

  .bottom-sheet,
  .assistant-sheet.active,
  .assistant-sheet.is-expanded {
    width: 100vw !important;
    height: min(var(--app-viewport-height, 100dvh), 940px);
    max-height: var(--app-viewport-height, 100dvh);
  }

  .assistant-sheet.active {
    inset: auto 0 0 !important;
    margin: 0 !important;
    transform: none !important;
  }

  body.keyboard-open .assistant-sheet.active {
    height: var(--app-viewport-height, 100dvh);
    border-radius: 0;
  }

  .bottom-nav button,
  .assistant-input-tools button,
  .assistant-empty-prompts button {
    min-width: 0;
  }
}

@media (max-width: 360px) {
  .topbar,
  .view-topbar,
  .simple-header,
  .avatar-studio-copy,
  .section-band {
    padding-right: max(14px, var(--app-safe-right));
    padding-left: max(14px, var(--app-safe-left));
  }

  .avatar-profile-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .avatar-gender { min-height: 58px; }
  .body-range-scale i { font-size: 0.4375rem; }
  .training-card { grid-template-columns: 78px minmax(0, 1fr) auto; }
  .training-card > img { width: 78px; height: 78px; }
  .bottom-nav { padding-right: max(2px, var(--app-safe-right)); padding-left: max(2px, var(--app-safe-left)); }
  .ai-nav__mark { width: 34px; height: 34px; flex-basis: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  .bottom-sheet.active { animation: none; transform: translate(-50%, 0); }
}
/* Same-origin legal texts stay inside MyEpigen instead of opening Telegram files or browser tabs. */
.legal-document-open {
  overflow: hidden;
}

.legal-document-viewer {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: grid;
  grid-template-rows: auto 1fr;
  background: #f7faf8;
  color: #12373a;
}

.legal-document-viewer[hidden] {
  display: none;
}

.legal-document-viewer__head {
  min-height: 64px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid rgba(50, 139, 136, 0.18);
  background: rgba(247, 250, 248, 0.96);
}

.legal-document-viewer__head button {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid rgba(50, 139, 136, 0.28);
  border-radius: 14px;
  background: #fff;
  color: #0b7773;
  font: inherit;
  font-weight: 700;
}

.legal-document-viewer__head strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.94rem;
}

.legal-document-viewer iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.legal-document-viewer__loading {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  padding: 12px 18px;
  border-radius: 999px;
  background: #e8f4f1;
  color: #477174;
  font-size: 0.9rem;
}

.health-pep__notice {
  margin: 0;
  padding: 14px 16px;
  border-radius: 14px;
  background: #e8f4f1;
  color: #355f62;
  line-height: 1.45;
}
