header {
    position: fixed;
    top: 0;
    width: 100%;
    min-height: 100px;
    display: flex;
    align-items: center;
    padding: calc(22px + env(safe-area-inset-top, 0px)) calc(36px + env(safe-area-inset-right, 0px)) 16px calc(36px + env(safe-area-inset-left, 0px));
    gap: 20px;
    z-index: 2;
    background: linear-gradient(rgba(232, 245, 255, 0.78), transparent);
}

.header-tools {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.net-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 6px 13px;
    border-radius: 20px;
    border: 1px solid #ffffffb8;
    background: #fbfaf1cc;
    font-size: 11px;
    color: var(--ink);
    white-space: nowrap;
    box-shadow: 0 4px 16px #2d60540f;
}

.net-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #b99346;
    flex-shrink: 0;
}

.net-pill.online .net-dot {
    background: #2f8b67;
    box-shadow: 0 0 0 3px #2f8b6724;
}

.net-pill.offline .net-dot {
    background: #8f9894;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    color: inherit;
    text-decoration: none;
    flex-shrink: 0;
}

.seal {
    border: 1px solid #a28248;
    color: #94723b;
    padding: 4px 9px;
    font: 17px/1.15 Georgia, serif;
}

.brand strong {
    font: 26px Georgia, "PMingLiU", serif;
    letter-spacing: 8px;
    display: block;
}

.brand small {
    font-size: 8px;
    letter-spacing: 1.6px;
    display: block;
    margin-top: 6px;
}

nav {
    display: flex;
    gap: 6px;
    align-items: center;
    margin: auto;
    background: #fbfaf1b8;
    padding: 5px;
    border: 1px solid #ffffffb0;
    border-radius: 30px;
    box-shadow: 0 4px 24px #45654507;
}

nav button {
    padding: 9px 15px;
    background: transparent;
    border-radius: 22px;
    font-size: 12px;
    white-space: nowrap;
}

nav button.active {
    background: var(--green);
    color: #fff9e9;
}

nav small {
    display: block;
    font-size: 8px;
    opacity: 0.7;
    margin-top: 2px;
}

.icon {
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: #fbfaf1b8;
}

.scene-caption {
    position: fixed;
    left: 36px;
    top: 21%;
    max-width: 280px;
    padding: 20px 22px;
    border-radius: 14px;
    background: rgba(246, 250, 255, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.68);
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 32px rgba(18, 52, 86, 0.12);
    pointer-events: none;
}

.eyebrow {
    font-size: 10px;
    color: var(--gold);
    letter-spacing: 2.5px;
    font-weight: 600;
}

h1 {
    font: 42px/1.4 Georgia, "PMingLiU", serif;
    letter-spacing: 4px;
    margin: 14px 0;
}

p {
    line-height: 1.9;
}

.scene-caption p {
    color: #425a5d;
    font-size: 12px;
}

.location {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-top: 25px;
    border-top: 1px solid #b8c5b663;
    padding-top: 20px;
}

.location-dot {
    width: 6px;
    height: 6px;
    background: #9a7c42;
    border-radius: 50%;
    box-shadow: 0 0 0 4px #a7824313;
}

.location strong {
    font-size: 12px;
    font-weight: 500;
    display: block;
}

.location small {
    display: block;
    font-size: 10px;
    color: var(--muted);
    margin-top: 6px;
}

.text-button {
    pointer-events: auto;
    border-bottom: 1px solid #a7824360;
    padding: 12px 0;
    background: transparent;
    font-size: 11px;
    letter-spacing: 1px;
}

.text-button span {
    margin-left: 28px;
}

.world-map {
    position: fixed;
    right: 36px;
    top: 135px;
    width: 170px;
    background: #fbfaf18c;
    border: 1px solid #ffffff90;
    padding: 14px;
    border-radius: 12px;
    backdrop-filter: blur(8px);
}

.map-head {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    letter-spacing: 1px;
}

