/* ==========================================
   Ink Wash Chinese Aesthetic Game Styles
   (水墨素色猫咪跃尘 · 雅致界面与移动端适配)
   ========================================== */

:root {
    --paper-bg: #f5f0e6;
    --paper-dark: #e8e1cf;
    --ink-black: #1a1a1c;
    --ink-charcoal: #2c2d30;
    --ink-grey: #6b6a65;
    --ink-light: #b0aba0;
    --cinnabar: #b83828;      /* 朱砂红 */
    --cinnabar-dark: #8c2518;
    --amber-gold: #cfa144;     /* 琥珀金 */
    --bamboo-green: #48664f;   /* 竹青 */
    --font-serif: "Songti SC", "SimSun", "STSong", "Noto Serif SC", serif;
    --font-calligraphy: "Kaiti SC", "STKaiti", "KaiTi", "Songti SC", serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--paper-bg);
    font-family: var(--font-calligraphy);
    color: var(--ink-black);
    position: fixed;
}

/* Xuan Paper Parchment Texture Simulation */
#gameContainer {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background-color: var(--paper-bg);
    /* Subtle organic paper grain overlay */
    background-image: 
        radial-gradient(circle at 20% 30%, rgba(0, 0, 0, 0.015) 0%, transparent 60%),
        radial-gradient(circle at 80% 70%, rgba(0, 0, 0, 0.02) 0%, transparent 70%);
}

#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    z-index: 1;
}

/* ==========================================
   HUD (Heads-Up Display)
   ========================================== */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 16px 20px;
    padding-top: max(16px, env(safe-area-inset-top));
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    z-index: 10;
}

.hud-left {
    display: flex;
    align-items: center;
    gap: 14px;
    pointer-events: auto;
}

.hud-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(245, 240, 230, 0.85);
    border: 2px solid var(--ink-charcoal);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.15s ease;
}

.hud-avatar:active {
    transform: scale(0.92);
}

.hud-info {
    display: flex;
    flex-direction: column;
}

