/* =========================================================
   坦克大战 — yicool.com.cn /tools/tank
   整屏工具布局（站点规范）：占满电脑端屏幕、保留左侧导航。
   ========================================================= */
body[data-page="tools"] .app { max-width: 100%; }
body[data-page="tools"] .main-content { max-width: 100%; border-right: 0; }

.tk-page {
    max-width: none;
    margin: 0;
    padding: 20px 16px 56px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* 标题区 */
.tk-hero { text-align: center; margin-bottom: 18px; }
.tk-title {
    font-size: 26px; font-weight: 800; color: var(--text-primary);
    margin: 0 0 6px; letter-spacing: .5px;
}
.tk-sub { color: var(--text-secondary); font-size: 14px; margin: 0; max-width: 640px; }

/* 游戏容器 */
.tk-game {
    width: 100%;
    max-width: 600px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 18px;
    padding: 16px;
    box-shadow: 0 12px 40px rgba(0,0,0,.18);
}

/* HUD */
.tk-hud {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 12px; flex-wrap: wrap;
}
.tk-hud-item {
    display: flex; flex-direction: column; line-height: 1.1;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color);
    border-radius: 10px; padding: 6px 12px; min-width: 64px;
}
.tk-hud-label { font-size: 11px; color: var(--text-secondary); }
.tk-hud-val { font-size: 18px; font-weight: 800; color: var(--accent); }
.tk-hud-lives { margin-left: auto; }
.tk-hud-lives .tk-hud-val { color: #e23b3b; letter-spacing: 2px; }

.tk-btn {
    border: 1px solid var(--border-color); background: var(--bg-primary, #fff);
    color: var(--text-primary); border-radius: 10px; padding: 8px 16px;
    font-size: 14px; font-weight: 700; cursor: pointer; transition: .15s;
}
.tk-btn:hover { border-color: var(--accent); }
.tk-btn-primary {
    background: var(--accent); color: #fff; border-color: var(--accent);
}
.tk-btn-primary:hover { filter: brightness(1.06); }
.tk-btn-ghost { background: transparent; }
/* 图标按钮：音效 / 音乐开关 */
.tk-icon-btn { padding: 8px 10px; font-size: 15px; line-height: 1; }
.tk-icon-btn.is-off { opacity: .45; text-decoration: line-through; }

/* 战场 */
.tk-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #14171c;
    border: 1px solid rgba(255,255,255,.07);
    border-radius: 12px;
    overflow: hidden;
    /* 内阴影营造战场纵深 */
    box-shadow: inset 0 0 70px rgba(0,0,0,.55), 0 6px 22px rgba(0,0,0,.22);
}
#tkCanvas {
    display: block;
    width: 100%;
    height: 100%;
    /* 画布按 devicePixelRatio 渲染高清位图，用平滑缩放而非像素化 */
    image-rendering: auto;
    touch-action: none;
}

/* 覆盖层 */
.tk-overlay {
    position: absolute; inset: 0;
    display: none;
    align-items: center; justify-content: center;
    background: rgba(10,12,16,.78);
    backdrop-filter: blur(2px);
    padding: 16px;
    text-align: center;
    z-index: 5;
}
.tk-overlay.show { display: flex; }
.tk-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px 26px;
    max-width: 380px;
    display: flex; flex-direction: column; gap: 12px;
}
.tk-panel h2 { margin: 0; font-size: 22px; color: var(--text-primary); }
.tk-panel p { margin: 0; font-size: 14px; color: var(--text-secondary); line-height: 1.6; }
.tk-panel .tk-tip { color: var(--accent); font-weight: 600; }
.tk-panel .tk-btn { width: 100%; margin-top: 4px; }

