:root {
    --bg-color: #0c0c0e;
    --primary: #cba85a;
    /* Gold/Amber for Boss vibe */
    --primary-hover: #e8c97d;
    --text-main: #f0f0f5;
    --text-muted: #8e8e9c;
    --glass-bg: rgba(20, 20, 25, 0.65);
    --glass-border: rgba(255, 255, 255, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: radial-gradient(circle at 50% 60%, #151515 0%, #000000 80%);
    color: var(--text-main);
    font-family: 'Outfit', sans-serif;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
}

/* Typography */
h1 {
    font-size: 2.5rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--primary);
    letter-spacing: 1px;
    line-height: 1.1;
    /* Closer to subtitle */
    margin-bottom: 2rem;
    /* Further from content */
}

.subtitle {
    font-size: 1.2rem;
    font-weight: 300;
    color: var(--text-muted);
}

h2 {
    font-size: 1.8rem;
    font-weight: 500;
    margin-bottom: 10px;
}

h3 {
    font-size: 1.2rem;
    font-weight: 500;
    color: var(--primary);
    margin-bottom: 15px;
}

p {
    font-size: 1.05rem;
    line-height: 1.6;
    margin-bottom: 20px;
    color: #d0d0d8;
}

/* Canvas & 3D Studio Space */
.canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.floor-glow {
    position: absolute;
    bottom: -15%;
    left: 50%;
    transform: translateX(-50%) rotateX(75deg);
    width: 90vw;
    height: 50vh;
    background: radial-gradient(ellipse at center, rgba(6, 6, 8, 0.9) 0%, rgba(5, 5, 7, 0) 70%);
    pointer-events: none;
    z-index: 1;
}

canvas,
.overlay-animation {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transform: scale(0.74) translateY(-5%);
}

canvas {
    filter: contrast(1.1) brightness(0.9) drop-shadow(0 40px 60px rgba(0, 0, 0, 0.8));
    transition: filter 0.3s;
    position: relative;
    /* Enable z-index natively without class override */
    z-index: 2;
}

.overlay-animation {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 3;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.overlay-animation.active {
    opacity: 1;
}

/* No flies info animation */
.no-flies-info {
    position: absolute;
    top: 30%;
    right: calc(42% + 15vw);
    /* Move to left side of the pile */
    display: flex;
    flex-direction: row-reverse;
    /* Text then Line pointing right */
    align-items: center;
    opacity: 0;
    pointer-events: none;
    z-index: 9999;
}

.no-flies-info .info-line {
    width: 0px;
    height: 2px;
    background: var(--primary);
    box-shadow: 0 0 10px var(--primary);
    transition: width 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.no-flies-info .info-text {
    width: 180px;
    margin-right: 10px;
    color: var(--primary);
    font-size: 0.9rem;
    line-height: 1.3;
    background: rgba(0, 0, 0, 0.85);
    padding: 10px;
    border-radius: 12px;
    border: 1px solid var(--primary);
    transform: translateX(-30px);
    opacity: 0;
    transition: all 0.5s ease 0.4s;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
}

.no-flies-info.show {
    opacity: 1;
}

.no-flies-info.show .info-line {
    width: 120px;
}

.no-flies-info.show .info-text {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

#webcamVideo {
    display: none;
}

/* Glass Overlay Framework */
.glass-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(12px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.5s ease, backdrop-filter 0.5s ease;
}

.glass-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    backdrop-filter: blur(0px);
}

.modal-content {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 1rem 3rem;
    /* Reduced top/bottom padding */
    border-radius: 16px;
    width: 800px;
    max-width: 90%;
    box-shadow: 0 24px 40px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.modal-content h1 {
    margin-bottom: 2rem;
    margin-top: 1rem;
}

.modal-content p {
    text-align: left;
}

.btn-primary,
.btn-secondary {
    background: var(--primary);
    color: #000;
    border: none;
    padding: 15px 40px;
    font-size: 1.1rem;
    font-weight: 800;
    cursor: pointer;
    border-radius: 8px;
    transition: transform 0.2s, background 0.2s;
    font-family: inherit;
    margin-top: 10px;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Tutorial Specific Container Framework */
#tutorialBoxContainer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    pointer-events: auto;
    /* Active layer */
}

#tutorialBoxContainer.hidden {
    display: none !important;
}

#tutorialBoxContainer * {
    pointer-events: auto;
    /* Ensure buttons work */
}

.tutorial-box {
    background: var(--primary);
    color: #000;
    padding: 2rem;
    border-radius: 12px;
    width: 550px;
    position: absolute;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    transition: all 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
    pointer-events: auto !important;
    z-index: 9999;
    /* Ensure box handles clicks */
}

.tutorial-box * {
    pointer-events: auto !important;
    /* Force children too */
}

.tutorial-box h2 {
    color: #000;
    font-weight: 800;
}

.tutorial-box p {
    color: #111;
    margin-bottom: 15px;
    text-align: left;
}

.tutorial-box .btn-secondary {
    background: #111;
    color: var(--primary);
    border: none;
    padding: 10px 20px;
}

.tutorial-focus {
    z-index: 200 !important;
    /* explicitly omitting position override so absolute objects stay exactly where they are */
    pointer-events: none !important;
    /* Disable clicking during tutorial */
    border-radius: 12px;
}

.highlight-ring {
    position: absolute;
    border: 3px solid var(--primary);
    border-radius: 8px;
    box-shadow: 0 0 15px var(--primary), inset 0 0 15px var(--primary);
    pointer-events: none !important;
    /* Ring should never block clicks */
    z-index: 150;
    transition: all 0.5s ease;
    background: rgba(203, 168, 90, 0.05);
    /* very subtle tint */
}

/* Main UI Elements */
.main-ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.main-ui.hidden {
    display: none;
}

.main-ui>* {
    pointer-events: auto;
}

.top-bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 20px 40px;
    z-index: 10000;
    /* Absolute highest tier */
    pointer-events: none;
    /* Allow clicks through empty top bar */
}

