/* ============================================
 * 倒水大师 - 共享样式
 * 被 index.html 和 level.html 共用
 * ============================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;  /* 移动端去掉点击灰色高亮 */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', sans-serif;
    background: linear-gradient(135deg, #1a1a2e, #16213e, #0f3460);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ====================================
 * 顶部栏（首页 .home-header / 关卡页 #game-ui）
 * ==================================== */

.home-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

#game-ui {
    position: fixed;
    top: 12px;
    left: 0;
    right: 0;
    padding: 0 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
}

.settings-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.15);
    margin-top: -6px;
}
.settings-btn:hover { background: rgba(255,255,255,0.2); }
.settings-btn:active { transform: scale(0.95); }

.wechat-capsule {
    display: flex;
    align-items: center;
    background: rgba(0,0,0,0.4);
    border-radius: 14px;
    padding: 2px 5px;
    border: 1px solid rgba(255,255,255,0.1);
    opacity: 0.7;
    pointer-events: none;
    height: 28px;
    min-width: 68px;
}
/* 胶囊左侧"点点点"按钮：debug 入口，单独开启点击 */
.capsule-btn.dots-btn {
    pointer-events: auto;
    cursor: pointer;
}
.capsule-btn.dots-btn:active { opacity: 0.6; }

.capsule-btn {
    width: 28px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.capsule-dots {
    display: flex;
    align-items: center;
    gap: 3px;
}

.capsule-dots span {
    width: 4px;
    height: 4px;
    background: white;
    border-radius: 50%;
}

.capsule-dots span:nth-child(2) { width: 6px; height: 6px; }

.capsule-divider {
    width: 1px;
    height: 18px;
    background: rgba(255,255,255,0.3);
    margin: 0 2px;
}

.capsule-circle-dot {
    width: 15px;
    height: 15px;
    border: 1px solid rgba(255,255,255,0.8);
    border-radius: 50%;
    position: relative;
}
.capsule-circle-dot::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 5px;
    height: 5px;
    background: rgba(255,255,255,0.8);
    border-radius: 50%;
}

/* ====================================
 * 首页
 * ==================================== */

#home-screen {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    background: linear-gradient(135deg, #1a1a2e, #16213e, #0f3460);
}

.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.game-preview {
    display: flex;
    gap: 20px;
    align-items: flex-end;
}

.preview-bottle {
    width: 44px;
    height: 70px;
    border: 2px solid rgba(255,255,255,0.5);
    border-top: none;
    border-radius: 0 0 10px 10px;
    position: relative;
    overflow: hidden;
}
.preview-bottle::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -5px;
    right: -5px;
    height: 5px;
    border: 2px solid rgba(255,255,255,0.5);
    border-bottom: none;
    border-radius: 5px 5px 0 0;
}

