:root {
    /* Color Palette - Premium Dark Fantasy */
    --clr-bg-deep: #050510;
    --clr-bg-surface: #0a0a1a;
    --clr-bg-accent: #151530;
    --clr-primary: #833ab4;
    --clr-primary-glow: rgba(131, 58, 180, 0.5);
    --clr-gold: #c3922e;
    --clr-gold-light: #f3d179;
    --clr-gold-glow: rgba(195, 146, 46, 0.4);
    --clr-danger: #ff4757;
    --clr-success: #2ed573;
    --clr-mana: #1e90ff;
    --clr-block: #70a1ff;
    --clr-text-main: #f1f2f6;
    --clr-text-dim: #a4b0be;

    /* Fonts */
    --font-heading: 'Cinzel', serif;
    --font-ui: 'Outfit', sans-serif;
    --font-body: 'Lora', serif;

    /* Spacing & Sizes */
    --card-w: 160px;
    --card-h: 220px;
    --card-w-mob: 100px;
    --card-h-mob: 140px;
}

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

body {
    font-family: var(--font-body);
    background-color: #000;
    color: var(--clr-text-main);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    touch-action: none;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background-color: var(--clr-bg-deep);
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 1200px;
}

#fx-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

#vignette {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle, transparent 20%, rgba(0,0,0,0.8) 100%);
    z-index: 2;
    pointer-events: none;
}

/* -------------------------------------------------------------
   GLOBAL HUD
------------------------------------------------------------- */
#global-hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    padding: 0 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(to bottom, rgba(0,0,0,0.9), transparent);
    z-index: 100;
    font-family: var(--font-heading);
    transition: opacity 0.4s ease;
}

#global-hud.hide { opacity: 0; pointer-events: none; }

.hud-left, .hud-right { display: flex; align-items: center; gap: 20px; }

.gold-box {
    background: rgba(0,0,0,0.5);
    padding: 5px 15px;
    border: 1px solid var(--clr-gold);
    border-radius: 20px;
    color: var(--clr-gold);
    font-weight: 800;
    box-shadow: 0 0 10px var(--clr-gold-glow);
}

#relic-container {
    display: flex;
    gap: 8px;
}

.relic-icon {
    width: 32px;
    height: 32px;
    background: var(--clr-bg-accent);
    border: 1px solid var(--clr-gold);
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    box-shadow: 0 0 5px var(--clr-gold-glow);
    cursor: help;
}

.floor-display {
    font-size: 1.4rem;
    color: var(--clr-text-main);
    letter-spacing: 3px;
    text-shadow: 0 0 10px var(--clr-primary-glow);
}

.icon-btn {
    background: none;
    border: 1px solid var(--clr-text-dim);
    color: var(--clr-text-main);
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
}

.icon-btn:hover { background: var(--clr-bg-accent); border-color: var(--clr-gold); }

/* -------------------------------------------------------------
   SCREENS & LAYERS
------------------------------------------------------------- */
#ui-layer {
    position: absolute;
    inset: 0;
    z-index: 10;
}

