/* Account profile only. Native IDs, labels, states and handlers stay in app.js. */
#profile-modal .profile-menu-heading { display: none; }
#profile-modal :is(.profile-avatar-orbit, .profile-action-shell) { display: contents; }
#profile-modal .profile-invite-legacy-mark { display: contents; }

@media (min-width: 721px) {
  /* Reference coordinate system: 1122 × 1402, fitted to the available viewport. */
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal {
    padding: 16px;
    overflow: auto;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-menu-card {
    --profile-unit: calc(100cqw / 1122);
    --profile-field-mask: linear-gradient(90deg, transparent, #0001 1.5%, #0007 3%, #000e 5%, #000 7%, #000 93%, #000e 95%, #0007 97%, #0001 98.5%, transparent), linear-gradient(0deg, transparent, #0001 1.5%, #0007 3%, #000e 5%, #000 7%, #000 93%, #000e 95%, #0007 97%, #0001 98.5%, transparent);
    position: relative;
    isolation: isolate;
    container-type: inline-size;
    flex: 0 0 auto;
    width: min(672px, calc(100vw - 32px), calc((100dvh - 32px) * .8));
    aspect-ratio: 1122 / 1402;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    font-family: Arial, sans-serif;
    text-align: center;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-menu-card::before,
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-menu-card::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-position: center;
    background-repeat: no-repeat;
    background-size: 100% 100%;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-menu-card::before {
    z-index: -2;
    background-image: linear-gradient(to bottom, transparent 42%, rgb(0 3 20 / .6) 59%, rgb(0 3 20 / .35) 89%, transparent), url("assets/profile/space-background.png");
    mask-image: var(--profile-field-mask);
    mask-composite: intersect;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-menu-card::after {
    z-index: -1;
    background-image: url("assets/profile/frame.svg");
  }

  /* Title rails and the original close control. */
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-menu-heading {
    position: absolute;
    display: block;
    top: calc(var(--profile-unit) * 111);
    left: calc(var(--profile-unit) * 280);
    width: calc(var(--profile-unit) * 562);
    margin: 0;
    color: #48d7ff;
    font: 600 calc(var(--profile-unit) * 28)/1.3 Arial, sans-serif;
    letter-spacing: calc(var(--profile-unit) * 8);
    text-indent: calc(var(--profile-unit) * 8);
    text-transform: uppercase;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-menu-heading::before,
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-menu-heading::after {
    content: "";
    position: absolute;
    top: 50%;
    width: calc(var(--profile-unit) * 148);
    height: calc(var(--profile-unit) * 9);
    pointer-events: none;
    background: radial-gradient(circle at calc(100% - var(--profile-unit) * 5) center, #00dbff 0 calc(var(--profile-unit) * 4.5), transparent calc(var(--profile-unit) * 5)), linear-gradient(90deg, transparent, #00d5ff) left center / calc(100% - var(--profile-unit) * 20) max(.5px, var(--profile-unit)) no-repeat;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-menu-heading::before { left: 0; }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-menu-heading::after { right: 0; transform: scaleX(-1); }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-close {
    z-index: 3;
    top: calc(var(--profile-unit) * 114);
    right: calc(var(--profile-unit) * 116);
    display: grid;
    place-items: center;
    width: max(32px, calc(var(--profile-unit) * 68));
    height: max(32px, calc(var(--profile-unit) * 68));
    padding: 0;
    border: calc(var(--profile-unit) * 2.5) solid #ed75ff;
    border-radius: 50%;
    background: radial-gradient(circle at 50% 35%, #400449, #160724 78%);
    box-shadow: 0 0 calc(var(--profile-unit) * 10) #ec2dff80, inset 0 0 calc(var(--profile-unit) * 13) #a52dda45;
    font-size: 0;
    cursor: pointer;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-close::before,
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-close::after {
    content: "";
    position: absolute;
    width: 50%;
    height: 2px;
    border-radius: 2px;
    background: #ffe1ff;
    transform: rotate(45deg);
    pointer-events: none;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-close::after { transform: rotate(-45deg); }

  /* Real photograph and an independent transparent orbit. */
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-avatar-orbit {
    position: absolute;
    display: block;
    top: calc(var(--profile-unit) * 147);
    left: calc(var(--profile-unit) * 337);
    width: calc(var(--profile-unit) * 448);
    height: calc(var(--profile-unit) * 448);
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-avatar-orbit::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: url("assets/profile/avatar-orbit.svg") center / contain no-repeat;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-avatar {
    position: absolute;
    top: calc(var(--profile-unit) * 49);
    left: calc(var(--profile-unit) * 49);
    width: calc(var(--profile-unit) * 350);
    height: calc(var(--profile-unit) * 350);
    margin: 0;
    border: 0;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: none;
    transform: none;
    filter: none;
    mix-blend-mode: normal;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-name {
    position: absolute;
    top: calc(var(--profile-unit) * 589);
    left: calc(var(--profile-unit) * 150);
    width: calc(var(--profile-unit) * 822);
    margin: 0;
    font: 700 calc(var(--profile-unit) * 56)/1.16 Arial, sans-serif;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    text-shadow: 0 0 calc(var(--profile-unit) * 11) rgb(244 181 92 / .12);
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-contact-status {
    position: absolute;
    top: calc(var(--profile-unit) * 661);
    left: calc(var(--profile-unit) * 150);
    width: calc(var(--profile-unit) * 822);
    margin: 0;
    font: 400 calc(var(--profile-unit) * 34)/1.2 Arial, sans-serif;
    color: #96d4ff;
    text-shadow: none;
  }

  /* Reusable action shell: polygon fill, thin double contour, native button. */
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-actions {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    top: calc(var(--profile-unit) * 722);
    left: calc(var(--profile-unit) * 147);
    width: calc(var(--profile-unit) * 828);
    gap: calc(var(--profile-unit) * 20);
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action-shell {
    --action-fill: linear-gradient(110deg, #08132ee8, #0d2349e8 56%, #111333ed);
    --action-edge: linear-gradient(100deg, #4eabff, #4459f3 55%, #826aff);
    --action-ink: #78adf3;
    --action-icon: #5aa9f7;
    --action-glow: #2460d92a;
    position: relative;
    display: block;
    flex: none;
    height: calc(var(--profile-unit) * 116);
    isolation: isolate;
    filter: drop-shadow(0 0 calc(var(--profile-unit) * 9) var(--action-glow));
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action-shell::before,
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action-shell::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action-shell::before {
    background: var(--action-fill);
    clip-path: polygon(3% 0, 97% 0, 100% 21%, 100% 79%, 97% 100%, 3% 100%, 0 79%, 0 21%);
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action-shell::after {
    background: var(--action-edge);
    mask: url("assets/profile/action-frame.svg") center / 100% 100% no-repeat;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    height: 100%;
    min-width: 0;
    padding: 0 calc(var(--profile-unit) * 67) 0 calc(var(--profile-unit) * 184);
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--action-ink);
    font: 700 calc(var(--profile-unit) * 36)/1.15 Arial, sans-serif;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
    box-shadow: none;
    text-shadow: 0 0 calc(var(--profile-unit) * 5) rgb(255 255 255 / .15);
    transform: none;
    opacity: 1;
    transition: filter .15s ease;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action-shell:has(> .hidden) { display: none; }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-invite-legacy-mark { display: none; }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action::before {
    content: "";
    position: absolute;
    left: calc(var(--profile-unit) * 56);
    top: calc(var(--profile-unit) * 19);
    width: calc(var(--profile-unit) * 80);
    height: calc(var(--profile-unit) * 78);
    background: var(--action-icon);
    mask: var(--profile-icon) center / contain no-repeat;
    pointer-events: none;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action::after {
    content: "";
    position: absolute;
    right: calc(var(--profile-unit) * 60);
    top: 50%;
    width: calc(var(--profile-unit) * 19);
    height: calc(var(--profile-unit) * 19);
    border-top: calc(var(--profile-unit) * 3.5) solid var(--action-icon);
    border-right: calc(var(--profile-unit) * 3.5) solid var(--action-icon);
    transform: translateY(-50%) rotate(45deg);
    pointer-events: none;
  }

  /* Role colors and masks; labels are always the current native textContent. */
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-add-contact {
    --profile-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 84 84'%3E%3Ccircle cx='30' cy='24' r='14' fill='white'/%3E%3Cpath d='M4 68c0-16 10-26 26-26s26 10 26 26z' fill='white'/%3E%3Cpath d='M66 39v28M52 53h28' fill='none' stroke='white' stroke-width='6' stroke-linecap='round'/%3E%3C/svg%3E");
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-add-contact:disabled {
    color: #4c81cc;
    text-shadow: none;
    --profile-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 84 84'%3E%3Ccircle cx='30' cy='24' r='14' fill='white'/%3E%3Cpath d='M4 68c0-16 10-26 26-26 5 0 10 1 14 4a22 22 0 0 0-3 22z' fill='white'/%3E%3Cpath fill-rule='evenodd' d='M62 40a17 17 0 1 0 0 34 17 17 0 0 0 0-34zm-9 17 6 6 12-13-4-4-9 10-3-3z' fill='white'/%3E%3C/svg%3E");
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-add-contact:disabled::after { content: none; }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action-shell:has(> #profile-private) {
    --action-fill: radial-gradient(ellipse at 27% -30%, #004cffb0, transparent 68%), linear-gradient(105deg, #0088d4ec, #0737f6f2 51%, #3a07d9f0 78%, #ba00ddf0);
    --action-edge: linear-gradient(95deg, #a8fcff, #00e2ff 17%, #7c89ff 60%, #ea72ff 90%, #ffe7ff);
    --action-ink: #f5f5ff;
    --action-icon: #c7fcff;
    --action-glow: #126cffb0;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-private {
    --profile-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 84 84'%3E%3Cpath d='M15 12h42c13 0 19 8 19 21v12c0 13-7 20-20 20H34L14 77V61C6 57 5 51 5 42V33c0-13 2-21 10-21z' fill='none' stroke='white' stroke-width='4.5' stroke-linejoin='round'/%3E%3Ccircle cx='26' cy='38' r='4.5' fill='white'/%3E%3Ccircle cx='42' cy='38' r='4.5' fill='white'/%3E%3Ccircle cx='58' cy='38' r='4.5' fill='white'/%3E%3C/svg%3E");
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action-shell:has(> #profile-invite),
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action-shell:has(> #profile-block.profile-action--success) {
    --action-fill: linear-gradient(105deg, #00252bef, #001b2ded 60%, #001d26ef);
    --action-edge: linear-gradient(90deg, #07e6cc, #00acba 64%, #04f1c9);
    --action-ink: #e6f9ff;
    --action-icon: #06d9cb;
    --action-glow: #00daba55;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-invite {
    --profile-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 84 84'%3E%3Ccircle cx='18' cy='30' r='10' fill='white' opacity='.75'/%3E%3Ccircle cx='43' cy='23' r='13' fill='white'/%3E%3Cpath d='M22 72V61c0-14 8-22 21-22s21 8 21 22v11zM1 71v-8c0-13 6-20 16-20h4a29 29 0 0 0-5 18v10z' fill='white'/%3E%3Cpath d='M74 29v25M62 42h24' stroke='white' stroke-width='6' stroke-linecap='round'/%3E%3C/svg%3E");
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action-shell:has(> #profile-block.profile-action--danger) {
    --action-fill: linear-gradient(105deg, #2a0b24ef, #210a23ed 62%, #320b2bea);
    --action-edge: linear-gradient(90deg, #fb408a, #bd286f 58%, #fc55ad);
    --action-ink: #f5d5f4;
    --action-icon: #ed3e91;
    --action-glow: #e9247c55;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-block {
    --profile-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 84 84'%3E%3Ccircle cx='42' cy='42' r='29' fill='none' stroke='white' stroke-width='6.5'/%3E%3Cpath d='m22 62 40-40' stroke='white' stroke-width='6.5'/%3E%3C/svg%3E");
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-block.profile-action--success {
    --profile-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 84 84'%3E%3Cpath d='M28 35V22a16 16 0 0 1 31-5M24 35h38v37H24z' fill='none' stroke='white' stroke-width='6' stroke-linejoin='round'/%3E%3Ccircle cx='43' cy='52' r='4' fill='white'/%3E%3Cpath d='M43 56v6' stroke='white' stroke-width='4'/%3E%3C/svg%3E");
  }

  /* Preserve native hidden/disabled states and keyboard access. */
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal :is(.profile-actions, #profile-contact-status).hidden { display: none; }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action:disabled { cursor: not-allowed; box-shadow: none; transform: none; }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action:hover:not(:disabled),
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-close:hover { filter: brightness(1.16); transform: none; }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal :is(.profile-action, #profile-close):focus-visible { outline: 2px solid #ddfbff; outline-offset: -5px; }
}

/* Motion follows the login scene: local star flares and travelling edge light. */
@media (min-width: 721px) {
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-scene-effects {
    position: absolute;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    mask-image: var(--profile-field-mask);
    mask-composite: intersect;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal :is(.profile-menu-heading, .profile-avatar-orbit, #profile-name, #profile-contact-status, .profile-actions) { z-index: 1; }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal :is(.profile-action-shell, #profile-close, #profile-avatar) {
    transition: transform .22s cubic-bezier(.22, 1, .36, 1), filter .22s ease, box-shadow .22s ease;
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action-shell::before {
    background: linear-gradient(110deg, transparent 30%, #ffffff16 46%, #ffffff30 50%, transparent 65%) -160% 0 / 260% 100% no-repeat, var(--action-fill);
  }
  #profile-modal[data-profile-motion="running"] .profile-action-shell::before { animation: profile-action-sheen 7.6s ease-in-out infinite; }
  #profile-modal[data-profile-motion="running"] .profile-action-shell::after { animation: profile-rim-breathe 3.8s ease-in-out infinite; }
  #profile-modal[data-profile-motion="running"] .profile-action-shell:nth-child(2)::before { animation-delay: -1.3s; }
  #profile-modal[data-profile-motion="running"] .profile-action-shell:nth-child(3)::before { animation-delay: -2.6s; }
  #profile-modal[data-profile-motion="running"] .profile-action-shell:nth-child(4)::before { animation-delay: -3.9s; }
  #profile-modal[data-profile-motion="running"] .profile-action-shell:nth-child(even)::after { animation-delay: -1.9s; }
  #profile-modal[data-profile-motion="running"] #profile-close { animation: profile-close-breathe 4.2s ease-in-out infinite; }
  #profile-modal[data-profile-motion="running"] .profile-avatar-orbit::after { animation: profile-orbit-breathe 6.8s ease-in-out infinite; }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action-shell:has(> .profile-action:hover:not(:disabled)),
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action-shell:has(> .profile-action:focus-visible) {
    transform: translateY(calc(var(--profile-unit) * -2));
    filter: brightness(1.15) drop-shadow(0 0 calc(var(--profile-unit) * 15) var(--action-glow));
  }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-action-shell:has(> .profile-action:active:not(:disabled)) { transform: scale(.985); filter: brightness(1.28) drop-shadow(0 0 calc(var(--profile-unit) * 18) var(--action-glow)); }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-close:hover { transform: scale(1.08) rotate(6deg); filter: brightness(1.2); }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-close:active { transform: scale(.93) rotate(-4deg); }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-avatar:hover { transform: scale(1.025); }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal #profile-avatar:active { transform: scale(.975); }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-avatar-orbit:has(> #profile-avatar:hover)::after { filter: brightness(1.25) drop-shadow(0 0 calc(var(--profile-unit) * 8) #5d9aff80); }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal .profile-avatar-orbit:has(> #profile-avatar:active)::after { filter: brightness(1.5); }
}
@keyframes profile-action-sheen {
  0%, 30% { background-position: -160% 0, 0 0; }
  70%, 100% { background-position: 260% 0, 0 0; }
}
@keyframes profile-rim-breathe { 0%, 100% { opacity: .73; filter: brightness(1); } 50% { opacity: 1; filter: brightness(1.3); } }
@keyframes profile-close-breathe { 0%, 100% { box-shadow: 0 0 5px #ec2dff60, inset 0 0 7px #a52dda35; } 50% { box-shadow: 0 0 10px #ec2dff95, inset 0 0 10px #c34bff60; } }
@keyframes profile-orbit-breathe { 0%, 100% { opacity: .88; transform: rotate(-1deg); } 50% { opacity: 1; transform: rotate(1deg); } }
@media (prefers-reduced-motion: reduce) {
  #profile-modal *, #profile-modal *::before, #profile-modal *::after { animation: none !important; transition: none !important; }
  body:has(#message-form[data-composer-theme="neon-space"]) #profile-modal :is(#profile-avatar, #profile-close, .profile-action-shell) { transform: none !important; }
}
