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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: #f8fafc;
    color: #1e293b;
    padding: 20px;
    overflow-x: hidden;
    transition: background 0.3s, color 0.3s;
}

.container {
    max-width: 800px;
    margin: 0 auto;
}

h1 {
    text-align: center;
    margin-bottom: 20px;
    color: #333;
}

.input-wrapper {
    position: relative;
    margin-bottom: 15px;
}

#input-area {
    width: 100%;
    height: 200px;
    padding: 15px;
    font-size: 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    resize: vertical;
    outline: none;
    transition: border-color 0.3s;
}

#input-area:focus {
    border-color: #2563eb;
}

.candidate-box {
    position: fixed;
    background: white;
    border: 1px solid #ccc;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 10px;
    min-width: 300px;
    z-index: 1000;
}

.candidate-box.hidden {
    display: none;
}

.candidate-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 8px;
    margin-bottom: 8px;
    border-bottom: 1px solid #eee;
    font-size: 14px;
}

#code-display {
    font-weight: bold;
    color: #2563eb;
    font-family: monospace;
    font-size: 16px;
}

#page-info {
    color: #666;
    font-size: 12px;
}

.candidate-body {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 36px;
}

.candidate-nav {
    display: none;
    width: 28px;
    height: 36px;
    border: none;
    border-radius: 6px;
    background: #f0f0f0;
    color: #666;
    font-size: 18px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0 0 4px 0;
    transition: background 0.15s;
}

.candidate-nav:hover {
    background: #e0e0e0;
}

.candidate-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.candidate-nav:active {
    background: #d0d0d0;
}

.candidate-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.candidate-item {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
    user-select: none;
    gap: 6px;
    white-space: nowrap;
}

.candidate-item:hover {
    background: #f0f0f0;
}

.candidate-item.exact-match {
    background: #eff6ff;
}

/* 反查模式下的提示文本 */
.candidate-item.candidate-hint {
    color: #999;
    font-size: 14px;
    cursor: default;
    pointer-events: none;
}
.candidate-item.candidate-hint:hover {
    background: transparent;
}

/* 反查模式下的五笔编码提示 */
.candidate-item .wubi-code {
    color: #888;
    font-size: 13px;
    margin-left: 4px;
    font-family: monospace;
}

/* PC端序号小字 */
.candidate-num {
    color: #999;
    font-size: 12px;
    min-width: 16px;
    text-align: center;
}

.candidate-text {
    font-size: 18px;
}

/* 旧的独立序号方块样式，保留但不使用 */
.candidate-index {
    display: none;
}

.candidate-code {
    display: none;
}

.settings {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    margin-bottom: 15px;
}

.settings label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

#page-size {
    width: 60px;
    padding: 5px;
    border: 1px solid #ddd;
    border-radius: 4px;
    text-align: center;
}

#toggle-im {
    padding: 8px 16px;
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
}

#toggle-im:hover {
    background: #1d4ed8;
}

.im-status {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: bold;
}

.im-status.english {
    background: #e0e0e0;
    color: #666;
}

.im-status.chinese {
    background: #eff6ff;
    color: #2563eb;
}

.help {
    background: white;
    padding: 20px;
    border-radius: 8px;
}

.help h3 {
    margin-bottom: 12px;
    color: #333;
}

.help ul {
    list-style: none;
}

.help li {
    padding: 6px 0;
    font-size: 14px;
    color: #555;
}

kbd {
    display: inline-block;
    padding: 2px 8px;
    background: #f5f5f5;
    border: 1px solid #ccc;
    border-radius: 3px;
    box-shadow: 0 1px 0 rgba(0,0,0,0.1);
    font-family: monospace;
    font-size: 12px;
    margin: 0 2px;
}

/* ===== 虚拟键盘 ===== */
.virtual-keyboard {
    display: none;
    background: #d1d5db;
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 15px;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.vk-row {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 10px;
}

.vk-row:last-child {
    margin-bottom: 0;
}

.vk-btn {
    flex: 1;
    height: 44px;
    background: #ffffff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s, transform 0.05s, box-shadow 0.05s;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 1px rgba(0,0,0,0.08);
}

.vk-btn:active {
    background: #e5e7eb;
    transform: scale(0.97);
    box-shadow: 0 0 1px rgba(0,0,0,0.08);
}

/* 字母键统一宽度（按每行10个计算） */
.vk-row .vk-btn:not(.vk-wide):not(.vk-space):not(.vk-fn) {
    flex: 0 0 auto;
    width: calc((100% - 54px) / 10);
    max-width: 60px;
}

.vk-btn.vk-space {
    flex: 3;
    max-width: 200px;
    font-size: 14px;
}

.vk-btn.vk-wide {
    flex: 1.5;
    max-width: 90px;
    font-size: 14px;
}

.vk-btn.vk-fn {
    background: #c8cdd4;
    color: #374151;
    font-size: 14px;
}

.vk-btn.vk-fn:active {
    background: #b0b6bf;
}

/* ===== 移动端固定底部面板 ===== */
#mobile-input-panel {
    display: flex;
    flex-direction: column;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 999;
    background: #d1d5db;
    border-top: 1px solid #b0b6bf;
}