.screen {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.screen.hide {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

/* -------------------------------------------------------------
   PREMIUM BUTTONS & PANELS
------------------------------------------------------------- */
.premium-btn {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.2rem;
    padding: 12px 30px;
    background: linear-gradient(135deg, #2c3e50, #000);
    color: var(--clr-text-main);
    border: 2px solid var(--clr-gold);
    border-radius: 4px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
}

.premium-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    transform: translateX(-100%);
    transition: transform 0.5s;
}

.premium-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 25px var(--clr-gold-glow);
    background: linear-gradient(135deg, var(--clr-bg-accent), #000);
}

.premium-btn:hover::before { transform: translateX(100%); }

.premium-btn.main-btn {
    font-size: 1.8rem;
    padding: 20px 60px;
    border-radius: 50px;
}

.premium-btn.outline { background: transparent; }

.premium-panel {
    background: rgba(10, 10, 26, 0.9);
    border: 1px solid var(--clr-gold);
    padding: 30px;
    border-radius: 4px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.9), inset 0 0 40px rgba(195, 146, 46, 0.1);
    backdrop-filter: blur(15px);
    max-width: 500px;
    width: 95%;
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}

.panel-title {
    font-family: var(--font-heading);
    font-size: 2rem;
    color: var(--clr-gold);
    margin-bottom: 30px;
    text-align: center;
    border-bottom: 2px solid var(--clr-gold);
    padding-bottom: 15px;
}

/* -------------------------------------------------------------
   MENU SCREEN
------------------------------------------------------------- */
#screen-menu { background: radial-gradient(circle at center, var(--clr-bg-surface), var(--clr-bg-deep)); }

.logo-container { text-align: center; margin-bottom: 60px; position: relative; display: flex; flex-direction: column; align-items: center; }

.main-menu-icon {
    width: 120px;
    height: 120px;
    margin-bottom: 20px;
    filter: drop-shadow(0 0 20px var(--clr-gold-glow));
    animation: float 4s ease-in-out infinite;
}

.logo-text {
    font-family: var(--font-heading);
    font-size: clamp(2.5rem, 10vw, 5rem);
    background: linear-gradient(to bottom, #fff, #aaa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: clamp(5px, 2vw, 15px);
    margin-bottom: -10px;
}

.sub-logo {
    font-family: var(--font-heading);
    font-size: clamp(1.5rem, 5vw, 3rem);
    color: var(--clr-gold);
    letter-spacing: clamp(4px, 1vw, 8px);
}

.glow-sphere {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 300px; height: 300px;
    background: radial-gradient(circle, var(--clr-primary-glow), transparent 70%);
    z-index: -1;
    animation: pulseGlow 4s infinite alternate;
}

.version-tag {
    position: absolute;
    bottom: 20px;
    color: var(--clr-text-dim);
    font-family: var(--font-ui);
    font-size: 0.8rem;
    letter-spacing: 2px;
}

/* -------------------------------------------------------------
   MAP SCREEN
------------------------------------------------------------- */
#screen-map { background: var(--clr-bg-deep); }

.map-scroll {
    width: 100%;
    max-width: 800px;
    padding: 100px 5% 50px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.map-title {
    font-size: 2.5rem;
    color: var(--clr-text-main);
    margin-bottom: 50px;
}

.node-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 40px;
    width: 100%;
    padding: 20px;
}

.map-node {
    width: 80px; height: 80px;
    border-radius: 50%;
    background: var(--clr-bg-surface);
    border: 2px solid var(--clr-text-dim);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    cursor: pointer;
    position: relative;
    transition: all 0.3s;
    justify-self: center;
}

.map-node.active {
    border-color: var(--clr-gold);
    box-shadow: 0 0 20px var(--clr-gold-glow);
}

.map-node.active:hover {
    transform: scale(1.1);
    background: var(--clr-bg-accent);
}

.map-node.completed { opacity: 0.3; pointer-events: none; }

/* -------------------------------------------------------------
   COMBAT SCREEN
------------------------------------------------------------- */
#screen-combat { 
    background: var(--clr-bg-deep); 
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.combat-scene {
    height: calc(100% - 150px);
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    padding-top: 60px;
    min-height: 0;
}

.enemy-platform, .player-platform {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 10px;
}

.enemy-area, .player-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    width: 250px;
}

/* Entities */
.entity-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
}

.hero-sprite {
    width: clamp(60px, 15vh, 150px);
    height: clamp(80px, 20vh, 200px);
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 150"><path d="M40,20 Q50,0 60,20 L75,50 L85,110 L50,140 L15,110 L25,50 Z" fill="%232c3e50" stroke="%23ecf0f1" stroke-width="3"/><rect x="40" y="5" width="20" height="20" fill="%238e44ad"/><path d="M25,60 L75,60 M50,45 L50,110" stroke="%23ecf0f1" stroke-width="4"/></svg>') no-repeat center;
    background-size: contain;
    filter: drop-shadow(0 20px 20px rgba(0,0,0,0.8));
    animation: breathe 3s infinite alternate ease-in-out;
}

.enemy-sprite {
    width: clamp(80px, 18vh, 180px);
    height: clamp(100px, 22vh, 220px);
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    filter: drop-shadow(0 20px 20px rgba(0,0,0,0.8));
    animation: breathe 2.5s infinite alternate-reverse ease-in-out;
}

/* Intent Bubble */
.intent-bubble {
    position: absolute;
    top: -40px;
    background: rgba(0,0,0,0.8);
    border: 1px solid var(--clr-danger);
    padding: 5px 15px;
    border-radius: 20px;
    font-family: var(--font-heading);
    font-size: 1.2rem;
    box-shadow: 0 0 15px var(--clr-danger);
    animation: bounce 2s infinite;
}

/* Vitals & Health Bars */
.vitals { width: 100%; max-width: 200px; margin-top: 10px; }

.health-bar-container {
    height: 12px;
    background: #111;
    border: 1px solid #333;
    border-radius: 6px;
    position: relative;
    overflow: visible;
}

