/* ================================================================
   单词连连看 · 共用样式（/english/css/lianliankan.css）
   ----------------------------------------------------------------
   两个页面共用（逻辑见 /english/js/lianliankan-core.js）：
     /english/textbook/31/lianliankan.html   课本版：三上单词表，按单元多选
     /english/games/lianliankan/index.html   通用版：1~6 年级词库，按年级 + 学期

   结构：
     .llk-bar       工具栏（筛选下拉 + 进度 + 重新开始）
     .llk-filter    一块筛选（标签 + 下拉按钮 + 面板）
     .llk-tip       提示条（选卡提示 / 配对结果 / 全部完成）
     .llk-board     游戏区：左英文列、右中文列，上面盖一层连线画布
     .llk-card      单词卡（<button>，选中 / 连错 / 已消除三种状态）
     .llk-timer     「已用时间」（由核心插到页头卡标题行右侧）
     .llk-win       通关祝贺弹层（结构由核心注入）

   配色、圆角、断点一律取自 /css/style.css 的整站令牌（详见 design.md）：
   青绿清新系，禁止冷蓝冷灰；触屏反馈不依赖 :hover，桌面 hover 包在
   @media (hover: hover) and (pointer: fine) 里。
   ================================================================ */

/* ===== 工具栏 ===== */
.llk-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

/* 单元多选下拉（与课本拼读页 words.html 的单元筛选同一套观感与交互） */
.llk-filter {
    display: flex;
    align-items: center;
    gap: 8px;
    order: 1;
}

.llk-filter-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink-2);
    white-space: nowrap;
}

.llk-select-wrap {
    position: relative;
}

/* 默认态就要看得出「这里能点」：浅青绿底 + 青绿描边 + 主色字，
   白底浅灰边在米白页面上几乎看不见（打开时变实心主色，对比更强） */
.llk-select {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 15px;
    border: 1px solid var(--coral);
    border-radius: var(--radius-pill);
    background: var(--coral-softer);
    box-shadow: var(--shadow-sm);
    color: var(--coral-deep);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.llk-select-text {
    white-space: nowrap;
}

.llk-select-arrow {
    flex: 0 0 auto;
    color: var(--coral-deep);
    opacity: 0.75;
    transition: transform 0.25s ease, color 0.15s ease, opacity 0.15s ease;
}

.llk-select:focus-visible {
    outline: 2px solid var(--coral-deep);
    outline-offset: 2px;
}

/* 面板打开时：实心主色 + 白字（--coral-deep 上白字对比度足够） */
.llk-select.active {
    background: var(--coral-deep);
    border-color: var(--coral-deep);
    color: #fff;
}

.llk-select.active .llk-select-arrow {
    color: #fff;
    opacity: 1;
    transform: rotate(180deg);
}

@media (hover: hover) and (pointer: fine) {
    .llk-select:hover {
        background: var(--coral-soft);
        border-color: var(--coral-deep);
    }

    .llk-select.active:hover {
        background: var(--coral-hover);
        border-color: var(--coral-hover);
    }
}

/* 下拉面板：白底圆角 + 站点阴影；最高 60vh，内部可滚 */
.llk-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 1300;
    min-width: 100%;
    width: max-content;
    max-width: calc(100vw - 2.5rem);
    max-height: 60vh;
    overflow-y: auto;
    padding: 6px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-panel);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* display:flex 会盖掉 [hidden] 的默认 display:none，这里要显式声明 */
.llk-menu[hidden] {
    display: none;
}

.llk-menu.align-right {
    left: auto;
    right: 0;
}

