/* ============================================================
   dig & pop  |  style.css
   Layout: Score(top-left)  Timer(top-right)  Cat+Grid(center)
   ============================================================ */

/* ---------- CSS Variables (Hand-drawn ink style) ---------- */
:root {
    --paper:          #f0e8d5;
    --paper-dark:     #e2d8c0;
    --paper-game:     #f5efe0;
    --ink:            #251507;
    --ink-light:      #4a3520;
    --ink-red:        #8b1a1a;
    --ink-dim:        #7a6a52;
    --block-face:     #ddd0b0;
    --block-hover:    #c8bb98;
    --block-broken:   #b5aca0;
    --bar-bg:         #c8b898;
    --bar-fill:       #251507;
    --ui-font:        'Caveat', 'Comic Sans MS', cursive;
    --game-w:         615px;
    --game-h:         885px;
}

/* ---------- Reset & Body ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background: var(--paper-dark);
    background-image:
        radial-gradient(ellipse at 20% 30%, rgba(255,250,230,0.5) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 70%, rgba(200,180,140,0.3) 0%, transparent 50%);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100dvh;
    min-height: 100vh;
    font-family: var(--ui-font);
    user-select: none;
    overflow: hidden;
}

/* ============================================================
   OVERLAY SCREENS (Start / Game Over / Video)
   ============================================================ */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(35, 20, 5, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}
.overlay.hidden { display: none; }

.overlay-box {
    background: var(--paper);
    border: 3px solid var(--ink);
    border-radius: 4px;
    padding: 40px 50px;
    text-align: center;
    max-width: 480px;
    width: 90%;
    box-shadow: 6px 6px 0 var(--ink);
    animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    overflow: hidden;
}
@keyframes popIn {
    from { transform: scale(0.7); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

.overlay-title {
    font-size: 42px;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 4px;
    letter-spacing: 1px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
}
#start-logo {
    width: clamp(120px, 14vw, 220px);
    max-width: 100%;
    max-height: 120px;
    height: auto;
    display: block;
    margin: 0 auto;
    object-fit: contain;
}
.logo-wrap { display: flex; align-items: center; justify-content: center; gap: 12px; }
.logo-text {
    font-size: 36px;
    font-weight: 700;
    color: var(--ink);
    line-height: 1;
    display: block;
}
.overlay-subtitle {
    font-size: 15px;
    color: var(--ink-dim);
    margin-bottom: 24px;
    letter-spacing: 4px;
    text-transform: uppercase;
    font-family: 'Segoe UI', sans-serif;
}

.how-to-play {
    list-style: none;
    text-align: left;
    margin-bottom: 28px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.how-to-play li {
    color: var(--ink);
    font-size: 18px;
    background: rgba(0,0,0,0.04);
    padding: 7px 14px;
    border-radius: 2px;
    border-left: 3px solid var(--ink);
    font-family: var(--ui-font);
}
.how-to-play strong { color: var(--ink-red); }

.result-label {
    color: var(--ink-dim);
    font-size: 20px;
    margin-bottom: 4px;
    letter-spacing: 2px;
    font-family: 'Segoe UI', sans-serif;
}
#final-score-display {
    font-size: 80px;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 8px;
}
#final-blocks-display {
    color: var(--ink-dim);
    font-size: 18px;
    margin-bottom: 24px;
}

.btn-primary {
    background: var(--ink);
    color: var(--paper);
    border: 2px solid var(--ink);
    padding: 13px 42px;
    font-size: 22px;
    font-weight: 700;
    border-radius: 3px;
    cursor: pointer;
    font-family: var(--ui-font);
    box-shadow: 4px 4px 0 var(--ink-light);
    transition: transform 0.1s, box-shadow 0.1s;
    letter-spacing: 1px;
}
.btn-primary:hover  { background: var(--ink-red); border-color: var(--ink-red); }
.btn-primary:active { transform: translate(3px,3px); box-shadow: 1px 1px 0 var(--ink-light); }

