html:has(.profile-dialog[open]) { overflow: hidden; }
dialog.profile-dialog[open] {
  --profile-edge: clamp(.85rem, 3vw, 1.5rem);
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  box-sizing: border-box;
  inline-size: 100%;
  block-size: 100vh;
  block-size: 100dvh;
  max-inline-size: none;
  max-block-size: none;
  margin: 0;
  padding: env(safe-area-inset-top) max(var(--profile-edge), env(safe-area-inset-right)) env(safe-area-inset-bottom) max(var(--profile-edge), env(safe-area-inset-left));
  border: 0;
  border-radius: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}
.profile-dialog::backdrop { background: var(--bg); }
.profile-chrome, #profile-form, #profile-family { width: min(100%, 64rem); margin-inline: auto; }
.profile-chrome, .profile-brand { display: flex; align-items: center; gap: .7rem; }
.profile-chrome { justify-content: space-between; padding-block: .55rem; border-bottom: 1px solid var(--line); }
.profile-brand { min-width: 0; }
.profile-brand img { flex: none; width: 2rem; height: 2rem; }
#profile-title { font: 700 clamp(1.1rem, 2.3vw, 1.5rem)/1.1 system-ui, sans-serif; letter-spacing: -.035em; margin: 0; }
#profile-close { display: grid; place-items: center; flex: none; width: 44px; min-height: 44px; margin: 0; padding: 0; background: var(--bg-card); border-color: var(--line); }
#profile-form:not([hidden]) {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-block-size: 0;
}
.profile-meter { padding-block: .8rem .6rem; }
.profile-meter-labels { display: flex; align-items: baseline; justify-content: space-between; gap: .35rem 1rem; }
.profile-meter p { margin: 0 0 .45rem; font-size: .8125rem; font-weight: 650; }
#profile-chapter { color: var(--forest); }
#profile-step { text-align: end; font-variant-numeric: tabular-nums; }
.profile-track {
  block-size: .375rem;
  overflow: hidden;
  border-radius: 1rem;
  background: var(--mint);
}
.profile-track > span {
  display: block;
  inline-size: calc(100% * var(--profile-ratio, 0));
  block-size: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--forest), #4b7961);
}
.battery-meter { display: block; inline-size: 100%; block-size: .5rem; appearance: none; border: 0; border-radius: 1rem; overflow: hidden; background: var(--mint); accent-color: var(--forest); }
.battery-meter::-webkit-progress-bar { background: var(--mint); border-radius: 1rem; }
.battery-meter::-webkit-progress-value { background: var(--forest); border-radius: 1rem; }
.battery-meter::-moz-progress-bar { background: var(--forest); border-radius: 1rem; }
#profile-questions {
  min-block-size: 0;
  margin-inline: -.375rem;
  padding: .375rem .375rem .875rem;
  overflow: auto;
  overscroll-behavior: contain;
  scroll-padding-block: .4rem;
}
.profile-scene {
  display: grid;
  grid-template-areas: 'art' 'prompt' 'response';
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  align-items: start;
  gap: clamp(.75rem, 2.7vw, 1.35rem);
}
.profile-prompt { grid-area: prompt; min-width: 0; }
.profile-response { grid-area: response; min-width: 0; }
#profile-question-title { font: 500 clamp(1.95rem, 4.4vw, 3.6rem)/1.06 var(--display); letter-spacing: -.048em; margin: 0; text-wrap: balance; overflow-wrap: anywhere; }
#profile-question-title:focus, #profile-family-title:focus { outline: none; }
.profile-art {
  --art-bg: #dbeae0;
  --art-ink: #225744;
  --art-accent: #e6a58f;
  grid-area: art;
  display: grid;
  place-items: center;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: clamp(6.6rem, 27vw, 9rem);
  border-radius: var(--radius);
  border: 1px solid #ffffffbf;
  background:
    radial-gradient(ellipse at 40% 0%, #ffffffbd, transparent 72%),
    radial-gradient(ellipse at 85% 115%, var(--art-accent), transparent 60%),
    var(--art-bg);
  color: var(--art-ink);
}
.profile-scene[data-tone="warm"] .profile-art { --art-bg: #f5e4d6; --art-ink: #793b2a; --art-accent: #f3c597; }
.profile-scene[data-tone="iris"] .profile-art { --art-bg: #e8e7f4; --art-ink: #474274; --art-accent: #c6bfe8; }
.profile-art::after {
  content: '';
  position: absolute;
  z-index: -1;
  inset: -15% -30%;
  background: linear-gradient(117deg, transparent 36%, #ffffff70 50%, transparent 63%);
  opacity: 0;
}
.profile-orbit {
  position: absolute;
  z-index: -1;
  width: min(75%, 20rem);
  aspect-ratio: 1;
  border: 1px solid currentColor;
  border-radius: 42%;
  opacity: .18;
  rotate: -23deg;
}
.profile-orbit::before, .profile-orbit::after { content: ''; position: absolute; border-radius: 50%; }
.profile-orbit::before { inset: 8%; border: 1px dashed currentColor; }
.profile-orbit::after { top: 12%; left: 14%; width: .75rem; aspect-ratio: 1; background: var(--art-accent); }
.profile-drawing { position: absolute; inset: 0; inline-size: min(100%, 26rem); block-size: 100%; margin-inline: auto; }
.scene-line { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; opacity: .72; }
.scene-dot { fill: currentColor; opacity: .52; transform-box: fill-box; transform-origin: center; }
.scene-letter {
  fill: currentColor;
  text-anchor: middle;
  font: 500 38px var(--display);
  opacity: .85;
  transform-box: fill-box;
  transform-origin: center;
}
.scene-letter-small { font-size: 30px; }
.scene-letter-large { font-size: 57px; }
:is(.profile-art-icon, .profile-retiring-symbol) {
  display: grid;
  grid-area: 1 / 1;
  place-items: center;
  position: relative;
  width: clamp(3.05rem, 8vw, 5.2rem);
  aspect-ratio: 1;
  border-radius: 28%;
  border: 1px solid #fff9;
  background: linear-gradient(150deg, #ffffffd9, #ffffff77);
  box-shadow: 0 14px 30px #162b2227, inset 0 1px 0 #fff;
}
.profile-retiring-symbol { display: none; }
:is(.profile-art-icon, .profile-retiring-symbol) .ui-icon { width: 55%; height: 55%; }
.profile-options { display: grid; gap: .45rem; }
.profile-option {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .65rem;
  min-height: 3rem;
  padding: .55rem .8rem;
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  background: var(--bg-card);
  font-weight: 620;
  cursor: pointer;
}
.profile-option input {
  position: absolute;
  z-index: 1;
  inset-block-start: 50%;
  inset-inline-end: .8rem;
  inline-size: 1.3rem;
  block-size: 1.3rem;
  margin: 0;
  transform: translateY(-50%);
  opacity: 0;
}
.profile-option:has(:checked) { background: var(--mint); border-color: var(--forest); }
.profile-option:has(:focus-visible) { outline: 3px solid var(--coral); outline-offset: 2px; }
.profile-option-check {
  display: grid;
  place-items: center;
  inline-size: 1.3rem;
  block-size: 1.3rem;
  border: 1px solid var(--line-control);
  border-radius: 50%;
  color: var(--bg-card);
}
.profile-option-check .ui-icon { inline-size: .84rem; block-size: .84rem; visibility: hidden; }
.profile-option:has(:checked) .profile-option-check { border-color: var(--forest); background: var(--forest); }
.profile-option:has(:checked) .profile-option-check .ui-icon { visibility: visible; }
@media (hover: hover) and (pointer: fine) {
  .profile-option:hover { border-color: var(--line-control); }
  .profile-option:has(:checked):hover { border-color: var(--forest); }
}
.profile-question-note { margin: .55rem 0 0; }
.profile-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .55rem; padding-top: 1rem; }
.profile-actions button { width: auto; min-height: 44px; }
.profile-controls {
  column-gap: clamp(.3rem, 1.5vw, .7rem);
  padding-block: .55rem .7rem;
  border-top: 1px solid var(--line);
}
.profile-controls button { min-width: 0; margin-block: 0; padding-inline: clamp(.55rem, 2.7vw, 1rem); font-size: .9rem; }
.profile-controls button[hidden] { display: none; }
#profile-back { display: inline-flex; align-items: center; justify-content: center; gap: .33rem; }
#profile-back .ui-icon { width: 1rem; height: 1rem; }
#profile-next { min-inline-size: min(7.3rem, 100%); margin-inline-start: auto; }
#profile-family { max-width: 36rem; min-block-size: 0; padding-block: clamp(1rem, 5vw, 4rem); overflow: auto; overscroll-behavior: contain; }
#profile-family-title { margin-top: 1.2rem; font-family: var(--display); font-size: clamp(2.2rem, 6vw, 3.8rem); }
.profile-family-emblem { display: grid; width: 4.4rem; aspect-ratio: 1; place-items: center; border-radius: 1.15rem; background: var(--mint); }
.profile-family-emblem .ui-icon { width: 2rem; height: 2rem; }
.profile-complete {
  position: fixed;
  z-index: 6;
  inset: auto 0 calc(5.5rem + env(safe-area-inset-bottom)) 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  inline-size: max-content;
  max-inline-size: calc(100% - 2rem);
  margin: 0 auto;
  padding: .65rem 1rem;
  border-radius: 1.5rem;
  background: var(--forest);
  color: #fffefa;
  font-size: .9rem;
  font-weight: 650;
  pointer-events: none;
}
.profile-complete:empty { inline-size: 0; block-size: 0; padding: 0; overflow: hidden; }
.profile-complete .ui-icon { inline-size: 1rem; block-size: 1rem; }
[data-profile-text="large"] #exercise-zone .prompt,
[data-profile-text="large"] #exercise-zone .choice,
[data-profile-text="large"] #exercise-zone .inp,
[data-profile-text="large"] #feedback .fb-rule { font-size: 1.3em; }
@media (min-width: 760px) {
  .profile-scene {
    grid-template-areas: 'art prompt' 'art response';
    grid-template-columns: minmax(0, .84fr) minmax(0, 1.16fr);
    grid-template-rows: auto 1fr;
    column-gap: clamp(1rem, 3vw, 2.5rem);
  }
  .profile-art { min-height: clamp(14rem, 43dvh, 23rem); }
  #profile-form { block-size: min(100%, 43rem); }
}
@media (max-width: 759px) and (max-height: 680px) {
  .profile-scene {
    grid-template-areas: 'art prompt' 'response response';
    grid-template-columns: 3.6rem minmax(0, 1fr);
    gap: .63rem;
    align-items: center;
  }
  #profile-question-title { font-size: clamp(1.62rem, 5.45vw, 2.15rem); }
  .profile-art { min-height: 3.6rem; border-radius: var(--control-radius); }
  .profile-art-icon, .profile-retiring-symbol { width: 2.25rem; }
  .profile-drawing { width: 180%; max-width: none; margin-inline-start: -40%; }
}
@media (min-width: 760px) and (max-height: 520px) {
  .profile-scenes { column-gap: 1rem; }
  .profile-art { min-height: clamp(7rem, 47dvh, 12rem); }
  #profile-question-title { font-size: clamp(1.75rem, 4.4vh, 2.45rem); }
  .profile-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-height: 460px) {
  .profile-chrome, .profile-controls { padding-block: .28rem; }
  .profile-meter { padding-block: .4rem .3rem; }
  .profile-option { min-height: 44px; }
}
@media (min-width: 1024px) { .profile-complete { inset-block-end: 2rem; } }
@media (prefers-reduced-motion: no-preference) {
  .profile-dialog[open] { animation: profile-open 260ms ease-out; }
  .profile-dialog { --step-ease: cubic-bezier(.18,.76,.25,1); }
  .profile-scene { --step-offset: 14px; --art-turn: -16deg; --symbol-exit: -34px; }
  .profile-scene[data-direction="back"] { --step-offset: -14px; --art-turn: 16deg; --symbol-exit: 34px; }
  #profile-question-title { animation: profile-copy 330ms var(--step-ease) 20ms both; }
  .profile-option { animation: profile-choice-in 320ms var(--step-ease) calc(40ms + var(--option, 0) * 34ms) both; }
  .profile-question-note { animation: profile-copy 320ms var(--step-ease) 160ms both; }
  .profile-option, .profile-option-check, .profile-actions button, #profile-close {
    transition: background-color 160ms, border-color 160ms, scale 150ms;
  }
  .profile-option:active, .profile-actions button:active:not(:disabled), #profile-close:active { scale: .985; }
  .profile-option:has(:checked) .profile-option-check .ui-icon { animation: profile-check 320ms var(--step-ease); }
  .profile-option:has(:checked)::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    border: 2px solid var(--forest);
    pointer-events: none;
    animation: profile-answer-echo 410ms ease-out both;
  }
  #profile-next[data-ready] { animation: profile-ready 280ms var(--step-ease) both; }
  .profile-track > span { transition: inline-size 420ms var(--step-ease); }
  .profile-art { animation: profile-plate 350ms var(--step-ease) both; }
  .profile-art::after { animation: profile-light 850ms ease-out both; }
  .profile-orbit { animation: profile-orbit-in 580ms var(--step-ease) both; }
  .profile-retiring-symbol { display: grid; animation: profile-retire-symbol 230ms ease-in both; }
  .profile-art[data-replacing] .profile-art-icon { animation-delay: 55ms; }
  .profile-art-icon, .profile-family-emblem {
    animation: profile-symbol 490ms cubic-bezier(.22,.72,.27,1) both;
  }
  .profile-complete:not(:empty) { animation: profile-confirm 380ms var(--step-ease) both; }
  .profile-complete .ui-icon { animation: profile-check 340ms var(--step-ease) 35ms both; }
  #profile-family:not([hidden]) > :is(h2, p, .profile-actions) { animation: profile-copy 340ms var(--step-ease) both; }
  .scene-line {
    stroke-dasharray: 1 1;
    animation: profile-draw 360ms var(--step-ease) calc(65ms + var(--piece) * 32ms) both;
  }
  .scene-dot, .scene-letter { animation: profile-mark 350ms var(--step-ease) calc(88ms + var(--piece) * 32ms) backwards; }
  [data-question="dictation"] .profile-art-icon, [data-question="audio"] .profile-art-icon { animation-name: profile-listen; }
  [data-question="goal"] .profile-art-icon, [data-question="detect_errors"] .profile-art-icon { animation-name: profile-focus; }
  [data-question="pace"] .scene-piece:nth-child(2) { transform-box: fill-box; transform-origin: bottom left; animation: profile-needle 670ms var(--step-ease) both; }

  @keyframes profile-open { from { opacity: .52; } to { opacity: 1; } }
  @keyframes profile-copy {
    from { opacity: .53; transform: translate(var(--step-offset, 0px), 12px); }
    to { opacity: 1; transform: none; }
  }
  @keyframes profile-choice-in {
    from { opacity: .55; transform: translate(calc(var(--step-offset) * .65), 13px) scale(.985); }
    to { opacity: 1; transform: none; }
  }
  @keyframes profile-check {
    0% { opacity: .4; transform: scale(.52) rotate(-20deg); }
    60% { opacity: 1; transform: scale(1.28) rotate(5deg); }
    100% { transform: none; }
  }
  @keyframes profile-answer-echo { from { transform: scale(.98); opacity: .46; } to { transform: scale(1.022); opacity: 0; } }
  @keyframes profile-ready { 45% { transform: translateY(-1px) scale(1.025); } }
  @keyframes profile-plate { from { opacity: .61; transform: translateY(9px) scale(.98); } }
  @keyframes profile-confirm { from { opacity: .55; transform: translateY(12px) scale(.96); } }
  @keyframes profile-light { 0% { opacity: 0; translate: -30% 0; } 36% { opacity: .64; } 100% { opacity: 0; translate: 35% 0; } }
  @keyframes profile-orbit-in { from { opacity: .05; transform: scale(.8) rotate(var(--art-turn)); } }
  @keyframes profile-symbol {
    0% { opacity: .12; transform: translate(var(--step-offset, 0px), 12px) scale(.63) rotate(var(--art-turn, -7deg)); }
    58% { opacity: 1; transform: translateY(-4px) scale(1.11) rotate(4deg); }
    78% { transform: translateY(1px) scale(.98) rotate(-1deg); }
    100% { transform: none; }
  }
  @keyframes profile-retire-symbol { from { opacity: .7; } to { opacity: 0; transform: translateX(var(--symbol-exit)) scale(.69) rotate(var(--art-turn)); } }
  @keyframes profile-listen {
    0% { opacity: .22; transform: translateX(var(--step-offset)) scale(.62); }
    42% { opacity: 1; transform: scale(1.14); }
    67% { transform: rotate(-5deg) scale(.94); }
    82% { transform: rotate(2deg) scale(1.035); }
    100% { transform: none; }
  }
  @keyframes profile-focus { 0% { opacity: .3; transform: scale(1.28); } 65% { opacity: 1; transform: scale(.95); } 100% { transform: none; } }
  @keyframes profile-draw { from { stroke-dashoffset: 1.01; } to { stroke-dashoffset: 0; } }
  @keyframes profile-mark { from { opacity: 0; transform: translateY(9px) scale(.45); } }
  @keyframes profile-needle { 0% { rotate: -56deg; } 68% { rotate: 7deg; } 100% { rotate: 0deg; } }
}
@media (min-width: 1120px) and (prefers-reduced-motion: no-preference) {
  .profile-scene { --step-offset: 22px; }
  .profile-scene[data-direction="back"] { --step-offset: -22px; }
}
