/* ===== 基础重置与变量 ===== */
:root {
    --accent: #c8a97e;
    --accent-light: #e8d5b5;
    --text-primary: rgba(255, 255, 255, 0.92);
    --text-secondary: rgba(255, 255, 255, 0.6);
    --text-muted: rgba(255, 255, 255, 0.4);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --g-blur: 20px;
    --g-blur-heavy: 40px;
    --g-blur-light: 10px;
    --g-ease: cubic-bezier(0.32, 0.72, 0, 1);
    --g-radius: 18px;
    --g-radius-lg: 24px;
    --g-radius-full: 9999px;
    --g-shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.14);
    /* 流体缩放参考：390px = 100% */
    --fluid: (100vw / 390);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: auto;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: #0a0a0f;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* ===== 应用容器 ===== */
#app {
    position: fixed;
    inset: 0;
    z-index: 10;
}

/* 桌面端：居中＋圆角手机框 */
@media (min-width: 500px) {
    body {
        background: #000;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    #app {
        position: relative;
        width: 430px;
        height: min(932px, 100vh - 40px);
        max-height: 100vh;
        border-radius: 44px;
        overflow: hidden;
        box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 20px 60px rgba(0, 0, 0, 0.6);
        inset: auto;
    }
}

/* 大屏平板端 */
@media (min-width: 800px) {
    #app {
        width: 430px;
        height: 932px;
    }
}

/* ===== 场景切换 ===== */
.scene {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.6s ease;
}

.scene.active {
    opacity: 1;
    pointer-events: auto;
}

/* 锁屏界面 */
#scene-lock {
    touch-action: none;
}

/* 顶部状态栏 */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: calc(12px + var(--safe-top)) 24px 4px;
    z-index: 2;
}

.status-time {
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.3px;
    opacity: 0.9;
}

.status-icons {
    display: flex;
    align-items: center;
    gap: 4px;
}

.status-icon {
    width: 17px;
    height: 17px;
    opacity: 0.8;
}

.battery {
    display: flex;
    align-items: center;
    gap: 3px;
    margin-left: 1px;
}

.battery-text {
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
}

.battery-icon {
    width: 23px;
    height: 11px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 2.5px;
    padding: 1px;
    position: relative;
}

.battery-icon::after {
    content: '';
    position: absolute;
    right: -4px;
    top: 2.5px;
    width: 1.5px;
    height: 4px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 0 1px 1px 0;
}

.battery-level {
    width: 100%;
    height: 100%;
    background: white;
    border-radius: 1px;
}

/* 主时间区域 */
.lock-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: clamp(40px, 8vh, 80px);
    z-index: 2;
    transition: transform 0.5s var(--g-ease), opacity 0.5s var(--g-ease);
}

.lock-date-row {
    font-size: clamp(13px, calc(16 * (100vw / 390)), 18px);
    color: var(--text-secondary);
    letter-spacing: 0.8px;
    margin-bottom: clamp(4px, calc(6 * (100vw / 390)), 8px);
    font-weight: 500;
}

.lock-time {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif;
    font-size: clamp(68px, calc(92 * (100vw / 390)), 120px);
    font-weight: 350;
    line-height: 1;
    letter-spacing: -1.5px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    margin: 2px 0;
    padding: 0;
}

/* 每个时间字符 */
.time-char {
    display: inline-block;
    position: relative;
    z-index: 2;
    color: rgba(255, 255, 255, 0.92);
}

/* 冒号特殊处理 */
.time-char[data-char=":"] {
    font-weight: 300;
    color: rgba(255, 255, 255, 0.35);
}

/* 通知区域 */
.notifications {
    flex: 0 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    margin-top: auto;
    padding: 0 clamp(12px, calc(16 * (100vw / 390)), 20px) clamp(12px, calc(16 * (100vw / 390)), 20px);
    z-index: 2;
    max-height: 140px;
    transition: transform 0.5s var(--g-ease), opacity 0.5s var(--g-ease);
}