/* ============================================================
   RESPONSIVE / RWD  — 絕對滿版與置中容器
   ============================================================ */
#game-wrapper {
    position: fixed; 
    inset: 0;
    overflow: hidden; 
}

#game-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); 
    width:  var(--game-w);
    height: var(--game-h);
    background-image: url('bg.png'); 
    background-size: cover;          
    background-position: top center; 
    background-repeat: no-repeat;    
    background-color: #ffffff;       
    border-radius: 3px;
    border: 3px solid var(--ink);
    box-shadow: 6px 6px 0 var(--ink);
}

/* ============================================================
   UI LAYER  — Score (left) / Timer (right)
   ============================================================ */
#ui-layer {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 58px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    background: rgba(240,232,210,0.0);
    border-bottom: 2px solid var(--ink);
    z-index: 10;
    pointer-events: none;
}

#score-display,
#time-display {
    font-size: 30px;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: 1px;
}
#score-display span { color: var(--ink-red); font-size: 34px; }
#time-display span  { color: var(--ink); font-size: 34px; }
#time-display span .digit-img {
    height: 34px; width: auto; vertical-align: middle; display: inline-block; margin-right: -4px;
}
#time-display.danger span { animation: blink 0.6s infinite; }
#time-display.danger span .digit-img { animation: blink 0.6s infinite; }
@keyframes blink { 0%,100% { opacity:1; } 50% { opacity:.3; } }

/* ============================================================
   STATUS EFFECTS ROW
   ============================================================ */
#status-row {
    position: absolute; top: 62px; left: 0; right: 0; height: 34px;
    display: flex; align-items: center; justify-content: center; gap: 6px;
    padding: 0 16px; z-index: 10; pointer-events: none; overflow: hidden;
}
.status-badge {
    background: var(--paper); border: 2px solid; border-radius: 2px;
    padding: 2px 10px; font-size: 16px; font-weight: 700; font-family: var(--ui-font);
    white-space: nowrap; box-shadow: 2px 2px 0 var(--ink);
    animation: badgeIn 0.25s ease-out forwards;
}
@keyframes badgeIn {
    from { transform: scale(0.5) translateY(-10px); opacity: 0; }
    to   { transform: scale(1)   translateY(0);     opacity: 1; }
}

/* ============================================================
   SCORE MULTIPLIER BADGE
   ============================================================ */
#multiplier-badge {
    position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
    background: var(--paper); color: var(--ink-red); font-size: 22px; font-weight: 700;
    font-family: var(--ui-font); padding: 3px 16px; border-radius: 2px;
    border: 2px solid var(--ink-red); z-index: 10; box-shadow: 3px 3px 0 var(--ink-red);
    animation: pulse 0.7s ease-in-out infinite alternate; pointer-events: none;
}
#multiplier-badge.hidden { display: none; }
@keyframes pulse { from { transform: translateX(-50%) scale(1); } to { transform: translateX(-50%) scale(1.06); } }

/* ============================================================
   CAT CHARACTER
   ============================================================ */
#cat {
    position: absolute; width: 400px; display: flex; flex-direction: column;
    align-items: center; cursor: pointer; z-index: 6;
    transition: left 0.32s cubic-bezier(0.25, 1.2, 0.5, 1), top  0.32s cubic-bezier(0.25, 1.2, 0.5, 1);
}
#cat-body {
    width: 400px; height: auto; display: block; mix-blend-mode: multiply;
    transition: transform 0.12s; filter: drop-shadow(2px 3px 2px rgba(0,0,0,0.2));
}
#cat-body:hover { filter: drop-shadow(2px 3px 2px rgba(0,0,0,0.2)) brightness(0.95); }

