   * { box-sizing: border-box; }
    [hidden] { display: none !important; }

    html, body {
        margin: 0;
        padding: 0;
        /* 关键：禁用双击缩放，但保留滚动 */
        touch-action: manipulation;
        -ms-touch-action: manipulation;
    }

    body {
        font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
                     system-ui, -apple-system, "Segoe UI", sans-serif;
        min-height: 100vh;
        padding: 22px 16px 70px;
        color: #1e293b;
        background-color: #eef2ff;
        background-image:
            radial-gradient(circle at 10% 6%, #e0e7ff 0, transparent 42%),
            radial-gradient(circle at 90% 2%, #fce7f3 0, transparent 38%),
            radial-gradient(circle at 50% 102%, #dbeafe 0, transparent 55%);
        background-attachment: fixed;
        -webkit-font-smoothing: antialiased;
        -webkit-tap-highlight-color: transparent;
    }

    .wrap {
        max-width: 760px;
        margin: 0 auto;
        display: flex;
        flex-direction: column;
        gap: 22px;
    }

    /* ---------- 顶部导航 ---------- */
    .nav {
        align-self: center;
        display: flex;
        justify-content: center;
        gap: 5px;
        padding: 6px;
        border-radius: 999px;
        background: rgba(255, 255, 255, .78);
        border: 1px solid rgba(255, 255, 255, .95);
        box-shadow: 0 14px 34px -20px rgba(49, 46, 129, .75);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        touch-action: manipulation;
    }
    .nav a {
        display: block;
        padding: 9px 20px;
        border-radius: 999px;
        font-size: 14.5px;
        font-weight: 700;
        letter-spacing: .6px;
        white-space: nowrap;
        color: #64748b;
        text-decoration: none;
        touch-action: manipulation;
        transition: background .15s, color .15s, box-shadow .15s;
    }
    .nav a:hover {
        color: #4338ca;
        background: #eef2ff;
    }
    .nav a.active {
        color: #fff;
        background: linear-gradient(135deg, #6366f1, #8b5cf6);
        box-shadow: 0 10px 20px -10px rgba(99, 102, 241, .95);
    }

    .card {
        background: #fff;
        border-radius: 26px;
        padding: 26px 26px 28px;
        border: 1px solid rgba(255,255,255,.9);
        box-shadow:
            0 24px 60px -30px rgba(49, 46, 129, .45),
            0 4px 16px -6px rgba(15, 23, 42, .08);
    }

    /* ---------- 标题 ---------- */
    h1 {
        margin: 0 0 5px;
        font-size: 19px;
        font-weight: 800;
        letter-spacing: .6px;
        color: #312e81;
    }
    .sub {
        margin: 0;
        font-size: 13px;
        color: #94a3b8;
    }

    /* ---------- 状态栏 ---------- */
    .hud {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        margin: 20px 0 4px;
    }
    .hud-item {
        background: #f8fafc;
        border: 1px solid #eef2f7;
        border-radius: 16px;
        padding: 10px 8px;
        text-align: center;
    }
    .hud-item .k {
        display: block;
        font-size: 12px;
        color: #94a3b8;
        margin-bottom: 3px;
        letter-spacing: .5px;
    }
    .hud-item .v {
        font-size: 22px;
        font-weight: 800;
        color: #334155;
        font-variant-numeric: tabular-nums;
    }
    #score { color: #4f46e5; }
    #timer { color: #0ea5e9; }

    /* ---------- 题目区 ---------- */
    .stage { padding-top: 8px; }

    .question {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: clamp(6px, 2.2vw, 18px);
        min-height: 152px;
        /* 高级版题目更长（19 × 9 = 171），字号整体收窄以防溢出 */
        font-size: clamp(34px, 9.5vw, 70px);
        font-weight: 800;
        line-height: 1.1;
        letter-spacing: 1px;
        color: #1e293b;
        font-variant-numeric: tabular-nums;
        user-select: none;
        -webkit-user-select: none;
    }
    .q-op { color: #a5b4fc; }

    /* 数字位固定宽度，避免 1 → 19 切换时左右跳动 */
    .q-num {
        display: inline-block;
        min-width: 1.15em;
        text-align: center;
    }

    .q-answer {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        /* 答案最多 3 位（171），预留更宽的下划线 */
        min-width: 1.9em;
        padding: 0 .05em .04em;
        color: #4338ca;
        border-bottom: 6px solid #c7d2fe;
        border-radius: 4px;
        transition: border-color .15s, color .15s;
    }

    .caret {
        display: inline-block;
        width: 4px;
        height: .68em;
        margin-left: 5px;
        border-radius: 2px;
        background: #818cf8;
        animation: blink 1.1s steps(1, end) infinite;
    }
    @keyframes blink {
        0%, 50%      { opacity: 1; }
        50.01%, 100% { opacity: 0; }
    }

    body[data-state="idle"] .caret,
    body[data-state="finished"] .caret { opacity: 0; animation: none; }
    body[data-state="idle"] .q-answer { border-bottom-color: #e2e8f0; color: #cbd5e1; }

    .question.shake { animation: shake .2s ease-in-out; }
    @keyframes shake {
        0%, 100% { transform: translateX(0); }
        25%      { transform: translateX(-7px); }
        75%      { transform: translateX(7px); }
    }

    .feedback {
        min-height: 30px;
        text-align: center;
        font-size: 16px;
        font-weight: 700;
        color: #e11d48;
        font-variant-numeric: tabular-nums;
        opacity: 0;
        transition: opacity .16s;
    }
    .feedback.show { opacity: 1; }

    /* ---------- 按钮 / 结果 ---------- */
    .controls { text-align: center; padding-top: 2px; }

    .btn {
        appearance: none;
        border: none;
        cursor: pointer;
        font-family: inherit;
        font-size: 18px;
        font-weight: 800;
        letter-spacing: 1.5px;
        padding: 14px 46px;
        border-radius: 999px;
        color: #fff;
        background: linear-gradient(135deg, #6366f1, #8b5cf6);
        box-shadow: 0 14px 26px -12px rgba(99, 102, 241, .95);
        transition: transform .12s, box-shadow .12s;
        touch-action: manipulation;
        user-select: none;
        -webkit-user-select: none;
    }
    .btn:hover  { transform: translateY(-2px); box-shadow: 0 20px 32px -12px rgba(99,102,241,1); }
    .btn:active { transform: translateY(0) scale(.975); }

    .hint {
        margin: 14px 0 0;
        font-size: 13px;
        color: #94a3b8;
        letter-spacing: .3px;
    }

    .result { text-align: center; padding: 4px 0 2px; }
    .result:not([hidden]) { animation: pop .3s cubic-bezier(.2, .9, .3, 1.25); }
    @keyframes pop {
        from { opacity: 0; transform: scale(.9) translateY(8px); }
        to   { opacity: 1; transform: none; }
    }
    .result-score {
        font-size: 66px;
        font-weight: 900;
        line-height: 1;
        color: #4f46e5;
        font-variant-numeric: tabular-nums;
    }
    .result-score small { font-size: 20px; margin-left: 6px; color: #818cf8; }
    .result-meta {
        margin: 16px 0 22px;
        font-size: 15px;
        color: #64748b;
    }
    .result-meta b { color: #334155; font-variant-numeric: tabular-nums; }

    /* ---------- 触屏数字键盘 ---------- */
    .keypad {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        max-width: 340px;
        margin: 20px auto 0;
        transition: opacity .2s;
    }
    body:not([data-state="running"]) .keypad {
        opacity: .38;
        pointer-events: none;
    }
    .keypad button {
        font-family: inherit;
        font-size: 22px;
        font-weight: 700;
        padding: 14px 0;
        border-radius: 16px;
        border: 1px solid #e2e8f0;
        background: #f8fafc;
        color: #334155;
        cursor: pointer;
        transition: background .1s, transform .08s;
        /* 关键：禁用双击缩放，保证连点不放大 */
        touch-action: manipulation;
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }
    .keypad button:active {
        background: #e0e7ff;
        border-color: #c7d2fe;
        transform: scale(.95);
    }
    .keypad .zero { grid-column: 2; }

    /* ---------- 历史记录 ---------- */
    .history h2 {
        margin: 0 0 14px;
        font-size: 16px;
        font-weight: 800;
        letter-spacing: .6px;
        color: #312e81;
    }
    .table-wrap { overflow-x: auto; }
    table {
        width: 100%;
        border-collapse: collapse;
        font-size: 14px;
    }
    th, td {
        padding: 10px 8px;
        text-align: center;
        white-space: nowrap;
        border-bottom: 1px solid #f1f5f9;
    }
    th {
        font-size: 12.5px;
        font-weight: 600;
        color: #94a3b8;
    }
    td { color: #475569; font-variant-numeric: tabular-nums; }
    tbody tr:hover td { background: #f8fafc; }
    td.score-cell { color: #4f46e5; font-weight: 800; }
    .empty {
        padding: 26px 0;
        text-align: center;
        color: #cbd5e1;
        font-size: 14px;
    }

    @media (max-width: 420px) {
        .card { padding: 20px 16px 22px; border-radius: 22px; }
        .hud-item .v { font-size: 19px; }
        .question { min-height: 128px; }
        .nav a { padding: 8px 6px; font-size: 13.5px; }
    }