.notif-card {
    border-radius: clamp(18px, calc(22 * (100vw / 390)), 24px);
    padding: clamp(8px, calc(10 * (100vw / 390)), 12px) clamp(10px, calc(14 * (100vw / 390)), 16px);
    border: 0.5px solid rgba(255, 255, 255, 0.12);
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.4s var(--g-ease);
    position: relative;
    z-index: 2;
    background: rgba(30, 30, 35, 0.35);
    margin-bottom: 6px;
}

.notif-card.show {
    opacity: 1;
    transform: translateY(0);
}

.notif-card-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.notif-app-icon {
    font-size: clamp(12px, calc(14 * (100vw / 390)), 16px);
    width: clamp(16px, calc(20 * (100vw / 390)), 22px);
    height: clamp(16px, calc(20 * (100vw / 390)), 22px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.notif-app-name {
    font-size: clamp(10px, calc(12 * (100vw / 390)), 13px);
    color: var(--text-muted);
    font-weight: 500;
}

.notif-badge {
    font-size: clamp(10px, calc(11 * (100vw / 390)), 12px);
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.15);
    padding: 1px 5px;
    border-radius: 8px;
    margin-left: -2px;
}

.notif-time {
    font-size: clamp(10px, calc(11 * (100vw / 390)), 12px);
    color: var(--text-muted);
    margin-left: auto;
}

.notif-card-body {
    padding-left: clamp(20px, calc(26 * (100vw / 390)), 30px);
}

.notif-sender {
    font-size: clamp(12px, calc(14 * (100vw / 390)), 16px);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1px;
}

.notif-preview {
    font-size: clamp(11px, calc(13 * (100vw / 390)), 14px);
    color: var(--text-secondary);
    line-height: 1.4;
}

/* 底部控制区域 */
.lock-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 clamp(24px, calc(32 * (100vw / 390)), 40px) calc(16px + var(--safe-bottom));
    z-index: 2;
    transition: transform 0.5s var(--g-ease), opacity 0.5s var(--g-ease);
}

.control-btn {
    width: clamp(40px, calc(48 * (100vw / 390)), 54px);
    height: clamp(40px, calc(48 * (100vw / 390)), 54px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    z-index: 2;
    background: rgba(30, 30, 35, 0.25);
    border: 0.5px solid rgba(255, 255, 255, 0.08);
}

.control-btn:active {
    transform: scale(0.9);
}

.control-btn svg {
    width: clamp(18px, calc(22 * (100vw / 390)), 26px);
    height: clamp(18px, calc(22 * (100vw / 390)), 26px);
    stroke: white;
    opacity: 0.85;
}

.home-indicator {
    width: clamp(50px, calc(60 * (100vw / 390)), 70px);
    height: clamp(4px, calc(4.5 * (100vw / 390)), 5px);
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s ease;
}

#scene-lock .home-indicator {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.home-indicator:active {
    animation: none;
}

#scene-lock .home-indicator:active {
    transform: translateX(-50%) scaleX(1.1);
}

/* ===== 桌面/主屏幕 ===== */
#scene-home {
    align-items: center;
    justify-content: flex-start;
    padding: 0;
    overflow: hidden;
}

#scene-home::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(
        ellipse 80% 60% at 50% 40%,
        transparent 0%,
        rgba(0, 0, 0, 0.15) 60%,
        rgba(0, 0, 0, 0.35) 100%
    );
    pointer-events: none;
    z-index: 1;
}

.home-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: clamp(12px, calc(20 * (100vw / 390)), 28px) 0 calc(12px + var(--safe-bottom));
    transform: translateY(40px);
    opacity: 0;
    transition: transform 0.5s var(--g-ease), opacity 0.5s ease;
}

.scene.active .home-content {
    transform: translateY(0);
    opacity: 1;
    transition-delay: 0.2s;
}

