/* Full-screen scene: the doors retain one shared 2:3 frame; only sky/water extend. */
/* Retain the host geometry: its resize handler persists the floating ball's clamped position. */
body.tiny-home-open.tiny-home-portal-open .main-float-root,
body.tiny-home-open.tiny-home-portal-open .main-float-root * {
    visibility: hidden !important;
    pointer-events: none !important;
}
.th-portal {
    --th-portal-ink: #254957;
    --th-portal-paper: #f6fbfc;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    position: relative;
    isolation: isolate;
    overflow: hidden;
    color: var(--th-portal-ink);
    background: #8dc0df;
}
.th-portal *, .th-portal-visit-layer * { box-sizing: border-box; }
.th-portal button, .th-portal-visit-layer button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.th-portal button:focus-visible, .th-portal-visit-layer button:focus-visible, .th-portal-visit-layer input:focus-visible {
    outline: 3px solid #235f74;
    outline-offset: 4px;
}
.th-portal-scene { position: absolute; inset: 0; overflow: hidden; }
.th-portal-stage {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 100%;
    height: var(--th-portal-art-height, auto);
    aspect-ratio: 2 / 3;
    overflow: hidden;
    flex: 0 0 auto;
}
.th-portal-art { position: absolute; inset: 0; width: 100%; height: 100%; display: block; object-fit: fill; user-select: none; }
.th-portal[data-th-fill="extended"] .th-portal-art { clip-path: inset(12% 0 22%); }
.th-portal[data-th-fill="extended"] .th-portal-scene::before,
.th-portal[data-th-fill="extended"] .th-portal-scene::after {
    content: '';
    position: absolute;
    left: 0; right: 0;
    background-image: url('assets/tiny-home-portal/dream-gateway-v1.webp');
    background-repeat: no-repeat;
    pointer-events: none;
}
.th-portal[data-th-fill="extended"] .th-portal-scene::before {
    top: 0;
    height: calc(var(--th-portal-sky-height) + 1px);
    background-position: center top;
    background-size: 100% var(--th-portal-sky-image-height);
}
.th-portal[data-th-fill="extended"] .th-portal-scene::after {
    bottom: 0;
    height: calc(var(--th-portal-water-height) + 1px);
    background-position: center bottom;
    background-size: 100% var(--th-portal-water-image-height);
}
.th-portal-atmosphere { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.th-portal-cloud { position: absolute; width: 76%; height: auto; object-fit: contain; pointer-events: none; user-select: none; }
.th-portal-cloud--far { top: 12%; left: -22%; opacity: .56; animation: th-portal-cloud-far 38s ease-in-out infinite alternate; }
.th-portal-cloud--near { top: 29%; right: -28%; opacity: .38; animation: th-portal-cloud-near 47s ease-in-out infinite alternate; }
.th-portal-sunlight {
    position: absolute;
    inset: 28% 10% 21%;
    border-radius: 50%;
    background: radial-gradient(ellipse at 50% 62%, rgba(255, 226, 157, .34), rgba(255, 235, 182, .09) 36%, transparent 68%);
    animation: th-portal-light 9s ease-in-out infinite alternate;
}
.th-portal-water { position: absolute; z-index: 1; left: 0; right: 0; top: var(--th-portal-water-top, 76%); bottom: 0; overflow: hidden; pointer-events: none; }
.th-portal-ripple {
    position: absolute;
    width: 45%;
    height: 9%;
    left: 8%;
    top: 38%;
    border: 1px solid rgba(248, 255, 253, .7);
    border-radius: 50%;
    box-shadow: 0 1px 0 rgba(100, 159, 172, .2), inset 0 1px 0 rgba(255, 255, 255, .2);
    animation: th-portal-water 8s ease-out infinite;
}
.th-portal-ripple:nth-child(2) { left: 51%; top: 12%; width: 37%; animation-delay: -2.7s; }
.th-portal-ripple:nth-child(3) { left: 31%; top: 68%; width: 56%; animation-delay: -5.4s; }
.th-portal[data-th-motion="paused"] .th-portal-motion-layer { animation-play-state: paused; }
.th-portal[data-th-motion="running"] .th-portal-cloud { will-change: transform; }
.th-portal-header {
    position: absolute;
    z-index: 3;
    left: 0;
    right: 0;
    top: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    column-gap: 8px;
    padding: max(12px, var(--safe-area-inset-top, env(safe-area-inset-top, 0px))) max(14px, env(safe-area-inset-right, 0px)) 0 max(14px, env(safe-area-inset-left, 0px));
    pointer-events: none;
}
.th-portal-tool { pointer-events: auto; width: 48px; height: 48px; min-width: 44px; min-height: 44px; border: 1px solid rgba(255,255,255,.8); border-radius: 50%; padding: 0; background: #edf6f9; color: #355a68; font-size: 12px !important; }
.th-portal-back { font-size: 31px !important; line-height: 1; padding-bottom: 4px; }
.th-portal-door {
    position: absolute;
    z-index: 2;
    display: block;
    min-width: 44px;
    min-height: 44px;
    border: 0;
    border-radius: 44% 44% 4% 4%;
    background: transparent;
    padding: 0;
    color: #3f514a;
    transform: translate(-50%, -50%);
    touch-action: manipulation;
}
.th-portal-door::before { content: ''; position: absolute; inset: 0; border-radius: inherit; box-shadow: 0 0 30px 8px rgba(255, 240, 193, .52); opacity: 0; transition: opacity .2s ease; pointer-events: none; }
.th-portal-door:hover::before, .th-portal-door:focus-visible::before { opacity: 1; }
.th-portal-door:active::before { opacity: .7; }
.th-portal-door--user { left: 50%; top: 50.55%; width: 26.4%; height: 24.9%; }
.th-portal-door--char { left: 17.4%; top: 52.25%; width: 18.2%; height: 16.5%; }
.th-portal-door--visit { left: 82.75%; top: 52.25%; width: 18.5%; height: 16.5%; }
.th-portal-plaque {
    position: absolute;
    left: 50%;
    top: 40.3%;
    transform: translate(-50%, -50%);
    width: 94%;
    min-height: 21px;
    display: block;
    padding: 4px 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: 1px solid #c5ab6d;
    border-radius: 3px;
    background: #fcf2d8;
    color: #4c492d;
    box-shadow: 0 2px 5px rgba(50, 62, 56, .23), inset 0 1px 0 #fff9e9;
    font-size: clamp(10px, 3vw, 13px);
    font-weight: 700;
    line-height: 1.3;
    text-align: center;
}
.th-portal-door--user .th-portal-plaque { width: 88%; top: 39.6%; left: 48.9%; }
.th-portal-door--char .th-portal-plaque { display: flex; align-items: center; justify-content: center; gap: 3px; }
.th-portal-door--visit .th-portal-plaque { left: 48.1%; }
.th-portal-plaque-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.th-portal-plaque-count { flex: 0 0 auto; font-size: 9px; }
.th-portal-plaque--blank { min-height: 21px; }
.th-portal-footer { position: absolute; z-index: 3; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 12px max(14px, var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))); pointer-events: none; }
.th-portal-motion-toggle { pointer-events: auto; min-height: 44px; display: flex; align-items: center; justify-content: center; gap: 7px; padding: 0 16px; border: 1px solid rgba(255,255,255,.7); border-radius: 999px; background: #dfeef1; color: #2a5262; font-size: 11px !important; }
.th-portal-motion-toggle:disabled { opacity: .85; cursor: default; }
.th-portal-motion-icon { font-size: 14px; line-height: 1; }
.th-portal-art-status { margin: 0; padding: 5px 9px; background: #edf6f9; color: #345765; border-radius: 6px; font-size: 11px; }
.th-portal.is-art-unavailable .th-portal-door { background: linear-gradient(110deg, #e8f1ed, #fff1cc); border: 3px solid #f9fbf1; box-shadow: 0 6px 22px rgba(72, 105, 106, .2), inset 0 0 0 3px #d5ded4; }
.th-portal.is-art-unavailable .th-portal-art { visibility: hidden; }

@keyframes th-portal-cloud-far { from { transform: translate3d(-3%, 0, 0); } to { transform: translate3d(23%, 3%, 0); } }
@keyframes th-portal-cloud-near { from { transform: translate3d(7%, 0, 0); } to { transform: translate3d(-24%, -5%, 0); } }
@keyframes th-portal-light { from { opacity: .4; } to { opacity: .95; } }
@keyframes th-portal-water { 0% { transform: scale(.48); opacity: 0; } 18% { opacity: .52; } 100% { transform: scale(1.55); opacity: 0; } }

/* Input-only visit dialog: no network, no implied connection or ID validation. */
.th-portal-visit-layer { position: absolute; z-index: 80; inset: 0; display: flex; align-items: center; justify-content: center; overflow-y: auto; overscroll-behavior: contain; padding: max(22px, var(--safe-area-inset-top, env(safe-area-inset-top, 0px))) 18px max(22px, var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))); background: rgba(26, 51, 65, .48); }
.th-portal-visit-dialog { position: relative; flex: 0 0 auto; width: min(100%, 360px); max-height: 100%; overflow-y: auto; padding: 30px 24px 24px; border: 1px solid #e0edf2; border-radius: 24px; background: #f6fbfc; color: #254957; box-shadow: 0 16px 60px rgba(20, 47, 64, .24); }
.th-portal-visit-close { position: absolute; top: 6px; right: 6px; min-width: 44px; min-height: 44px; border: 0; background: transparent; color: #4b6a78; font-size: 28px !important; }
.th-portal-visit-symbol { display: flex; width: 44px; height: 48px; align-items: center; justify-content: center; margin-bottom: 18px; border: 1px solid #a7c3ce; border-radius: 24px 24px 4px 4px; color: #79979b; font-size: 25px; background: #e8f1ef; }
.th-portal-visit-dialog h3 { margin: 0 0 10px; font-size: 20px; line-height: 1.4; color: inherit; }
.th-portal-visit-dialog p { margin: 0 0 25px; font-size: 12px; line-height: 1.7; color: #4b6a78; }
.th-portal-visit-form label { display: block; margin: 0 0 8px; font-size: 13px; font-weight: 700; }
.th-portal-visit-form input { display: block; width: 100%; min-width: 0; height: 48px; margin: 0; padding: 0 13px; border: 1px solid #a5bec9; border-radius: 10px; background: #fff; color: #254957; font: inherit; font-size: 16px; }
.th-portal-visit-form input::placeholder { color: #637c87; font-size: 13px; }
.th-portal-visit-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.th-portal-visit-actions button { min-width: 72px; min-height: 44px; padding: 0 14px; border: 1px solid #b2cbd5; border-radius: 10px; background: #f6fbfc; color: #365b6a; font-size: 13px; }
.th-portal-visit-actions button:last-child { background: #365f70; border-color: #365f70; color: #fff; }
.th-portal-visit-actions button:disabled { opacity: .48; cursor: default; }

/* Residence directories continue the sky palette while retaining the existing cards. */
.th-panel--directory { color: #254957; background: linear-gradient(180deg, #e7f1f6, #f5f9f9 62%, #eaf3f4); }
.th-panel--directory .th-head { background: #f1f7fa; border-bottom-color: #cfdee5; -webkit-backdrop-filter: none; backdrop-filter: none; grid-template-columns: 44px minmax(0, 1fr) 58px; }
.th-panel--directory .th-head h2 { color: #254957; }
.th-panel--directory .th-back, .th-panel--directory .th-head-tool { min-width: 44px; min-height: 44px; background: #fff; border-color: #c4d8e2; color: #365f70; box-shadow: none; }
.th-panel--directory .th-body { padding: 20px 16px max(26px, var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))); }
.th-directory-intro { position: relative; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 12px; margin: 2px 2px 20px; }
.th-directory-intro h3 { margin: 0; color: #254957; font-size: 21px; font-weight: 750; line-height: 1.45; }
.th-directory-intro p { flex-basis: 100%; margin: 0; color: #5a7480; font-size: 12px; line-height: 1.6; }
.th-directory-intro__head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 12px; }
.th-association-button { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 44px; padding: 0 11px; border: 1px solid #bad0da; border-radius: 999px; background: #f8fcfd; color: #365f70; font: inherit; font-size: 12px; cursor: pointer; vertical-align: middle; }
.th-association-button > span { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.th-association-menu { display: flex; flex: 1 0 100%; flex-direction: column; gap: 4px; margin-top: 10px; padding: 6px; max-height: min(40vh, 280px); overflow-y: auto; overscroll-behavior: contain; border: 1px solid #c5d9e1; border-radius: 14px; background: #fff; box-shadow: 0 10px 25px rgba(50, 91, 108, .12); }
.th-association-menu button { display: flex; align-items: center; width: 100%; min-height: 44px; gap: 8px; padding: 8px 11px; border: 0; border-radius: 8px; background: transparent; color: #365666; font: inherit; font-size: 13px; text-align: left; word-break: break-word; cursor: pointer; }
.th-association-menu button[aria-selected="true"], .th-association-menu button[aria-checked="true"], .th-association-menu button.is-selected { background: #e5f0f4; font-weight: 700; }
.th-association-menu button:hover { background: #edf5f7; }
.th-directory-empty { padding: 28px 12px; font-size: 13px; line-height: 1.75; text-align: center; color: #5a7480; }
.th-directory-empty strong { display: block; margin-bottom: 7px; color: #345765; font-size: 15px; }
.th-historical-residents { margin: 2px 0 20px; border-top: 1px solid #cedfe5; padding-top: 10px; }
.th-historical-residents summary { min-height: 44px; padding: 10px 2px; color: #5a7480; font-size: 12px; line-height: 1.6; cursor: pointer; }
.th-historical-residents summary:focus-visible { outline: 3px solid #235f74; outline-offset: 3px; }
.th-historical-residents .th-resident-strip { padding-top: 10px; }
.th-panel--directory .th-resident-strip { gap: 12px; padding-bottom: 22px; margin-bottom: 4px; }
.th-panel--directory .th-resident { width: 76px; padding: 11px 5px 10px; background: #f7fbfc; border-radius: 18px; }
.th-panel--directory .th-resident.is-selected { background: #fff; border-color: #6d9baa; box-shadow: 0 6px 16px rgba(54, 95, 112, .12); }
.th-panel--directory .th-resident__avatar { width: 48px; height: 48px; background: #7d9eab; }
.th-panel--directory .th-resident__name { color: #345765; max-width: 65px; }
.th-panel--directory .th-section-head { gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.th-panel--directory .th-section-head h3 { color: #254957; overflow-wrap: anywhere; }
.th-panel--directory .th-section-sub { color: #607a85; }
.th-panel--directory .th-home-card { background: #fff; border: 1px solid #e0e9ed; box-shadow: 0 7px 20px rgba(44, 81, 95, .07); -webkit-backdrop-filter: none; backdrop-filter: none; }
.th-panel--directory .th-home-card__main strong { color: #254957; }
.th-panel--directory .th-home-card__main small { color: #607a85; }
.th-panel--directory .th-home-card__chevron { color: #6d8d9c; }
.th-panel--directory .th-btn--primary { background: #416f81; border-color: #416f81; box-shadow: 0 5px 14px rgba(51, 94, 111, .14); color: #fff; min-height: 44px; }
.th-panel--directory .th-badge { color: #416574; background: #edf4f7; border-color: #c9dce4; }
.th-panel--directory .th-empty, .th-panel--directory .th-resident-empty { color: #5a7480; background: #f5fafb; border-color: #c6dbe3; }
.th-panel--directory button:focus-visible { outline: 3px solid #235f74; outline-offset: 3px; }

html[data-appearance="dark"] .th-panel--directory { color: #e5f0f5; background: #1d303b; }
html[data-appearance="dark"] .th-panel--directory .th-head { background: #233945; border-color: #3c5360; }
html[data-appearance="dark"] .th-panel--directory .th-back,
html[data-appearance="dark"] .th-panel--directory .th-head-tool,
html[data-appearance="dark"] .th-association-button,
html[data-appearance="dark"] .th-association-menu,
html[data-appearance="dark"] .th-panel--directory .th-home-card,
html[data-appearance="dark"] .th-panel--directory .th-resident { background: #2b4350; color: #e5f0f5; border-color: #4e6977; }
html[data-appearance="dark"] .th-panel--directory .th-head h2,
html[data-appearance="dark"] .th-directory-intro h3,
html[data-appearance="dark"] .th-directory-empty strong,
html[data-appearance="dark"] .th-panel--directory .th-section-head h3,
html[data-appearance="dark"] .th-panel--directory .th-home-card__main strong,
html[data-appearance="dark"] .th-panel--directory .th-resident__name { color: #e5f0f5; }
html[data-appearance="dark"] .th-directory-intro p,
html[data-appearance="dark"] .th-directory-empty,
html[data-appearance="dark"] .th-panel--directory .th-home-card__main small,
html[data-appearance="dark"] .th-panel--directory .th-section-sub { color: #b2c9d3; }
html[data-appearance="dark"] .th-panel--directory .th-resident.is-selected { background: #365565; border-color: #90b9c8; }
html[data-appearance="dark"] .th-association-menu button { color: #e5f0f5; }
html[data-appearance="dark"] .th-association-menu button[aria-selected="true"],
html[data-appearance="dark"] .th-association-menu button[aria-checked="true"],
html[data-appearance="dark"] .th-association-menu button.is-selected,
html[data-appearance="dark"] .th-association-menu button:hover { background: #3b5969; }
html[data-appearance="dark"] .th-panel--directory .th-badge { color: #d1e5ed; background: #345261; border-color: #526f7e; }
html[data-appearance="dark"] .th-panel--directory .th-empty,
html[data-appearance="dark"] .th-panel--directory .th-resident-empty { color: #bdd2dc; background: #243d49; border-color: #4e6977; }
html[data-appearance="dark"] .th-historical-residents { border-color: #496371; }
html[data-appearance="dark"] .th-historical-residents summary { color: #b2c9d3; }
html[data-appearance="dark"] .th-portal-visit-dialog { background: #233c49; color: #e5f0f5; border-color: #557382; }
html[data-appearance="dark"] .th-portal-visit-dialog p,
html[data-appearance="dark"] .th-portal-visit-close { color: #bfd5df; }
html[data-appearance="dark"] .th-portal-visit-form input { background: #162f3b; color: #f0f8fb; border-color: #668a9b; }
html[data-appearance="dark"] .th-portal-visit-form input::placeholder { color: #acc5d0; }
html[data-appearance="dark"] .th-portal-visit-actions button { background: #2b4959; color: #e5f0f5; border-color: #668a9b; }
html[data-appearance="dark"] .th-portal-visit-actions button:last-child { background: #d8edf5; color: #233c49; border-color: #d8edf5; }
html[data-appearance="dark"] .th-portal-visit-layer button:focus-visible,
html[data-appearance="dark"] .th-portal-visit-layer input:focus-visible,
html[data-appearance="dark"] .th-panel--directory button:focus-visible { outline-color: #b3e1f3; }

@media (prefers-reduced-motion: reduce) {
    .th-portal-motion-layer { animation: none !important; will-change: auto !important; }
    .th-portal-door::before { transition: none; }
}
@media (max-width: 350px) {
    .th-portal-header { padding-left: 10px; padding-right: 10px; }
    .th-portal-plaque { padding-left: 3px; padding-right: 3px; font-size: 10px; }
    .th-panel--directory .th-body { padding-left: 12px; padding-right: 12px; }
    .th-association-button > span { max-width: 145px; }
    .th-portal-visit-dialog { padding: 27px 18px 20px; }
}
@media (max-height: 440px) and (min-width: 500px) {
    .th-portal-visit-dialog { padding-top: 18px; }
    .th-portal-visit-symbol { display: none; }
    .th-portal-visit-dialog p { margin-bottom: 15px; }
}