.map-head small {
    font-size: 8px;
    color: var(--muted);
}

.map-inner {
    height: 108px;
    position: relative;
    margin: 10px 0;
    border-radius: 50%;
    background: radial-gradient(ellipse, #eef3e6, transparent);
}

.map-inner button {
    position: absolute;
    background: #f5f2df;
    border: 1px solid #c5cbb7;
    border-radius: 3px;
    font-size: 9px;
    padding: 3px 6px;
}

.map-hall {
    left: 50%;
    top: 4px;
    transform: translateX(-50%);
}

.map-tower {
    left: 5px;
    top: 48px;
}

.map-library {
    right: 4px;
    top: 54px;
}

.map-chant {
    right: 25px;
    bottom: 0;
}

.map-gallery {
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
}

#mapPlayer {
    position: absolute;
    width: 5px;
    height: 5px;
    background: #a78243;
    border-radius: 50%;
    box-shadow: 0 0 0 3px #a7824320;
    left: 50%;
    top: 65%;
}

.world-map p {
    font-size: 9px;
    text-align: center;
    letter-spacing: 1px;
    color: var(--muted);
    margin: 0;
}

.interaction {
    position: fixed;
    bottom: 205px;
    left: 50%;
    transform: translateX(-50%);
    background: #fcfbf1ed;
    box-shadow: 0 8px 50px #234b3720;
    border: 1px solid #c8b681;
    padding: 13px 20px;
    min-width: 240px;
    border-radius: 9px;
    text-align: center;
}

.interaction small {
    display: block;
    font-size: 9px;
    letter-spacing: 2px;
    color: var(--gold);
}

.interaction strong {
    display: block;
    font: 20px Georgia, "PMingLiU", serif;
    margin: 5px;
}

.interaction button {
    background: var(--green);
    color: #fff7df;
    padding: 8px 18px;
    border-radius: 4px;
    font-size: 11px;
}

.interaction button span {
    margin-left: 22px;
}

footer {
    position: fixed;
    bottom: calc(25px + env(safe-area-inset-bottom, 0px));
    left: calc(36px + env(safe-area-inset-left, 0px));
    right: calc(36px + env(safe-area-inset-right, 0px));
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 20px;
    z-index: 2;
}