/* 触控控制（默认隐藏，窄屏显示） */
.tk-controls {
    display: none;
    margin-top: 16px;
    width: 100%;
    align-items: center; justify-content: space-between;
}
.tk-dpad {
    display: grid;
    grid-template-columns: repeat(3, 56px);
    grid-template-rows: repeat(2, 56px);
    gap: 6px;
}
.tk-pad {
    border: 1px solid var(--border-color);
    background: var(--bg-primary, #fff);
    border-radius: 12px; font-size: 20px; color: var(--text-primary);
    cursor: pointer; user-select: none; -webkit-user-select: none;
    display: flex; align-items: center; justify-content: center;
}
.tk-pad:active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tk-pad-up    { grid-column: 2; grid-row: 1; }
.tk-pad-left  { grid-column: 1; grid-row: 2; }
.tk-pad-down  { grid-column: 2; grid-row: 2; }
.tk-pad-right { grid-column: 3; grid-row: 2; }
.tk-fire {
    width: 88px; height: 88px; border-radius: 50%;
    border: none; background: var(--accent); color: #fff;
    font-size: 30px; cursor: pointer; user-select: none; -webkit-user-select: none;
    box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent);
}
.tk-fire:active { filter: brightness(1.1); transform: scale(.96); }

.tk-help {
    margin: 14px 2px 0; font-size: 12.5px; color: var(--text-secondary);
    line-height: 1.7; text-align: center;
}
.tk-help b { color: var(--text-primary); }

/* 移动端：显示触控控制，HUD 更紧凑 */
@media (max-width: 820px) {
    .tk-controls { display: flex; }
    .tk-page { padding: 14px 10px 48px; }
    .tk-title { font-size: 22px; }
    .tk-game { padding: 12px; border-radius: 14px; }
    .tk-hud-item { min-width: 54px; padding: 5px 9px; }
    .tk-hud-val { font-size: 16px; }
    .tk-hud-lives { margin-left: 0; }
}
@media (max-width: 600px) {
    .tk-dpad { grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(2, 50px); }
    .tk-fire { width: 76px; height: 76px; font-size: 26px; }
}

/* =========================================================
   模式选择 / 地图选择 / 双人 HUD / 道具图例
   ========================================================= */

/* 弹窗允许更高并在小屏内滚动（地图选择器较高） */
.tk-panel { max-height: 100%; overflow: auto; }
.tk-panel-wide { max-width: 540px; }

.tk-field { display: flex; flex-direction: column; gap: 8px; }
.tk-field-label { font-size: 12.5px; font-weight: 700; color: var(--text-secondary); text-align: left; }
.tk-hint { margin: 0; font-size: 12px; color: var(--text-secondary); text-align: left; line-height: 1.5; }

/* 模式分段控件 */
.tk-seg {
    display: flex; gap: 6px;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color);
    border-radius: 12px; padding: 4px;
}
.tk-seg-btn {
    flex: 1;
    border: 0; background: transparent;
    color: var(--text-secondary);
    border-radius: 9px; padding: 9px 10px;
    font-size: 14px; font-weight: 700; cursor: pointer;
    transition: .15s;
}
.tk-seg-btn:hover { color: var(--text-primary); }
.tk-seg-btn.is-sel {
    background: var(--accent); color: #fff;
    box-shadow: 0 3px 10px color-mix(in srgb, var(--accent) 35%, transparent);
}
/* 坦克型号选择：型号较多，允许换行，每行 3 个 */
.tk-kind-seg { flex-wrap: wrap; }
.tk-kind-seg .tk-seg-btn { flex: 1 1 calc(33.333% - 6px); padding: 8px 6px; font-size: 13px; }