/* 应用网格 */
.home-app-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: clamp(12px, calc(20 * (100vw / 390)), 24px) clamp(8px, calc(12 * (100vw / 390)), 16px);
    padding: clamp(32px, calc(60 * (100vw / 390)), 80px) clamp(16px, calc(24 * (100vw / 390)), 32px) 0;
    width: 100%;
    max-width: clamp(340px, calc(400 * (100vw / 390)), 460px);
}

/* Dock — 纯透明底板 */
.home-dock {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: clamp(10px, calc(16 * (100vw / 390)), 20px);
    padding: clamp(8px, calc(12 * (100vw / 390)), 16px) clamp(16px, calc(24 * (100vw / 390)), 28px);
    border-radius: clamp(18px, calc(22 * (100vw / 390)), 26px);
    background: transparent;
    margin-bottom: 8px;
    position: relative;
}

/* 应用图标 */
.home-app {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(2px, calc(4 * (100vw / 390)), 6px);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.home-app-icon {
    width: clamp(44px, calc(56 * (100vw / 390)), 68px);
    height: clamp(44px, calc(56 * (100vw / 390)), 68px);
    border-radius: clamp(11px, calc(14 * (100vw / 390)), 17px);
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0.5px solid rgba(255, 255, 255, 0.08);
    position: relative;
    overflow: hidden;
}

.home-app-icon::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    /* 只有极淡的底色区分不同应用类别，主体玻璃效果由 WebGL 提供 */
    opacity: 0.25;
    pointer-events: none;
    z-index: 1;
}