/* Mining progress bar */
#mine-bar-wrap {
    width: 100px; height: 8px; background: var(--bar-bg); border: 1px solid var(--ink);
    border-radius: 0; margin-top: 4px; overflow: hidden; opacity: 0; transition: opacity 0.2s;
}
#mine-bar-wrap.visible { opacity: 1; }
#mine-bar {
    height: 100%; width: 0%; background: var(--ink); transition: width 0.15s ease-out, background 0.2s;
}
#mine-bar.warn  { background: #7a4000; }
#mine-bar.close { background: var(--ink-red); }

/* Click animation */
#cat.clicked #cat-body { animation: catPop 0.22s ease-out; }
@keyframes catPop {
    0%   { transform: scale(1.05) translateY(0);    }
    35%  { transform: scale(1.18) translateY(-10px); }
    100% { transform: scale(1)    translateY(0);    }
}
#cat.shake #cat-body { animation: catShake 0.28s ease-out; }
@keyframes catShake {
    0%,100% { transform: rotate(0deg);  }
    25%     { transform: rotate(-6deg); }
    75%     { transform: rotate(6deg);  }
}

/* ============================================================
   BLOCK GRID
   ============================================================ */
#block-grid {
    position: absolute; left: 0; right: 0; bottom: 40px;
    display: grid; grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(3, 90px);
    gap: 2px; z-index: 3; border-top: 3px solid var(--ink); border-bottom: 3px solid var(--ink);
    background: var(--block-face); 
}

/* ---------- Single Block ---------- */
.block {
    width: 100%; height: 90px; background: var(--block-face); border-radius: 0;
    border-right:  2px solid var(--ink); border-bottom: 2px solid var(--ink);
    cursor: pointer; transition: transform 0.08s, background 0.15s;
    display: flex; justify-content: center; align-items: center;
    font-size: 40px; font-weight: 700; font-family: var(--ui-font);
    color: rgba(37, 21, 7, 0.22); position: relative; overflow: hidden;
}

.block:nth-child(5n) { border-right: none; }

.block::before {
    content: "?"; position: absolute; font-size: 42px; color: rgba(37, 21, 7, 0.18);
    font-weight: 700; pointer-events: none; font-family: var(--ui-font); z-index: 2; 
}
.block::after {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background: transparent; transition: background 0.1s; z-index: 3;
}
.block:not(.destroyed):hover  { background: var(--block-hover); }
.block:not(.destroyed):active { transform: scale(0.96); }

/* Crack stages */
.block.crack-1::after { background: linear-gradient(135deg, transparent 40%, rgba(37,21,7,0.25) 41%, rgba(37,21,7,0.25) 42%, transparent 43%); }
.block.crack-2::after { background: linear-gradient(135deg, transparent 30%, rgba(37,21,7,0.35) 31%, rgba(37,21,7,0.35) 33%, transparent 34%), linear-gradient( 45deg, transparent 55%, rgba(37,21,7,0.25) 56%, rgba(37,21,7,0.25) 57%, transparent 58%); filter: brightness(0.92); }
.block.crack-3::after { background: linear-gradient(135deg, transparent 20%, rgba(37,21,7,0.5) 21%, rgba(37,21,7,0.5) 24%, transparent 25%), linear-gradient( 45deg, transparent 45%, rgba(37,21,7,0.4) 46%, rgba(37,21,7,0.4) 48%, transparent 49%), linear-gradient( 90deg, transparent 60%, rgba(37,21,7,0.3) 61%, rgba(37,21,7,0.3) 62%, transparent 63%); filter: brightness(0.82); }

/* Destroyed state */
.block.destroyed { background: rgba(0,0,0,0.06); cursor: default; border-color: rgba(37,21,7,0.3); }
.block.destroyed::before { content: ""; }
.block.burst { animation: blockBurst 0.35s ease-out forwards; }
@keyframes blockBurst {
    0%   { transform: scale(1.12); filter: brightness(1.8); }
    50%  { transform: scale(0.94); }
    100% { transform: scale(1);    filter: brightness(1); }
}

.block.target-glow { background: var(--block-hover); box-shadow: inset 0 0 0 2px var(--ink-red); }