.water {
    position: absolute;
    bottom: 0;
    left: 0; right: 0;
    border-radius: 0 0 8px 8px;
    animation: fillUp 2s ease-in-out infinite;
}
.preview-bottle:nth-child(1) .water {
    background: linear-gradient(to top, #ff6b6b, #ff8e8e);
    height: 60%;
    animation-delay: 0s;
}
.preview-bottle:nth-child(2) .water {
    background: linear-gradient(to top, #4ecdc4, #7ee8de);
    height: 80%;
    animation-delay: 0.3s;
}
.preview-bottle:nth-child(3) .water {
    background: linear-gradient(to top, #f9ca24, #f0932b);
    animation-delay: 0.6s;
}
@keyframes fillUp {
    0%, 100% { height: 60%; }
    50% { height: 85%; }
}

.game-title {
    font-size: 2.2rem;
    font-weight: 700;
    background: linear-gradient(90deg, #f093fb, #f5576c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
}

.game-subtitle {
    color: #888;
    font-size: 0.95rem;
}

.home-footer {
    padding: 30px 20px 50px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

.start-btn {
    width: 100%;
    max-width: 260px;
    padding: 18px;
    font-size: 1.2rem;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border: none;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.4);
}
.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(102, 126, 234, 0.5);
}
.start-btn:active { transform: translateY(0); }

/* ====================================
 * 关卡页
 * ==================================== */

.game-level {
    position: fixed;
    top: 14px;
    left: 0;
    right: 0;
    text-align: center;
    color: white;
    font-size: 1.4rem;
    font-weight: 700;
    z-index: 102;
    pointer-events: none;
}

.level-preview-cups {
    position: fixed;
    top: 88px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 16px;
    z-index: 101;
}

.level-cup {
    width: 45px;
    height: 62px;
    border: 3px solid rgba(255,255,255,0.6);
    border-top: none;
    border-radius: 0 0 10px 10px;
    position: relative;
    background: rgba(255,255,255,0.08);
}
.level-cup::before {
    content: '';
    position: absolute;
    top: -4px;
    left: -7px;
    right: -7px;
    height: 5px;
    border: 3px solid rgba(255,255,255,0.6);
    border-bottom: none;
    border-radius: 5px 5px 0 0;
    background: rgba(255,255,255,0.08);
}

.level-cup-label {
    position: absolute;
    top: 25%;
    left: 3px;
    right: 3px;
    height: 31%;
    border-radius: 2px;
}

.level-cup.completed { animation: cupDisappear 0.4s ease forwards; }
@keyframes cupDisappear {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.6; }
    100% { transform: scale(0); opacity: 0; }
}

/* 游戏瓶子区域（外层是若干行） */
.bottles-area {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 48px;  /* 两排间距，让第一排上浮更明显 */
    padding: 8px 16px;
    max-width: 100%;
}
.bottle-row {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 8px;
    flex-wrap: nowrap;
}

.bottle {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    user-select: none;
}
.bottle.selected { transform: translateY(-20px); }

.bottle-glass {
    width: 48px;
    /* 根据 capacity 动态计算 */
    height: calc(var(--layer-h, 27px) * var(--cap, 4) + 2px * (var(--cap, 4) - 1) + 8px);
    border: 2px solid rgba(255,255,255,0.45);
    border-top: none;
    border-radius: 0 0 14px 14px;
    background: rgba(255,255,255,0.06);
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 12px rgba(255,255,255,0.05);
}

.bottle-neck {
    width: 34px;
    height: 8px;
    border: 2px solid rgba(255,255,255,0.45);
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    background: rgba(255,255,255,0.06);
}

.bottle-selector {
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 54px;
    height: 10px;
    border-radius: 50%;
    background: transparent;
    transition: background 0.2s;
}
.bottle.selected .bottle-selector { background: rgba(255, 220, 50, 0.35); }

.bottle.completed {
    animation: bottleDisappear 0.5s ease forwards;
    pointer-events: none;
}
@keyframes bottleDisappear {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
    100% { transform: scale(0); opacity: 0; }
}

/* 归类完成但对应杯还没入桌 → 瓶子里打对勾，等待 */
.bottle.pending-check { pointer-events: none; }
.bottle.pending-check .bottle-glass::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 30px;
    color: #ffffff;
    font-weight: 900;
    text-shadow:
        0 0 4px rgba(0,0,0,0.6),
        0 0 10px rgba(92,214,118,0.9),
        0 0 2px rgba(255,255,255,0.9);
    z-index: 10;
    animation: checkPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}
@keyframes checkPop {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(-20deg); }
    60%  { opacity: 1; transform: translate(-50%, -50%) scale(1.3) rotate(5deg); }
    100% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0); }
}

.water-layers {
    position: absolute;
    bottom: 4px;
    left: 4px;
    right: 4px;
    display: flex;
    flex-direction: column-reverse;
    gap: 2px;
    border-radius: 0 0 10px 10px;
    overflow: hidden;
}

