/* Typing Practice 页面专用样式（只服务这一个页面）
   配色走 css/theme.css（本页 <head> 第一条引用）：主色 --amber、答对 --teal、答错 --danger
   本页保留自己的变量名（--blue/--green/--red/--text/--page-bg 等）作为 theme 变量的别名，
   这样下面的规则不用逐行改类名；别名值随深浅两套配色一起变 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* 主色：原来 Google 蓝，全站主题化后换成琥珀；--blue-dark 是 hover 时更深一档 */
    --blue: var(--amber);
    --blue-dark: color-mix(in srgb, var(--amber) 80%, var(--ink));
    /* 答对 / 答错：沿用 24 点页的 --teal / --danger，浅底和描边由 color-mix 推 */
    --green: var(--teal);
    --green-bg1: color-mix(in srgb, var(--teal) 14%, var(--card));
    --green-bg2: color-mix(in srgb, var(--teal) 24%, var(--card));
    --green-border: color-mix(in srgb, var(--teal) 45%, var(--line));
    --red: var(--danger);
    --red-bg1: color-mix(in srgb, var(--danger) 14%, var(--card));
    --red-bg2: color-mix(in srgb, var(--danger) 24%, var(--card));
    --red-border: color-mix(in srgb, var(--danger) 45%, var(--line));
    /* 正文 / 副文案 / 卡片 / 描边 */
    --text: var(--ink);
    --text-2: var(--ink-soft);
    /* 背景渐变已在 css/theme.css 的 body::before 画好，这里不再给 body 加底色，否则会把渐变盖住 */
    --page-bg: transparent;
    --card-bg: var(--card);
    --border: var(--line);
}

