/* ── Drill Mini-game Overlay ─────────────────────────────────────────────── */
/* Ported from drilling-v3.html prototype                                    */

#drill-overlay {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #020408;
    background-image: radial-gradient(ellipse at 50% 80%, #1a0b08 0%, #020408 70%);
    font-family: 'Share Tech Mono', monospace;
    color: #fff;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

/* ══════════ PANEL ══════════ */
.drill-panel {
    width: 100%; max-width: 440px;
    background: rgba(6, 10, 18, 0.95);
    border: 1px solid rgba(0, 243, 255, 0.15);
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.9), inset 0 0 30px rgba(0,243,255,0.03);
    padding: 24px;
    position: relative;
    backdrop-filter: blur(10px);
}

/* ══════════ HEADER ══════════ */
.drill-header {
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid rgba(0, 243, 255, 0.1);
    padding-bottom: 12px; margin-bottom: 12px;
}
.drill-header-title {
    font-family: 'Oxanium', sans-serif; font-weight: 700; font-size: 16px;
    letter-spacing: 0.15em; text-transform: uppercase;
    color: #00f3ff; text-shadow: 0 0 10px rgba(0,243,255,0.4);
    display: flex; align-items: center; gap: 8px;
}
.drill-header-tier {
    font-size: 12px; color: #64748b; letter-spacing: 0.1em; text-transform: uppercase;
}
.drill-header-tier span { color: #ffaa00; font-weight: bold; }

/* ══════════ SEISMOGRAPH ══════════ */
.seismo-wrap {
    width: 100%; height: 40px;
    background: transparent;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    margin-bottom: 16px;
    position: relative; overflow: hidden;
    -webkit-mask-image: linear-gradient(to right, transparent, black 10%, black 90%, transparent);
    mask-image: linear-gradient(to right, transparent, black 10%, black 90%, transparent);
}
.seismo-wrap canvas { width: 100%; height: 100%; }
.seismo-label {
    position: absolute; top: 4px; left: 10%;
    font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase;
    color: rgba(0,243,255,0.5); pointer-events: none;
}

/* ══════════ STATS ROW ══════════ */
.drill-stats-row {
    display: flex; justify-content: space-between; padding: 0 4px 12px 4px; margin-bottom: 16px;
    font-size: 11px; letter-spacing: 0.15em; text-transform: uppercase; color: #64748b;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.drill-stats-row span { display: flex; align-items: baseline; gap: 8px; }
.drill-stats-row .val { color: #fff; font-weight: bold; font-size: 13px; font-family: 'Oxanium', sans-serif; }
.drill-stats-row .val.danger { color: #ff0055; text-shadow: 0 0 8px rgba(255,0,85,0.5); }
.drill-stats-row .val.good { color: #00ff66; text-shadow: 0 0 8px rgba(0,255,102,0.5); }

/* ══════════ GAME AREA ══════════ */
.game-area {
    display: flex; gap: 12px; height: 360px; margin-bottom: 16px; position: relative;
}

/* DEPTH GAUGE */
.depth-gauge {
    width: 30px; background: transparent;
    border-right: 1px solid rgba(255,255,255,0.05);
    position: relative; overflow: hidden;
}
.depth-fill {
    position: absolute; top: 0; left: 0; right: 0; height: 0%;
    background: linear-gradient(to bottom, transparent, rgba(255,170,0,0.1));
    border-bottom: 2px solid #ffaa00;
    box-shadow: 0 5px 15px rgba(255,170,0,0.4);
    transition: height 0.15s linear;
    z-index: 2;
}
.depth-number {
    position: absolute; bottom: 0px; width: 100%; text-align: center;
    font-family: 'Oxanium', sans-serif; font-size: 11px; font-weight: bold; color: #ffaa00;
    text-shadow: 0 0 8px rgba(255,170,0,0.6);
    pointer-events: none; z-index: 3;
    background: rgba(6, 10, 18, 0.95);
    padding-top: 4px;
}

/* ══════════ SHAFT ══════════ */
.shaft {
    flex-grow: 1;
    border: 1px solid rgba(0,243,255,0.1);
    border-radius: 4px; position: relative;
    overflow: hidden; cursor: pointer; touch-action: none;
    background: #000;
}

/* Scrolling geological layers (300% height for parallax) */
.shaft-layers {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 300%;
    background-image: linear-gradient(to bottom,
        #3b180a 0%, #240b03 15%,
        #00f3ff 15%, rgba(0,243,255,0.1) 15.2%,
        #240b03 15.2%, #140501 40%,
        #00f3ff 40%, rgba(0,243,255,0.1) 40.2%,
        #140501 40.2%, #0a0200 70%,
        #00f3ff 70%, rgba(0,243,255,0.1) 70.2%,
        #0a0200 70.2%, #000000 100%
    );
    transition: transform 0.15s linear;
    z-index: 0;
}

/* Stratum labels */
.stratum-label {
    position: absolute;
    width: 100%;
    text-align: center;
    font-family: 'Oxanium', sans-serif;
    font-weight: 700;
    font-size: 14px;
    color: rgba(0, 243, 255, 0.15);
    letter-spacing: 0.3em;
    text-transform: uppercase;
    pointer-events: none;
    text-shadow: 0 0 10px rgba(0, 243, 255, 0.05);
}

/* Static grain texture overlay */
.shaft-texture {
    position: absolute; inset: 0; opacity: 0.2; pointer-events: none;
    background-image:
        repeating-linear-gradient(0deg, transparent, transparent 4px, rgba(0,0,0,0.5) 4px, rgba(0,0,0,0.5) 8px),
        repeating-linear-gradient(90deg, transparent, transparent 4px, rgba(0,0,0,0.3) 4px, rgba(0,0,0,0.3) 8px);
    mix-blend-mode: multiply;
    z-index: 1;
}

/* Static 3D side shadows */
.shaft-shadows {
    position: absolute; inset: 0; pointer-events: none; z-index: 1;
    background: linear-gradient(90deg, rgba(0,0,0,0.95) 0%, rgba(0,0,0,0) 25%, rgba(0,0,0,0) 75%, rgba(0,0,0,0.95) 100%);
    box-shadow: inset 0 0 30px rgba(0,0,0,0.8);
}

/* SOFT LAYER (Target Zone) */
.soft-layer {
    position: absolute; left: 10px; right: 10px;
    background: rgba(0,243,255,0.03);
    border: 1px dashed rgba(0,243,255,0.2);
    border-radius: 2px;
    transition: height 0.3s ease, border-color 0.2s, background 0.2s;
    z-index: 2;
}
.soft-layer.resonating {
    background: rgba(0,255,102,0.08);
    border: 1px solid rgba(0,255,102,0.4);
    box-shadow: 0 0 15px rgba(0,255,102,0.15), inset 0 0 15px rgba(0,255,102,0.1);
}
.soft-layer.grinding {
    background: rgba(255,0,85,0.08);
    border: 1px solid rgba(255,0,85,0.4);
    box-shadow: 0 0 15px rgba(255,0,85,0.2), inset 0 0 15px rgba(255,0,85,0.1);
}

/* ══════════ HIGH-TECH PLASMA DRILL ══════════ */
.drill-bit {
    --drill-glow: #00f3ff;
    position: absolute;
    left: 50%; transform: translateX(-50%);
    width: 32px; height: 56px;
    z-index: 10;
    filter: drop-shadow(0 5px 15px var(--drill-glow));
}
.drill-cable {
    position: absolute;
    bottom: 100%; left: 50%; transform: translateX(-50%);
    width: 4px; height: 1200px;
    background: linear-gradient(90deg, #000 0%, var(--drill-glow) 50%, #000 100%);
    box-shadow: 0 0 15px var(--drill-glow);
    opacity: 0.9;
}
.drill-mount {
    position: absolute;
    top: 0; left: 20%; right: 20%; height: 8px;
    background: linear-gradient(90deg, #1e293b, #94a3b8, #1e293b);
    border-radius: 2px 2px 0 0;
    border-bottom: 2px solid var(--drill-glow);
    z-index: 2;
}
.drill-body {
    position: absolute;
    top: 8px; bottom: 0; left: 0; right: 0;
    clip-path: polygon(10% 0, 90% 0, 100% 20%, 100% 70%, 50% 100%, 0 70%, 0 20%);
    background: linear-gradient(90deg, #020617 0%, #475569 25%, #f8fafc 50%, #334155 75%, #020617 100%);
    overflow: hidden;
    z-index: 1;
}
.drill-threads {
    position: absolute;
    inset: -30px;
    background-image: repeating-linear-gradient(
        -25deg,
        transparent 0, transparent 8px,
        var(--drill-glow) 8px, #fff 10px, var(--drill-glow) 12px,
        rgba(0,0,0,0.8) 12px, rgba(0,0,0,0.8) 16px
    );
    background-size: 100% 32px;
    mix-blend-mode: hard-light;
    opacity: 0.9;
    animation: spin-drill 0.2s linear infinite;
    animation-play-state: paused;
}
.plasma-beam {
    position: absolute;
    top: 98%; left: 50%; transform: translateX(-50%);
    width: 4px; height: 0px;
    background: #fff;
    box-shadow: 0 0 15px 5px var(--drill-glow), 0 0 30px 10px var(--drill-glow);
    border-radius: 0 0 10px 10px;
    transition: height 0.1s ease-out, opacity 0.1s;
    z-index: 0;
}
@keyframes spin-drill {
    to { background-position: 0 32px; }
}

/* --- DRILL STATES --- */
.drill-bit.active .drill-threads { animation-play-state: running; }
.drill-bit.active .plasma-beam { height: 45px; opacity: 1; }
.drill-bit.damage {
    --drill-glow: #ff0055;
    animation: drill-shake 0.1s infinite;
}
.drill-bit.damage .drill-threads {
    animation-play-state: running;
    animation-duration: 0.4s;
    opacity: 0.6;
}
.drill-bit.damage .plasma-beam {
    height: 15px;
    opacity: 0.5;
    animation: beam-sputter 0.1s infinite;
}

@keyframes drill-shake {
    0%, 100% { transform: translateX(-50%); }
    25% { transform: translateX(calc(-50% - 2px)) rotate(-2deg); }
    75% { transform: translateX(calc(-50% + 2px)) rotate(2deg); }
}
@keyframes beam-sputter {
    0%, 100% { height: 15px; opacity: 0.5; }
    50% { height: 25px; opacity: 0.8; }
}

/* INTEGRITY GAUGE */
.integrity-gauge {
    width: 14px; background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 3px; position: relative; overflow: hidden;
    display: flex; align-items: flex-end; padding: 2px;
}
.integrity-fill {
    width: 100%; border-radius: 1px;
    transition: height 0.12s linear, background 0.3s, box-shadow 0.3s;
    background: #10b981;
    box-shadow: 0 0 10px #10b981;
}

/* ══════════ LOOT TRAY ══════════ */
.loot-tray {
    display: flex; gap: 8px; margin-bottom: 16px;
    min-height: 36px; flex-wrap: wrap;
}
.loot-item {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 10px;
    background: rgba(0,255,102,0.05);
    border: 1px solid rgba(0,255,102,0.3);
    border-radius: 4px; font-size: 12px;
    color: #00ff66; letter-spacing: 0.05em;
    animation: loot-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
@keyframes loot-pop {
    0% { transform: scale(0.8) translateY(10px); opacity: 0; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}
.loot-empty {
    font-size: 12px; color: #475569;
    letter-spacing: 0.15em; text-transform: uppercase;
    line-height: 36px; width: 100%; text-align: center;
    border: 1px dashed rgba(255,255,255,0.1);
    border-radius: 4px;
}

/* ══════════ BUTTONS ══════════ */
.drill-btn {
    width: 100%; padding: 16px 10px; border-radius: 4px;
    font-family: 'Oxanium', sans-serif; font-weight: 700;
    font-size: 14px; letter-spacing: 0.15em; text-transform: uppercase;
    cursor: pointer; transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); border: 1px solid;
    position: relative; overflow: hidden;
    background: none;
}
.drill-btn:active { transform: scale(0.98); }
.drill-btn:disabled { opacity: 0.3; cursor: not-allowed; filter: grayscale(1); }
.drill-btn-extract {
    background: rgba(0,255,102,0.05);
    border-color: #10b981; color: #10b981;
}
.drill-btn-extract:hover:not(:disabled) {
    background: rgba(0,255,102,0.15); color: #fff;
    box-shadow: 0 0 25px rgba(0,255,102,0.2);
    border-color: #00ff66;
}
.drill-btn-start {
    background: rgba(0,243,255,0.05);
    border-color: #00f3ff; color: #00f3ff;
}
.drill-btn-start:hover:not(:disabled) {
    background: rgba(0,243,255,0.15); color: #fff;
    box-shadow: 0 0 25px rgba(0,243,255,0.3);
    border-color: #fff;
}

/* ══════════ PARTICLES, FLOATS, MARKERS ══════════ */
.drill-particle {
    position: absolute; width: 3px; height: 3px;
    border-radius: 50%; pointer-events: none; z-index: 15; opacity: 0;
}
.loot-marker {
    position: absolute; width: 8px; height: 8px;
    border-radius: 50%; z-index: 4; pointer-events: none;
    animation: loot-glow 1.5s ease-in-out infinite;
}
@keyframes loot-glow {
    0%, 100% { opacity: 0.4; transform: scale(0.8); box-shadow: 0 0 5px currentColor; }
    50% { opacity: 1; transform: scale(1.5); box-shadow: 0 0 15px currentColor; }
}
.float-text {
    position: absolute; left: 50%; transform: translateX(-50%);
    font-family: 'Oxanium', sans-serif; font-weight: 700; font-size: 14px;
    white-space: nowrap; pointer-events: none; z-index: 20;
    animation: float-up 1.8s ease-out forwards;
}
@keyframes float-up {
    0% { opacity: 1; transform: translateX(-50%) translateY(0); }
    100% { opacity: 0; transform: translateX(-50%) translateY(-60px); }
}

/* ══════════ OVERLAYS ══════════ */
.drill-overlay-result {
    position: absolute; inset: 0;
    background: rgba(6, 10, 18, 0.95);
    backdrop-filter: blur(8px); z-index: 50;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    padding: 30px; opacity: 0; pointer-events: none;
    transition: opacity 0.35s; border-radius: 8px;
}
.drill-overlay-result.active { opacity: 1; pointer-events: auto; }
.overlay-icon { width: 56px; height: 56px; margin-bottom: 16px; font-size: 48px; text-align: center; }
.overlay-title {
    font-family: 'Oxanium', sans-serif; font-weight: 700; font-size: 20px;
    letter-spacing: 0.2em; text-transform: uppercase; margin-bottom: 8px;
}
.overlay-sub {
    font-size: 12px; color: #94a3b8; text-align: center;
    line-height: 1.6; margin-bottom: 24px; max-width: 280px;
}
.overlay-loot-box {
    width: 100%; background: rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px; padding: 16px; margin-bottom: 24px;
}
.overlay-loot-title {
    font-size: 11px; color: #64748b; letter-spacing: 0.15em;
    text-transform: uppercase; margin-bottom: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.05); padding-bottom: 6px;
}
.overlay-loot-items { display: flex; flex-direction: column; gap: 6px; }
.overlay-loot-row { display: flex; justify-content: space-between; font-size: 13px; }
.overlay-loot-row .name { color: #cbd5e1; }
.overlay-loot-row .value { font-weight: bold; font-family: 'Oxanium', sans-serif; }
.text-fail { color: #ff0055; text-shadow: 0 0 15px rgba(255,0,85,0.5); }
.text-win { color: #00ff66; text-shadow: 0 0 15px rgba(0,255,102,0.5); }

/* Idle hint */
.idle-hint {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    pointer-events: none; z-index: 6; opacity: 0.4;
}
.idle-hint-text {
    font-family: 'Oxanium', sans-serif; font-size: 12px;
    letter-spacing: 0.2em; text-transform: uppercase; color: #00f3ff;
}
.idle-hint-arrow {
    font-size: 24px; color: #00f3ff;
    animation: hint-bob 1.5s ease-in-out infinite;
}
@keyframes hint-bob {
    0%, 100% { transform: translateY(0); } 50% { transform: translateY(8px); }
}

/* ══════════ MOBILE ══════════ */
@media (max-width: 500px) {
    .drill-panel {
        max-width: 100%;
        height: 100%;
        border-radius: 0;
        padding: 12px;
        display: flex;
        flex-direction: column;
    }
    .game-area {
        flex: 1;
        height: auto;
        min-height: 200px;
    }
}

/* ══════════ LANDSCAPE MOBILE ══════════ */
@media (max-height: 440px) and (orientation: landscape) {
    #drill-overlay {
        align-items: stretch;
    }
    .drill-panel {
        max-width: 100%;
        height: 100%;
        border-radius: 0;
        padding: 8px 12px;
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto 1fr auto;
        gap: 0 12px;
        overflow: hidden;
    }
    .drill-header {
        grid-column: 1 / -1;
        padding-bottom: 6px;
        margin-bottom: 6px;
    }
    .drill-header-title { font-size: 13px; }
    .seismo-wrap {
        grid-column: 2 / 3;
        grid-row: 2 / 3;
        height: 32px;
        margin-bottom: 6px;
        align-self: start;
    }
    .drill-stats-row {
        grid-column: 2 / 3;
        grid-row: 2 / 3;
        align-self: start;
        margin-top: 38px;
        padding: 0 0 6px 0;
        margin-bottom: 6px;
        font-size: 10px;
    }
    .game-area {
        grid-column: 1 / 2;
        grid-row: 2 / 4;
        height: auto;
        min-height: 0;
        margin-bottom: 0;
    }
    .loot-tray {
        grid-column: 2 / 3;
        grid-row: 2 / 3;
        align-self: end;
        margin-bottom: 0;
        min-height: 28px;
        max-height: 60px;
        overflow-y: auto;
    }
    .loot-item { padding: 3px 6px; font-size: 11px; }
    #drill-btn-main {
        grid-column: 2 / 3;
        grid-row: 3 / 4;
        padding: 10px 8px;
        font-size: 12px;
        align-self: end;
        margin-bottom: 0;
    }
    /* Result overlays — ensure they cover the grid */
    .drill-overlay-result {
        grid-column: 1 / -1;
        grid-row: 1 / -1;
        padding: 16px;
    }
    .overlay-title { font-size: 16px; }
    .overlay-sub { font-size: 12px; margin-bottom: 12px; }
    .overlay-loot-box { padding: 10px; margin-bottom: 12px; }
    .overlay-icon { width: 40px; height: 40px; font-size: 36px; margin-bottom: 10px; }
}

/* Extra-small landscape (very short phones like iPhone SE landscape ~320px) */
@media (max-height: 360px) and (orientation: landscape) {
    .drill-panel { padding: 4px 8px; gap: 0 8px; }
    .drill-header { padding-bottom: 4px; margin-bottom: 4px; }
    .drill-header-title { font-size: 12px; gap: 4px; }
    .drill-header-title svg { width: 14px; height: 14px; }
    .drill-header-tier { font-size: 10px; }
    .seismo-wrap { height: 26px; margin-bottom: 4px; }
    .drill-stats-row { margin-top: 30px; font-size: 10px; padding-bottom: 4px; margin-bottom: 4px; }
    .drill-stats-row .val { font-size: 11px; }
    .depth-gauge { width: 22px; }
    .depth-number { font-size: 10px; }
    .integrity-gauge { width: 10px; }
    .drill-bit { width: 26px; height: 46px; }
    .loot-tray { max-height: 48px; }
    .loot-item { padding: 2px 4px; font-size: 10px; }
    #drill-btn-main { padding: 8px 6px; font-size: 12px; }
}
