/* ============================================================================
   FlintHub — 许愿树 · 样式
   ----------------------------------------------------------------------------
   ⚠️ 零内联：本文件是唯一放颜色的地方；视图里不写 style=""，SVG 的填色全走 class。
   ⚠️ 颜色一律走 --mn-* 变量或本文件顶部的 --wt-* 变量。
      **禁止**写 @media (prefers-color-scheme: dark) —— 本站主题切换是整套
      assets/css/themes/*.css 覆盖 :root 变量，不是系统偏好（life_sim / ai_polish 踩过）。
   ⚠️ 牌色（红/紫/墨绿/金）是**语义色**，不跟 --mn-primary 走：
      换主题色把许愿牌染成蓝色，就没人认得这是许愿牌了。
   ========================================================================== */

/* ---------------------------------------------------------------- 1 容器 */

.wt-wrap {
    --wt-leaf: var(--mn-alert-success-text);
    --wt-ink: var(--mn-text);
    --wt-tag-normal: #b03a2e;
    --wt-tag-strong: #6c3483;
    --wt-tag-secret: #1d6f5c;
    --wt-tag-done: #d4a02a;
    --wt-cord: #8a6b4a;
    --wt-trunk: #7a5230;
    --wt-trunk-dark: #5c3c22;
    padding: 20px 22px 18px;
}

.wt-head {
    margin-bottom: 14px;
    text-align: center;
}

.wt-title {
    margin: 0 0 6px;
    font-size: 20px;
    font-weight: 700;
    color: var(--mn-text);
}

.wt-stats {
    margin: 0;
    font-size: 13px;
    color: var(--mn-text-secondary);
}

.wt-dot {
    margin: 0 6px;
    color: var(--mn-text-muted);
}

/* ---------------------------------------------------------------- 2 舞台 */

.wt-stage {
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: var(--mn-radius-lg);
    background: var(--mn-bg);
}

.wt-tree {
    display: block;
    width: 100%;
    /* 窄屏不把整棵树等比缩到看不清字：保底 620px + 横向滚动 */
    min-width: 620px;
    height: auto;
    aspect-ratio: 3 / 2;
    /* currentColor = 主色，供 .wt-sky 的渐变端点使用 */
    color: var(--mn-primary);
    font-family: inherit;
}

/* 图片风格：16:9，与背景图 1:1（牌子比线稿版大 1.5 倍，字号随之变大） */
.wt-tree-photo {
    aspect-ratio: 16 / 9;
}

/* 背景图本身带色，这里只兜一个底色：图没加载出来时不至于纯白 */
.wt-photo {
    fill: var(--mn-primary-subtle);
}

/* 后层牌子略透明 —— 制造「被叶子挡住」的景深，不是 bug */
.wt-tags-back {
    opacity: 0.86;
}

/* ------------------------------------------------------------ 3 SVG 底景 */

