* {
    box-sizing: border-box
}

html,
body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    color: #2b2b2b;
    background: #f7f5ef
}

.hud {
    max-width: 980px;
    margin: 0 auto;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    overflow: visible;
    position: relative
}

.hud h1 {
    margin: 0;
    font-size: 32px;
    letter-spacing: .1em;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    white-space: nowrap
}

.stats {
    color: #4b5563;
    font-size: 14px
}

.ip {
    display: flex;
    align-items: center;
    gap: 8px
}

.avatar-wrap {
    position: relative;
    display: inline-block
}

.ip .avatar {
    width: 92px;
    height: auto;
    display: block;
    filter: drop-shadow(0 2px 1px rgba(0, 0, 0, .05));
    border-radius: 6px;
    background: #f8f4ea
}

.ip.elder .avatar {
    width: 180px;
    background: transparent;
    filter: none;
    border-radius: 8px
}

.ip .bubble {
    min-height: 24px;
    max-width: 260px;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: 10px;
    padding: 6px 10px;
    color: #9a3412;
    opacity: 0;
    transform: translateY(-6px);
    transition: all .25s
}

.ip .bubble.show {
    opacity: 1;
    transform: translateY(0)
}

.scene {
    max-width: 980px;
    margin: 0 auto 12px auto;
    padding: 12px;
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 14px;
    background-image: url('assets/fengmian.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat
}

.cabinet {
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    overflow: hidden;
    background-color: rgba(243, 237, 227, .76);
    background-image: repeating-linear-gradient(0deg, rgba(0, 0, 0, .04) 0 1px, transparent 1px 48px)
}

.cabinet-title {
    padding: 10px 12px;
    font-weight: 700;
    background: #e6d9c2;
    border-bottom: 1px solid #d6c4a6;
    letter-spacing: .3em
}

.herb-grid {
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px
}

.herb {
    user-select: none;
    cursor: grab;
    background: #f8f4ea;
    border: 1px solid #d6cfc2;
    border-radius: 12px;
    padding: 10px;
    text-align: center;
    box-shadow: 0 1px 0 rgba(0, 0, 0, .04)
}

.herb:active {
    cursor: grabbing
}

.herb .name {
    font-weight: 600
}

.work {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 14px
}

.prescription {
    background: rgba(255, 255, 255, .5);
    border: 1px solid rgba(229, 231, 235, .5);
    border-radius: 14px;
    padding: 12px
}

.prescription-title {
    font-weight: 700;
    margin-bottom: 6px
}

.formula-name {
    font-size: 18px;
    font-weight: 700;
    margin: 6px 0 8px 0
}

.formula-list {
    margin: 0;
    padding-left: 18px;
    min-height: 60px
}

.formula-list li {
    margin: 4px 0
}

.actions {
    margin-top: 10px;
    display: flex;
    gap: 8px
}

.secondary {
    background: #e2e8f0;
    color: #111827;
    border: none;
    border-radius: 10px;
    padding: 8px 12px;
    cursor: pointer
}

.link {
    background: transparent;
    border: none;
    color: #6366f1;
    cursor: pointer
}

.pot-area {
    background: rgba(255, 255, 255, .5);
    border: 1px solid rgba(229, 231, 235, .5);
    border-radius: 14px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative
}

.pot {
    position: relative;
    width: min(82%, 560px);
    height: auto;
    background: transparent;
    border: none;
    box-shadow: none
}

.pot:after {
    content: none
}

.pot-sprite {
    display: block;
    width: 100%;
    height: auto;
    pointer-events: none
}

.steam {
    position: absolute;
    left: 50%;
    top: -2%;
    transform: translateX(-50%);
    width: 140px;
    height: 90px;
    pointer-events: none;
    opacity: 0;
    transition: opacity .2s
}

.steam span {
    position: absolute;
    bottom: -10px;
    left: 50%;
    width: 18px;
    height: 18px;
    background: rgba(238, 242, 255, .9);
    border-radius: 50%;
    filter: blur(.5px);
    animation: rise 1.8s linear infinite;
    opacity: 0
}

.steam span:nth-child(1) {
    left: 35%;
    animation-delay: 0s
}

.steam span:nth-child(2) {
    left: 55%;
    animation-delay: .3s
}

.steam span:nth-child(3) {
    left: 70%;
    animation-delay: .6s
}

.pot.boil .steam {
    opacity: 1
}

@keyframes rise {
    0% {
        transform: translate(-50%, 0) scale(.8);
        opacity: 0
    }

    10% {
        opacity: 1
    }

    60% {
        opacity: .9
    }

    100% {
        transform: translate(-50%, -70px) scale(1.2);
        opacity: 0
    }
}

.added-title {
    margin-top: 10px;
    font-weight: 700
}

.added-list {
    list-style: none;
    margin: 6px 0 0 0;
    padding: 0;
    min-height: 60px;
    width: 100%
}

.added-list li {
    padding: 6px;
    border-top: 1px dashed #e5e7eb;
    display: flex;
    justify-content: space-between
}

.primary {
    background: #6366f1;
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 15px;
    cursor: pointer
}

.footer {
    max-width: 980px;
    margin: 8px auto 20px auto;
    color: #64748b;
    font-size: 12px;
    text-align: center
}

.result-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .25);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000
}