/* Game Logo */
#game-logo {
    position: absolute; right: 18px; bottom: 18px;
    width: clamp(60px, 6vw, 120px);
    max-width: 120px !important;
    max-height: 120px;
    height: auto;
    z-index: 99; opacity: 0.85; pointer-events: none; user-select: none;
}

@keyframes rowSlideInFromBottom {
    from { transform: translateY(94px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

/* ============================================================
   COLUMN ARROWS
   ============================================================ */
#col-arrows {
    position: absolute; bottom: 325px; left: 0; right: 0; display: grid;
    grid-template-columns: repeat(5, 1fr); gap: 2px; z-index: 5; pointer-events: none;
}
.col-arrow {
    width: 100%; height: 24px; display: flex; justify-content: center; align-items: center;
    font-size: 16px; color: rgba(37,21,7,0.0); pointer-events: none; transition: color 0.2s;
    font-family: var(--ui-font);
}
.col-arrow.active { color: var(--ink-red); animation: arrowBounce 0.45s ease-in-out infinite alternate; }
@keyframes arrowBounce { from { transform: translateY(0); } to { transform: translateY(-4px); } }

/* ============================================================
   FLOATING EFFECT TEXTS & MEME ANIMATIONS (從方塊飛出放大的動畫)
   ============================================================ */
#effects-layer { position: absolute; inset: 0; pointer-events: none; z-index: 20; }
.floating-text {
    position: absolute; font-weight: 700; font-family: var(--ui-font);
    text-shadow: 1px 1px 0 rgba(255,240,210,0.8);
    animation: floatUp 1.1s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    white-space: nowrap; font-size: 24px; color: var(--ink);
    transform: translate(-50%, 0); pointer-events: none;
}
.floating-text.big { font-size: 36px; text-shadow: 1px 1px 0 rgba(255,240,210,0.9); }
.floating-text.negative { color: var(--ink-red); font-size: 26px; }
.floating-text.meme { font-size: 30px; animation: floatUpSpin 1.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }

@keyframes floatUp {
    0%   { transform: translate(-50%, 0)     scale(0.7); opacity: 1; }
    15%  { transform: translate(-50%, -15px) scale(1.2); opacity: 1; }
    100% { transform: translate(-50%, -90px) scale(1);   opacity: 0; }
}
@keyframes floatUpSpin {
    0%   { transform: translate(-50%, 0)     scale(0.7) rotate(-5deg); opacity: 1; }
    20%  { transform: translate(-50%, -20px) scale(1.3) rotate(5deg);  opacity: 1; }
    100% { transform: translate(-50%, -100px) scale(1)  rotate(-3deg); opacity: 0; }
}

/* ⭐ 圖片飛天放大的特殊動畫設定 */
.floating-meme-img {
    position: absolute;
    width: 80px; 
    height: auto;
    z-index: 100;
    pointer-events: none;
    animation: floatMemeUp 1.5s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes floatMemeUp {
    0% { 
        transform: translate(-50%, -50%) scale(0.1); 
        opacity: 0; 
    }
    15% { 
        transform: translate(-50%, calc(-50% - 60px)) scale(1.5) rotate(8deg); 
        opacity: 1; 
        filter: drop-shadow(0 0 10px rgba(255,255,255,0.8)); 
    }
    30% { 
        transform: translate(-50%, calc(-50% - 90px)) scale(1.3) rotate(-5deg); 
        opacity: 1; 
        filter: drop-shadow(0 0 20px rgba(255,255,255,0.8)); 
    }
    75% { 
        transform: translate(-50%, calc(-50% - 400px)) scale(3) rotate(5deg); 
        opacity: 1; 
        filter: drop-shadow(0 0 30px rgba(255,255,255,0.8)); 
    }
    100% { 
        transform: translate(-50%, calc(-50% - 550px)) scale(4) rotate(0deg); 
        opacity: 0; 
    }
}

/* ============================================================
   SCREEN FLASH (閃綠光毒藥加入)
   ============================================================ */
#game-container.flash-red   { animation: flashRed   0.35s ease-out; }
#game-container.flash-gold  { animation: flashGold  0.35s ease-out; }
#game-container.flash-blue  { animation: flashBlue  0.35s ease-out; }
#game-container.flash-green { animation: flashGreen 0.4s ease-out; }

@keyframes flashRed   { 0%,100% { box-shadow: 6px 6px 0 var(--ink); } 40% { box-shadow: 6px 6px 0 var(--ink), inset 0 0 60px rgba(139,26,26,0.25); } }
@keyframes flashGold  { 0%,100% { box-shadow: 6px 6px 0 var(--ink); } 40% { box-shadow: 6px 6px 0 var(--ink), inset 0 0 60px rgba(160,110,0,0.2); } }
@keyframes flashBlue  { 0%,100% { box-shadow: 6px 6px 0 var(--ink); } 40% { box-shadow: 6px 6px 0 var(--ink), inset 0 0 60px rgba(0,80,160,0.15); } }
@keyframes flashGreen { 0%,100% { box-shadow: 6px 6px 0 var(--ink); } 40% { box-shadow: 6px 6px 0 var(--ink), inset 0 0 80px rgba(50,205,50,0.4); } }

/* ============================================================
   VIDEO OVERLAY
   ============================================================ */
#video-overlay {
    position: absolute; inset: 0; background: rgba(0, 0, 0, 0.85);
    z-index: 500; display: flex; flex-direction: column;
    justify-content: center; align-items: center; backdrop-filter: blur(4px);
}
#video-overlay.hidden { display: none; }
#meme-video {
    width: 100%; max-height: 80%; object-fit: contain;
    box-shadow: 0 0 30px rgba(0,0,0,0.5); background: #000;
}
#skip-video-btn {
    margin-top: 25px; padding: 12px 30px; background: var(--ink);
    color: var(--paper); border: 2px solid var(--paper); border-radius: 4px;
    font-family: var(--ui-font); font-size: 22px; cursor: pointer;
    transition: transform 0.1s; box-shadow: 3px 3px 0 var(--ink-light);
}
#skip-video-btn:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--ink-light); }