.hud-level-title {
    font-size: 19px;
    font-weight: bold;
    color: var(--ink-black);
    letter-spacing: 1px;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

.hud-stats {
    display: flex;
    gap: 12px;
    font-size: 14px;
    color: var(--ink-charcoal);
    margin-top: 2px;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(250, 246, 238, 0.7);
    padding: 2px 8px;
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.hud-right {
    display: flex;
    gap: 10px;
    pointer-events: auto;
}

.hud-btn {
    background: rgba(245, 240, 230, 0.9);
    border: 1.5px solid var(--ink-charcoal);
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 14px;
    font-family: var(--font-calligraphy);
    color: var(--ink-charcoal);
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.stat-icon {
    display: inline-block;
    vertical-align: middle;
    color: var(--ink-charcoal);
    flex-shrink: 0;
}

.hud-btn:active {
    transform: scale(0.94);
    background: var(--paper-dark);
}

/* ==========================================
   Mobile & Tablet Touch Virtual Controls
   ========================================== */
#touchControls {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 16px 24px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none;
    z-index: 10;
}

.touch-cluster {
    display: flex;
    gap: 14px;
    pointer-events: auto;
}

.touch-btn {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background: rgba(248, 245, 238, 0.88);
    border: 2px solid var(--ink-charcoal);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), inset 0 1px 2px rgba(255, 255, 255, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--ink-black);
    font-size: 22px;
    font-weight: bold;
    touch-action: none;
    cursor: pointer;
    transition: transform 0.08s ease, background 0.08s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.touch-btn span {
    font-size: 11px;
    margin-top: 1px;
    letter-spacing: 0.5px;
    color: var(--ink-grey);
}

.touch-btn svg {
    margin-bottom: 1px;
    transition: transform 0.1s ease;
}

.touch-btn:active svg {
    transform: scale(1.1);
}

.touch-btn:active, .touch-btn.active {
    transform: scale(0.90);
    background: rgba(220, 215, 202, 0.95);
    border-color: var(--cinnabar);
    color: var(--cinnabar);
}

.btn-charge-jump {
    width: 80px;
    height: 80px;
    background: rgba(248, 244, 235, 0.92);
    border: 2.5px solid var(--ink-charcoal);
    position: relative;
}

.btn-charge-jump:active {
    border-color: var(--cinnabar);
    background: rgba(235, 220, 215, 0.95);
}

/* ==========================================
   Modals & Screens (Start, Victory, Defeat, Select)
   ========================================== */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(20, 22, 25, 0.65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
    transition: opacity 0.25s ease;
    padding: 20px;
}

.modal-overlay.hidden {
    display: none;
}

/* Traditional Chinese Parchment Card */
.scroll-card {
    position: relative;
    max-width: 480px;
    width: 100%;
    background: #f7f3e8;
    border: 3px solid var(--ink-charcoal);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
    padding: 36px 30px 30px;
    text-align: center;
    border-radius: 8px;
    background-image: 
        linear-gradient(rgba(0, 0, 0, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 0, 0, 0.02) 1px, transparent 1px);
    background-size: 20px 20px;
}

/* Decorative corner frames (中国传统回纹角标) */
.scroll-card::before, .scroll-card::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid var(--cinnabar);
}

.scroll-card::before {
    top: 8px;
    left: 8px;
    border-right: none;
    border-bottom: none;
}

.scroll-card::after {
    bottom: 8px;
    right: 8px;
    border-left: none;
    border-top: none;
}

/* Red Cinnabar Seal Stamp (朱砂红印) */
.seal-stamp {
    position: absolute;
    top: -18px;
    right: 28px;
    width: 52px;
    height: 52px;
    background: var(--cinnabar);
    color: #fff;
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    font-weight: bold;
    font-family: var(--font-calligraphy);
    letter-spacing: 2px;
    border-radius: 4px;
    transform: rotate(6deg);
}

.modal-title {
    font-size: 32px;
    font-weight: bold;
    color: var(--ink-black);
    letter-spacing: 4px;
    margin-bottom: 6px;
    font-family: var(--font-calligraphy);
}

.modal-subtitle {
    font-size: 15px;
    color: var(--ink-grey);
    margin-bottom: 22px;
    letter-spacing: 2px;
}

.modal-body {
    margin: 18px 0 26px;
    font-size: 15px;
    line-height: 1.8;
    color: var(--ink-charcoal);
}

.stars-rating {
    font-size: 36px;
    color: var(--amber-gold);
    margin: 8px 0;
    letter-spacing: 6px;
}

.rank-badge {
    display: inline-block;
    padding: 4px 18px;
    margin: 10px 0 16px;
    background: rgba(184, 56, 40, 0.1);
    color: var(--cinnabar);
    border: 1px solid var(--cinnabar);
    border-radius: 20px;
    font-weight: bold;
    font-size: 16px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 14px 0 20px;
    background: rgba(0, 0, 0, 0.03);
    padding: 12px;
    border-radius: 6px;
    border: 1px dashed rgba(0, 0, 0, 0.12);
}

.stat-box .label {
    font-size: 12px;
    color: var(--ink-grey);
}

.stat-box .val {
    font-size: 17px;
    font-weight: bold;
    color: var(--ink-black);
    margin-top: 4px;
}

/* Calligraphic Action Buttons */
.modal-actions {
    display: flex;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
}

.btn-primary {
    background: var(--cinnabar);
    color: #fff;
    border: 2px solid var(--cinnabar-dark);
    border-radius: 24px;
    padding: 10px 28px;
    font-size: 17px;
    font-weight: bold;
    font-family: var(--font-calligraphy);
    letter-spacing: 2px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(184, 56, 40, 0.3);
    transition: all 0.15s ease;
}

.btn-primary:active {
    transform: scale(0.95);
    background: var(--cinnabar-dark);
}

.btn-secondary {
    background: rgba(245, 240, 230, 0.95);
    color: var(--ink-black);
    border: 2px solid var(--ink-charcoal);
    border-radius: 24px;
    padding: 10px 24px;
    font-size: 16px;
    font-weight: bold;
    font-family: var(--font-calligraphy);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    transition: all 0.15s ease;
}

.btn-secondary:active {
    transform: scale(0.95);
    background: var(--paper-dark);
}

.btn-pwa-install {
    border-color: var(--cinnabar);
    color: var(--cinnabar-dark);
    background: #fffdf8;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-pwa-install:hover {
    background: #fff4f2;
}

/* ==========================================
   Start Screen & Instructions
   ========================================== */
.instruction-box {
    background: rgba(255, 255, 255, 0.5);
    border-radius: 6px;
    padding: 14px 16px;
    margin: 16px 0 24px;
    font-size: 14px;
    text-align: left;
    line-height: 1.7;
    border-left: 3px solid var(--cinnabar);
}

.instruction-box ul {
    list-style: none;
    margin-top: 6px;
}

.instruction-box li {
    margin-bottom: 5px;
    position: relative;
    padding-left: 18px;
}

.instruction-box li::before {
    content: "▪";
    position: absolute;
    left: 4px;
    color: var(--cinnabar);
}

/* ==========================================
   Level Selection Grid
   ========================================== */
.level-select-container {
    max-width: 580px;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin: 18px 0 24px;
    max-height: 55vh;
    overflow-y: auto;
    padding-right: 4px;
}

.level-card {
    background: #fffdf8;
    border: 2px solid var(--ink-charcoal);
    border-radius: 6px;
    padding: 16px;
    position: relative;
    text-align: left;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.level-card.locked {
    background: #eae6dd;
    border: 2px dashed #999;
    opacity: 0.65;
    filter: grayscale(0.85);
}

.level-card.locked .card-stamp {
    border-color: #888;
    color: #888;
}

.level-card.locked .btn-card-play {
    background: #888;
    cursor: not-allowed;
}

.card-stamp {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1.5px solid var(--cinnabar);
    color: var(--cinnabar);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 13px;
    font-weight: bold;
}

.card-title {
    font-size: 17px;
    font-weight: bold;
    color: var(--ink-black);
    margin-bottom: 3px;
}

.card-subtitle {
    font-size: 12px;
    color: var(--ink-grey);
    margin-bottom: 8px;
}

.card-stars {
    font-size: 18px;
    color: var(--amber-gold);
    margin-bottom: 6px;
}

.card-time {
    font-size: 12px;
    color: var(--ink-grey);
    margin-bottom: 10px;
}

.btn-card-play {
    width: 100%;
    background: var(--ink-charcoal);
    color: #fff;
    border: none;
    border-radius: 14px;
    padding: 6px 0;
    font-family: var(--font-calligraphy);
    font-size: 14px;
    cursor: pointer;
}

.btn-card-play:active {
    background: var(--cinnabar);
}

/* ==========================================
   Responsive Adaptations (Tablet & Mobile)
   ========================================== */
@media (min-width: 900px) {
    /* On larger tablets / desktops */
    .hud-level-title {
        font-size: 22px;
    }
    .hud-avatar {
        width: 48px;
        height: 48px;
    }
    .touch-btn {
        width: 74px;
        height: 74px;
        font-size: 24px;
    }
    .btn-charge-jump {
        width: 88px;
        height: 88px;
    }
}

@media (max-width: 480px) {
    /* Compact phones */
    #hud {
        padding: 10px 14px;
    }
    .hud-avatar {
        width: 38px;
        height: 38px;
        font-size: 20px;
    }
    .hud-level-title {
        font-size: 16px;
    }
    .hud-stats {
        font-size: 12px;
        gap: 6px;
    }
    .hud-btn {
        padding: 4px 10px;
        font-size: 12px;
    }
    .touch-btn {
        width: 58px;
        height: 58px;
        font-size: 18px;
    }
    .btn-charge-jump {
        width: 70px;
        height: 70px;
    }
    .scroll-card {
        padding: 24px 18px 20px;
    }
    .modal-title {
        font-size: 26px;
    }
}

/* Orientation landscape optimization on mobile phones */
@media (max-height: 500px) and (orientation: landscape) {
    #hud {
        padding-top: 6px;
        padding-bottom: 6px;
    }
    #touchControls {
        padding-bottom: 8px;
    }
    .touch-btn {
        width: 52px;
        height: 52px;
        font-size: 17px;
    }
    .btn-charge-jump {
        width: 62px;
        height: 62px;
    }
    .scroll-card {
        padding: 16px 24px;
        max-height: 90vh;
        overflow-y: auto;
    }
    .modal-title {
        font-size: 22px;
        margin-bottom: 2px;
    }
    .modal-subtitle {
        margin-bottom: 10px;
    }
    .instruction-box {
        margin: 8px 0 12px;
        padding: 8px 12px;
    }
}
