* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary: #5a4fa0;
    --primary-dark: #3d3578;
    --bg: #1a1830;
    --surface: #2d2b55;
    --surface2: #3b3870;
    --text: #e8e6f0;
    --text-dim: #9b97b8;
    --accent: #ff6b6b;
    --success: #51cf66;
    --key-bg: #3b3870;
    --key-active: #5a4fa0;
    --key-text: #fff;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow: hidden;
    position: fixed;
    width: 100%;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

header {
    padding: 0.5rem 0.8rem;
    background: var(--surface);
    border-bottom: 1px solid var(--surface2);
}

header h1 {
    font-size: 1rem;
    text-align: center;
    color: var(--text);
    margin-bottom: 0.4rem;
}

nav {
    display: flex;
    gap: 0.3rem;
    justify-content: center;
}

.tab {
    background: var(--surface2);
    border: none;
    color: var(--text-dim);
    padding: 0.35rem 0.8rem;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
}

.tab.active {
    background: var(--primary);
    color: white;
}

/* 面板 */
.panel {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 0.6rem;
    -webkit-overflow-scrolling: touch;
}

.panel.active {
    display: flex;
    flex-direction: column;
}

/* 显示区 */
.display-box {
    background: var(--surface);
    border: 1px solid var(--surface2);
    border-radius: 10px;
    padding: 0.8rem;
    min-height: 3rem;
    font-size: 1.3rem;
    line-height: 1.6;
    color: var(--text);
    word-break: break-all;
    white-space: pre-wrap;
    direction: ltr;
    text-align: left;
}

/* 光标动画 */
.display-box .cursor {
    display: inline-block;
    width: 2px;
    height: 1.3em;
    background: var(--text);
    vertical-align: text-bottom;
    animation: blink 1s step-end infinite;
    margin-left: 1px;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.input-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.action-btn {
    background: var(--surface2);
    border: none;
    color: var(--text);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
}

.action-btn.primary {
    background: var(--primary);
}

.action-btn:active {
    opacity: 0.7;
}

/* 打字测试 */
.typing-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.typing-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-dim);
    padding: 0.3rem 0;
}

.typing-target {
    text-align: center;
    padding: 0.8rem;
    background: var(--surface);
    border-radius: 10px;
    position: relative;
}

.target-word {
    font-size: 2rem;
    font-weight: bold;
    color: var(--accent);
}

.target-meaning {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-top: 0.2rem;
}

.play-sm {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
}

.typing-display {
    min-height: 2.5rem;
    font-size: 1.5rem;
    text-align: center;
}

.typing-controls {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.typing-correct {
    animation: flash-green 0.3s;
}

@keyframes flash-green {
    0% { background: var(--surface); }
    50% { background: rgba(81, 207, 102, 0.2); }
    100% { background: var(--surface); }
}

/* 单词列表 */
.words-area {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.words-categories {
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

.cat-btn {
    background: var(--surface2);
    border: none;
    color: var(--text-dim);
    padding: 0.3rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    cursor: pointer;
}

.cat-btn.active {
    background: var(--primary);
    color: white;
}

.words-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.word-card {
    display: flex;
    align-items: center;
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--surface2);
    gap: 0.5rem;
}

.word-card .wc-play {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--surface2);
    border: none;
    font-size: 0.8rem;
    cursor: pointer;
    flex-shrink: 0;
}

.word-card .wc-play:active {
    background: var(--primary);
}

.word-card .wc-info {
    flex: 1;
}

.word-card .wc-korean {
    font-size: 1.1rem;
    font-weight: 600;
}

.word-card .wc-roman {
    font-size: 0.75rem;
    color: var(--accent);
}

.word-card .wc-meaning {
    font-size: 0.8rem;
    color: var(--text-dim);
    text-align: right;
    flex-shrink: 0;
}

/* 键盘 */
.keyboard {
    background: var(--surface);
    padding: 0.4rem 0.3rem;
    padding-bottom: calc(0.4rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--surface2);
}

.compose-status {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-dim);
    height: 1.2rem;
    line-height: 1.2rem;
}

.kb-row {
    display: flex;
    justify-content: center;
    gap: 0.2rem;
    margin-bottom: 0.2rem;
}

.kb-key {
    background: var(--key-bg);
    border: none;
    border-radius: 6px;
    color: var(--key-text);
    font-size: 1.1rem;
    min-width: 2.2rem;
    height: 2.6rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: background 0.1s;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
}

.kb-key:active,
.kb-key.key-pressed {
    background: var(--key-active);
    transform: scale(0.93);
    box-shadow: 0 0 8px rgba(90, 79, 160, 0.6);
}

.kb-key .key-main {
    font-size: 1.1rem;
    line-height: 1.1;
}

.kb-key .key-sub {
    font-size: 0.55rem;
    color: var(--text-dim);
    margin-top: 0rem;
    line-height: 1;
}

.key-shift {
    min-width: 2.8rem;
    font-size: 1.2rem;
}

.key-shift.active {
    background: var(--primary);
}

.key-space {
    flex: 1;
    max-width: 50%;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.key-bksp, .key-enter {
    min-width: 2.8rem;
    font-size: 1rem;
}

.kb-row-bottom {
    gap: 0.3rem;
}

/* 按键弹出提示 */
.key-popup {
    position: absolute;
    top: -2.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    color: #333;
    font-size: 1.5rem;
    font-weight: bold;
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    pointer-events: none;
    z-index: 50;
}

/* 响应式 - 大屏 */
@media (min-width: 500px) {
    .kb-key {
        min-width: 2.6rem;
        height: 3rem;
        font-size: 1.2rem;
    }
    .display-box {
        font-size: 1.5rem;
    }
}

@media (min-width: 768px) {
    #app {
        max-width: 500px;
        margin: 0 auto;
    }
}