html, body {
    min-height: 100%;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--page-bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ===== 全站导航栏 / 页脚：样式统一在 css/site.css（本页 <head> 最后引用），此处不再复制一份 ===== */
/* 导航与正文之间留 30px，和其余游戏页一致（本页不再压缩到 6px，页面允许纵向滚动） */
.site-head {
    margin-bottom: 30px;
}

/* ===== 页面标题：与 1-9 Number Grid 页同一个位置和字号 ===== */
h1 {
    margin: 33px 0 6px;
    font-size: 32px;
    font-weight: 600;
    line-height: 1.2;
}

/* ===== 两栏布局（/css/game-layout.css，在本页样式表之后引用）===== */
/* .container 和栅格容器夹在 body 与 main.main-col 之间，把 flex:1 接力下去，版权声明统一贴底（全站一致）。
   选择器多写一层 body 是为了压过后引用的公共表（同为类选择器时后来者赢）。 */
body .container {
    flex: 1;
    display: flex;
    flex-direction: column;
}

body .page-layout {
    flex: 1;
}

/* ===== 游戏卡片：顶部两排切换按钮 + 当前模式的游戏面板（模仿 24 点页 / 1-9 宫格页的 .game-area） ===== */
.game-area {
    margin: 26px 0 0;
    padding: clamp(18px, 4vw, 26px);
    border: 1px solid color-mix(in srgb, var(--amber) 35%, var(--line));
    border-radius: 22px;
    background: linear-gradient(160deg, color-mix(in srgb, var(--amber) 20%, var(--card)), var(--card) 65%);
    box-shadow: 0 18px 36px var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    text-align: center;
}

/* ===== 模式 / 难度按钮栏：样式仿照 1-9 Number Grid 页面顶部的难度按钮（.diff-btn） ===== */
.switch-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

/* 隐藏的难度条：.switch-bar 的 display:flex 会盖掉 [hidden]，这里显式收起 */
.switch-bar[hidden] {
    display: none;
}

.switch-btn,
.level-bar-placeholder .ghost-btn {
    font-family: inherit;
    padding: 10px 18px;
    font-size: 15px;
    border: 1px solid var(--line);
    background: var(--tile);
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    color: var(--ink);
    transition: border-color .15s, background .15s;
}

.switch-btn:hover {
    border-color: var(--amber);
}

/* 选中的模式 / 难度：琥珀实底 + 深色字，与 1-9 宫格页的选中态同一做法 */
.switch-btn.active {
    background: linear-gradient(135deg, var(--amber), color-mix(in srgb, var(--amber) 60%, var(--pink)));
    border-color: transparent;
    color: var(--on-accent);
}

/* 难度按钮比模式按钮小一档 */
.switch-btn.small,
.level-bar-placeholder .ghost-btn {
    padding: 6px 14px;
    font-size: 13px;
}

/* Word Practice 难度条占位：不可见元素与另外两排按钮同尺寸，窄屏换行行为也一致 */
.level-bar-placeholder .ghost-btn {
    visibility: hidden;
}

/* 13px 字号 × 约 1.2 行高 + 6px × 2 上下内边距 + 1px × 2 边框，与 .switch-btn.small 同高 */
.level-bar-placeholder {
    min-height: calc(13px * 1.2 + 6px * 2 + 1px * 2);
}

/* Challenge / Extreme 暂未开放：置灰，点击只弹 Coming soon（悬停不高亮） */
.switch-btn.locked {
    opacity: .55;
    cursor: not-allowed;
    color: color-mix(in srgb, var(--ink-soft) 70%, transparent);
}

.switch-btn.locked:hover {
    border-color: var(--line);
}

/* ===== 模式面板：同一时间只显示当前模式的游戏区 ===== */
.panel {
    display: none;
    width: 100%;
}

.panel.active {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* 键盘区一行：键帽组居中，右侧控制列由各模式自行定位 */
.play-row {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 16px;
    margin-top: 6px;
}

/* 右侧控制列：宽度固定为切换键帽的 56px，保持切换按钮隐藏的难度下占位不变；
   计时徽章排在列内下方，出现/消失不推动切换按钮 */
.panel-side {
    flex: 0 0 56px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

/* Keyboard Practice（Beginner）：A/a 切换按钮连同 i 提示固定在卡片右侧，
   与参考界面一致；键帽组仍居中，按钮不再挤在键帽旁边。
   注意 .game-area 的 padding 是 clamp(18px, 4vw, 26px)，会随视口变化；这里用 calc 把这部分抵消掉，
   使按钮距卡片右边缘始终固定 30px，不会随屏幕宽度漂移 */
#panel-keyboard .play-row {
    position: relative;
}

#panel-keyboard .panel-side {
    position: absolute;
    top: 0;
    right: calc(30px - clamp(18px, 4vw, 26px));
}

/* 字符键位（iOS 风格键帽） */
.keys {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    max-width: 420px; /* 强制两排各5个：5×58+4×26=394px < 420px，6个需478px放不下 */
    gap: 20px 26px; /* 行距20px，列距约一个半字 */
}

/* 高等：5 个单词固定分两排；每个单词合并为「一个」键帽框，字母在同一框内连续排列 */
.keys.hard {
    flex-direction: column;
    align-items: center;
    max-width: 980px;
    gap: 20px;
}

.word-row {
    display: flex;
    justify-content: center;
    align-items: center;
}

.keys.hard .word {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px; /* 同一单词内字母只留很小间距，视觉上连成整体 */
    height: 66px;
    padding: 0 12px;
    border-radius: 10px;
    background: linear-gradient(var(--card), color-mix(in srgb, var(--ink) 8%, var(--tile)));
    border: 1px solid var(--line);
    border-bottom-width: 2px;
    box-shadow: 0 2px 3px var(--shadow), inset 0 1px 0 color-mix(in srgb, var(--ink) 10%, var(--tile));
    transition: transform .12s, background .15s, border-color .15s, color .15s, box-shadow .15s;
}

.keys.hard .word + .word {
    margin-left: 52px;
}

/* 单词框之间的间距（在原 26px 基础上翻倍） */
.keys.hard .ch {
    width: 34px;
    text-align: center;
    font-size: 25px;
    font-weight: 500;
    line-height: 1;
    color: var(--ink);
    border-radius: 6px;
    transition: color .15s, background .15s;
}

/* 含当前待输入字母的单词框：整框上浮 + 蓝框；当前字母在框内单独高亮 */
.keys.hard .word.current {
    border-color: var(--amber);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--amber) 25%, transparent), 0 4px 8px var(--shadow);
    transform: translateY(-3px);
}

.keys.hard .ch.current {
    color: var(--amber-text);
    background: color-mix(in srgb, var(--amber) 12%, transparent);
}

.keys.hard .ch.correct {
    color: var(--green);
}

.keys.hard .ch.fixed {
    color: var(--amber-text);
}

.keys.hard .ch.correct.was-correct {
    color: var(--teal);
}

.keys.hard .ch.error {
    color: var(--red);
    animation: shake .3s ease;
}