.wt-sky {
    fill: url(#wtSkyGrad);
}

.wt-wall {
    fill: var(--mn-text-muted);
    fill-opacity: 0.10;
}

.wt-roof {
    fill: var(--mn-text-muted);
    fill-opacity: 0.20;
}

.wt-tile {
    stroke: var(--mn-text-muted);
    stroke-opacity: 0.28;
    stroke-width: 1.4;
    fill: none;
}

.wt-lantern-cord {
    stroke: var(--mn-text-muted);
    stroke-opacity: 0.55;
    stroke-width: 1.4;
}

.wt-lantern-body {
    fill: var(--wt-tag-normal);
    fill-opacity: 0.88;
}

.wt-lantern-cap {
    fill: var(--wt-tag-done);
    fill-opacity: 0.85;
}

/* ------------------------------------------------------------ 4 树干枝条 */

.wt-trunk {
    fill: var(--wt-trunk);
}

.wt-trunk-shadow {
    fill: var(--wt-trunk-dark);
    fill-opacity: 0.45;
}

.wt-bark {
    stroke: var(--wt-trunk-dark);
    stroke-opacity: 0.55;
    stroke-width: 2.4;
    stroke-linecap: round;
    fill: none;
}

.wt-branch {
    stroke: var(--wt-trunk);
    stroke-linecap: round;
    fill: none;
}

.wt-trunk-g1 {
    stop-color: var(--wt-trunk-dark);
}

.wt-trunk-g2 {
    stop-color: var(--wt-trunk);
}

.wt-trunk-g3 {
    stop-color: var(--wt-trunk-dark);
}

/*
 * 树干是棕色、牌色是朱红，两者在**深色主题**下都会偏暗。
 * color-mix 往「文字色」方向拉一点：浅色主题文字是深色 → 略微压深；
 * 深色主题文字是浅色 → 提亮。一条规则同时解决两个方向。
 * 不支持 color-mix 的浏览器退回上面的固定色，视觉不崩。
 */
@supports (color: color-mix(in srgb, red, blue)) {
    .wt-wrap {
        --wt-trunk: color-mix(in srgb, var(--mn-text) 26%, #7a5230);
        --wt-trunk-dark: color-mix(in srgb, var(--mn-text) 16%, #4a2f18);
        --wt-tag-normal: color-mix(in srgb, var(--mn-text) 12%, #b03a2e);
        --wt-tag-strong: color-mix(in srgb, var(--mn-text) 12%, #6c3483);
        --wt-tag-secret: color-mix(in srgb, var(--mn-text) 12%, #1d6f5c);
    }
}

/* ---------------------------------------------------------------- 5 叶簇 */

.wt-leaf {
    /* 叶子用「主题的成功绿」——浅色 #16a34a / 暗夜 #4ade80，深浅主题自动适配 */
    fill: var(--wt-leaf);
}

.wt-leaf-1 {
    fill-opacity: 0.42;
}

.wt-leaf-2 {
    fill-opacity: 0.66;
}

.wt-leaf-3 {
    fill-opacity: 0.92;
}

.wt-leaves-back .wt-leaf {
    fill-opacity: 0.34;
}

/* ---------------------------------------------------------------- 6 地面 */

.wt-ground-shadow {
    fill: var(--mn-text);
    fill-opacity: 0.10;
}

.wt-ground-line {
    stroke: var(--mn-text-muted);
    stroke-opacity: 0.22;
    stroke-width: 1.6;
}

/* ------------------------------------------------------------ 7 许愿牌 */

.wt-tag-cord {
    stroke: var(--wt-cord);
    stroke-width: 1.3;
    stroke-linecap: round;
}

.wt-tag-body {
    stroke: rgba(0, 0, 0, 0.22);
    stroke-width: 0.8;
}

.wt-tag-normal {
    fill: var(--wt-tag-normal);
}

.wt-tag-strong {
    fill: var(--wt-tag-strong);
}

.wt-tag-secret {
    fill: var(--wt-tag-secret);
}

.wt-tag-done {
    stroke: var(--wt-tag-done);
    stroke-width: 1.6;
}

.wt-tag text {
    text-anchor: middle;
    fill: #fff6ec;
    letter-spacing: 0.2px;
}

/*
 * 牌面只有 2~4 字标题，字号 16（牌宽 44 的 1/2.75）。
 * 行距 18 / 中线 y=62 / 字号 16 三个值由 TreeSvg::TAG_* 常量驱动，
 * 改这里必须同步改那三个常量，否则整块字会偏。
 * ⚠️ 竖向总高 = 3×行距 + 字号 = 70，可用区间 76.8（牌身已加长到 96），两端各留 3.4。
 */
.wt-tag-wish {
    font-size: 16px;
    fill-opacity: 0.96;
}

/* 牌子上有气泡可看 —— 给个「有更多信息」的鼠标指针 */
.wt-tag {
    cursor: help;
}

/* 内圈细描边：同形状缩到 93%，只描边不填充 */
.wt-tag-inner {
    fill: none;
    stroke: rgba(255, 246, 236, 0.42);
    stroke-width: 1.1;
}

/* 穿孔：半透明黑圆，视觉上就是「洞」 */
.wt-tag-hole {
    fill: rgba(0, 0, 0, 0.42);
}

/* 流苏金珠：class 覆盖 <use> 继承下来的分类色 */
.wt-tassel-bead {
    fill: #d8a83c;
}

/* 流苏：颜色跟分类走，已还愿用金色。fill 从 <use> 继承进 <g id="wtTassel"> */
.wt-tassel-normal {
    fill: var(--wt-tag-normal);
}

.wt-tassel-strong {
    fill: var(--wt-tag-strong);
}

.wt-tassel-secret {
    fill: var(--wt-tag-secret);
}

.wt-tassel-done {
    fill: var(--wt-tag-done);
}

.wt-seal {
    fill: var(--wt-tag-done);
    stroke: #fff6ec;
    stroke-width: 0.6;
}

.wt-seal-text {
    font-size: 5px;
    fill: #6b1d10 !important;
}

/* 自家牌子：一圈光晕，满树里一眼能找到 */
.wt-tag-mine .wt-tag-body {
    stroke: var(--wt-tag-done);
    stroke-width: 1.8;
}

.wt-tag-mine .wt-tag-cord {
    stroke: var(--wt-tag-done);
    stroke-width: 1.8;
}

/*
 * 刚许完愿时的定位高亮。
 * ⚠️ 只能用 filter / opacity 做脉冲，**不能用 transform** ——
 *    `.wt-tag` 外层的 transform 是定位属性，CSS 的 transform 会把它顶掉，
 *    牌子会瞬移到画布原点（本文件 §8 同一条坑）。
 */
@keyframes wt-pulse {
    0%,
    100% {
        filter: none;
    }

    50% {
        filter: drop-shadow(0 0 7px var(--wt-tag-done));
    }
}

.wt-hl {
    animation: wt-pulse 1.2s ease-in-out 3;
}

@media (prefers-reduced-motion: reduce) {
    .wt-hl {
        filter: drop-shadow(0 0 7px var(--wt-tag-done));
        animation: none;
    }
}

/* ---------------------------------------------------- 8 随风摆动（关键） */

/*
 * ⚠️⚠️ 旋转轴心必须是「挂绳顶端」，否则牌子会绕画布原点甩出去。
 *   transform-origin 对 SVG 元素默认参照的是 **viewport**（不是元素自身），
 *   必须用 transform-box: fill-box 把参照系改成「元素自己的包围盒」，
 *   再取 top center —— 牌子的 bbox 顶边就是挂绳起点 (0,0)，正好是挂点。
 *
 * ⚠️ 摆动只能加在**内层** <g> 上：外层的 transform 是**属性**（定位），
 *   CSS 的 transform 优先级更高，写在同一层会把定位整个顶掉 → 牌子全部瞬移到原点。
 */
.wt-sway {
    transform-box: fill-box;
    transform-origin: top center;
    animation: wt-sway 5s ease-in-out infinite;
}

@keyframes wt-sway {
    0%,
    100% {
        transform: rotate(-2.2deg);
    }

    50% {
        transform: rotate(2.2deg);
    }
}

/*
 * 8 档错峰：周期 3.6s ~ 6.8s，配**负** animation-delay 让动画从周期中途开始。
 * 负延迟是关键 —— 全用 0 延迟会整齐划一地同时摆，像机械臂而不是风。
 * ⚠️ 零内联禁 style="animation-delay:…"，所以只能靠这 8 个 class 分档。
 */
.wt-sway-1 {
    animation-duration: 4.2s;
    animation-delay: -0.3s;
}

.wt-sway-2 {
    animation-duration: 5.6s;
    animation-delay: -1.7s;
}

.wt-sway-3 {
    animation-duration: 3.6s;
    animation-delay: -0.9s;
}

.wt-sway-4 {
    animation-duration: 6.4s;
    animation-delay: -2.6s;
}

.wt-sway-5 {
    animation-duration: 4.8s;
    animation-delay: -3.4s;
}

.wt-sway-6 {
    animation-duration: 5.2s;
    animation-delay: -0.6s;
}

.wt-sway-7 {
    animation-duration: 3.9s;
    animation-delay: -2.1s;
}

.wt-sway-8 {
    animation-duration: 6.8s;
    animation-delay: -4.2s;
}

/* 无障碍：用户要求减少动效时整段关掉 */
@media (prefers-reduced-motion: reduce) {
    .wt-sway {
        animation: none;
    }
}

/* ---------------------------------------------------------------- 9 空态 */

.wt-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    pointer-events: none;
    text-align: center;
}

.wt-empty-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--mn-text);
}

.wt-empty-hint {
    margin: 0;
    font-size: 13px;
    color: var(--mn-text-muted);
}

.wt-empty-box {
    padding: 40px 20px;
    text-align: center;
}

/* ---------------------------------------------------------------- 10 底栏 */

.wt-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
}

.wt-bar-pager {
    flex: 1 1 auto;
    min-width: 0;
}

.wt-bar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.wt-meter {
    font-size: 12px;
    color: var(--mn-text-muted);
}

/* ------------------------------------------------------------ 11 许愿弹层 */

.wt-modal[hidden] {
    display: none;
}

.wt-modal {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.wt-modal-mask {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.wt-modal-box {
    position: relative;
    width: 100%;
    max-width: 420px;
    max-height: 86vh;
    overflow-y: auto;
    padding: 18px 20px 16px;
    background: var(--mn-bg-card);
    border: 1px solid var(--mn-border);
    border-radius: var(--mn-radius-lg);
    box-shadow: var(--mn-shadow-lg, var(--mn-shadow-sm));
}

.wt-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.wt-modal-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--mn-text);
}

.wt-modal-x {
    padding: 0 4px;
    font-size: 22px;
    line-height: 1;
    color: var(--mn-text-muted);
    background: none;
    border: 0;
    cursor: pointer;
}

.wt-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.wt-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.wt-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--mn-text-secondary);
}