.health-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #b33939, #ff5252);
    width: 100%;
    border-radius: 6px;
    transition: width 0.4s cubic-bezier(0.19, 1, 0.22, 1);
}

.health-text {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.7rem;
    font-weight: 900;
    font-family: var(--font-ui);
}

.block-indicator {
    position: absolute;
    left: -15px;
    top: -10px;
    width: 30px; height: 30px;
    background: var(--clr-block);
    border: 2px solid #fff;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 900;
    font-size: 0.8rem;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
    z-index: 5;
}

.block-indicator.hide { display: none; }

.name-tag {
    text-align: center;
    font-family: var(--font-heading);
    color: var(--clr-text-dim);
    margin-top: 5px;
    font-size: 0.9rem;
}

/* Status Effects */
.status-bar {
    display: flex;
    gap: 5px;
    margin-bottom: 5px;
    height: 25px;
}

.status-icon {
    width: 20px; height: 20px;
    background-size: contain;
    position: relative;
    cursor: help;
}

.status-val {
    position: absolute;
    bottom: -5px; right: -5px;
    background: #000;
    color: #fff;
    font-size: 0.6rem;
    padding: 1px 3px;
    border-radius: 3px;
}

/* -------------------------------------------------------------
   COMBAT CONTROLS & CARDS
------------------------------------------------------------- */
#combat-controls {
    width: 100%;
    height: 150px;
    background: linear-gradient(to top, rgba(0,0,0,0.9), transparent);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    position: relative;
    z-index: 100;
}

/* Energy Orb */
.energy-inner {
    width: 100px; height: 100px;
    background: radial-gradient(circle at 30% 30%, var(--clr-mana), #000);
    border-radius: 50%;
    border: 3px solid #70a1ff;
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 0 30px rgba(30, 144, 255, 0.4);
}

.energy-wave {
    position: absolute;
    bottom: 0; left: 0; width: 200%; height: 100%;
    background: rgba(255,255,255,0.1);
    border-radius: 40%;
    animation: wave 4s linear infinite;
}

#energy-text {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    font-weight: 900;
    z-index: 2;
    text-shadow: 0 0 15px rgba(0,0,0,0.8);
}

/* Hand Section */
.hand-section {
    flex: 1;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding-bottom: 30px;
}

#hand-container {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    width: 100%;
    height: 100%;
    position: relative;
    overflow-x: auto;
    scrollbar-width: none;
}
#hand-container::-webkit-scrollbar { display: none; }

/* WORLD BEST 3D CARDS */
.game-card {
    width: var(--card-w);
    height: var(--card-h);
    background: var(--clr-bg-surface);
    border: 2px solid #555;
    border-radius: 12px;
    margin: 0 -30px;
    transition: transform 0.2s cubic-bezier(0.2, 0, 0.2, 1), box-shadow 0.2s;
    cursor: grab;
    position: relative;
    background: linear-gradient(135deg, #2c3e50 0%, #1a1a2a 100%);
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    padding: 12px;
    z-index: 10;
    transform-style: preserve-3d;
    will-change: transform;
    flex-shrink: 0;
    transform-origin: bottom center;
}

.game-card:hover {
    z-index: 100;
    transform: translateY(-50px) scale(1.2) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) !important;
    border-color: var(--clr-gold);
    box-shadow: 0 20px 40px rgba(0,0,0,1), 0 0 20px var(--clr-gold-glow);
}

.game-card.dragging {
    cursor: grabbing;
    z-index: 1000;
    opacity: 0.9;
    transform: scale(1.1) !important;
}

.card-cost-badge {
    position: absolute;
    top: -12px; left: -12px;
    width: 36px; height: 36px;
    background: var(--clr-mana);
    border: 2px solid #fff;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-heading);
    font-weight: 900;
    font-size: 1.2rem;
    box-shadow: 0 5px 10px rgba(0,0,0,0.5);
}

.card-name {
    font-family: var(--font-heading);
    font-size: 0.9rem;
    text-align: center;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    color: var(--clr-gold-light);
}

.card-art-box {
    flex: 1;
    background: rgba(0,0,0,0.3);
    border-radius: 6px;
    margin-bottom: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3rem;
}

.card-desc-box {
    font-size: 0.75rem;
    text-align: center;
    color: var(--clr-text-dim);
    line-height: 1.4;
    font-family: var(--font-ui);
}