.home-app[data-app="message"] .home-app-icon::before {
    background: linear-gradient(135deg, #34C759, #28A745);
}

.home-app[data-app="photos"] .home-app-icon::before {
    background: linear-gradient(135deg, #FF6B6B, #FFD93D, #6BCB77, #4D96FF);
}

.home-app[data-app="music"] .home-app-icon::before {
    background: linear-gradient(135deg, #FF2D55, #D11A3E);
}

.home-app[data-app="settings"] .home-app-icon::before {
    background: linear-gradient(135deg, #8E8E93, #555557);
}

.home-app[data-app="gift"] .home-app-icon::before {
    background: linear-gradient(135deg, #FF9500, #E08500);
}

.home-app[data-app="browser"] .home-app-icon::before {
    background: linear-gradient(135deg, #007AFF, #0055CC);
}

.home-app[data-app="weather"] .home-app-icon::before {
    background: linear-gradient(135deg, #47B5FF, #1363DF);
}

.home-app[data-app="calculator"] .home-app-icon::before {
    background: linear-gradient(135deg, #2C3E50, #3498DB);
}

.home-app-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(
        135deg,
        rgba(255, 255, 255, 0.25) 0%,
        rgba(255, 255, 255, 0.06) 40%,
        transparent 50%
    );
    pointer-events: none;
    z-index: 2;
}

.home-app-icon svg {
    width: clamp(20px, calc(26 * (100vw / 390)), 32px);
    height: clamp(20px, calc(26 * (100vw / 390)), 32px);
    stroke: rgba(255, 255, 255, 0.95);
    position: relative;
    z-index: 3;
    filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.5));
}

.home-app:active .home-app-icon {
    transform: scale(0.88);
    transition: transform 0.15s ease;
}

.home-dock .home-app-icon {
    width: clamp(38px, calc(50 * (100vw / 390)), 60px);
    height: clamp(38px, calc(50 * (100vw / 390)), 60px);
    border-radius: clamp(11px, calc(14 * (100vw / 390)), 17px);
}

.home-dock .home-app-icon svg {
    width: clamp(17px, calc(22 * (100vw / 390)), 27px);
    height: clamp(17px, calc(22 * (100vw / 390)), 27px);
}

.home-app-label {
    font-size: clamp(9px, calc(11 * (100vw / 390)), 13px);
    color: rgba(255, 255, 255, 0.92);
    font-weight: 500;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
    letter-spacing: 0.2px;
    max-width: clamp(56px, calc(68 * (100vw / 390)), 80px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

/* ── 应用锁定状态（未领取礼物） ── */
.home-app.app-locked .home-app-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: rgba(0, 0, 0, 0.45);
    z-index: 4;
    cursor: default;
}

.home-app.app-locked .home-app-icon::before {
    opacity: 0.15 !important;
}

.home-app.app-locked .home-app-icon svg {
    opacity: 0.35;
    filter: none;
}

.home-app.app-locked .home-app-label {
    opacity: 0.5;
}

.home-app.app-locked {
    cursor: default;
}

#scene-home .home-indicator {
    position: absolute;
    bottom: calc(6px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
}

/* ===== 信件界面 ===== */
#scene-letter {
    align-items: center;
    justify-content: center;
    padding: calc(20px + var(--safe-top)) clamp(16px, calc(20 * (100vw / 390)), 24px) calc(20px + var(--safe-bottom));
    overflow: hidden;
    background: rgba(0, 0, 0, 0.4);
}

/* 返回按钮 — 信件场景左上角 */
.letter-back {
    position: absolute;
    top: calc(12px + var(--safe-top));
    left: 12px;
    width: clamp(30px, calc(36 * (100vw / 390)), 42px);
    height: clamp(30px, calc(36 * (100vw / 390)), 42px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    background: rgba(30, 30, 35, 0.3);
    border: 0.5px solid rgba(255, 255, 255, 0.1);
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.3s ease, transform 0.3s ease, background 0.2s;
}

.scene.active .letter-back {
    opacity: 1;
    transform: scale(1);
    transition-delay: 0.3s;
}

.letter-back:active {
    transform: scale(0.85);
    background: rgba(255, 255, 255, 0.15);
}

.letter-back svg {
    width: clamp(14px, calc(18 * (100vw / 390)), 22px);
    height: clamp(14px, calc(18 * (100vw / 390)), 22px);
    stroke: rgba(255, 255, 255, 0.8);
}

.letter-scroll {
    width: 100%;
    max-width: clamp(320px, calc(360 * (100vw / 390)), 400px);
    max-height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: clamp(20px, calc(32 * (100vw / 390)), 40px) clamp(16px, calc(24 * (100vw / 390)), 32px);
    border-radius: clamp(18px, calc(22 * (100vw / 390)), 26px);
    position: relative;
    z-index: 2;
    background: rgba(0, 0, 0, 0.2);
    border: 0.5px solid rgba(255, 255, 255, 0.08);
    transform: scale(0.92);
    opacity: 0;
    transition: transform 0.5s var(--g-ease), opacity 0.5s ease;
}

.scene.active .letter-scroll {
    transform: scale(1);
    opacity: 1;
    transition-delay: 0.15s;
}

.letter-scroll::-webkit-scrollbar {
    display: none;
}

.letter-header {
    text-align: center;
    margin-bottom: clamp(20px, calc(28 * (100vw / 390)), 36px);
}

.letter-stamp {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: clamp(6px, calc(8 * (100vw / 390)), 10px) clamp(14px, calc(20 * (100vw / 390)), 26px);
    border-radius: clamp(18px, calc(22 * (100vw / 390)), 26px);
    border: 1px solid var(--accent);
    color: var(--accent);
    font-size: clamp(12px, calc(14 * (100vw / 390)), 16px);
    letter-spacing: 4px;
    margin-bottom: clamp(8px, calc(12 * (100vw / 390)), 16px);
}

.letter-date {
    font-size: clamp(10px, calc(12 * (100vw / 390)), 14px);
    color: var(--text-muted);
    letter-spacing: 2px;
}

.letter-body {
    margin-bottom: clamp(16px, calc(24 * (100vw / 390)), 32px);
}

.letter-greeting {
    font-size: clamp(14px, calc(16 * (100vw / 390)), 20px);
    margin-bottom: clamp(12px, calc(16 * (100vw / 390)), 20px);
    color: var(--text-primary);
}

.letter-text {
    font-size: clamp(13px, calc(15 * (100vw / 390)), 17px);
    line-height: 1.8;
    color: var(--text-secondary);
    margin-bottom: clamp(8px, calc(12 * (100vw / 390)), 16px);
    text-indent: 2em;
}

.letter-divider {
    width: clamp(32px, calc(40 * (100vw / 390)), 48px);
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    margin: clamp(16px, calc(24 * (100vw / 390)), 32px) auto;
}

.gift-section {
    text-align: center;
}

.gift-label {
    font-size: clamp(12px, calc(14 * (100vw / 390)), 16px);
    color: var(--accent-light);
    margin-bottom: clamp(8px, calc(12 * (100vw / 390)), 16px);
    letter-spacing: 1px;
}

.cdkey-box {
    display: inline-flex;
    align-items: center;
    gap: clamp(6px, calc(10 * (100vw / 390)), 14px);
    padding: clamp(10px, calc(14 * (100vw / 390)), 18px) clamp(14px, calc(20 * (100vw / 390)), 26px);
    border-radius: clamp(11px, calc(14 * (100vw / 390)), 17px);
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.15);
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: clamp(42px, calc(52 * (100vw / 390)), 62px);
}

.cdkey-box:hover {
    border-color: rgba(255, 255, 255, 0.25);
    background: rgba(0, 0, 0, 0.4);
}

.cdkey-mask {
    font-size: clamp(12px, calc(14 * (100vw / 390)), 16px);
    color: var(--text-muted);
    letter-spacing: 1px;
}

.cdkey-text {
    font-family: 'SF Mono', ui-monospace, 'Courier New', monospace;
    font-size: clamp(12px, calc(15 * (100vw / 390)), 18px);
    font-weight: 600;
    letter-spacing: 2px;
    color: var(--accent-light);
    user-select: all;
    display: none;
}

.cdkey-text.show {
    display: inline;
}

.copy-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: clamp(26px, calc(32 * (100vw / 390)), 38px);
    height: clamp(26px, calc(32 * (100vw / 390)), 38px);
    border-radius: clamp(6px, calc(8 * (100vw / 390)), 10px);
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-primary);
}

.copy-btn svg {
    width: clamp(13px, calc(16 * (100vw / 390)), 20px);
    height: clamp(13px, calc(16 * (100vw / 390)), 20px);
}

.letter-footer {
    text-align: right;
}

.letter-sign {
    font-size: clamp(12px, calc(14 * (100vw / 390)), 16px);
    color: var(--text-muted);
    font-style: italic;
}

/* ===== Toast 提示 ===== */
.toast {
    position: fixed;
    bottom: calc(40px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: clamp(8px, calc(10 * (100vw / 390)), 14px) clamp(14px, calc(20 * (100vw / 390)), 26px);
    border-radius: clamp(10px, calc(13 * (100vw / 390)), 16px);
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: var(--text-primary);
    font-size: clamp(11px, calc(13 * (100vw / 390)), 15px);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    z-index: 100;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* 桌面端 Toast 跟随容器 */
@media (min-width: 500px) {
    .toast {
        position: absolute;
    }
}

/* ===== 极小屏微调 (≤360px) ===== */
@media (max-width: 360px) {
    .lock-main {
        padding-top: 5vh;
    }
    .lock-time {
        font-size: 58px;
        letter-spacing: -1px;
    }
    .lock-date-row {
        font-size: 12px;
    }
    .lock-bottom {
        padding-left: 16px;
        padding-right: 16px;
    }
    .home-app-grid {
        gap: 10px 6px;
        padding: 24px 10px 0;
    }
    .home-app-icon {
        width: 40px;
        height: 40px;
        border-radius: 10px;
    }
    .home-app-icon svg {
        width: 18px;
        height: 18px;
    }
    .home-dock .home-app-icon {
        width: 36px;
        height: 36px;
        border-radius: 10px;
    }
    .home-dock .home-app-icon svg {
        width: 16px;
        height: 16px;
    }
    .home-dock {
        gap: 8px;
        padding: 6px 12px;
    }
    .home-app-label {
        font-size: 8px;
    }
    .letter-scroll {
        padding: 16px 12px;
    }
    .letter-text {
        font-size: 12px;
    }
}