.water-layer {
    height: var(--layer-h, 27px);
    border-radius: 2px;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

/* 木桌 */
.game-table {
    position: fixed;
    top: 150px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 99;
    pointer-events: none;
}
.table-panel {
    width: 280px;
    height: 12px;
    background: linear-gradient(180deg, #a0714f 0%, #7a5230 50%, #5c3d1e 100%);
    border-radius: 4px 4px 0 0;
    box-shadow: 0 -2px 4px rgba(0,0,0,0.2);
}
.table-legs {
    display: flex;
    justify-content: space-between;
    width: 252px;
    height: 34px;
}
.table-leg {
    width: 14px;
    height: 34px;
    background: linear-gradient(180deg, #7a5230 0%, #5c3d1e 100%);
    border-radius: 0 0 3px 3px;
}

/* 底部道具栏 */
#game-controls {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 16px;
    z-index: 100;
}

.tool-item {
    position: relative;
    width: 68px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s;
}
.tool-item:active { transform: scale(0.93); }

.tool-block {
    width: 68px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
}
.tool-block.shuffle    { background: linear-gradient(135deg, #a29bfe, #6c5ce7); }
.tool-block.undo       { background: linear-gradient(135deg, #55efc4, #00b894); }
.tool-block.add-bottle { background: linear-gradient(135deg, #fdcb6e, #f39c12); }

.tool-block .tool-icon { font-size: 18px; line-height: 1; }
.tool-block .tool-text { font-size: 10px; color: rgba(255,255,255,0.9); font-weight: 500; line-height: 1; }

.tool-count {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #ff4757;
    color: white;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    box-shadow: 0 2px 6px rgba(255,71,87,0.4);
}

/* 新手引导（仅第 1 关激活） */
.guide-hint {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.85);
    font-size: 0.9rem;
    text-align: center;
    padding: 8px 20px;
    background: rgba(0,0,0,0.45);
    border-radius: 20px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 100;
    white-space: nowrap;
    animation: guidePulse 2s ease-in-out infinite;
    pointer-events: none;
    transition: opacity 0.3s;
    display: none;  /* 默认不显示，JS 根据 LEVEL_ID 决定激活 */
}
.guide-hint.active { display: block; }
.guide-hint.hidden { opacity: 0; }
@keyframes guidePulse {
    0%, 100% { opacity: 0.85; }
    50% { opacity: 1; }
}

/* ====================================
 * 设置弹窗（共用）
 * ==================================== */

.modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
}
.modal-overlay.show { display: flex; }

.modal {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 20px;
    width: 85%;
    max-width: 280px;
}

.modal-header {
    position: relative;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.modal h2 { color: white; font-size: 1.1rem; margin: 0; text-align: center; }

.close-btn {
    position: absolute;
    right: -8px; top: -4px;
    width: 28px; height: 34px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: rgba(255,255,255,0.6);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}
.close-btn:hover { color: white; background: rgba(255,255,255,0.1); }

.setting-item {
    display: flex;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    cursor: pointer;
}
.setting-item:last-child { border-bottom: none; }

.setting-icon { font-size: 20px; margin-right: 12px; width: 24px; text-align: center; }
.setting-label { color: #ccc; font-size: 1rem; flex: 1; }

.checkbox {
    width: 22px; height: 22px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    background: transparent;
}
.checkbox.checked { background: #667eea; border-color: #667eea; }
.checkbox::after {
    content: '✓';
    color: white;
    font-size: 14px;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.2s;
}
.checkbox.checked::after { opacity: 1; }

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid rgba(255,255,255,0.1);
}
.modal-action-btn {
    flex: 1;
    padding: 10px 0;
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 0.95rem;
    cursor: pointer;
    text-align: center;
}
.btn-home { background: linear-gradient(135deg, #667eea, #764ba2); }
.btn-home:active { opacity: 0.8; }
.btn-restart { background: linear-gradient(135deg, #f0932b, #ff6b6b); }
.btn-restart:active { opacity: 0.8; }

/* ====================================
 * 过关庆祝
 * ==================================== */

.win-overlay {
    position: fixed;
    inset: 0;
    z-index: 199;
    pointer-events: none;
    overflow: hidden;
    background: transparent;
    display: none;
}
.win-overlay.active {
    display: block;
    background: rgba(0,0,0,0.75);
}

.win-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    z-index: 200;
    pointer-events: auto;
    opacity: 0;
    transition: opacity 0.4s, transform 0.4s;
    display: none;
}
.win-modal.show {
    display: block;
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.confetti {
    position: fixed;
    top: -20px;
    width: 10px;
    height: 10px;
    z-index: 199;
    pointer-events: none;
    animation: confettiFall linear forwards;
}
.star {
    position: fixed;
    z-index: 199;
    pointer-events: none;
    font-size: 16px;
    animation: starPop linear forwards;
}
@keyframes confettiFall {
    0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(105vh) rotate(720deg); opacity: 0; }
}
@keyframes starPop {
    0%   { opacity: 0; transform: scale(0) rotate(0deg); }
    30%  { opacity: 1; transform: scale(1.4) rotate(90deg); }
    100% { opacity: 0; transform: scale(0.6) rotate(360deg) translateY(-30px); }
}

#win-modal {
    background: linear-gradient(145deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    border: 1.5px solid rgba(255,215,0,0.35);
    border-radius: 24px;
    padding: 28px 20px 24px;
    width: 82%;
    max-width: 300px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6), 0 0 40px rgba(255,215,0,0.08);
}
.win-stars {
    font-size: 2rem;
    margin-bottom: 8px;
    animation: winStarsPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.1s both;
}
.win-title {
    font-size: 1.5rem;
    font-weight: bold;
    color: #FFD700;
    margin-bottom: 8px;
    text-shadow: 0 0 20px rgba(255,215,0,0.5);
}
.win-sub {
    color: rgba(255,255,255,0.75);
    font-size: 0.9rem;
    margin-bottom: 20px;
}
.win-btns {
    display: flex;
    gap: 10px;
    justify-content: center;
}
.win-btn {
    flex: 1;
    padding: 12px 8px;
    border: none;
    border-radius: 14px;
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
}
.win-btn:active { transform: scale(0.95); opacity: 0.85; }
.btn-next {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #1a1a2e;
}
@keyframes winStarsPop {
    0%   { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.win-active .bottles-area { pointer-events: none; }
.win-active #game-controls { pointer-events: none; opacity: 0.4; }

/* ====================================
 * Debug 选关弹窗
 * ==================================== */
.debug-level-list {
    max-height: 52vh;
    overflow-y: auto;
    margin: -4px -4px 0;
    padding: 4px;
}
.debug-level-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    margin: 6px 0;
    border-radius: 10px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    cursor: pointer;
    color: white;
    font-size: 0.95rem;
    transition: all 0.2s;
}
.debug-level-item:active {
    transform: scale(0.98);
    background: rgba(102, 126, 234, 0.25);
}
.debug-level-meta {
    font-size: 0.78rem;
    color: rgba(255,255,255,0.55);
    font-weight: normal;
}
.debug-empty-hint {
    color: rgba(255,255,255,0.5);
    text-align: center;
    padding: 20px 0;
    font-size: 0.9rem;
}