.llk-option {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.llk-option:active {
    transform: scale(0.99);
}

@media (hover: hover) and (pointer: fine) {
    .llk-option:hover {
        background: var(--bg-soft);
    }
}

.llk-option.is-on {
    color: var(--coral-deep);
    font-weight: 700;
    background: var(--bg-soft);
}

/* 选项左侧的方框勾：勾上时主色实心 + 白勾 */
.llk-check {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid var(--line);
    border-radius: 4px;
    color: #fff;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.llk-option.is-on .llk-check {
    background: var(--coral-deep);
    border-color: var(--coral-deep);
}

/* 单选筛选（如通用版的「学期」）右侧的对勾：多选用左侧方框，单选用右侧勾 */
.llk-option-check {
    flex: 0 0 auto;
    margin-left: auto;
    color: var(--coral-deep);
}

/* 面板底部「清除 / 完成」：吸在面板底部，列表滚动时也看得到 */
.llk-menu-foot {
    position: sticky;
    bottom: 0;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 4px;
    padding: 9px 2px 2px;
    border-top: 1px solid var(--line-soft);
    background: #fff;
}

.llk-menu-btn {
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.llk-menu-btn:active {
    transform: scale(0.96);
}

.llk-menu-btn.is-plain {
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink-3);
}

.llk-menu-btn.is-main {
    border: 1px solid var(--coral-deep);
    background: transparent;
    color: var(--coral-deep);
}

@media (hover: hover) and (pointer: fine) {
    .llk-menu-btn.is-plain:hover {
        border-color: var(--coral-deep);
        color: var(--coral-deep);
    }

    .llk-menu-btn.is-main:hover {
        background: var(--coral-deep);
        color: #fff;
    }
}

.llk-status {
    display: flex;
    align-items: center;
    gap: 12px;
    order: 3;
    margin-left: auto;
    min-width: 0;
}

/* 通关进度：上面一行「第 X 关 / 共 Y 关」+「还剩 N 组 · P%」，下面一条进度条 */
.llk-progress {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1 1 auto;
    min-width: 150px;
}

.llk-progress-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.llk-level {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--ink-2);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.llk-left {
    font-size: 0.85rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.llk-track {
    height: 8px;
    border-radius: var(--radius-pill);
    background: var(--chip-bg);
    box-shadow: inset 0 1px 2px rgba(20, 60, 52, 0.08);
    overflow: hidden;
}

.llk-fill {
    display: block;
    width: 0;
    height: 100%;
    border-radius: var(--radius-pill);
    background: linear-gradient(90deg, var(--coral), var(--coral-2));
    transition: width 0.35s ease;
}

/* 全部连完：进度条换成金色收尾 */
.llk-progress.is-done .llk-fill {
    background: linear-gradient(90deg, var(--gold), var(--coral-2));
}

/* 「已用时间」：由 js/lianliankan.js 插到页头卡标题行（.page-head-top）右侧。
   想让计时尽量大，又不愿意把标题行顶高，所以：
     1) 行高压到 1，元素高度就等于字号，不再跟着 body 的 1.5 行高膨胀；
     2) 用上下负外边距把那点溢出抵消掉 —— 标题行的高度是标题 h1 决定的
        （桌面 1.4rem × 1.2 ≈ 1.68rem，手机 1.2rem × 1.2 ≈ 1.44rem，
        见 /css/style.css 与 Bootstrap 的 heading 行高），
        计时器「字号 + 负外边距」不超过这个值，标题行就不会变高。
   多出来的部分只是上下各溢出 2～3px，被页头卡的内边距吸收，看不见。 */
.llk-timer {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    /* 右对齐；上下对称的负外边距＝抵消字号超出标题行的那部分高度 */
    margin: -0.18rem 0 -0.18rem auto;
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    color: var(--coral-deep);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.llk-timer i {
    font-size: 1.5rem;
    line-height: 1;
}

@media (max-width: 767.98px) {
    /* 手机（标题 1.2rem）：1.65rem − 两侧各 0.12rem = 1.41rem < 1.44rem */
    .llk-timer {
        margin: -0.12rem 0 -0.12rem auto;
        font-size: 1.65rem;
    }

    .llk-timer i {
        font-size: 1.25rem;
    }
}

/* 从平板起一行放得下：单元筛选 …… 进度条 重新开始 */
@media (min-width: 768px) {
    .llk-status {
        order: 2;
    }

    .llk-again {
        order: 3;
        margin-left: 0.5rem;
    }
}

/* 手机竖屏：第一行是「单元筛选 + 重新开始」，进度条独占第二行、拉满可用宽度 */
@media (max-width: 767.98px) {
    .llk-status {
        flex: 1 1 100%;
        margin-left: 0;
    }

    .llk-progress {
        min-width: 0;
    }
}

/* 「重新开始」跟在单元筛选后面：手机竖屏落在第一行右侧（order 2），
   桌面用 order 挪到进度条右边；margin-left:auto 让它贴到行尾 */
.llk-again {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    order: 2;
    flex: 0 0 auto;
    margin-left: auto;
    padding: 7px 14px;
    border: 1px solid var(--coral-deep);
    border-radius: var(--radius-pill);
    background: #fff;
    color: var(--coral-deep);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.llk-again:active {
    transform: scale(0.96);
}

@media (hover: hover) and (pointer: fine) {
    .llk-again:hover {
        background: var(--coral-deep);
        color: #fff;
    }
}

/* ===== 提示条 ===== */
.llk-tip {
    margin: 0 0 14px;
    padding: 9px 14px;
    border-radius: var(--radius-sm);
    background: var(--bg-soft);
    color: var(--ink-2);
    font-size: 0.9rem;
    line-height: 1.6;
}

.llk-tip.is-ok {
    background: var(--coral-soft);
    color: var(--coral-deep);
}

.llk-tip.is-warn {
    background: var(--bg-soft);
    color: var(--gold-deep);
}

.llk-tip.is-done {
    background: var(--coral-soft);
    color: var(--coral-deep);
    font-weight: 600;
}

/* ===== 游戏区 ===== */
.llk-board {
    position: relative;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    align-items: start;
}

@media (min-width: 768px) {
    .llk-board {
        gap: 14px;
    }
}

/* 大屏不再拉满整行：两列各一行词，太宽反而不好瞄 */
@media (min-width: 1024px) {
    .llk-board {
        max-width: 760px;
        margin: 0 auto;
        gap: 18px;
    }
}

.llk-col {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

@media (min-width: 768px) {
    .llk-col {
        gap: 10px;
    }
}

/* 连线画布：盖在两列之上，只画线，不接事件（点击照旧落到卡片上） */
.llk-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 3;
}

/* ===== 单词卡 ===== */
.llk-card {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 50px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
    color: var(--ink);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.35;
    text-align: center;
    word-break: break-word;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.15s ease, border-color 0.15s ease, background-color 0.15s ease,
        opacity 0.25s ease, box-shadow 0.15s ease;
}

/* 中文卡稍收一档，与英文卡区分（也避免长释义把卡撑太高） */
.llk-card[data-kind="cn"] {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--ink-2);
}

.llk-card:active {
    transform: scale(0.97);
}

.llk-card:focus-visible {
    outline: 2px solid var(--coral-deep);
    outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
    .llk-card:hover {
        border-color: var(--coral);
        box-shadow: var(--shadow-card);
    }
}

/* 选中的卡：浅底 + 主色青绿描边（与句读页高亮同一套表达） */
.llk-card.is-picked {
    border-color: var(--coral-deep);
    background: var(--coral-soft);
    color: var(--coral-deep);
    box-shadow: inset 0 0 0 1px var(--coral-deep);
}

/* 连错的卡：抖一下 */
.llk-card.is-wrong {
    border-color: var(--coral-hover);
    animation: llk-shake 0.32s ease;
}

@keyframes llk-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* 连对的卡：淡出（动画结束后由脚本移除） */
.llk-card.is-gone {
    opacity: 0;
    transform: scale(0.94);
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    .llk-card,
    .llk-select,
    .llk-option,
    .llk-menu-btn,
    .llk-fill,
    .llk-again {
        transition: none;
    }

    .llk-card.is-wrong {
        animation: none;
    }
}

/* 小屏（< 600，手机竖屏）：字号要比桌面更大一点才看得清，
   卡高同步抬高，卡片间距略收紧以免一屏放不下 6 组词 */
@media (max-width: 599.98px) {
    .llk-card {
        min-height: 54px;
        padding: 9px 10px;
        font-size: 1.12rem;
        border-radius: var(--radius-sm);
    }

    .llk-card[data-kind="cn"] {
        font-size: 1.06rem;
    }

    .llk-col {
        gap: 7px;
    }

    .llk-board {
        gap: 8px;
    }
}

/* 底部小字说明 */
.llk-hint {
    margin: 20px 0 0;
    font-size: 0.85rem;
    line-height: 1.7;
    color: var(--muted);
    text-align: center;
}

/* ================================================================
   通关祝贺弹层（全部连完后出现，见 lianliankan.html 与 js 的 openWin）
   ----------------------------------------------------------------
   结构：
     .llk-win           遮罩 + 居中卡片
     .llk-win-mask      半透明遮罩，点它关闭
     .llk-win-card      白卡片
     .llk-win-confetti  彩带层（JS 生成小方块，纯 CSS 动画，不需要图片素材）
     .llk-win-badge     奖杯圆标
     .llk-win-stars     星级评价
     .llk-win-time      本局用时（大号数字，成就感的核心）
     .llk-win-stats     关卡 / 单词 / 连错 三格
     .llk-win-actions   再来一局 / 换单元
   ================================================================ */
.llk-win {
    position: fixed;
    inset: 0;
    z-index: 1500;               /* 要高于单元下拉面板（1300） */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 16px;
}

/* display:flex 会盖掉 [hidden] 的 display:none，这里要显式声明（同 .llk-menu） */
.llk-win[hidden] {
    display: none;
}

.llk-win-mask {
    position: absolute;
    inset: 0;
    background: rgba(58, 34, 12, 0.42);
    animation: llk-win-fade 0.2s ease;
    /* 在遮罩上拖动时别把后面的页面也滚了（弹层卡片自己还能滚） */
    touch-action: none;
}

.llk-win-card {
    position: relative;
    width: 100%;
    max-width: 360px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    padding: 26px 22px 20px;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-panel);
    text-align: center;
    animation: llk-win-pop 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.25);
}

/* 彩带：从卡片顶部往下飘，飘完淡出；小方块的颜色与延迟由 JS 逐个给 */
.llk-win-confetti {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: inherit;
    pointer-events: none;
}

.llk-win-confetti i {
    position: absolute;
    top: -14px;
    width: 7px;
    height: 11px;
    border-radius: 2px;
    opacity: 0;
    animation: llk-win-fall 1.6s ease-in forwards;
}

@keyframes llk-win-fall {
    0% { opacity: 0; transform: translateY(0) rotate(0); }
    12% { opacity: 1; }
    100% { opacity: 0.85; transform: translateY(340px) rotate(420deg); }
}

@keyframes llk-win-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes llk-win-pop {
    from { opacity: 0; transform: translateY(16px) scale(0.94); }
    to { opacity: 1; transform: none; }
}

.llk-win-close {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    font-size: 0.95rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.llk-win-close:active {
    transform: scale(0.92);
}

.llk-win-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    margin: 0 0 10px;
    border-radius: 50%;
    background: linear-gradient(160deg, var(--coral-soft), var(--coral-softer));
    color: var(--coral-deep);
    font-size: 1.7rem;
    line-height: 1;
}

.llk-win-title {
    margin: 0;
    font-size: 1.28rem;
    font-weight: 700;
    color: var(--ink);
}

.llk-win-stars {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 10px 0 2px;
    color: var(--gold);
    font-size: 1.5rem;
    line-height: 1;
}

/* 没点亮的星用浅色（:not 保证只挑空心星，不会把亮星也压暗） */
.llk-win-stars .bi-star:not(.bi-star-fill) {
    color: var(--line);
}

.llk-win-time {
    margin: 6px 0 0;
    font-size: 2.5rem;
    font-weight: 800;
    line-height: 1.1;
    color: var(--coral-deep);
    font-variant-numeric: tabular-nums;
}

.llk-win-sub {
    margin: 8px 0 0;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--ink-3);
}