/* 触屏设备默认显示虚拟键盘 */
@media (hover: none) and (pointer: coarse) {
    body {
        padding: 10px 10px 320px;
    }

    .container {
        max-width: 100%;
    }

    h1 {
        font-size: 20px;
        margin-bottom: 12px;
    }

    #input-area {
        height: 120px;
        font-size: 18px;
        padding: 12px;
        resize: none;
    }

    /* 候选框：白色卡片 + 圆角 + 阴影，两边留边距 */
    .candidate-box {
        position: relative;
        width: calc(100% - 16px);
        min-width: auto;
        max-width: none;
        margin: 6px 8px 0;
        padding: 8px 12px;
        flex-shrink: 0;
        background: #fff;
        border: none;
        border-radius: 10px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    }

    .candidate-header {
        padding-bottom: 6px;
        margin-bottom: 8px;
        border-bottom: 1px solid #eee;
    }

    #code-display {
        color: #2563eb;
    }

    .candidate-body {
        gap: 2px;
        min-height: 38px;
    }

    .candidate-nav {
        display: none;
    }

    .candidate-nav:active {
        background: #d0d3d8;
    }

    .candidate-scroll-track {
        display: block;
    }

    .candidate-list {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 8px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        scroll-snap-type: x mandatory;
        padding-bottom: 2px;
    }

    .candidate-list::-webkit-scrollbar {
        display: none;
    }

    .candidate-item {
        flex-shrink: 0;
        padding: 5px 14px;
        border-radius: 18px;
        border-right: none;
        background: #f5f5f5;
        font-size: 17px;
        gap: 4px;
        scroll-snap-align: start;
        transition: background 0.15s;
    }

    .candidate-item .candidate-num {
        font-size: 11px;
        color: #bbb;
        min-width: auto;
    }

    .candidate-item.exact-match .candidate-num {
        color: #7ab8e8;
    }

    .candidate-item:active {
        background: #e0e0e0;
    }

    .candidate-item.exact-match {
        background: #eff6ff;
        color: #2563eb;
    }

    .virtual-keyboard {
        display: block;
        border-radius: 0;
        padding: 4px 10px 12px;
        margin-bottom: 0;
        flex-shrink: 0;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
    }

    .settings {
        flex-wrap: wrap;
        gap: 10px;
        padding: 12px;
        font-size: 13px;
        margin-bottom: 10px;
    }

    .settings label {
        gap: 6px;
    }

    .vk-row {
        gap: 5px;
        margin-bottom: 8px;
    }

    .vk-btn {
        height: 48px;
        font-size: 18px;
        border-radius: 8px;
    }

    /* 移动端字母键同样统一宽度（gap 5px，9个gap共45px） */
    .vk-row .vk-btn:not(.vk-wide):not(.vk-space):not(.vk-fn) {
        width: calc((100% - 45px) / 10);
        max-width: 60px;
    }

    .vk-btn.vk-wide,
    .vk-btn.vk-fn {
        font-size: 14px;
    }

    /* 移动端数字行按键同字母键宽度 */
    .vk-letter-view .vk-row:first-child .vk-btn:not(.vk-wide):not(.vk-space):not(.vk-fn) {
        width: calc((100% - 45px) / 10);
        max-width: 60px;
    }

    /* 移动端符号面板网格 */
    .vk-symbol-grid {
        grid-template-columns: repeat(10, 1fr);
        gap: 4px;
        max-height: 220px;
    }

    .vk-symbol-btn {
        height: 42px;
        font-size: 17px;
        border-radius: 6px;
    }

    .help {
        padding: 15px;
        font-size: 13px;
    }

    .help h3 {
        font-size: 15px;
    }
}

/* ===== 符号面板 ===== */
.vk-view.hidden {
    display: none;
}

.vk-symbol-view {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.vk-symbol-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 6px;
    max-height: 180px;
    overflow-y: auto;
    padding: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.vk-symbol-btn {
    height: 40px;
    border: none;
    border-radius: 6px;
    background: #ffffff;
    color: #1f2937;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s, transform 0.05s;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.vk-symbol-btn:active {
    background: #e5e7eb;
    transform: scale(0.95);
}

/* PC 端可手动展开虚拟键盘（添加 .show-on-pc 类） */
.virtual-keyboard.show-on-pc {
    display: block;
}

/* 自定义光标（英文模式下 readOnly textarea 无原生 caret） */
.custom-caret {
    position: fixed;
    width: 2px;
    background: #333;
    pointer-events: none;
    z-index: 1000;
    animation: caret-blink 1s step-end infinite;
    display: none;
}

/* ===== 候选词滚动进度条 ===== */
.candidate-scroll-track {
    display: none;
    height: 2px;
    background: #e0e0e0;
    border-radius: 1px;
    margin-top: 6px;
    position: relative;
    overflow: hidden;
}

.candidate-scroll-thumb {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: #aaa;
    border-radius: 1px;
}

@keyframes caret-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}