/* 地图选择网格（内置 55 张 + 自建，滚动浏览） */
.tk-map-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    max-height: 320px;
    overflow: auto;
    padding: 2px;
    overscroll-behavior: contain;
}
.tk-map-card {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    border: 2px solid var(--border-color);
    background: var(--bg-primary, #fff);
    border-radius: 12px; padding: 8px 6px 7px;
    cursor: pointer; transition: .15s;
    font: inherit; color: inherit;
}
.tk-map-card:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--border-color)); }
.tk-map-card.is-sel {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, var(--bg-primary, #fff));
}
.tk-map-thumb {
    width: 100%; aspect-ratio: 1 / 1;
    border-radius: 7px; display: block;
    background: #16191e;
}
.tk-map-name { font-size: 12px; font-weight: 700; color: var(--text-primary); }
.tk-map-meta { font-size: 10.5px; color: var(--text-secondary); }

/* 双人模式 HUD 项：默认隐藏，由 .tk-hud.is-2p 打开 */
.tk-hud .is-2p { display: none; }
.tk-hud.is-2p .is-2p { display: flex; }
.tk-hud-name .tk-hud-val { font-size: 15px; }

/* 道具状态条（护盾 / 冻结 / 钢化倒计时） */
.tk-buffs {
    flex-basis: 100%;
    min-height: 16px;
    font-size: 12px; font-weight: 700;
    color: var(--accent);
    letter-spacing: .3px;
}

/* 道具图例 */
.tk-legend {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
    margin: 14px 2px 0; padding: 10px 12px;
    border: 1px dashed var(--border-color); border-radius: 10px;
    font-size: 12px; color: var(--text-secondary);
}
.tk-legend-t { font-weight: 800; color: var(--text-primary); }

@media (max-width: 900px) {
    .tk-map-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
    .tk-map-grid { grid-template-columns: repeat(2, 1fr); max-height: 230px; }
    .tk-panel-wide { max-width: 100%; }
    .tk-hud-name { display: none; }
}

/* =========================================================
   电脑端满屏布局（保留左侧导航栏）
   —— 站点骨架 .app / .main-content 已在 style.css 中解除限宽，
      这里只需解除工具容器自身限宽，并把说明信息搬到右侧栏，
      让战场在桌面端铺满可用区域（高度受视口约束，正方形居中）。
   ========================================================= */
@media (min-width: 1101px) {
    .tk-page { padding: 14px 22px 26px; }
    .tk-hero {
        margin-bottom: 10px;
        display: flex; align-items: baseline; justify-content: center; gap: 14px; flex-wrap: wrap;
    }
    .tk-title { font-size: 22px; margin: 0; }
    .tk-sub { margin: 0; font-size: 13px; }
    .tk-game {
        max-width: none;
        display: grid;
        grid-template-columns: minmax(0, 1fr) 320px;
        gap: 18px;
        align-items: start;
        padding: 16px 18px;
    }
    .tk-main { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
    .tk-stage {
        /* 画布为正方形：宽度取「可用宽度」与「视口剩余高度」的较小值，避免需要滚动才看得全 */
        max-width: min(100%, calc(100vh - 170px));    /* 回退：不支持 dvh 的浏览器 */
        max-width: min(100%, calc(100dvh - 170px));
        margin: 0 auto;
    }
    /* 左侧导航栏折叠后，画布可再放大一些，让折叠有可见效果 */
    body.left-collapsed .tk-stage {
        max-width: min(100%, calc(100dvh - 140px));
    }
    .tk-side {
        display: flex; flex-direction: column; gap: 10px;
        max-height: calc(100vh - 190px);
        max-height: calc(100dvh - 190px);
        overflow: auto;
        overscroll-behavior: contain;
        padding-right: 2px;
    }
    .tk-legend, .tk-help { margin: 0; }
    .tk-help { text-align: left; }
}

/* 中等桌面 / 横屏平板：单列，但同样放大战场、限制高度 */
@media (min-width: 821px) and (max-width: 1100px) {
    .tk-game { max-width: min(100%, 1000px); }
    .tk-stage {
        max-width: min(100%, calc(100vh - 180px));
        max-width: min(100%, calc(100dvh - 180px));
        margin: 0 auto;
    }
    body.left-collapsed .tk-stage {
        max-width: min(100%, calc(100dvh - 150px));
    }
}

/* =========================================================
   全屏：舞台整体进入全屏，画布保持正方形并居中放大
   ========================================================= */
.tk-stage:fullscreen,
.tk-stage:-webkit-full-screen {
    width: 100vw; height: 100vh;
    aspect-ratio: auto;
    border: none; border-radius: 0;
    display: flex; align-items: center; justify-content: center;
    background: #0b0d10;
}
.tk-stage:fullscreen #tkCanvas,
.tk-stage:-webkit-full-screen #tkCanvas {
    width: min(100vw, 100vh);
    height: min(100vw, 100vh);
}
.tk-btn.is-on { border-color: var(--accent); color: var(--accent); }

/* =========================================================
   自建地图编辑器
   ========================================================= */
.tk-panel-editor { max-width: 720px; width: 100%; }
.tk-ed-main {
    display: flex; gap: 14px; align-items: flex-start;
    margin: 4px 0 10px;
}
#tkEditCanvas {
    width: 264px; height: 264px; flex: 0 0 auto;
    border: 1px solid var(--border-color); border-radius: 10px;
    background: #16191e; cursor: crosshair; touch-action: none;
}
.tk-ed-side { flex: 1 1 auto; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.tk-seg-wrap { flex-wrap: wrap; }

.tk-palette { display: flex; flex-wrap: wrap; gap: 6px; }
.tk-pal {
    display: inline-flex; align-items: center; gap: 5px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary, #fff);
    color: var(--text-secondary);
    border-radius: 9px; padding: 5px 9px;
    font-size: 12px; font-weight: 700; cursor: pointer; transition: .15s;
}
.tk-pal i {
    width: 13px; height: 13px; border-radius: 3px; display: inline-block;
    border: 1px solid rgba(0, 0, 0, .28);
}
.tk-pal:hover { color: var(--text-primary); }
.tk-pal.is-sel {
    border-color: var(--accent); color: var(--accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}

.tk-input {
    border: 1px solid var(--border-color); background: var(--bg-primary, #fff);
    color: var(--text-primary); border-radius: 9px; padding: 8px 10px;
    font-size: 14px; width: 100%; box-sizing: border-box;
}
.tk-input:focus { outline: none; border-color: var(--accent); }
.tk-range { width: 100%; accent-color: var(--accent); }
.tk-fire-rate-row { display: flex; align-items: center; gap: 12px; }
.tk-fire-rate-row .tk-range { flex: 1 1 auto; }
.tk-fire-rate-val { min-width: 42px; text-align: right; font-size: 14px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }

.tk-ed-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

/* 地图卡片：自建地图虚线边框 + 右上角删除 */
.tk-map-card { position: relative; }
.tk-map-card.is-custom { border-style: dashed; }
.tk-map-del {
    position: absolute; top: 3px; right: 5px;
    width: 18px; height: 18px; line-height: 17px; text-align: center;
    border-radius: 50%; font-size: 14px; font-weight: 700;
    background: rgba(0, 0, 0, .5); color: #fff; cursor: pointer;
}
.tk-map-del:hover { background: #e04a4a; }

@media (max-width: 620px) {
    .tk-ed-main { flex-direction: column; align-items: center; }
    #tkEditCanvas { width: 100%; max-width: 320px; height: auto; aspect-ratio: 1 / 1; }
    .tk-ed-side { width: 100%; }
    .tk-panel-editor { max-width: 100%; }
}

/* 联网对战面板 */
.tk-net-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tk-input-code {
    width: 130px; text-transform: uppercase; letter-spacing: 3px; font-weight: 700;
    text-align: center;
}
.tk-net-code {
    font-size: 1.6rem; letter-spacing: 4px; color: var(--accent, #136ce9);
    background: rgba(19, 108, 233, .12); padding: 2px 12px; border-radius: 8px;
}
.tk-net-host, .tk-net-guest { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line, #2a2f37); }
.tk-btn-sm { padding: 4px 10px; font-size: 12px; }
.tk-msg { min-height: 18px; margin: 10px 0 0; color: var(--accent, #136ce9); font-size: 13px; }
#tkNetLoginHint a { color: var(--accent, #136ce9); text-decoration: underline; }
@media (max-width: 620px) {
    .tk-net-row { flex-direction: column; align-items: stretch; }
    .tk-input-code { width: 100%; }
}