.top-bar>* {
    pointer-events: auto;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 300;
}

.dot {
    width: 10px;
    height: 10px;
    background: #0f0;
    border-radius: 50%;
    box-shadow: 0 0 8px #0f0;
}

.badge {
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid #333;
    font-size: 0.9rem;
}

.total-weight {
    font-size: 1.2rem;
    font-weight: 300;
}

#pileWeightDisplay {
    font-weight: 800;
    color: var(--primary);
    font-size: 1.5rem;
    position: relative;
    z-index: 9999999 !important;
    /* Ultimate absolute top layer */
}

.glass-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(8px);
    border-radius: 12px;
    padding: 25px;
    width: 320px;
}

.left-panel {
    position: absolute;
    left: 40px;
    top: 28%;
    transform: translateY(-50%);
    width: 250px;
    padding: 20px;
}

.left-panel ul {
    list-style: none;
    margin-top: 10px;
}

.left-panel li {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-weight: 300;
    font-size: 0.95rem;
}

.modal-content p {
    margin-bottom: 1.2rem;
    color: rgba(255, 255, 255, 0.8);
    line-height: 1.5;
}

.device-preference {
    font-weight: 500;
    color: #cba85a !important;
    /* Gold accent */
    font-size: 0.95rem;
    margin-top: 20px !important;
}

.welcome-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 25px;
    margin-top: 15px;
}

.data-disclaimer {
    font-size: 0.75rem !important;
    line-height: 1.3 !important;
    opacity: 0.5;
    font-style: italic;
    margin-top: 20px;
}

.modal-content h3 {
    font-size: 0.95rem;
}

.percent {
    font-weight: 800;
    color: var(--primary);
    font-family: monospace;
    font-size: 1.05rem;
}

.placeholder-text {
    font-style: italic;
    color: var(--text-muted);
    text-align: center;
    margin-top: 30px;
}

/* Dynamic Spotlight UI for Action Information (Positioned at Bottom Center) */
.action-info-container {
    position: absolute;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);
    width: 720px;
    max-width: 55vw;
    height: auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    padding: 18px 24px;
    border-radius: 16px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease, transform 0.5s ease;
    z-index: 50;
}

.action-info-container.active {
    opacity: 1;
    pointer-events: auto;
}

/* Dedicated Animation Area to the Left of Text Box */
.action-media {
    position: relative;
    width: 110px;
    min-width: 110px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 18px;
    flex-shrink: 0;
}

/* Standalone Large Video Animation on Bottom-Left (Outside Info Box, Below Played Cards) */
.action-bg-video {
    position: fixed;
    bottom: -10px;
    left: 20px;
    width: 390px;
    height: 390px;
    object-fit: contain;
    opacity: 0.95;
    z-index: 60;
    pointer-events: none;
    filter: drop-shadow(0 15px 35px rgba(0, 0, 0, 0.9));
    transition: opacity 0.4s ease;
    border-radius: 14px;
    display: none;
}

