* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
    background: #0b0716;
    color: #efe9ff;
    font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    -webkit-text-size-adjust: 100%;
    background-color: #0b0716 !important;
    background: radial-gradient(ellipse at 50% 30%, #2a1a4a 0%, #150d28 45%, #0b0716 100%);
}

button,
a {
    outline: none;
    -webkit-appearance: none;
    border: none;
    background: none;
}

::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(120, 90, 200, 0.4);
    border-radius: 5px;
}

.l2d-bg {
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 0;
    background: #0b0716;
    background: radial-gradient(ellipse at 50% 30%, #2a1a4a 0%, #150d28 45%, #0b0716 100%);
    overflow: hidden;
    pointer-events: none;
    -webkit-transition: opacity 0.3s ease;
    transition: opacity 0.3s ease;
}

.l2d-bg.is-hidden {
    opacity: 0;
}

.l2d-stage {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    box-sizing: border-box;
    background: transparent;
}

.l2d-stage canvas {
    display: block;
    position: absolute;
    left: 0;
    top: 0;
    width: 100% !important;
    height: 100% !important;
}

.l2d-loading {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    margin-top: -22px;
    text-align: center;
    color: #b0a0d0;
    font-size: 13px;
    pointer-events: none;
    z-index: 5;
}

.l2d-loading .spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(180, 160, 240, 0.2);
    border-top-color: #b0a0d0;
    border-radius: 50%;
    -webkit-animation: l2d-spin 0.8s linear infinite;
    animation: l2d-spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
    margin-top: -3px;
}

@-webkit-keyframes l2d-spin {
    from {
        -webkit-transform: rotate(0deg);
    }
    to {
        -webkit-transform: rotate(360deg);
    }
}

@keyframes l2d-spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.l2d-status {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 8px;
    text-align: center;
    font-size: 12px;
    color: #b0a0d0;
    pointer-events: none;
    z-index: 10;
}

.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: 12px 18px 10px;
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    align-items: center;
    -webkit-box-pack: justify;
    -webkit-justify-content: space-between;
    justify-content: space-between;
    z-index: 3;
    background: #0b0716;
    background: -webkit-linear-gradient(top, rgba(11, 7, 22, 0.92), rgba(11, 7, 22, 0));
    background: linear-gradient(to bottom, rgba(11, 7, 22, 0.92), rgba(11, 7, 22, 0));
    pointer-events: none;
}

.topbar .title {
    font-size: 15px;
    letter-spacing: 3px;
    color: #b8aae0;
    font-weight: 600;
}

.icon-btn {
    pointer-events: auto;
    width: 36px;
    height: 36px;
    margin: 0 0 0 10px;
    padding: 0;
    border-radius: 5px;
    border: 1px solid rgba(190, 170, 255, 0.18);
    background: rgba(28, 18, 48, 0.55);
    color: #cfc1ff;
    font-size: 13px;
    letter-spacing: 1px;
    line-height: 1;
    cursor: pointer;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    transition: background 0.2s, border-color 0.2s;
}

.icon-btn:active {
    background: rgba(60, 40, 100, 0.8);
    border-color: rgba(190, 170, 255, 0.4);
}

.messages {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 82px;
    max-height: 372px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px 16px 6px;
    z-index: 2;
    background: transparent;
}

.messages::-webkit-scrollbar {
    display: none;
}

.bubble {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: 5px;
    font-size: 14.5px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
    -webkit-animation: pop 0.22s ease-out both;
    animation: pop 0.22s ease-out both;
    margin-bottom: 10px;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.bubble:last-child {
    margin-bottom: 0;
}

.bubble.user {
    margin-left: auto;
    margin-right: 0;
    background: rgba(109, 75, 216, 0.55);
    border: 1px solid rgba(154, 107, 255, 0.35);
    border-bottom-right-radius: 5px;
    color: #ffffff;
}

.bubble.ai {
    margin-left: 0;
    margin-right: auto;
    background: rgba(28, 18, 48, 0.5);
    border: 1px solid rgba(190, 170, 255, 0.18);
    border-bottom-left-radius: 5px;
    color: #ece6ff;
}

.bubble.sys {
    margin-left: auto;
    margin-right: auto;
    font-size: 12px;
    color: #a99fd0;
    background: transparent;
    padding: 2px 6px;
}

@-webkit-keyframes pop {
    0% {
        opacity: 0;
        -webkit-transform: translateY(8px) scale(0.97);
        transform: translateY(8px) scale(0.97);
    }
    100% {
        opacity: 1;
        -webkit-transform: none;
        transform: none;
    }
}

@keyframes pop {
    0% {
        opacity: 0;
        -webkit-transform: translateY(8px) scale(0.97);
        transform: translateY(8px) scale(0.97);
    }
    100% {
        opacity: 1;
        -webkit-transform: none;
        transform: none;
    }
}

.composer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 12px 14px 16px;
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-box-align: end;
    -webkit-align-items: flex-end;
    align-items: flex-end;
    z-index: 3;
    background: #0b0716;
    background: -webkit-linear-gradient(bottom, rgba(11, 7, 22, 0.96), rgba(11, 7, 22, 0.4));
    background: linear-gradient(to top, rgba(11, 7, 22, 0.96), rgba(11, 7, 22, 0.4));
}