.result-overlay.show {
    display: flex
}

.result-overlay img {
    max-width: 70vw;
    max-height: 70vh;
    transform: scale(.2);
    animation: pop .5s cubic-bezier(.2, .9, .2, 1) forwards
}

@keyframes pop {
    0% {
        transform: scale(.2);
        opacity: .4
    }

    60% {
        transform: scale(1.15);
        opacity: 1
    }

    100% {
        transform: scale(1)
    }
}

/* 适配iPhone等小屏幕手机（< 768px） */
@media(max-width:768px) {
    /* 基础设置 */
    html, body {
        height: auto;
        overflow: auto;
    }
    
    body {
        display: block;
    }
    
    .hud {
        flex-direction: column;
        padding: 10px;
        text-align: center;
        flex-shrink: 0;
    }
    
    .hud h1 {
        font-size: 18px;
        position: static;
        transform: none;
        margin: 8px 0;
    }
    
    .stats {
        font-size: 12px;
        margin-top: 5px;
    }
    
    .ip.elder .avatar {
        width: 80px;
    }
    
    /* 场景容器 */
    .scene {
        display: flex;
        flex-direction: column;
        padding: 6px;
        gap: 8px;
        overflow: visible;
    }
    
    /* 药柜 */
    .cabinet {
        flex: 1;
        overflow-y: auto;
    }
    
    /* 工作区域 */
    .work {
        display: flex;
        flex-direction: column;
        gap: 8px;
        overflow: visible;
    }
    
    /* 药方和药锅 */
    .prescription,
    .pot-area {
        flex: 1;
        padding: 8px;
        overflow-y: auto;
    }
    
    /* 药柜网格 */
    .herb-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 3px;
        padding: 3px;
    }
    
    .herb {
        padding: 6px 2px;
        font-size: 11px;
        touch-action: manipulation;
        min-height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .cabinet-title {
        padding: 5px 6px;
        font-size: 13px;
    }
    
    /* 药房布局 */
    .prescription {
        display: flex;
        flex-direction: column;
    }
    
    .prescription-title {
        font-size: 14px;
        margin-bottom: 3px;
    }
    
    .formula-name {
        font-size: 13px;
        margin: 3px 0 4px 0;
    }
    
    .formula-list {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 3px;
        padding-left: 0;
        list-style: none;
        min-height: 60px;
    }
    
    .formula-list li {
        font-size: 12px;
        margin: 0;
        padding: 3px 5px;
        border: 1px solid rgba(229, 231, 235, 0.5);
        border-radius: 4px;
    }
    
    .pot {
        width: min(70%, 180px);
    }
    
    .added-title {
        font-size: 13px;
        margin-top: 5px;
    }
    
    .added-list {
        min-height: 40px;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 2px;
        list-style: none;
        padding: 0;
    }
    
    .added-list li {
        padding: 3px 2px;
        font-size: 10px;
        text-align: center;
        border: 1px solid rgba(229, 231, 235, 0.5);
        border-radius: 4px;
    }
    
    .actions {
        flex-direction: row;
        justify-content: space-between;
        gap: 5px;
        margin-top: 12px;
        padding-top: 5px;
        border-top: 1px solid rgba(229, 231, 235, 0.5);
    }
    
    .actions .secondary,
    .actions .link {
        flex: 1;
        padding: 3px 4px !important;
        font-size: 10px !important;
        min-height: 28px !important;
        min-width: 28px !important;
        border-radius: 6px !important;
        font-weight: normal !important;
    }
    
    .footer {
        font-size: 10px;
        padding: 0 8px;
        flex-shrink: 0;
    }
    
    /* 横屏适配 */
    @media (orientation: landscape) {
        /* 基础布局 */
        html, body {
            height: 100%;
            overflow: hidden;
        }
        
        body {
            display: flex;
            flex-direction: column;
        }
        
        .hud {
            flex-shrink: 0;
        }
        
        .scene {
            flex: 1;
            display: flex !important;
            flex-direction: row !important;
            gap: 4px;
            padding: 4px;
            overflow: hidden;
        }
        
        /* 左中右布局 */
        .cabinet {
            flex: 1;
            overflow: hidden;
        }
        
        .work {
            flex: 2;
            display: flex !important;
            flex-direction: row !important;
            gap: 4px;
            overflow: hidden;
        }
        
        .prescription {
            flex: 1;
            padding: 4px;
            overflow: hidden;
        }
        
        .pot-area {
            flex: 1;
            padding: 4px;
            overflow: hidden;
        }
        
        /* 药柜网格 */
        .herb-grid {
            grid-template-columns: repeat(2, 1fr);
            gap: 2px;
            padding: 2px;
        }
        
        .herb {
            padding: 4px 2px;
            font-size: 10px;
            min-height: 28px;
        }
        
        .cabinet-title {
            padding: 4px 5px;
            font-size: 12px;
        }
        
        /* 药房布局 */
        .prescription-title {
            font-size: 12px;
            margin-bottom: 2px;
        }
        
        .formula-name {
            font-size: 11px;
            margin: 2px 0 3px 0;
        }
        
        .formula-list {
            grid-template-columns: 1fr;
            gap: 1px;
            min-height: 40px;
        }
        
        .formula-list li {
            font-size: 10px;
            padding: 2px 3px;
        }
        
        /* 药锅区域 */
        .pot {
            width: min(50%, 140px);
        }
        
        .added-title {
            font-size: 12px;
            margin-top: 3px;
        }
        
        .added-list {
            grid-template-columns: 1fr;
            gap: 1px;
            min-height: 30px;
        }
        
        .added-list li {
            padding: 2px 3px;
            font-size: 10px;
        }
        
        /* 按钮 */
        .actions {
            gap: 3px;
            margin-top: 3px;
        }
        
        .actions .secondary,
        .actions .link {
            padding: 2px 4px !important;
            font-size: 9px !important;
            min-height: 24px !important;
        }
    }
}