.llk-win-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 16px 0 18px;
}

.llk-win-stat {
    padding: 9px 4px;
    border-radius: var(--radius-md);
    background: var(--bg-soft);
}

.llk-win-stat .num {
    display: block;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.llk-win-stat .lab {
    display: block;
    margin-top: 2px;
    font-size: 0.74rem;
    color: var(--muted);
}

.llk-win-actions {
    display: flex;
    gap: 10px;
}

.llk-win-btn {
    flex: 1 1 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 46px;
    padding: 0 12px;
    border-radius: var(--radius-pill);
    font-family: inherit;
    font-size: 0.96rem;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.llk-win-btn:active {
    transform: scale(0.97);
}

.llk-win-btn.is-main {
    border: 1px solid var(--coral-deep);
    background: var(--coral-deep);
    color: #fff;
}

.llk-win-btn:not(.is-main) {
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink-2);
}

@media (hover: hover) and (pointer: fine) {
    .llk-win-close:hover {
        background: var(--bg-soft);
        color: var(--ink-2);
    }

    .llk-win-btn.is-main:hover {
        background: var(--coral-hover);
        border-color: var(--coral-hover);
    }

    .llk-win-btn:not(.is-main):hover {
        border-color: var(--coral-deep);
        color: var(--coral-deep);
    }
}

/* 手机竖屏：卡片贴近屏幕两边，用时数字再放大一档 */
@media (max-width: 767.98px) {
    .llk-win {
        padding: 16px 14px;
    }

    .llk-win-card {
        padding: 24px 18px 18px;
    }

    .llk-win-time {
        font-size: 2.7rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .llk-win-mask,
    .llk-win-card {
        animation: none;
    }

    .llk-win-confetti {
        display: none;
    }
}