/* 窄窗口：缩小单词框与字母，保证两排单词始终完整可见、不被裁切 */
@media (max-width: 980px) {
    .keys.hard {
        max-width: 96vw;
    }

    .keys.hard .word {
        height: 56px;
        padding: 0 8px;
        border-radius: 9px;
    }

    .keys.hard .ch {
        width: 26px;
        font-size: 21px;
    }

    .keys.hard .word + .word {
        margin-left: 36px;
    }
}

@media (max-width: 620px) {
    .keys.hard .word {
        height: 46px;
        padding: 0 6px;
        gap: 2px;
        border-radius: 8px;
    }

    .keys.hard .ch {
        width: 22px;
        font-size: 18px;
    }

    .keys.hard .word + .word {
        margin-left: 24px;
    }
}

.keycap {
    width: 58px;
    height: 66px;
    border-radius: 10px;
    background: linear-gradient(var(--card), color-mix(in srgb, var(--ink) 8%, var(--tile)));
    border: 1px solid var(--line);
    border-bottom-width: 2px;
    box-shadow: 0 2px 3px var(--shadow), inset 0 1px 0 color-mix(in srgb, var(--ink) 10%, var(--tile));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 25px;
    font-weight: 500;
    color: var(--ink);
    transition: transform .12s, background .15s, border-color .15s, color .15s, box-shadow .15s;
    user-select: none;
}

/* 数字 0 带斜杠：与字母 O 区分；斜杠颜色用 currentColor，随键帽状态（绿/红/蓝）自动变化 */
.char-zero {
    position: relative;
    display: inline-block;
    line-height: 1;
}

.char-zero::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 0.09em;
    height: 0.09em; /* 略超出 0 的上下边缘 */
    background: currentColor;
    border-radius: 0.05em;
    transform: translate(-50%, -50%); /* "/" 方向斜杠 */
}

/* 大写 I 手写体：上下小横 + 中间竖线，与小写 l 区分；颜色用 currentColor，随键帽状态（绿/红/蓝）自动变化 */
.char-i {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    height: 0.65em; /* 与大写字母帽高一致 */
    width: 0.25em; /* 稍微把容器宽度调宽一点，容纳加粗后的线条 */
}

/* 上下横杠（帽子和底座） */
.char-i::before, .char-i::after {
    content: "";
    width: 100%;
    height: 0.12em; /* 从 0.08em 调粗到 0.12em（让上下横杠变粗） */
    background: currentColor;
    border-radius: 0.04em;
}

/* 中间的竖线 */
.char-i .stem {
    flex: 1;
    width: 0.12em; /* 从 0.08em 调粗到 0.12em（让中间竖线变粗） */
    background: currentColor;
    border-radius: 0.04em;
}

/* 小写 l 手写体：斜体字形（斜一笔、底部右弯），与大写 I、数字 1 区分；颜色继承键帽状态色 */
.char-l {
    font-style: italic; /* normal */
    display: inline-block; /* transform 效果需要块级或行内块级元素 */
    transform: skewX(4deg); /* 反向倾斜 12 度拉直，可根据效果微调 10deg ~ 15deg */
}

.keycap.current {
    border-color: var(--amber);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--amber) 25%, transparent), 0 4px 8px var(--shadow);
    transform: translateY(-3px) scale(1.08);
}

.keycap.correct {
    background: linear-gradient(var(--green-bg1), var(--green-bg2));
    border-color: var(--green-border);
    color: var(--green);
}

/* 回退后重新输入且正确 → 蓝色（已修正） */
.keycap.fixed {
    background: linear-gradient(color-mix(in srgb, var(--amber) 14%, var(--tile)), color-mix(in srgb, var(--amber) 24%, var(--tile)));
    border-color: color-mix(in srgb, var(--amber) 45%, var(--line));
    color: var(--amber-text);
}

/* 回退了原本正确的字符 → 偏浅的绿色（被改过） */
.keycap.correct.was-correct {
    background: linear-gradient(var(--green-bg1), var(--green-bg2));
    border-color: var(--green-border);
    color: var(--teal);
}

.keycap.error {
    background: linear-gradient(var(--red-bg1), var(--red-bg2));
    border-color: var(--red-border);
    color: var(--red);
    animation: shake .3s ease;
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    20% {
        transform: translateX(-5px);
    }
    40% {
        transform: translateX(5px);
    }
    60% {
        transform: translateX(-4px);
    }
    80% {
        transform: translateX(4px);
    }
}

