:root {
    --bg-color: #2d2d2d;
    --text-color: #ffffff;
    --key-bg: #444;
    --key-border: #222;
    --key-active: #007bff;
    --key-text: #eee;
    --accent-color: #00a8ff;
    --display-bg: #333; /* Display area background */
    --input-text: #fff; /* Input text color */
    --btn-active-text: #fff; /* Text color for active buttons */
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

.container {
    width: 90%;
    max-width: 1000px;
    text-align: center;
    padding: 20px;
}

header {
    margin-bottom: 30px;
}

.controls-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.mode-controls {
    margin: 0;
}

.theme-controls select {
    padding: 10px 15px;
    border-radius: 5px;
    background: var(--key-bg);
    color: var(--text-color);
    border: 1px solid var(--key-border);
    cursor: pointer;
    font-family: inherit;
    font-size: 1em;
    outline: none;
    transition: all 0.2s;
}

.theme-controls select:hover {
    border-color: var(--accent-color);
}

.mode-btn {
    background: var(--key-bg);
    border: 1px solid var(--key-border);
    color: var(--text-color);
    padding: 10px 20px;
    cursor: pointer;
    margin: 0 5px;
    border-radius: 5px;
    transition: all 0.2s;
}

.mode-btn.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: var(--btn-active-text);
}

.display-area {
    background: var(--display-bg);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative; /* 为绝对定位子元素提供基准 */
}

#input-area {
    width: 100%;
    height: 120px; /* 稍微增加高度 */
    background: transparent;
    border: none;
    color: var(--input-text);
    font-size: 1.2em;
    resize: none;
    outline: none;
    z-index: 1; /* 降低输入框层级，让按键信息覆盖它 */
    position: relative;
}

/* ... existing code ... */

.hidden {
    display: none !important;
}

/* 移除旧的 info-panel 样式 */

.current-key-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: absolute;
    top: 50%; /* 居中定位 */
    left: 50%;
    transform: translate(-50%, -50%); /* 居中偏移 */
    pointer-events: none; /* 防止遮挡鼠标对输入框的操作 */
    opacity: 0; /* 默认隐藏 */
    z-index: 10; /* 确保在最上层 */
    transition: opacity 0.3s ease; /* 添加渐变过渡 */
    background: rgba(0, 0, 0, 0.6); /* 添加半透明背景增强可读性 */
    padding: 10px 20px;
    border-radius: 10px;
    backdrop-filter: blur(2px);
}

.current-key-info.visible {
    opacity: 1; /* 显示状态 */
}

.key-large {
    font-size: 3em; /* 字体再大一点 */
    font-weight: bold;
    color: var(--accent-color);
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}

.key-trans {
    font-size: 1.4em;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* Keyboard Layout */
.keyboard-container {
    background: #1a1a1a;
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
    display: inline-block;
}

.row {
    display: flex;
    justify-content: space-between; /* 改为两端对齐 */
    margin-bottom: 4px; /* 压缩行间距 */
    width: 100%; /* 确保占满容器宽度 */
}

/* 第一排功能键特殊布局 */
.keyboard-container .row:first-child {
    justify-content: flex-start; /* 左对齐，以便自定义间距 */
}

.key[data-key="Escape"] {
    margin-right: 60px; /* ESC 与 F1 之间的间距 */
}

.key[data-key="F4"],
.key[data-key="F8"] {
    margin-right: 40px; /* F键分组之间的间距 */
}

.key {
    width: 50px;
    height: 50px;
    margin: 3px;
    background: var(--key-bg);
    border: 2px solid var(--key-border);
    border-radius: 8px;
    color: var(--key-text);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    transition: all 0.1s;
    box-shadow: 0 4px 0 var(--key-border);
    flex-grow: 0; /* 默认不自动拉伸 */
    flex-shrink: 0; /* 默认不自动压缩 */
}

/* 特殊按键宽度定义 - 参照标准键盘比例 */
/* 基础单位 u ≈ 50px + margin */

.key[data-key="Backspace"] { width: 100px; }
.key[data-key="Tab"] { width: 80px; }
.key[data-key="Backslash"] { width: 80px; }
.key[data-key="CapsLock"] { width: 90px; }
.key[data-key="Enter"] { width: 115px; }
.key[data-key="ShiftLeft"] { width: 120px; }
.key[data-key="ShiftRight"] { width: 140px; }

.key[data-key="ControlLeft"], 
.key[data-key="MetaLeft"], 
.key[data-key="AltLeft"], 
.key[data-key="AltRight"], 
.key[data-key="MetaRight"], 
.key[data-key="ContextMenu"], 
.key[data-key="ControlRight"] { 
    width: 65px; 
}

.key.space {
    width: 340px; /* 调整空格键宽度以适配 */
    flex-grow: 1; /* 空格键可以适当拉伸填充 */
}

/* 移除原来的 .key.special 定义，改用具体宽度控制 */
.key:active, .key.active {
    transform: translateY(4px);
    box-shadow: 0 0 0 var(--key-border);
    background: var(--key-active);
    border-color: #0056b3;
}

.stats-panel {
    display: flex;
    justify-content: space-around;
    margin-top: 10px;
    font-size: 0.9em;
    color: var(--input-text);
    opacity: 0.8;
}

.settings {
    margin-top: 20px;
}

/* Theme Definitions */

/* Sakura Pink Theme */
body.theme-sakura {
    --bg-color: #ffe6f2;
    --text-color: #5c2b2b;
    --key-bg: #fff0f5;
    --key-border: #ffb7c5;
    --key-active: #ff69b4;
    --key-text: #d63384;
    --accent-color: #ff1493;
    --display-bg: #fff5f8;
    --input-text: #5c2b2b;
    --btn-active-text: #fff;
}

/* Hacker Green Theme */
body.theme-hacker {
    --bg-color: #0d1117;
    --text-color: #00ff00;
    --key-bg: #161b22;
    --key-border: #30363d;
    --key-active: #2ea043;
    --key-text: #00ff00;
    --accent-color: #3fb950;
    --display-bg: #000;
    --input-text: #00ff00;
    --btn-active-text: #fff;
}

/* Retro Grey Theme */
body.theme-retro {
    --bg-color: #e0e0e0;
    --text-color: #333333;
    --key-bg: #f5f5f5;
    --key-border: #bbb;
    --key-active: #d35400;
    --key-text: #555;
    --accent-color: #d35400;
    --display-bg: #ccc;
    --input-text: #333;
    --btn-active-text: #fff;
}