.composer-textarea {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    flex: 1;
    resize: none;
    max-height: 96px;
    min-height: 44px;
    padding: 11px 14px;
    border-radius: 5px;
    border: 1px solid rgba(190, 170, 255, 0.2);
    background: rgba(28, 18, 48, 0.6);
    color: #efe9ff;
    font-size: 14.5px;
    line-height: 1.4;
    font-family: inherit;
    outline: none;
    margin-right: 8px;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.composer-textarea:focus {
    border-color: rgba(154, 107, 255, 0.55);
    background: rgba(34, 22, 58, 0.75);
}

.composer-textarea::-webkit-input-placeholder {
    color: #a99fd0;
}

.composer-textarea::-moz-placeholder {
    color: #a99fd0;
    opacity: 1;
}

.composer-textarea:-ms-input-placeholder {
    color: #a99fd0;
}

.composer-btn {
    -webkit-box-flex: 0;
    -webkit-flex: 0 0 auto;
    flex: 0 0 auto;
    height: 44px;
    padding: 0 20px;
    border-radius: 5px;
    border: none;
    background: #7fd8ff;
    background: -webkit-linear-gradient(135deg, #6d4bd8, #9a6bff);
    background: linear-gradient(135deg, #6d4bd8, #9a6bff);
    color: #ffffff;
    font-size: 14.5px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(109, 75, 216, 0.35);
}

.composer-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

.composer-btn:active {
    opacity: 0.85;
}

.sheet {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    background: #1f1436;
    border-top: 1px solid rgba(190, 170, 255, 0.22);
    border-radius: 20px 20px 0 0;
    padding: 18px 16px 18px;
    max-height: 86%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    -webkit-transform: translateY(105%);
    transform: translateY(105%);
    -webkit-transition: -webkit-transform 0.25s ease;
    transition: transform 0.25s ease;
}

.sheet.show {
    -webkit-transform: translateY(0);
    transform: translateY(0);
}

.sheet-title {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 12px;
}

.sheet label {
    display: block;
    font-size: 13px;
    color: #a99fd0;
    margin-bottom: 12px;
}

.sheet input,
.sheet textarea {
    display: block;
    width: 100%;
    padding: 11px 13px;
    border-radius: 12px;
    border: 1px solid rgba(190, 170, 255, 0.22);
    background: rgba(255, 255, 255, 0.05);
    color: #efe9ff;
    font-size: 15px;
    font-family: inherit;
    outline: none;
    margin-top: 6px;
    -webkit-appearance: none;
    -webkit-border-radius: 12px;
}

.sheet textarea {
    resize: vertical;
}

.row {
    display: block;
    font-size: 14px;
    color: #efe9ff;
    margin-bottom: 12px;
}

.row input[type="checkbox"] {
    width: 22px;
    height: 22px;
}

.sheet-actions {
    display: block;
    margin-top: 6px;
}

.sheet-actions:after {
    content: "";
    display: table;
    clear: both;
}

.sheet-actions button {
    float: left;
    width: 50%;
    height: 46px;
    border-radius: 14px;
    border: 1px solid rgba(190, 170, 255, 0.22);
    background: rgba(255, 255, 255, 0.06);
    color: #efe9ff;
    font-size: 15px;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    -webkit-appearance: none;
    -webkit-border-radius: 14px;
}

.sheet-actions button:first-child {
    width: 49%;
    margin-right: 2%;
}

.sheet-actions button+button {
    width: 49%;
    margin-left: 0;
}

.sheet-actions .primary {
    border: none;
    background: #7fd8ff;
    background: -webkit-linear-gradient(135deg, #7fd8ff, #b78cff);
    background: linear-gradient(135deg, #7fd8ff, #b78cff);
    color: #140b26;
    font-weight: 700;
}

body.keyboard-open .messages {
    display: none;
}

.settings-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9500;
    background: #fbf9ff;
    background: -webkit-linear-gradient(top, #ffffff 0%, #f3eeff 100%);
    background: linear-gradient(180deg, #ffffff 0%, #f3eeff 100%);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    box-shadow: 0 -8px 32px rgba(90, 60, 180, 0.22);
    -webkit-box-shadow: 0 -8px 32px rgba(90, 60, 180, 0.22);
    padding: 20px 18px 24px;
    box-sizing: border-box;
    max-height: 86%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    -webkit-transform: translate3d(0, 100%, 0);
    transform: translate3d(0, 100%, 0);
    -webkit-transition: -webkit-transform 0.26s ease;
    transition: transform 0.26s ease;
}

.settings-sheet.is-show {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
}

.settings-sheet .sheet-title {
    font-size: 17px;
    font-weight: 600;
    color: #3a2a6a;
    margin-bottom: 16px;
    text-align: center;
}

.settings-sheet label {
    display: block;
    font-size: 13px;
    color: #5a4a7a;
    margin-bottom: 14px;
}

.settings-sheet input,
.settings-sheet textarea {
    display: block;
    width: 100%;
    box-sizing: border-box;
    margin-top: 6px;
    padding: 10px 12px;
    font-size: 14px;
    color: #2a1a4a;
    background: #ffffff;
    border: 1px solid rgba(160, 140, 220, 0.4);
    border-radius: 10px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    -webkit-transition: border-color 0.2s ease;
    transition: border-color 0.2s ease;
}

.settings-sheet input:focus,
.settings-sheet textarea:focus {
    border-color: #8a6ad0;
}

.settings-sheet input:disabled,
.settings-sheet textarea:disabled {
    background: #f0ecfa;
    color: #9a8aba;
}

.settings-sheet .persona-input {
    resize: vertical;
    min-height: 80px;
    line-height: 1.5;
}

.settings-sheet .lock-tip {
    font-size: 12px;
    color: #b06a2a;
    background: #fff4e6;
    border: 1px solid #ffd9a8;
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 14px;
}

.settings-sheet .lock-tip.hidden {
    display: none;
}

.settings-sheet .sheet-actions {
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-box-pack: justify;
    -webkit-justify-content: space-between;
    justify-content: space-between;
    margin-top: 8px;
}

.settings-sheet .sheet-actions button {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    flex: 1;
    padding: 12px 0;
    font-size: 15px;
    border-radius: 12px;
    border: 1px solid rgba(160, 140, 220, 0.4);
    background: #ffffff;
    color: #5a4a7a;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.settings-sheet .sheet-actions button.primary {
    background: #8a6ad0;
    color: #ffffff;
    border-color: #8a6ad0;
    margin-left: 10px;
}

.settings-sheet .sheet-actions button:active {
    opacity: 0.85;
}

.chat-app-container {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
    padding: 8px 12px 4px;
    pointer-events: auto;
}

.chat-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 4px 12px;
    flex-shrink: 0;
}

.chat-title {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    background: linear-gradient(135deg, #c7b3ff, #9d7aff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.chat-topbar-actions {
    display: flex;
}

.chat-icon-btn {
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: 5px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: #d9d0ff;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid rgba(180, 150, 255, 0.2);
    margin-left: 8px;
}

.chat-icon-btn:hover {
    background: rgba(170, 140, 255, 0.25);
    color: white;
    transform: scale(0.96);
}

.chat-messages {
    flex: 3;
    overflow-y: auto;
    padding: 12px 2px 12px;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: #4a3b6e #1a1328;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #1a1328;
    border-radius: 5px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #4a3b6e;
    border-radius: 5px;
}

.chat-message-row {
    display: flex;
    align-items: flex-start;
    max-width: 100%;
    margin-bottom: 10px;
    -webkit-animation: pop 0.22s ease-out both;
    animation: pop 0.22s ease-out both;
}

.chat-message-row:last-child {
    margin-bottom: 0;
}

.chat-message-row.bot {
    flex-direction: row;
}

.chat-message-row.user {
    flex-direction: row-reverse;
}

.chat-avatar {
    width: 34px;
    height: 34px;
    border-radius: 5px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
    background: rgba(42, 31, 61, 0.75);
    border: 1px solid rgba(170, 140, 255, 0.3);
    color: #cfc1ff;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.chat-message-row.bot .chat-avatar {
    background: rgba(74, 46, 122, 0.7);
    border-color: rgba(167, 139, 250, 0.5);
    color: #e0d6ff;
}

.chat-message-row.user .chat-avatar {
    background: rgba(42, 90, 110, 0.7);
    border-color: rgba(110, 200, 224, 0.5);
    color: #d6f0fa;
}

.chat-bubble-wrapper {
    max-width: calc(100% - 46px);
    display: flex;
    flex-direction: column;
}

.chat-message-row.bot .chat-bubble-wrapper {
    margin-left: 10px;
    align-items: flex-start;
}

.chat-message-row.user .chat-bubble-wrapper {
    margin-right: 10px;
    align-items: flex-end;
}

.chat-bubble {
    padding: 10px 14px;
    border-radius: 5px;
    font-size: 14.5px;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
    max-width: 100%;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.chat-message-row.bot .chat-bubble {
    background: rgba(28, 18, 48, 0.5);
    border: 1px solid rgba(190, 170, 255, 0.18);
    border-bottom-left-radius: 5px;
    color: #ece6ff;
}

.chat-message-row.user .chat-bubble {
    background: rgba(109, 75, 216, 0.55);
    border: 1px solid rgba(154, 107, 255, 0.35);
    border-bottom-right-radius: 5px;
    color: #ffffff;
}

.chat-composer {
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    padding: 10px 0 12px;
    border-top: 1px solid rgba(140, 110, 210, 0.15);
    margin-top: 8px;
}

.chat-composer-textarea {
    flex: 1;
    background: rgba(25, 20, 40, 0.6);
    border: 1px solid rgba(150, 120, 220, 0.3);
    border-radius: 5px;
    padding: 10px 16px;
    font-size: 0.95rem;
    color: #f0eaff;
    resize: none;
    outline: none;
    max-height: 96px;
    line-height: 1.4;
    transition: border 0.2s, box-shadow 0.2s;
    font-family: inherit;
    -webkit-appearance: none;
    margin-right: 8px;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.2);
}

.chat-composer-textarea::placeholder {
    color: #8a7aa8;
}

.chat-composer-textarea:focus {
    border-color: #9d7aff;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.2), 0 0 0 2px rgba(157, 122, 255, 0.2);
}

.chat-composer-btn {
    background: rgba(90, 61, 154, 0.7);
    border: 1px solid rgba(160, 130, 240, 0.3);
    border-radius: 5px;
    padding: 10px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 12px rgba(100, 70, 200, 0.2);
    white-space: nowrap;
    letter-spacing: 0.3px;
    -webkit-appearance: none;
    flex-shrink: 0;
}

.chat-composer-btn:hover {
    background: rgba(110, 80, 190, 0.85);
    transform: scale(0.97);
}

.chat-composer-btn:active {
    transform: scale(0.94);
}

.model-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9600;
    background: rgba(20, 14, 36, 0.98);
    border-top: 1px solid rgba(190, 170, 255, 0.2);
    border-radius: 12px 12px 0 0;
    padding: 18px 16px 24px;
    max-height: 70%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    -webkit-transform: translate3d(0, 100%, 0);
    transform: translate3d(0, 100%, 0);
    -webkit-transition: -webkit-transform 0.26s ease;
    transition: transform 0.26s ease;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}

.model-sheet.is-show {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
}

.model-sheet .model-sheet-title {
    font-size: 15px;
    font-weight: 600;
    color: #d9d0ff;
    margin-bottom: 14px;
    letter-spacing: 1px;
    text-align: center;
}

.model-item {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    margin-bottom: 8px;
    border-radius: 5px;
    border: 1px solid rgba(190, 170, 255, 0.18);
    background: rgba(40, 28, 70, 0.5);
    color: #ece6ff;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.model-item:active {
    background: rgba(80, 55, 140, 0.7);
}

.model-item.current {
    border-color: rgba(154, 107, 255, 0.7);
    background: rgba(109, 75, 216, 0.35);
}

.model-item .model-name {
    flex: 1;
    word-break: break-all;
    padding-right: 10px;
}

.model-item .model-badge {
    font-size: 12px;
    color: #9d7aff;
    flex-shrink: 0;
}

.model-item.current .model-badge {
    color: #b9a4ff;
}

.model-sheet-mask {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 9590;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.26s ease;
}

.model-sheet-mask.is-show {
    opacity: 1;
    pointer-events: auto;
}

#live2d-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    pointer-events: none;
    touch-action: none;
    transition: opacity 0.3s ease;
    opacity: 1;
    background: transparent;
    overflow: hidden;
}

#live2d-layer.hidden {
    opacity: 0;
    pointer-events: none;
}

#live2d-layer canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    pointer-events: auto;
    touch-action: none;
    cursor: grab;
}

#live2d-layer canvas.dragging {
    cursor: grabbing;
}

@media (max-width: 420px) {
    .chat-app-container {
        padding: 4px 8px 2px;
    }
    .chat-bubble {
        font-size: 0.9rem;
        padding: 8px 12px;
    }
    .chat-avatar {
        width: 34px;
        height: 34px;
        font-size: 1.1rem;
    }
    .chat-bubble-wrapper {
        max-width: calc(100% - 48px);
    }
    .chat-composer-btn {
        padding: 10px 16px;
        font-size: 0.9rem;
    }
    .icon-btn {
        width: 34px;
        height: 34px;
        font-size: 12px;
    }
}