* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary-color: #000;
    --secondary-color: #666;
    --bg-color: #fafafa;
    --card-bg: rgba(255, 255, 255, 0.8);
    --blur-bg: rgba(255, 255, 255, 0.7);
    --border-color: rgba(0, 0, 0, 0.1);
    --safe-area-top: env(safe-area-inset-top, 44px);
    --safe-area-bottom: env(safe-area-inset-bottom, 34px);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    overflow: hidden;
    color: var(--primary-color);
}

.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    background: var(--bg-color);
}

.screen.active {
    display: flex;
}

.safe-area-top {
    height: var(--safe-area-top);
    min-height: 44px;
    background: transparent;
    flex-shrink: 0;
}

/* 锁屏界面 */
#lockScreen {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    justify-content: center;
    align-items: center;
    transition: transform 0.3s ease, opacity 0.3s ease;
    cursor: grab;
}

.lock-content {
    text-align: center;
    color: white;
    margin-bottom: 100px;
}

.lock-time {
    font-size: 72px;
    font-weight: 200;
    letter-spacing: -2px;
    text-shadow: 0 2px 20px rgba(0, 0, 0, 0.2);
}

.lock-date {
    font-size: 18px;
    font-weight: 400;
    opacity: 0.9;
    margin-top: 8px;
}

.swipe-hint {
    position: absolute;
    bottom: calc(var(--safe-area-bottom) + 60px);
    left: 50%;
    transform: translateX(-50%);
    color: white;
    text-align: center;
    animation: bounce 2s infinite;
}

.swipe-arrow {
    width: 30px;
    height: 30px;
    border-left: 2px solid white;
    border-top: 2px solid white;
    transform: rotate(45deg);
    margin: 0 auto 10px;
    opacity: 0.8;
}

.swipe-hint span {
    font-size: 14px;
    opacity: 0.8;
}

@keyframes bounce {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-10px); }
}

/* 密码界面 */
#passwordScreen, #changePasswordScreen {
    background: var(--bg-color);
}

.password-content, .change-password-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.password-title {
    font-size: 20px;
    font-weight: 500;
    margin-bottom: 30px;
    color: var(--primary-color);
}

.password-dots {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.password-dots .dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--primary-color);
    background: transparent;
    transition: all 0.2s ease;
}

.password-dots .dot.filled {
    background: var(--primary-color);
}

.password-error {
    color: #ff3b30;
    font-size: 14px;
    height: 20px;
    margin-bottom: 20px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.password-error.show {
    opacity: 1;
}

.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    max-width: 280px;
    width: 100%;
}

.num-btn {
    width: 75px;
    height: 75px;
    border-radius: 50%;
    border: none;
    background: var(--card-bg);
    font-size: 28px;
    font-weight: 400;
    color: var(--primary-color);
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.num-btn:active {
    transform: scale(0.95);
    background: rgba(0, 0, 0, 0.1);
}

.num-btn.empty {
    background: transparent;
    box-shadow: none;
    cursor: default;
}

.num-btn.delete {
    background: transparent;
    box-shadow: none;
}

.num-btn.delete:active {
    background: rgba(0, 0, 0, 0.05);
}

.shake {
    animation: shake 0.4s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

/* 修改密码步骤 */
.password-step {
    text-align: center;
    margin-bottom: 10px;
}

.password-step.hidden {
    display: none;
}

.password-step-title {
    font-size: 18px;
    font-weight: 500;
    margin-bottom: 20px;
    color: var(--primary-color);
}

/* 聊天界面 */
#chatScreen {
    background: var(--bg-color);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--blur-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
}

.header-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--primary-color);
    transition: background 0.2s ease;
}

.header-btn:active {
    background: rgba(0, 0, 0, 0.05);
}

.char-name {
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 16px;
    border-radius: 20px;
    transition: background 0.2s ease;
}

.char-name:active {
    background: rgba(0, 0, 0, 0.05);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    max-width: 90%;
    align-items: flex-start;
    gap: 10px;
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.ai {
    align-self: flex-start;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 500;
    flex-shrink: 0;
    background-size: cover;
    background-position: center;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 20px;
    font-size: 15px;
    line-height: 1.4;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    position: relative;
    /* 预留气泡自定义CSS类点 */
}

.message.user .message-bubble {
    background: rgba(102, 126, 234, 0.85);
    color: white;
    border-top-right-radius: 6px;
}

.message.ai .message-bubble {
    background: rgba(255, 255, 255, 0.75);
    color: var(--primary-color);
    border-top-left-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

/* 语音气泡特有样式 */
.voice-bubble {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 80px;
}

.message.user .voice-bubble {
    flex-direction: row-reverse;
}

.voice-icon {
    width: 20px;
    height: 20px;
    opacity: 0.8;
}

.voice-icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

/* 文字图片气泡特有样式 */
.photo-bubble {
    /* 默认覆盖图可以在这修改或通过自定义CSS覆盖 */
    background-color: #ddd;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 24 24"><path fill="%23999" d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/></svg>');
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    color: transparent !important;
    min-width: 150px;
    min-height: 120px;
    cursor: pointer;
    user-select: none;
    transition: all 0.3s ease;
}

.photo-bubble.revealed {
    background-image: none !important;
    background-color: transparent !important;
    color: inherit !important;
    min-width: auto;
    min-height: auto;
}

.chat-input-area {
    padding: 12px 16px;
    padding-bottom: calc(12px + var(--safe-area-bottom));
    background: var(--blur-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-color);
}

.input-container {
    display: flex;
    align-items: center;
    gap: 8px;
    background: white;
    border-radius: 25px;
    padding: 6px 6px 6px 16px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.input-container input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 15px;
    background: transparent;
    color: var(--primary-color);
}

.input-container input::placeholder {
    color: #999;
}

.input-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--secondary-color);
    transition: all 0.2s ease;
}