.wt-help {
    font-size: 12px;
    color: var(--mn-text-muted);
}

.wt-textarea {
    resize: vertical;
    min-height: 76px;
}

/*
 * 牌面标题：内置的 4 字类型，胶囊形单选。
 * ⚠️ 名字叫 wt-title-chip 不是 wt-tag-*，避免和 SVG 牌子（.wt-tag）混在一起找错。
 * ⚠️ radio 用 opacity:0 + 绝对定位藏起来，不要 display:none —— 后者会让键盘无法聚焦、
 *    也读不到 :focus-within。
 */
.wt-titles {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0;
    margin: 0;
    border: 0;
}

.wt-titles-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.wt-title-chip {
    position: relative;
    padding: 7px 13px;
    font-size: 13px;
    line-height: 1.2;
    color: var(--mn-text);
    background: transparent;
    border: 1px solid var(--mn-border);
    border-radius: 999px;
    cursor: pointer;
    user-select: none;
}

.wt-title-chip input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
    pointer-events: none;
}

.wt-title-chip:has(input:checked) {
    color: var(--mn-primary);
    font-weight: 600;
    border-color: var(--mn-primary);
    background: var(--mn-primary-subtle);
}

.wt-title-chip:focus-within {
    outline: 2px solid var(--mn-primary);
    outline-offset: 1px;
}

