/* ============================================================
   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)
   ============================================================ */
.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;
}
@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;
}
#start-logo {
    width: 100%;
    max-width: 320px;
    height: auto;
    display: block;
    margin: 0 auto;
}
.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: 200px;
    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: 200px;
    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 below cat */
#mine-bar-wrap {
    width: 150px;
    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);    }
}
/* Shake on start mining a block */
#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  (4 cols × 3 rows)
   ============================================================ */
#block-grid {
    position: absolute;
    left: 50%;
    bottom: 40px;
    transform: translateX(-50%);
    display: grid;
    grid-template-columns: repeat(4, 90px);
    grid-template-rows:    repeat(3, 90px);
    gap: 2px;
    z-index: 3;
    border: 3px solid var(--ink);
    box-shadow: 5px 5px 0 var(--ink);
}

/* ---------- Single Block ---------- */
.block {
    width:  90px;
    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::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);
}
.block::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: transparent;
    transition: background 0.1s;
}
.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: var(--block-broken); 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); }
.block.selectable:not(.destroyed) { cursor: pointer; }
.block.locked { opacity: 0.45; cursor: default; filter: saturate(0.6); }
.block.locked:hover { background: var(--block-face); transform: none; }

/* Game Logo */
#game-logo {
    position: absolute;
    right: 18px;
    bottom: 18px;
    width: 90px;
    opacity: 0.85;
    pointer-events: none;
    user-select: none;
}

/* Animations */
@keyframes rowSlideIn {
    from { transform: translateY(-94px); opacity: 0; }
    to   { transform: translateY(0);     opacity: 1; }
}
@keyframes rowSlideInFromBottom {
    from { transform: translateY(94px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

/* ============================================================
   COLUMN ARROWS
   ============================================================ */
#col-arrows {
    position: absolute;
    bottom: 325px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(4 * 90px + 3 * 2px);
    display: flex;
    gap: 2px;
    z-index: 5;
    pointer-events: none;
}
.col-arrow {
    width: 90px;
    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
   ============================================================ */
#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; color: var(--ink); 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; }
}

/* ============================================================
   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; }
@keyframes flashRed  { 0%,100% { box-shadow: 5px 5px 0 var(--ink); } 40% { box-shadow: 5px 5px 0 var(--ink), inset 0 0 60px rgba(139,26,26,0.25); } }
@keyframes flashGold { 0%,100% { box-shadow: 5px 5px 0 var(--ink); } 40% { box-shadow: 5px 5px 0 var(--ink), inset 0 0 60px rgba(160,110,0,0.2); } }
@keyframes flashBlue { 0%,100% { box-shadow: 5px 5px 0 var(--ink); } 40% { box-shadow: 5px 5px 0 var(--ink), inset 0 0 60px rgba(0,80,160,0.15); } }

/* ============================================================
   BOARD CLEAR BANNER
   ============================================================ */
#clear-banner {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%) scale(0);
    background: var(--paper);
    color: var(--ink);
    font-size: 38px;
    font-weight: 700;
    font-family: var(--ui-font);
    padding: 18px 48px;
    border-radius: 3px;
    border: 3px solid var(--ink);
    box-shadow: 6px 6px 0 var(--ink);
    z-index: 50;
    pointer-events: none;
    white-space: nowrap;
    letter-spacing: 3px;
}
#clear-banner.show { animation: bannerPop 1.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }
@keyframes bannerPop {
    0%   { transform: translate(-50%, -50%) scale(0);   opacity: 0; }
    15%  { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
    70%  { transform: translate(-50%, -50%) scale(1);   opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
}

/* ============================================================
   SCROLLBAR (hidden)
   ============================================================ */
::-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; }
}
@media (orientation: portrait) {
    .overlay-box { max-width: 92vw; }
}

/* Portrait modifications */
#game-container.portrait-layout #block-grid { bottom: 50px; }
#game-container.portrait-layout #col-arrows { bottom: 335px; }
#game-container.portrait-layout #game-logo {
    width:   54px;
    right:   10px;
    bottom:  10px;
    opacity: 0.55;
    z-index: 4;
}

#game-container, #game-container * {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}