.move-wrap {
    display: flex;
    gap: 14px;
    align-items: center;
    min-width: 235px;
    padding: 9px 14px 9px 10px;
    border-radius: 12px;
    background: rgba(248, 251, 255, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(10px);
}

.move-wrap p {
    font-size: 11px;
    letter-spacing: 2px;
    margin: 0;
}

.move-wrap small {
    font-size: 8px;
    letter-spacing: 0.4px;
    display: block;
    color: #465d5f;
    margin-top: 5px;
}

.dpad {
    width: 89px;
    display: grid;
    grid-template-columns: repeat(3, 27px);
    grid-template-rows: repeat(2, 27px);
    gap: 4px;
}

.dpad button {
    background: #fcfbf0d0;
    border: 1px solid #c6d1c4;
    border-radius: 5px;
    touch-action: none;
}

.dpad button:first-child {
    grid-column: 2;
}

.dpad button:nth-child(2) {
    grid-row: 2;
    grid-column: 1;
}

.dpad button:nth-child(3) {
    grid-row: 2;
    grid-column: 2;
}

.dpad button:nth-child(4) {
    grid-row: 2;
    grid-column: 3;
}

.avatar-panel {
    width: 330px;
    background: #fcfbf1e0;
    backdrop-filter: blur(16px);
    border: 1px solid #fffdf6;
    border-radius: 12px;
    padding: 14px 17px;
    box-shadow: 0 12px 40px #3c634010;
}

.panel-heading {
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    letter-spacing: 1px;
    margin-bottom: 12px;
}

.panel-heading small {
    font-size: 8px;
    color: var(--gold);
    letter-spacing: 0;
}

.avatars {
    display: flex;
    gap: 7px;
}

.avatars button {
    flex: 1;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 7px;
    padding: 9px 6px;
    font-size: 11px;
}

.avatars button.selected {
    border-color: #9aa98c;
    background: #e5ecdd;
}

.avatars button > span {
    display: block;
    font: 22px Georgia, serif;
    color: #a38240;
    margin-bottom: 5px;
}

.avatars small {
    display: block;
    font-size: 8px;
    color: var(--muted);
    margin-top: 4px;
}

.actions {
    min-width: 235px;
}

.actions > button {
    display: flex;
    gap: 12px;
    align-items: center;
    background: var(--green);
    color: #fff9e9;
    padding: 12px 20px;
    border-radius: 8px;
    width: 100%;
    text-align: left;
    box-shadow: 0 8px 30px #345d441a;
}

.actions > button > span {
    font: 23px Georgia, serif;
    border-right: 1px solid #ffffff30;
    padding-right: 13px;
}

.actions small {
    font-size: 8px;
    letter-spacing: 1px;
    display: block;
    opacity: 0.65;
    margin-top: 3px;
}

.utility-row {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    padding: 4px 10px;
    border-radius: 8px;
    background: rgba(248, 251, 255, 0.76);
    border: 1px solid rgba(255, 255, 255, 0.68);
    backdrop-filter: blur(8px);
}

.utility-row button {
    background: transparent;
    font-size: 9px;
    padding: 5px 3px;
    color: #36514d;
}

.mobile-pill,
.map-close,
.joystick {
    display: none;
}

.joystick {
    position: relative;
    width: 88px;
    height: 88px;
    border-radius: 50%;
    background: radial-gradient(circle at center, rgba(251, 250, 241, 0.58) 0%, rgba(238, 245, 240, 0.84) 100%);
    border: 1.5px solid rgba(167, 130, 67, 0.45);
    box-shadow: 0 6px 20px rgba(22, 52, 44, 0.14), inset 0 0 12px rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(8px);
    touch-action: none;
}

.joystick-ring {
    position: absolute;
    inset: 14px;
    border-radius: 50%;
    border: 1px dashed rgba(45, 96, 84, 0.25);
    pointer-events: none;
}

.joystick-thumb {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 36px;
    height: 36px;
    margin-left: -18px;
    margin-top: -18px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #448576 0%, var(--green) 70%);
    border: 2px solid #fbfaf1;
    box-shadow: 0 4px 12px rgba(25, 58, 49, 0.35);
    pointer-events: none;
    transition: transform 0.14s ease-out;
}

.joystick.active .joystick-thumb {
    transition: none;
    box-shadow: 0 4px 16px rgba(25, 58, 49, 0.48), 0 0 0 4px rgba(167, 130, 67, 0.22);
}

.dragon-status {
    display: block;
    flex: 1 0 100%;
    margin-top: 4px;
    min-height: 44px;
    padding: 8px 12px;
    border-radius: 10px;
    background: rgba(251, 250, 241, 0.92);
    color: var(--ink);
    border: 1px solid rgba(154, 124, 66, 0.35);
    box-shadow: 0 4px 12px rgba(25, 58, 49, 0.12);
    font-size: 11px;
    line-height: 1.4;
    text-align: left;
    cursor: pointer;
    pointer-events: auto;
}

.dragon-status:disabled {
    cursor: default;
    opacity: 0.85;
}

.dragon-status[hidden] {
    display: none;
}

.model-status-stack {
    position: fixed;
    bottom: max(100px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    max-width: calc(100vw - 24px);
    pointer-events: none;
}

.model-status {
    max-width: 100%;
    min-height: 44px;
    padding: 10px 16px;
    border-radius: 999px;
    background: rgba(251, 250, 241, 0.94);
    color: var(--ink);
    border: 1px solid rgba(154, 124, 66, 0.38);
    box-shadow: 0 8px 24px rgba(25, 58, 49, 0.18);
    backdrop-filter: blur(8px);
    font-size: 12px;
    line-height: 1.4;
    cursor: pointer;
    pointer-events: auto;
}

.model-status:disabled {
    cursor: default;
    opacity: 0.88;
}

.model-status[hidden] {
    display: none;
}

@media (max-width: 1100px) {
    header {
        padding: calc(18px + env(safe-area-inset-top, 0px)) calc(22px + env(safe-area-inset-right, 0px)) 16px calc(22px + env(safe-area-inset-left, 0px));
        gap: 12px;
    }

    .brand strong {
        font-size: 22px;
    }

    .brand small {
        font-size: 6px;
    }

    nav button {
        padding: 8px 10px;
        font-size: 11px;
    }

    .scene-caption {
        left: 26px;
        top: 21%;
        max-width: 210px;
    }

    h1 {
        font-size: 35px;
    }

    .world-map {
        right: 24px;
        width: 145px;
        top: 120px;
    }

    .move-wrap {
        min-width: 170px;
    }

    .move-wrap p {
        font-size: 10px;
    }

    .move-wrap small {
        font-size: 7px;
    }

    .actions {
        min-width: 190px;
    }

    .avatar-panel {
        width: 300px;
    }

    footer {
        left: calc(24px + env(safe-area-inset-left, 0px));
        right: calc(24px + env(safe-area-inset-right, 0px));
    }
}

@media (max-width: 760px), (max-width: 960px) and (max-height: 500px) {
    .mobile-pill {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 5px;
    }

    .map-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 44px;
        min-height: 44px;
        margin: -10px -10px -10px 0;
        padding: 0;
        background: transparent;
        color: var(--muted);
        font-size: 18px;
        line-height: 1;
    }

    header {
        height: auto;
        min-height: 0;
        background: transparent;
        align-items: center;
        padding: calc(10px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-right, 0px)) 0 calc(12px + env(safe-area-inset-left, 0px));
        flex-wrap: nowrap;
        gap: 6px;
        pointer-events: none;
    }

    header > * {
        pointer-events: auto;
    }

    .brand {
        gap: 6px;
        padding: 4px 9px;
        min-height: 44px;
        border-radius: 22px;
        background: rgba(251, 250, 241, 0.88);
        border: 1px solid rgba(255, 255, 255, 0.84);
        backdrop-filter: blur(8px);
        box-shadow: 0 4px 14px rgba(24, 58, 48, 0.08);
    }

    .seal {
        font-size: 11px;
        line-height: 1.05;
        padding: 2px 4px;
    }

    .brand strong {
        font-size: 14px;
        letter-spacing: 2px;
    }

    .brand small {
        display: none;
    }

    #navToggle {
        min-height: 44px;
        padding: 0 11px;
        border-radius: 22px;
        background: rgba(251, 250, 241, 0.88);
        border: 1px solid rgba(255, 255, 255, 0.84);
        backdrop-filter: blur(8px);
        font-size: 11px;
        font-weight: 600;
        color: var(--ink);
        white-space: nowrap;
        box-shadow: 0 4px 14px rgba(24, 58, 48, 0.08);
    }

    .header-tools {
        margin-left: auto;
        gap: 6px;
    }

    .net-pill {
        min-height: 44px;
        padding: 0 9px;
        font-size: 10px;
        max-width: min(124px, 32vw);
        overflow: hidden;
        gap: 5px;
    }

    #netStatusText {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .icon {
        width: 44px;
        height: 44px;
    }

    nav {
        display: none;
        position: fixed;
        top: calc(60px + env(safe-area-inset-top, 0px));
        left: 50%;
        transform: translateX(-50%);
        width: min(296px, calc(100vw - 24px));
        max-height: calc(100vh - 140px);
        max-height: calc(100dvh - 140px);
        overflow-y: auto;
        flex-wrap: wrap;
        justify-content: center;
        gap: 6px;
        padding: 10px;
        border-radius: 14px;
        background: rgba(251, 250, 241, 0.96);
        border: 1px solid #d5ddce;
        box-shadow: 0 12px 32px rgba(22, 52, 44, 0.18);
        backdrop-filter: blur(12px);
        z-index: 5;
    }

    nav.open {
        display: flex;
    }

    nav button {
        min-height: 44px;
        font-size: 11px;
        padding: 6px 12px;
    }

    nav small {
        font-size: 7px;
    }

    .scene-caption {
        top: calc(62px + env(safe-area-inset-top, 0px));
        left: calc(12px + env(safe-area-inset-left, 0px));
        max-width: min(200px, calc(100vw - 90px));
        padding: 6px 11px;
        border-radius: 18px;
        box-shadow: 0 4px 14px rgba(18, 52, 86, 0.1);
    }

    .scene-caption .eyebrow,
    .scene-caption h1,
    .scene-caption > p,
    .scene-caption .text-button {
        display: none;
    }

    .location {
        margin-top: 0;
        padding-top: 0;
        border-top: 0;
        gap: 7px;
        flex-wrap: wrap;
    }

    .location strong {
        font-size: 11px;
        line-height: 1.25;
    }

    .location small {
        display: none;
    }

    .dragon-status {
        margin-top: 4px;
        min-height: 44px;
        padding: 6px 10px;
        font-size: 10px;
        border-radius: 8px;
    }

    .model-status-stack {
        bottom: auto;
        top: calc(108px + env(safe-area-inset-top, 0px));
    }

    .map-toggle {
        position: fixed;
        top: calc(62px + env(safe-area-inset-top, 0px));
        right: calc(12px + env(safe-area-inset-right, 0px));
        min-width: 44px;
        min-height: 44px;
        padding: 0 11px;
        border-radius: 22px;
        background: rgba(251, 250, 241, 0.88);
        border: 1px solid rgba(255, 255, 255, 0.84);
        backdrop-filter: blur(8px);
        font-size: 11px;
        font-weight: 600;
        color: var(--ink);
        box-shadow: 0 4px 14px rgba(24, 58, 48, 0.08);
        z-index: 3;
    }

    .world-map {
        display: none;
        right: calc(12px + env(safe-area-inset-right, 0px));
        top: calc(62px + env(safe-area-inset-top, 0px));
        width: 172px;
        padding: 12px;
        z-index: 5;
        background: rgba(251, 250, 241, 0.96);
        box-shadow: 0 12px 30px rgba(22, 52, 44, 0.18);
    }

    .world-map.open {
        display: block;
    }

    .map-head {
        font-size: 10px;
        align-items: center;
    }

    .map-head small {
        font-size: 8px;
    }

    .map-inner {
        height: 112px;
        margin: 8px 0;
    }

    .map-inner button {
        font-size: 10px;
        min-width: 34px;
        min-height: 30px;
        padding: 4px 7px;
    }

    .world-map p {
        font-size: 7px;
    }

    .map-tower {
        left: 0;
        top: 35px;
    }

    .map-library {
        right: 0;
        top: 37px;
    }

    .map-chant {
        right: 12px;
    }

    footer {
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        left: calc(12px + env(safe-area-inset-left, 0px));
        right: calc(12px + env(safe-area-inset-right, 0px));
        gap: 8px;
        flex-wrap: nowrap;
        align-items: flex-end;
        justify-content: space-between;
        pointer-events: none;
    }

    footer > * {
        pointer-events: auto;
    }

    .move-wrap {
        position: static;
        min-width: 0;
        padding: 0;
        background: transparent;
        border: 0;
        backdrop-filter: none;
    }

    .move-wrap p,
    .dpad {
        display: none;
    }

    .joystick {
        display: block;
    }

    .avatar-toggle {
        min-height: 44px;
        padding: 0 12px;
        border-radius: 22px;
        background: rgba(251, 250, 241, 0.9);
        border: 1px solid rgba(255, 255, 255, 0.86);
        backdrop-filter: blur(10px);
        font-size: 11px;
        font-weight: 600;
        color: var(--ink);
        white-space: nowrap;
        box-shadow: 0 6px 18px rgba(24, 58, 48, 0.12);
    }

    .avatar-toggle span {
        font-family: Georgia, serif;
        color: var(--gold);
        font-size: 14px;
    }

    .avatar-panel {
        display: none;
        position: fixed;
        left: 50%;
        bottom: calc(64px + env(safe-area-inset-bottom, 0px));
        transform: translateX(-50%);
        width: min(280px, calc(100vw - 24px));
        max-height: calc(100vh - 130px);
        max-height: calc(100dvh - 130px);
        overflow-y: auto;
        padding: 10px 12px;
        z-index: 5;
        background: rgba(252, 251, 241, 0.96);
        box-shadow: 0 12px 32px rgba(22, 52, 44, 0.2);
    }

    .avatar-panel.open {
        display: block;
    }

    .avatars button {
        min-height: 44px;
        font-size: 10px;
        padding: 6px;
    }

    .avatars button > span {
        font-size: 18px;
        margin-bottom: 2px;
    }

    .avatars small {
        font-size: 7px;
    }

    .panel-heading {
        margin-bottom: 5px;
        font-size: 8px;
    }

    .panel-heading small {
        font-size: 7px;
    }

    .actions {
        min-width: 0;
        width: auto;
        display: flex;
        flex-direction: column-reverse;
        align-items: flex-end;
        gap: 6px;
    }

    .actions > button {
        min-height: 44px;
        width: auto;
        padding: 6px 12px;
        gap: 8px;
        border-radius: 22px;
        font-size: 11px;
        white-space: nowrap;
    }

    .actions > button > span {
        font-size: 16px;
        padding-right: 8px;
    }

    .actions small {
        display: none;
    }

    .utility-row {
        position: static;
        flex-direction: row;
        gap: 2px;
        margin: 0;
        padding: 0 4px;
        border-radius: 22px;
        background: rgba(251, 250, 241, 0.88);
        border: 1px solid rgba(255, 255, 255, 0.84);
    }

    .utility-row button {
        min-height: 44px;
        padding: 0 7px;
        font-size: 10px;
        white-space: nowrap;
    }

    .interaction {
        bottom: calc(116px + env(safe-area-inset-bottom, 0px));
        padding: 8px 14px;
        min-width: 170px;
    }

    .interaction strong {
        font-size: 16px;
    }

    .interaction button {
        min-height: 44px;
        font-size: 11px;
    }

    .scene-caption.minimal {
        top: calc(62px + env(safe-area-inset-top, 0px));
    }
}

@media (max-width: 960px) and (max-height: 500px) {
    .joystick {
        width: 78px;
        height: 78px;
    }

    .joystick-ring {
        inset: 12px;
    }

    .joystick-thumb {
        width: 32px;
        height: 32px;
        margin-left: -16px;
        margin-top: -16px;
    }

    .interaction {
        bottom: calc(66px + env(safe-area-inset-bottom, 0px));
        padding: 6px 12px;
    }
}

@media (pointer: coarse) {
    .move-wrap {
        min-width: 0;
        padding: 0;
        background: transparent;
        border: 0;
    }

    .move-wrap p,
    .dpad {
        display: none;
    }

    .joystick {
        display: block;
    }

    .net-pill,
    .utility-row button {
        min-height: 44px;
    }

    .icon {
        min-width: 44px;
        min-height: 44px;
    }

    .brand,
    #navToggle,
    .net-pill,
    .icon,
    nav,
    .map-toggle,
    .world-map,
    .joystick,
    .avatar-toggle,
    .avatar-panel,
    .actions button,
    .utility-row,
    .utility-row button,
    .interaction,
    .ritual-status,
    .scene-caption,
    .move-wrap {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
}

