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

:root {
    --ink: #1F2E45;
    --paper-top: #F8F4EC;
    --paper-bottom: #EDE5D6;
    --card: #FFFFFF;
    --text-primary: #263140;
    --text-secondary: #978F80;
    --accent: #B5654A;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--paper-top);
    color: var(--text-primary);
    overscroll-behavior: none;
}

.page {
    display: none;
    min-height: 100vh;
    flex-direction: column;
    background: linear-gradient(180deg, var(--paper-top) 0%, var(--paper-bottom) 100%);
}
.page.active { display: flex; }

/* ===== 顶栏：宣纸底 + 墨色标题 ===== */
header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 16px 10px;
    min-height: 56px;
    padding-top: max(14px, env(safe-area-inset-top));
    position: relative;
}
header h1 {
    font-size: 26px;
    font-weight: 800;
    text-align: center;
    letter-spacing: 6px;
    color: var(--ink);
    text-indent: 6px; /* 抵消字距导致的视觉偏左 */
}
.header-btn {
    background: none;
    border: 1px solid var(--ink);
    color: var(--ink);
    font-size: 13px;
    padding: 7px 14px;
    border-radius: 20px;
    cursor: pointer;
    position: absolute;
    right: 16px;
}
.header-btn:active { background: rgba(31,46,69,0.08); }
.back-btn {
    background: none;
    border: none;
    color: var(--ink);
    font-size: 16px;
    padding: 6px 8px;
    cursor: pointer;
    position: absolute;
    left: 16px;
    font-weight: 600;
}

/* ===== 联系人列表：白色圆角卡片 ===== */
.contact-list {
    flex: 1;
    padding: 6px 0 110px;
    overflow: hidden;
}
.contact-item-wrapper {
    position: relative;
    overflow: hidden;
    margin: 7px 16px;
    border-radius: 20px;
}
.contact-item {
    display: flex;
    align-items: center;
    background: var(--card);
    border-radius: 20px;
    padding: 16px 18px;
    cursor: pointer;
    transition: transform 0.25s ease;
    position: relative;
    z-index: 1;
    box-shadow: 0 2px 10px rgba(31,46,69,0.08);
    /* 长按用于「置顶」，必须屏蔽系统长按菜单/文本选择 */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}
.contact-item-wrapper.swiped .contact-item {
    transform: translateX(-86px);
}
.contact-item:active { box-shadow: 0 1px 4px rgba(31,46,69,0.12); }

/* 圆形姓氏头像 */
.contact-avatar {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 23px;
    font-weight: 700;
}
.contact-text {
    flex: 1;
    margin-left: 16px;
    min-width: 0;
}
.contact-name {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
/* 置顶标记 */
.contact-pin-badge {
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    padding: 4px 7px;
    border-radius: 8px;
    color: #8A6A2F;
    background: #F3E4C4;
    letter-spacing: 0;
}

/* ★未接来电标记（v52）：红底白字，比「置顶」更急，所以排在名字后面第一个 */
/* ★未接次数角标（v54）：只显示数字，做成圆形小徽章（1 = 圆形，12 = 胶囊） */
.contact-missed-badge {
    flex-shrink: 0;
    box-sizing: border-box;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    border-radius: 10px;
    color: #FFFFFF;
    background: #E0554A;
    letter-spacing: 0;
}

/* 轻量提示条 */
.wuyan-hint {
    position: fixed;
    left: 50%;
    bottom: 96px;
    transform: translateX(-50%) translateY(8px);
    background: rgba(31,46,69,0.92);
    color: #fff;
    font-size: 14px;
    padding: 10px 18px;
    border-radius: 20px;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
    z-index: 9998;
    white-space: nowrap;
}
.wuyan-hint.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.contact-code {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
    letter-spacing: 0.5px;
    font-weight: 500;
}
.contact-call-hint {
    width: 22px;
    height: 22px;
    margin-left: 8px;
    flex-shrink: 0;
    opacity: 0.35;
}
.contact-delete-btn {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 86px;
    border: none;
    background: #E53935;
    color: white;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    z-index: 0;
    border-radius: 20px;
}

.empty-hint {
    display: none;
    text-align: center;
    color: var(--text-secondary);
    font-size: 15px;
    margin-top: 34vh;
    padding: 0 40px;
    line-height: 2;
}

/* ===== 联系人搜索框 ===== */
.search-wrap {
    padding: 2px 16px 6px;
    flex-shrink: 0;
}
.search-input {
    width: 100%;
    border: none;
    border-radius: 16px;
    background: var(--card);
    color: var(--text-primary);
    font-size: 16px;          /* iOS 上小于16px会触发自动放大，必须 >=16px */
    font-family: inherit;
    padding: 12px 16px;
    box-shadow: 0 2px 10px rgba(31,46,69,0.07);
    -webkit-appearance: none;
    appearance: none;
    outline: none;
}
.search-input::placeholder { color: var(--text-secondary); }
.no-match-hint {
    display: none;
    text-align: center;
    color: var(--text-secondary);
    font-size: 15px;
    margin-top: 32px;
    padding: 0 40px;
}

/* ===== 浮动按钮：墨蓝大圆 ===== */
.fab {
    position: fixed;
    right: 24px;
    bottom: max(24px, env(safe-area-inset-bottom));
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    background: var(--ink);
    color: #fff;
    font-size: 30px;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(31,46,69,0.35);
    z-index: 10;
    font-weight: 300;
}
.fab:active { transform: scale(0.92); }

/* ===== 二维码页 ===== */
.qr-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 24px 40px;
}
#qr-canvas {
    margin-top: 18px;
    width: 260px;
    height: 260px;
    max-width: 72vw;
    max-height: 72vw;
    background: #fff;
    border-radius: 24px;
    padding: 18px;
    box-shadow: 0 4px 16px rgba(31,46,69,0.1);
}
/* v49：按模板简化 —— 一行「我的 ID」+ 两行提示 + 一个橙色主按钮 */
.id-line {
    margin-top: 26px;
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 10px;
}
.id-label {
    font-size: 15px;
    color: var(--text-secondary);
}
.id-value {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text-primary);
}
.btn-accent {
    margin-top: 26px;
    padding: 14px 44px;
    border: none;
    border-radius: 26px;
    background: var(--accent);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(181,101,74,0.32);
}
.btn-accent:active { transform: scale(0.96); }
.link-btn {
    margin-top: 14px;
    background: none;
    border: none;
    padding: 6px 10px;
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    text-decoration: underline;
}
.hint {
    margin-top: 24px;
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.9;
}