.card-desc-box b { color: #fff; }

/* Card Types */
.game-card.type-attack { border-color: #b33939; }
.game-card.type-skill { border-color: #227093; }
.game-card.type-power { border-color: #833ab4; }

/* Piles */
.piles-section {
    display: flex;
    align-items: center;
    gap: 30px;
}

.pile-box {
    width: 70px; height: 90px;
    background: var(--clr-bg-accent);
    border: 2px solid var(--clr-text-dim);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-family: var(--font-heading);
}

.pile-box .count { font-size: 1.5rem; font-weight: 900; }
.pile-box .label { font-size: 0.6rem; color: var(--clr-text-dim); }

.end-turn-btn { font-size: 1rem; padding: 15px 25px; }

/* -------------------------------------------------------------
   SHOP & REWARDS
------------------------------------------------------------- */
.reward-overlay {
    background: rgba(0,0,0,0.9);
    width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.reward-title { font-size: 4rem; color: var(--clr-gold); margin-bottom: 40px; }

.reward-card-container { display: flex; gap: 20px; margin: 40px 0; }

.shop-panel {
    width: 90%; max-width: 1000px;
    background: var(--clr-bg-surface);
    border: 2px solid var(--clr-gold);
    padding: 30px;
}

.shop-item-grid {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 40px;
}

/* -------------------------------------------------------------
   ANIMATIONS
------------------------------------------------------------- */
@keyframes breathe {
    0% { transform: scale(1); }
    100% { transform: scale(1.05); }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

@keyframes wave {
    from { transform: translateX(0) rotate(0deg); }
    to { transform: translateX(-50%) rotate(360deg); }
}

@keyframes pulseGlow {
    from { transform: translate(-50%, -50%) scale(1); opacity: 0.3; }
    to { transform: translate(-50%, -50%) scale(1.5); opacity: 0.1; }
}

@keyframes floatUp {
    0% { transform: translateY(0); opacity: 1; }
    100% { transform: translateY(-100px); opacity: 0; }
}

.damage-number {
    position: absolute;
    top: 0;
    font-family: var(--font-heading);
    font-size: 3rem;
    font-weight: 900;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
}

.damage-number.show { animation: floatUp 1s forwards cubic-bezier(0.18, 0.89, 0.32, 1.28); opacity: 1; }
.damage-number.dmg { color: var(--clr-danger); text-shadow: 0 0 10px #000; }
.damage-number.block { color: var(--clr-block); text-shadow: 0 0 10px #000; }

.anim-hit { animation: hitShake 0.4s; }
@keyframes hitShake {
    0% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    50% { transform: translateX(10px); }
    75% { transform: translateX(-5px); }
    100% { transform: translateX(0); }
}

/* -------------------------------------------------------------
   RESPONSIVE
------------------------------------------------------------- */
@media (max-width: 1024px) {
    :root {
        --card-w: 120px;
        --card-h: 170px;
    }
    .game-card { margin: 0 -20px; }
}

@media (max-width: 600px) {
    :root {
        --card-w: 90px;
        --card-h: 130px;
    }
    .logo-container { margin-bottom: 20px; }
    .gold-box { font-size: 0.6rem; padding: 2px 6px; }
    .floor-display { font-size: 0.7rem; }
    .relic-icon { width: 20px; height: 20px; font-size: 0.7rem; }

    .combat-scene { height: calc(100% - 130px); padding-top: 60px; }
    #combat-controls { height: 130px; }
    .energy-inner { width: 50px; height: 50px; }
    #energy-text { font-size: 1.2rem; }
    
    .game-card { margin: 0 -15px; }
    .card-art-box { font-size: 1.5rem; }
    .card-cost-badge { width: 22px; height: 22px; font-size: 0.7rem; top: -6px; left: -6px; }

    .pile-box { width: 40px; height: 55px; }
    .end-turn-btn { padding: 6px 10px; font-size: 0.5rem; }

    .node-container { gap: 10px; grid-template-columns: repeat(2, 1fr); }
}

@media (max-height: 700px) {
    .combat-scene { padding-top: 30px; }
    .enemy-area, .player-area { width: 180px; margin: 0; }
    .vitals { margin-top: 2px; }
    .name-tag { font-size: 0.7rem; margin-top: 2px; }
    #combat-controls { height: clamp(120px, 25vh, 180px); }
    .hero-sprite, .enemy-sprite { transform: scale(0.9); }
    .energy-inner { width: 45px; height: 45px; }
}

@media (max-height: 600px) {
    .combat-scene { padding-top: 20px; }
    .hero-sprite, .enemy-sprite { display: none; } /* Hide large sprites on very short landscape or fold phones */
    #combat-controls { height: 120px; }
}