/* 计时徽章：本组完成后显示在切换键帽下方（右侧控制列内），中性色，两种难度都用它 */
.time-badge {
    font-size: 20px; /* 比模式按钮的字号稍大一点 */
    font-weight: 500;
    color: var(--ink-soft); /* 中性色，不再使用红色 */
    display: none;
    white-space: nowrap;
    text-align: center;
}

.case-toggle {
    font-family: inherit;
    width: 56px;
    height: 50px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: linear-gradient(var(--card), color-mix(in srgb, var(--ink) 6%, var(--tile)));
    font-size: 22px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    box-shadow: 0 1px 0 var(--shadow);
    transition: transform .1s, opacity .15s;
}

.case-toggle:active:not(:disabled) {
    transform: translateY(1px);
}

.case-toggle:disabled {
    opacity: .45;
    cursor: not-allowed;
}

/* 右上角切换按钮的「i」说明角标 + 悬停气泡（A/a 使用） */
.case-wrap {
    position: relative;
    display: inline-block;
}

/* 简单 / 高等：整体隐藏但保留占位，面板头部高度不变 */
.case-wrap.off {
    visibility: hidden;
}

/* i 角标的可悬停区域：比视觉 i 稍大，靠近即触发（不覆盖整个按钮） */
.case-info-wrap {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.case-info {
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: var(--blue);
    color: var(--on-accent);
    font-size: 12px;
    font-style: italic;
    font-weight: 700;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
    pointer-events: none;
}

.case-tip {
    position: absolute;
    top: calc(100% + 8px); /* 气泡出现在按钮下方（鼠标下方），不遮挡上方内容 */
    right: 0;
    width: 262px;
    background: rgba(23, 19, 58, 0.92);
    color: #fff;
    font-size: 13px;
    font-weight: 400;
    font-style: normal;
    line-height: 1.55;
    text-align: left;
    border-radius: 10px;
    padding: 10px 12px;
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    transition: opacity .15s, transform .15s;
    z-index: 60;
    box-shadow: 0 4px 14px var(--shadow);
    white-space: normal;
}

/* 仅当鼠标悬停在 i 角标附近时才显示气泡 */
.case-info-wrap:hover ~ .case-tip {
    opacity: 1;
    transform: translateY(0);
}

.hint {
    margin: 0 0 6px;
    font-size: 17px; /* 加大两个号 */
    color: var(--ink); /* 加深 */
    min-height: 44px; /* 预留两行高度，切换难度时下方键位不上下跳动 */
    text-align: center;
    transition: color .2s;
}

.hint.typing {
    color: var(--ink-soft);
}

/* 完成提示：未达标沿用普通提示语颜色 */
.hint.done {
    color: var(--ink);
    font-weight: 400;
}

/* 达标：整句绿色（Enter 键帽单独保持深色） */
.hint.done.pass {
    color: var(--green);
}

/* 用时数字加粗 */
.hint strong {
    font-weight: 700;
}

.hint b {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1px 10px;
    font-family: inherit;
    box-shadow: 0 1px 2px var(--shadow);
    color: var(--text);
    font-weight: 700;
}

/* 统计区：窄屏自动换行，卡片里不裁切 */
.stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
}

.stat {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 10px 26px;
    text-align: center;
    box-shadow: 0 1px 3px var(--shadow);
    min-width: 120px;
}

.stat span {
    display: block;
    font-size: 12px;
    color: var(--text-2);
    margin-bottom: 2px;
}

.stat strong {
    display: block;
    font-size: 22px;
    font-weight: 500;
}

#accValue.good {
    color: var(--green);
}

#accValue.bad {
    color: var(--red);
}

/* ===== 键盘图案（Key Finder） ===== */
/* 整排 13 个键的自然宽度是 682px（13×46 + 12×7），窄屏下靠 key 伸缩放进卡片，不裁切 */
.kb {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 682px;
}

.kb-row {
    display: flex;
    justify-content: center;
    gap: clamp(3px, 0.6vw, 7px);
}

.kb-key {
    flex: 1 1 0;
    min-width: 0;
    max-width: 46px;
    height: clamp(38px, 5.6vw, 52px);
    padding: 0 clamp(1px, 0.6vw, 6px);
    border-radius: 8px;
    background: linear-gradient(var(--card), color-mix(in srgb, var(--ink) 6%, var(--tile)));
    border: 1px solid var(--line);
    border-bottom-width: 2px;
    box-shadow: 0 2px 3px var(--shadow), inset 0 1px 0 color-mix(in srgb, var(--ink) 10%, var(--tile));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: clamp(13px, 1.2vw + 6px, 18px);
    font-weight: 500;
    color: var(--ink);
    /* background 不参与过渡：基础是渐变、激活是纯色，浏览器无法插值会导致背景不生效 */
    transition: transform .12s, border-color .15s, color .15s, box-shadow .15s;
    user-select: none;
    line-height: 1.1;
}