.input-btn:active {
    background: rgba(0, 0, 0, 0.05);
}

.send-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: transform 0.2s ease;
}

.send-btn:active {
    transform: scale(0.95);
}

/* 扩展功能面板 */
.extension-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--blur-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-color);
    padding: 20px;
    padding-bottom: calc(20px + var(--safe-area-bottom));
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 10;
}

.extension-panel.show {
    transform: translateY(0);
}

.extension-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

.extension-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.extension-icon {
    width: 56px;
    height: 56px;
    background: white;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--secondary-color);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s ease;
}

.extension-item:active .extension-icon {
    transform: scale(0.95);
}

.extension-item span {
    font-size: 12px;
    color: var(--secondary-color);
}

/* 设置界面 */
#settingsScreen {
    background: var(--bg-color);
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--blur-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
}

.back-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--primary-color);
    transition: background 0.2s ease;
}

.back-btn:active {
    background: rgba(0, 0, 0, 0.05);
}

.settings-title {
    font-size: 17px;
    font-weight: 600;
}

.settings-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
}

.settings-section {
    margin-bottom: 30px;
}

.settings-section-title {
    font-size: 13px;
    color: var(--secondary-color);
    text-transform: uppercase;
    margin-bottom: 10px;
    padding-left: 4px;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: white;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
}

.settings-item:active {
    background: #f5f5f5;
}

.settings-item span {
    font-size: 16px;
}

.settings-item svg {
    color: #ccc;
}

/* 世界书列表 */
.wb-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
    cursor: pointer;
    transition: background 0.2s ease;
}

.wb-item:active {
    background: #f5f5f5;
}

.wb-info {
    flex: 1;
    overflow: hidden;
}

.wb-name {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wb-meta {
    font-size: 12px;
    color: var(--secondary-color);
}

.wb-delete {
    padding: 8px;
    color: #ff3b30;
    font-size: 14px;
    margin-left: 10px;
    border-radius: 8px;
    background: rgba(255, 59, 48, 0.1);
}

/* 角色列表 */
.char-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: hidden;
}

.char-item-wrapper {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: #ff3b30;
}

.char-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: white;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), background 0.2s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
    z-index: 2;
    touch-action: pan-y;
}

.char-delete-btn {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 80px;
    background: #ff3b30;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    z-index: 1;
    border-radius: 0 12px 12px 0;
    cursor: pointer;
}

.char-item.swiped {
    transform: translateX(-80px);
}

.char-item:active {
    background: #f5f5f5;
}

.char-item.active {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border: 1px solid rgba(102, 126, 234, 0.3);
}

.char-avatar {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    font-weight: 500;
    background-size: cover;
    background-position: center;
}

/* 胶囊气泡半透明模糊按钮 */
.glass-btn {
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: var(--primary-color);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    text-align: center;
}

.glass-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.8);
}

/* 图片历史记录网格 */
.image-history-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 10px;
}

.history-img-item {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    background-size: cover;
    background-position: center;
    border: 2px solid transparent;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.history-img-item.selected {
    border-color: var(--primary-color);
}

/* 表单样式 */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--secondary-color);
    margin-bottom: 8px;
    padding-left: 4px;
}

.form-group input, .form-group textarea {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: white;
    font-size: 15px;
    color: var(--primary-color);
    outline: none;
    transition: border-color 0.2s ease;
    font-family: inherit;
    resize: vertical;
}

.form-group input:focus, .form-group textarea:focus {
    border-color: #667eea;
}

.char-info {
    flex: 1;
}

.char-item-name {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 2px;
}

.char-item-desc {
    font-size: 13px;
    color: var(--secondary-color);
}

.char-check {
    font-size: 18px;
    color: #667eea;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.char-item.active .char-check {
    opacity: 1;
}

/* 角色选择弹窗 */
.char-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.char-modal.show {
    opacity: 1;
    visibility: visible;
}

.char-modal-content {
    width: 100%;
    max-width: 400px;
    background: var(--bg-color);
    border-radius: 20px 20px 0 0;
    padding: 20px;
    padding-bottom: calc(20px + var(--safe-area-bottom));
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.char-modal.show .char-modal-content {
    transform: translateY(0);
}

.char-modal-header {
    text-align: center;
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 20px;
}

.char-modal-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.char-modal-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: white;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.char-modal-item:active {
    background: #f5f5f5;
}

.char-modal-item.active {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border: 1px solid rgba(102, 126, 234, 0.3);
}

.char-modal-item span {
    font-size: 16px;
    font-weight: 500;
}

.char-modal-close {
    width: 100%;
    padding: 16px;
    border: none;
    background: white;
    border-radius: 12px;
    font-size: 16px;
    color: #ff3b30;
    cursor: pointer;
    transition: background 0.2s ease;
}

.char-modal-close:active {
    background: #f5f5f5;
}

/* 隐藏类 */
.hidden {
    display: none !important;
}

/* 响应式调整 */
@media (max-width: 375px) {
    .num-btn {
        width: 65px;
        height: 65px;
        font-size: 24px;
    }
    
    .numpad {
        gap: 12px;
    }
    
    .lock-time {
        font-size: 60px;
    }
}

@media (min-width: 768px) {
    .screen {
        max-width: 414px;
        max-height: 896px;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        border-radius: 40px;
        overflow: hidden;
        box-shadow: 0 25px 80px rgba(0, 0, 0, 0.3);
    }
    
    body {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}
