* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --rose: #ffb7c5;
    --rose-dark: #e68a9f;
    --rose-light: #fff0f3;
    --cream: #fff8f5;
    --text: #4a3f3f;
    --text-light: #8a7a7a;
    --shadow: rgba(74, 63, 63, 0.08);
}

body {
    font-family: 'Noto Serif SC', 'Nunito', serif;
    color: var(--text);
    background: linear-gradient(135deg, #fff0f3 0%, #fff8f5 100%);
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* 飘落的爱心 */
.hearts {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.heart-float {
    position: absolute;
    color: var(--rose);
    opacity: 0.4;
    animation: floatUp linear infinite;
}

@keyframes floatUp {
    0% {
        transform: translateY(100vh) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 0.5;
    }
    90% {
        opacity: 0.3;
    }
    100% {
        transform: translateY(-10vh) rotate(360deg);
        opacity: 0;
    }
}

.hidden {
    display: none !important;
}

/* 登录页 */
.login-screen {
    position: relative;
    z-index: 1;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.login-box {
    background: white;
    padding: 2.5rem 1.8rem;
    border-radius: 24px;
    box-shadow: 0 20px 60px var(--shadow);
    text-align: center;
    width: 100%;
    max-width: 360px;
}

.login-box h1 {
    font-size: 1.6rem;
    margin-bottom: 0.5rem;
    color: var(--rose-dark);
}

.login-box .subtitle {
    color: var(--text-light);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.role-selector {
    display: flex;
    justify-content: center;
    gap: 1.2rem;
    margin-bottom: 1rem;
}

.role-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 90px;
    height: 90px;
    background: white;
    border: 2px solid rgba(255, 183, 197, 0.3);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    user-select: none;
}

.role-option:hover {
    transform: translateY(-3px);
    border-color: var(--rose);
}

.role-option.selected {
    background: linear-gradient(135deg, var(--rose), var(--rose-dark));
    border-color: transparent;
    color: white;
    box-shadow: 0 8px 24px rgba(255, 183, 197, 0.4);
}

.role-icon {
    font-size: 2rem;
    margin-bottom: 0.3rem;
}

.role-name {
    font-size: 0.85rem;
}

.login-box input {
    width: 100%;
    padding: 0.9rem 1.2rem;
    margin-bottom: 1rem;
    border: 1.5px solid rgba(255, 183, 197, 0.4);
    border-radius: 12px;
    font-size: 16px; /* 防止 iOS 聚焦时缩放 */
    font-family: inherit;
    outline: none;
    transition: border-color 0.3s ease;
}

.login-box input:focus {
    border-color: var(--rose-dark);
}

.passcode-wrap {
    position: relative;
    width: 100%;
    margin-bottom: 1rem;
}

.passcode-wrap input {
    margin-bottom: 0;
    padding-right: 3.5rem;
}

.toggle-pass {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--rose-dark);
    font-size: 0.85rem;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.login-box button {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, var(--rose), var(--rose-dark));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    margin-top: 0.5rem;
}

.login-box button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(255, 183, 197, 0.4);
}

.error {
    color: #e74c3c;
    font-size: 0.85rem;
    margin-top: 1rem;
    min-height: 1.2rem;
}

/* 聊天页 */
.chat-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    max-width: 720px;
    margin: 0 auto;
    background: white;
    box-shadow: 0 0 60px var(--shadow);
}

.chat-header {
    padding: 1rem 1.5rem;
    background: linear-gradient(135deg, var(--rose-light), white);
    border-bottom: 1px solid rgba(255, 183, 197, 0.3);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h2 {
    font-size: 1.2rem;
    color: var(--rose-dark);
}

.exit-btn {
    font-size: 0.8rem;
    color: var(--text-light);
    background: rgba(255, 183, 197, 0.15);
    border: 1px solid rgba(255, 183, 197, 0.3);
    border-radius: 20px;
    padding: 0.4rem 0.9rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
}

.exit-btn:hover {
    background: rgba(255, 183, 197, 0.3);
    color: var(--rose-dark);
}

.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 75%;
    padding: 0.8rem 1rem;
    border-radius: 18px;
    line-height: 1.5;
    font-size: 0.95rem;
    word-break: break-word;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.own {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--rose), var(--rose-dark));
    color: white;
    border-bottom-right-radius: 4px;
}

.message.other {
    align-self: flex-start;
    background: var(--rose-light);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.message-meta {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-bottom: 0.25rem;
}

.message.own .message-meta {
    color: rgba(255, 255, 255, 0.85);
}

.message-body {
    display: flex;
    align-items: flex-end;
    gap: 0.4rem;
}

.message-text {
    flex: 1;
}

.read-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    font-size: 0.65rem;
    flex-shrink: 0;
    margin-bottom: 0.1rem;
}

.read-check.unread {
    background: rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.7);
}

.message.own .read-check.unread {
    background: rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.7);
}

.read-check.read {
    background: #4cd964;
    color: white;
}

.input-area {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255, 183, 197, 0.3);
    display: flex;
    gap: 0.8rem;
    background: white;
}

.input-area input {
    flex: 1;
    min-width: 0;
    padding: 0.8rem 1rem;
    border: 1.5px solid rgba(255, 183, 197, 0.4);
    border-radius: 24px;
    font-size: 1rem;
    font-family: inherit;
    outline: none;
}

.input-area input:focus {
    border-color: var(--rose-dark);
}

.input-area button {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 0.8rem 1.5rem;
    background: linear-gradient(135deg, var(--rose), var(--rose-dark));
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 1rem;
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.input-area button:hover {
    transform: scale(1.05);
}

/* 系统提示 */
.system-message {
    text-align: center;
    color: var(--text-light);
    font-size: 0.8rem;
    margin: 0.5rem 0;
}

/* 响应式 */
@media (max-width: 640px) {
    .chat-screen {
        max-width: 100%;
        box-shadow: none;
    }

    .login-screen {
        padding: 1rem;
        align-items: flex-start;
        padding-top: 12vh;
    }

    .login-box {
        padding: 2rem 1.5rem;
        border-radius: 20px;
    }

    .login-box h1 {
        font-size: 1.4rem;
    }

    .chat-header {
        padding: 0.7rem 1rem;
        flex-shrink: 0;
    }

    .chat-header h2 {
        font-size: 1rem;
    }

    .messages {
        padding: 0.8rem;
        gap: 0.7rem;
    }

    .message {
        max-width: 90%;
        padding: 0.65rem 0.8rem;
        font-size: 0.9rem;
        border-radius: 16px;
    }

    .message-meta {
        font-size: 0.65rem;
    }

    .input-area {
        padding: 0.6rem 0.8rem;
        gap: 0.5rem;
        flex-shrink: 0;
        padding-bottom: calc(0.6rem + env(safe-area-inset-bottom));
    }

    .input-area input {
        padding: 0.65rem 0.9rem;
        font-size: 16px;
    }

    .input-area button {
        padding: 0.65rem 1rem;
        font-size: 0.9rem;
    }
}

@media (max-width: 360px) {
    .input-area button {
        padding: 0.65rem 0.8rem;
        font-size: 0.85rem;
    }
}