/* 1. 适配iPad横/竖屏（768px ~ 1024px） */
@media (min-width: 768px) and (max-width: 1024px) {
  .hud h1 {
    font-size: 24px; /* 缩小标题，避免iPad上溢出 */
    position: static; /* 取消绝对定位，适配触屏布局 */
    transform: none;
    margin: 10px 0;
  }
  .scene {
    grid-template-columns: 1fr; /* iPad竖屏药柜占满宽度 */
    padding: 8px;
  }
  .work {
    grid-template-columns: 1fr; /* iPad上药方和银锅上下排列 */
    gap: 10px;
  }
  .herb-grid {
    grid-template-columns: repeat(3, 1fr); /* iPad上药柜每行3个药材，更合理 */
  }
  .ip.elder .avatar {
    width: 120px; /* 缩小老者头像，适配iPad */
  }
  .pot-area {
    padding: 8px;
  }
}

/* 2. Windows桌面端（>1024px）强化 */
@media (min-width: 1024px) {
  .scene {
    grid-template-columns: 320px 1fr; /* 桌面端药柜更宽 */
  }
  .work {
    grid-template-columns: 1fr 380px; /* 桌面端银锅区域更宽 */
  }
  .herb-grid {
    grid-template-columns: repeat(2, 1fr); /* 桌面端保持2列 */
  }
  .hud {
    padding: 20px 16px; /* 桌面端增加头部内边距 */
  }
}

/* 3. 触屏交互优化（iPad专属） */
@media (hover: none) and (pointer: coarse) {
  /* iPad触屏取消hover效果，强化点击反馈 */
  .herb {
    touch-action: manipulation; /* 禁止触屏缩放/双击，提升响应速度 */
    padding: 14px 10px; /* 增大触屏点击区域 */
  }
  .herb:active {
    background: #f0ebe1; /* 触屏点击时的背景反馈 */
  }
  /* 按钮增大点击区域 */
  .secondary, .link {
    padding: 10px 16px;
    min-height: 44px; /* 符合iOS人机交互规范，最小点击区域44x44px */
    min-width: 44px;
  }
}




#bg-upload-btn,
#gif-fail-btn,
#gif-success-btn,
#bg-file,
#gif-fail-file,
#gif-success-file {
    display: none !important
}

#test-success,
#test-fail {
    display: none !important
}

.ui-bg {
    background: rgba(243, 237, 227, .65);
    border: 1px solid rgba(214, 196, 166, .55);
    border-radius: 14px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .06)
}

.ui-bg.full {
    position: absolute;
    inset: 0;
    border-radius: 0;
    border: none;
    box-shadow: none;
    pointer-events: none
}

.theme-chip {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    line-height: 18px
}

.settle-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .35);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2600
}

.settle-overlay.show {
    display: flex
}

.settle-modal {
    max-width: 520px;
    width: 86vw;
    background: rgba(243, 237, 227, .78);
    border: 1px solid rgba(214, 196, 166, .65);
    border-radius: 14px;
    padding: 16px;
    text-align: center
}

.settle-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 6px
}

.settle-sub {
    font-size: 15px;
    margin-bottom: 10px
}

.settle-gif {
    max-width: 100%;
    height: auto;
    display: inline-block;
    border-radius: 10px
}