.wt-cats {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0;
    margin: 0;
    border: 0;
}

.wt-cat {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    font-size: 13px;
    color: var(--mn-text);
    border: 1px solid var(--mn-border);
    border-radius: var(--mn-radius);
    cursor: pointer;
}

.wt-cat input {
    margin: 0;
}

.wt-cat-name {
    font-weight: 600;
}

.wt-cat-cost {
    margin-left: auto;
    font-size: 12px;
    color: var(--mn-text-muted);
}

.wt-cat:has(input:checked) {
    border-color: var(--mn-primary);
    background: var(--mn-primary-subtle);
}

.wt-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 4px;
}

/* --------------------------------------------------------- 12 我的许愿 */

.wt-mine-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
}

.wt-mine-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0;
    margin: 0;
    list-style: none;
}

.wt-mine-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--mn-border);
    border-left: 4px solid var(--mn-border);
    border-radius: var(--mn-radius);
    background: var(--mn-bg-card);
}

.wt-mine-normal {
    border-left-color: var(--wt-tag-normal);
}

.wt-mine-strong {
    border-left-color: var(--wt-tag-strong);
}

.wt-mine-secret {
    border-left-color: var(--wt-tag-secret);
}

.wt-mine-done {
    border-left-color: var(--wt-tag-done);
}

.wt-mine-main {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.wt-mine-sign {
    font-size: 13px;
    font-weight: 600;
    color: var(--mn-text);
}

.wt-mine-text {
    font-size: 14px;
    color: var(--mn-text-secondary);
    overflow-wrap: anywhere;
}

.wt-mine-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--mn-text-muted);
}

.wt-inline-form {
    margin: 0;
}

.wt-btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.wt-chip {
    padding: 2px 8px;
    font-size: 12px;
    border-radius: 999px;
    background: var(--mn-bg-tag, var(--mn-primary-subtle));
    color: var(--mn-text-secondary);
}

.wt-chip-done {
    background: var(--wt-tag-done);
    color: #4a2f08;
}

/* 「我的许愿」里显示牌面标题：用牌身的红，和分类 chip 区分开 */
.wt-chip-title {
    background: var(--wt-tag-normal);
    color: #fff6ec;
}

.wt-time {
    font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------ 13 窄屏 */

@media (max-width: 640px) {
    .wt-wrap {
        padding: 14px 12px;
    }

    .wt-title {
        font-size: 17px;
    }

    .wt-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .wt-bar-actions {
        justify-content: space-between;
    }
}

/* ------------------------------------------------------ 14 悬停气泡 */

/*
 * 牌子详情气泡：完整心愿 + 许愿人。由 assets/tree.js 创建并定位。
 *
 * ⚠️ 必须 `position: fixed` **且挂到 `document.body`**：
 *    `.wt-stage` 有 `overflow-x: auto; overflow-y: hidden`，
 *    气泡只要留在舞台里就一定会被裁掉 —— 尤其树顶那几块牌，气泡本来要往上弹。
 * ⚠️ 层级 800：高于正文，低于 `.wt-modal`（900）—— 打开许愿弹层时气泡不能盖上去。
 * ⚠️ `pointer-events: none`：否则气泡压到鼠标会把 `pointerout` 触发掉，一碰就闪。
 */
.wt-tip {
    position: fixed;
    z-index: 800;
    left: 0;
    top: 0;
    box-sizing: border-box;
    max-width: 260px;
    padding: 9px 12px;
    border: 1px solid var(--mn-border);
    border-radius: var(--mn-radius);
    background: var(--mn-bg-card);
    box-shadow: var(--mn-shadow-float);
    color: var(--mn-text);
    font-size: 13px;
    line-height: 1.6;
    overflow-wrap: anywhere;
    pointer-events: none;
}

.wt-tip[hidden] {
    display: none;
}

.wt-tip-text {
    margin: 0;
}

.wt-tip-sign {
    margin: 5px 0 0;
    color: var(--mn-text-muted);
    font-size: 12px;
    text-align: right;
}