/* ===== 扫码页 ===== */
.scan-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0E1622;
    overflow: hidden;
}
.scan-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.scan-result {
    display: none;
    padding: 20px;
    text-align: center;
    color: var(--accent);
}

/* 扫码页：手动粘贴配对码（摄像头开不了 / 距离远时的备用入口） */
.scan-manual {
    flex-shrink: 0;
    padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
}
.scan-manual-title {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 8px;
}
.pair-input {
    width: 100%;
    border: none;
    border-radius: 14px;
    background: var(--card);
    color: var(--text-primary);
    font-size: 16px;          /* iOS 上小于16px会触发自动放大 */
    font-family: inherit;
    line-height: 1.5;
    padding: 12px 14px;
    outline: none;
    resize: none;
    box-shadow: 0 2px 10px rgba(31,46,69,0.06);
    -webkit-appearance: none;
    appearance: none;
}
.pair-input::placeholder { color: var(--text-secondary); }
#btn-add-by-code { margin-top: 10px; }

/* ===== 通话页 / 来电页：深夜墨蓝渐变 ===== */
.call-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #0E1622 0%, #1A2A40 55%, #263C5A 100%);
    color: #fff;
    padding: 40px;
}
.call-avatar {
    width: 108px;
    height: 108px;
    border-radius: 50%;
    background: #2A3D58;
    border: 2px solid #4A6488;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 42px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 30px;
}
.call-name {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 12px;
    letter-spacing: 1px;
}
.call-code {
    font-size: 15px;
    color: #9FB2C8;
    margin-bottom: 8px;
}
.call-status {
    font-size: 14px;
    color: #6E84A0;
    margin-bottom: 80px;
}
.call-actions {
    display: flex;
    gap: 36px;
}
.call-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #33465F;
    color: #DCE6F2;
    box-shadow: 0 6px 16px rgba(0,0,0,0.3);
}
.call-btn.hangup { background: #D64550; color: #fff; font-weight: 700; }
.call-btn.accept { background: #2F9E63; color: #fff; font-weight: 700; width: 76px; height: 76px; }
.call-btn.on { background: #2F9E63; color: #fff; font-weight: 700; }
.call-btn:active { transform: scale(0.92); }

/* ===== 设置页 ===== */
.settings-container {
    padding: 24px;
}
.settings-container label {
    display: block;
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.settings-container input {
    width: 100%;
    padding: 13px;
    border: 1.5px solid #DDD6C8;
    border-radius: 12px;
    font-size: 16px;
    margin-bottom: 16px;
    background: #fff;
    color: var(--text-primary);
}
.btn-primary {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 14px;
    background: var(--ink);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}
.btn-primary:active { opacity: 0.85; }