.kb-key .kb-sub {
    font-size: clamp(8px, 0.7vw + 5px, 11px);
    color: var(--ink-soft);
    font-weight: 400;
}

.kb-key .kb-main {
    font-weight: 500;
}

.kb-key.single {
    font-size: clamp(15px, 1.6vw + 8px, 22px);
}

.kb-key.active {
    border-color: var(--amber);
    background: color-mix(in srgb, var(--amber) 14%, var(--tile));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--amber) 25%, transparent), 0 4px 8px var(--shadow);
    transform: translateY(-2px);
}

/* 目标是大写：上档字符变绿并放大，整个按键也放大 */
.kb-key.active.target-upper {
    border-color: var(--green);
    background: var(--green-bg1);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 25%, transparent), 0 4px 8px var(--shadow);
    transform: translateY(-2px) scale(1.18);
    z-index: 5;
}

.kb-key.active.target-upper .kb-sub {
    font-weight: 600;
    color: var(--green);
    font-size: 28px;
}

/* 目标是小写：加粗下档字符（蓝色，保持原样） */
.kb-key.active.target-lower .kb-main {
    font-weight: 600;
    color: var(--amber-text);
    font-size: 22px;
}

/* 单字符键（数字、符号）目标：整体加粗 */
.kb-key.active.target-lower.single,
.kb-key.active.target-upper.single {
    font-weight: 600;
    color: var(--amber-text);
}

.kb-key.correct {
    background: linear-gradient(var(--green-bg1), var(--green-bg2));
    border-color: var(--green-border);
    color: var(--green);
}

.kb-key.error {
    background: linear-gradient(var(--red-bg1), var(--red-bg2));
    border-color: var(--red-border);
    color: var(--red);
    animation: shake .3s ease;
}

.where-stats {
    display: flex;
    gap: 16px;
    margin-top: 20px;
}

/* ===== Toast 提示 ===== */
.toast {
    position: fixed;
    top: 22%;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    background: rgba(23, 19, 58, 0.92);
    color: #fff;
    padding: 12px 28px;
    border-radius: 24px;
    font-size: 15px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
    z-index: 99;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ==================== 正文卡片（与 24 Game 页同款） ==================== */
/* 游戏卡片到正文的 24px 间距由 .content 给；卡片为本页新增，不影响上面的游戏区样式 */
.content {
    display: grid;
    gap: 12px;
    margin-top: 24px;
}

.card {
    position: relative;
    background: #FDFCFE;
    padding: 20px 24px 20px 80px;
    box-shadow: 0 4px 12px rgba(90, 60, 200, 0.1);
}

.card[hidden] {
    display: none;
}

.card h2 {
    margin: 0 0 16px;
    font-size: 24px;
    color: #2a1f5c;
}

.card h2 .h-icon {
    position: absolute;
    left: 14px;
    top: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 58px;
    height: 58px;
    border-radius: 50%;
}

.card h2 .h-icon svg {
    width: 24px;
    height: 24px;
}

.h-icon-blue {
    background: #E4EDFF;
    color: #2563EB;
}

.h-icon-green {
    background: #DDF5E7;
    color: #15803D;
}

.h-icon-purple {
    background: #EDE4FE;
    color: #6D3BD1;
}

.h-icon-orange {
    background: #FFEBD8;
    color: #C2410C;
}

.card > p {
    max-width: 760px;
    margin: 8px 0;
    color: #5d5488;
}

.card strong {
    color: #2a1f5c;
}

.card > ol,
.card > ul {
    max-width: 760px;
    margin: 8px 0;
    padding-left: 16px;
    color: #5d5488;
}

.card > ol > li,
.card > ul > li {
    margin: 5px 0;
}

@media (max-width: 640px) {
    .card {
        padding: 18px 18px 18px 64px;
    }

    .card h2 {
        font-size: 20px;
    }

    .card h2 .h-icon {
        left: 12px;
        top: 12px;
        width: 40px;
        height: 40px;
    }

    .card h2 .h-icon svg {
        width: 20px;
        height: 20px;
    }
}