::-webkit-scrollbar { display: none; }

/* ============================================================
   RWD ADJUSTMENTS
   ============================================================ */
@media (max-width: 830px) {
    .overlay-title          { font-size: 32px; }
    .overlay-box            { padding: 28px 24px; }
    .how-to-play li         { font-size: 15px; }
    #final-score-display    { font-size: 60px; }
    .btn-primary            { font-size: 18px; padding: 10px 32px; }
}
@media (max-width: 480px) {
    .overlay-title          { font-size: 26px; }
    .overlay-subtitle       { font-size: 12px; letter-spacing: 2px; }
    .how-to-play li         { font-size: 13px; padding: 5px 10px; }
    #final-score-display    { font-size: 48px; }
    .btn-primary            { font-size: 16px; padding: 8px 24px; }
    #start-logo             { max-width: 160px; max-height: 100px; }
    .logo-text             { font-size: 22px; }
}
@media (orientation: portrait) { .overlay-box { max-width: 92vw; } }

#game-container.portrait-layout #block-grid { bottom: 50px; }
#game-container.portrait-layout #col-arrows { bottom: 335px; }
#game-container.portrait-layout #game-logo {
    width: clamp(60px, 14vw, 100px); right: 10px; bottom: 10px; opacity: 0.8; z-index: 99; 
}

/* Extra caps for very large viewports where vw-based sizing can exceed desired pixel size */
@media (min-width: 1600px) {
    #start-logo { width: 220px; max-height: 120px; }
    .logo-text  { font-size: 28px; }
    #game-logo  { width: 120px; max-height: 120px; }
}

/* Safety: always ensure overlay title area doesn't let image overflow */
.overlay-title img { display: block; max-width: 100%; height: auto; }
#game-container, #game-container * {
    -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}