.action-extra-img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 95px;
    max-height: 95px;
    height: auto;
    width: auto;
    object-fit: contain;
    display: none;
    z-index: 2;
    filter: drop-shadow(0 0 25px rgba(203, 168, 90, 0.85));
    animation: pulse-fade 3s infinite ease-in-out;
    pointer-events: none;
}

.action-content {
    position: relative;
    z-index: 2;
    text-align: left;
    flex: 1;
    border-left: 3px solid var(--primary);
    padding-left: 20px;
}

.action-content h2 {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 6px;
    text-shadow: 0 4px 15px rgba(0, 0, 0, 0.8);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.action-content p {
    font-size: 0.88rem;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
    font-weight: 300;
    margin-bottom: 0;
}

@keyframes pulse-fade {

    0%,
    100% {
        opacity: 0.45;
        transform: translate(-50%, -50%) scale(0.92);
    }

    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.08);
    }
}

/* Active Cards Display Node */
.active-cards-zone {
    position: absolute;
    top: 50%;
    left: 40px;
    width: 350px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    z-index: 55;
}

.active-container {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-start;
}

.active-container .card-wrapper {
    margin: 0;
    transform: none !important;
    cursor: pointer;
}

.active-container .card-wrapper:hover {
    transform: scale(1.15) !important;
    z-index: 100 !important;
}

.active-container .card-wrapper img {
    width: 75px;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(203, 168, 90, 0.4);
    border: 2px solid var(--primary);
    transition: transform 0.2s;
}

/* Action Cards Panel (Positioned on the Right Side) */
.bottom-panel {
    position: absolute;
    right: 35px;
    top: 50%;
    left: auto;
    bottom: auto;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: auto;
    height: auto;
    z-index: 60;
}

.card-hand {
    display: grid;
    grid-template-columns: repeat(2, minmax(130px, 155px));
    gap: 14px 14px;
    margin-bottom: 0;
    transition: all 0.3s ease;
}

@media (max-height: 768px) {
    .card-hand {
        grid-template-columns: repeat(2, minmax(115px, 135px));
        gap: 10px 10px;
    }
}

.card-hand:hover {
    margin-bottom: 0;
}

.card-wrapper {
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    margin-left: 0;
    cursor: pointer;
    transform-origin: center center;
    position: relative;
}

.card-wrapper:first-child {
    margin-left: 0;
}

.card-wrapper img {
    width: 100%;
    height: auto;
    border-radius: 10px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.7);
    display: block;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.card-wrapper:nth-child(1),
.card-wrapper:nth-child(2),
.card-wrapper:nth-child(3),
.card-wrapper:nth-child(4),
.card-wrapper:nth-child(5),
.card-wrapper:nth-child(6) {
    transform: none;
    z-index: 1;
}

.card-wrapper:hover {
    transform: scale(1.04) translateY(-2px) !important;
    z-index: 100 !important;
}

.card-wrapper:hover img {
    opacity: 0.45;
    filter: brightness(0.65) grayscale(0.2);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.7);
    border-color: rgba(203, 168, 90, 0.4);
}

.card-wrapper:hover+.card-wrapper {
    transform: none !important;
}

.card-wrapper.active img {
    opacity: 0.35;
    pointer-events: none;
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(203, 168, 90, 0.5);
}

/* Floating Card Magnifier / High-Res Preview on Hover */
.card-hover-preview {
    position: absolute;
    right: 365px;
    top: 50%;
    transform: translateY(-50%) scale(0.85);
    z-index: 500;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.9), 0 0 40px rgba(203, 168, 90, 0.35);
    border-radius: 16px;
    background: rgba(15, 15, 20, 0.88);
    backdrop-filter: blur(16px);
    border: 1.5px solid var(--primary);
    padding: 6px;
    will-change: transform, opacity;
}

.card-hover-preview.show {
    opacity: 1;
    transform: translateY(-50%) scale(1);
}

.card-hover-preview.hidden {
    display: none;
}

.card-hover-preview img {
    width: 340px;
    height: auto;
    display: block;
    border-radius: 12px;
}

/* Flying Card Transition Node */
.flying-card-anim {
    position: fixed;
    z-index: 99999;
    pointer-events: none;
    transform-origin: top left;
    transition: transform 0.55s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.55s ease;
    will-change: transform, opacity;
}

@keyframes pop-in {
    0% { transform: scale(0.75); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

.active-container .card-wrapper.pop-in {
    animation: pop-in 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@media (max-height: 768px) {
    .card-hover-preview {
        right: 320px;
    }
    .card-hover-preview img {
        width: 290px;
    }
}