/* ============ RESET & BASE ============ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --color-common: #9d9d9d;
    --color-uncommon: #1eff00;
    --color-rare: #0070dd;
    --color-epic: #a335ee;
    --color-legendary: #ff8000;
    --color-gold: #ffd100;
    --color-gold-dim: #b8960c;
    --color-bg: #0a0a14;
    --color-bg-card: #1a1a2e;
    --color-text: #e0d8c8;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Cinzel', serif;
    background: var(--color-bg);
    color: var(--color-text);
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    max-height: 100dvh;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
}

/* ============ BACKGROUND FLOURISH ============ */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 30% 20%, rgba(106, 27, 154, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 80%, rgba(0, 60, 140, 0.12) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(22, 22, 46, 0.9) 0%, var(--color-bg) 70%);
    z-index: 0;
    animation: bgShift 20s ease-in-out infinite alternate;
}

@keyframes bgShift {
    0%   { background-position: 0% 0%, 100% 100%, center; }
    100% { background-position: 100% 100%, 0% 0%, center; }
}

body::after {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.6) 100%);
    z-index: 0;
    pointer-events: none;
}

#particles {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.particle {
    position: absolute;
    border-radius: 50%;
    opacity: 0;
    animation: particleFloat linear infinite;
}

@keyframes particleFloat {
    0%   { transform: translateY(100vh) scale(0); opacity: 0; }
    10%  { opacity: 1; }
    90%  { opacity: 1; }
    100% { transform: translateY(-20vh) scale(1); opacity: 0; }
}

header, main, footer, .overlay {
    position: relative;
    z-index: 1;
}

/* ============ HEADER ============ */
header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    position: relative;
    flex-shrink: 0;
}

header h1 {
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--color-gold);
    text-shadow: 0 0 10px rgba(255, 209, 0, 0.3), 0 2px 4px rgba(0,0,0,0.5);
    letter-spacing: 2px;
    text-transform: uppercase;
}

#talentBtn {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(30, 30, 50, 0.8);
    border: 2px solid var(--color-gold-dim);
    border-radius: 8px;
    padding: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

#talentBtn:hover, #talentBtn:active {
    border-color: var(--color-gold);
    box-shadow: 0 0 12px rgba(255, 209, 0, 0.3);
}

.header-icon {
    width: 28px;
    height: 28px;
    display: block;
    image-rendering: pixelated;
}

/* ============ MAIN AREA ============ */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    gap: 10px;
    overflow: hidden;
    min-height: 0;
}

/* ============ BUFFS ============ */
#buffs {
    display: flex;
    gap: 8px;
    min-height: 24px;
    align-items: center;
    flex-shrink: 0;
    flex-wrap: wrap;
    justify-content: center;
}

.buff-icon {
    position: relative;
    width: 28px;
    height: 28px;
    border: 1px solid var(--color-gold-dim);
    border-radius: 4px;
    image-rendering: pixelated;
}

.buff-icon img { width: 100%; height: 100%; }

.buff-count {
    position: absolute;
    bottom: -2px;
    right: -2px;
    background: #000;
    color: #fff;
    font-size: 10px;
    padding: 0 3px;
    border-radius: 3px;
    font-family: sans-serif;
}

/* ============ CARD ============ */
.card-container {
    perspective: 1200px;
    width: 260px;
    height: 360px;
    flex-shrink: 0;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s ease;
    transform-style: preserve-3d;
}

.card-inner.flipped { transform: rotateY(180deg); }

.card-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 12px;
    overflow: hidden;
}

.card-back {
    background: linear-gradient(145deg, #1c1c3a, #0e0e20);
    border: 3px solid var(--color-gold-dim);
    border-radius: 12px;
}

.card-back-design {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255, 209, 0, 0.03) 10px, rgba(255, 209, 0, 0.03) 20px),
        repeating-linear-gradient(-45deg, transparent, transparent 10px, rgba(255, 209, 0, 0.03) 10px, rgba(255, 209, 0, 0.03) 20px);
}

.card-back-border {
    width: 80%;
    height: 85%;
    border: 2px solid rgba(255, 209, 0, 0.2);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-back-symbol {
    width: 80px;
    height: 80px;
    border: 3px solid rgba(255, 209, 0, 0.25);
    border-radius: 50%;
    position: relative;
}

.card-back-symbol::after {
    content: '?';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    color: rgba(255, 209, 0, 0.3);
    font-weight: 900;
}

.card-front {
    transform: rotateY(180deg);
    background: linear-gradient(180deg, #1a1a2e 0%, #12121f 100%);
    border: 3px solid var(--color-common);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 14px 14px;
    gap: 6px;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.card-front.rarity-common { border-color: var(--color-common); }
.card-front.rarity-uncommon { border-color: var(--color-uncommon); box-shadow: 0 0 20px rgba(30, 255, 0, 0.2), inset 0 0 20px rgba(30, 255, 0, 0.05); }
.card-front.rarity-rare { border-color: var(--color-rare); box-shadow: 0 0 20px rgba(0, 112, 221, 0.3), inset 0 0 20px rgba(0, 112, 221, 0.05); }
.card-front.rarity-epic { border-color: var(--color-epic); box-shadow: 0 0 25px rgba(163, 53, 238, 0.4), inset 0 0 25px rgba(163, 53, 238, 0.08); }
.card-front.rarity-legendary {
    border-color: var(--color-legendary);
    box-shadow: 0 0 35px rgba(255, 128, 0, 0.5), inset 0 0 30px rgba(255, 128, 0, 0.1);
    animation: legendaryPulse 2s ease-in-out infinite;
}

@keyframes legendaryPulse {
    0%, 100% { box-shadow: 0 0 35px rgba(255, 128, 0, 0.5), inset 0 0 30px rgba(255, 128, 0, 0.1); }
    50% { box-shadow: 0 0 50px rgba(255, 128, 0, 0.7), inset 0 0 40px rgba(255, 128, 0, 0.15); }
}

.card-icon-frame {
    width: 72px;
    height: 72px;
    border: 3px solid var(--color-gold-dim);
    border-radius: 8px;
    overflow: hidden;
    background: #000;
    flex-shrink: 0;
}

.card-icon-frame img {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    display: block;
}

.card-name {
    font-size: 1rem;
    font-weight: 700;
    text-align: center;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
    line-height: 1.2;
}

.card-name.rarity-common { color: #fff; }
.card-name.rarity-uncommon { color: var(--color-uncommon); }
.card-name.rarity-rare { color: var(--color-rare); }
.card-name.rarity-epic { color: var(--color-epic); }
.card-name.rarity-legendary { color: var(--color-legendary); }

.card-desc {
    font-family: 'Cinzel', serif;
    font-size: 0.73rem;
    color: var(--color-text);
    text-align: center;
    line-height: 1.4;
    flex: 1;
    display: flex;
    align-items: center;
    padding: 0 2px;
}

.bonus-effect {
    color: var(--color-gold);
    font-style: italic;
}

.card-rarity-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    padding: 2px 10px;
    border-radius: 3px;
    background: rgba(0,0,0,0.3);
    flex-shrink: 0;
}

.card-rarity-label.rarity-common { color: #fff; }
.card-rarity-label.rarity-uncommon { color: var(--color-uncommon); }
.card-rarity-label.rarity-rare { color: var(--color-rare); }
.card-rarity-label.rarity-epic { color: var(--color-epic); }
.card-rarity-label.rarity-legendary { color: var(--color-legendary); }

/* ============ ABILITIES BAR ============ */
#abilities {
    display: flex;
    gap: 10px;
    justify-content: center;
    min-height: 8px;
    flex-shrink: 0;
}

.ability-btn {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    border: 2px solid #333;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    background: #111;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.ability-btn img {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    display: block;
}

.ability-btn.ready {
    border-color: var(--color-gold);
    box-shadow: 0 0 10px rgba(255, 209, 0, 0.3);
    animation: abilityPulse 2s ease-in-out infinite;
}

.ability-btn.ready:active { transform: scale(0.92); }

@keyframes abilityPulse {
    0%, 100% { box-shadow: 0 0 6px rgba(255, 209, 0, 0.2); }
    50% { box-shadow: 0 0 16px rgba(255, 209, 0, 0.5); }
}

.ability-btn.on-cooldown {
    border-color: #333;
    opacity: 0.5;
    cursor: default;
}

.ability-btn.on-cooldown img { filter: grayscale(80%); }

.cd-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-family: sans-serif;
    font-size: 16px;
    font-weight: bold;
}

/* ============ DRAW BUTTON ============ */
#drawBtn {
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-gold);
    background: linear-gradient(180deg, #2a2a4a, #16162e);
    border: 2px solid var(--color-gold-dim);
    border-radius: 8px;
    padding: 12px 40px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: all 0.2s;
    flex-shrink: 0;
}

#drawBtn:hover {
    border-color: var(--color-gold);
    box-shadow: 0 0 15px rgba(255, 209, 0, 0.3);
}

#drawBtn:active { transform: scale(0.97); }
#drawBtn:disabled { opacity: 0.5; cursor: default; box-shadow: none; }

#drawBtn.queue-mode {
    background: linear-gradient(180deg, #3a2a1a, #2e1e0e);
    border-color: var(--color-legendary);
    color: var(--color-legendary);
}

/* ============ CARD HISTORY ============ */
#cardHistory {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 300px;
    min-height: 12px;
    flex-shrink: 0;
}

.history-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    opacity: 0.8;
}

.history-dot.rarity-common { background: #fff; opacity: 0.35; }
.history-dot.rarity-uncommon { background: var(--color-uncommon); }
.history-dot.rarity-rare { background: var(--color-rare); }
.history-dot.rarity-epic { background: var(--color-epic); }
.history-dot.rarity-legendary { background: var(--color-legendary); box-shadow: 0 0 5px rgba(255, 128, 0, 0.6); }

/* ============ FOOTER / XP BAR ============ */
footer {
    flex-shrink: 0;
    padding: 6px 16px 12px;
}

#xpBarContainer {
    width: 100%;
    height: 16px;
    background: #1a0a2e;
    border: 1px solid #3a1a5e;
    border-radius: 3px;
    position: relative;
    overflow: hidden;
}

#xpFill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #6a1b9a, #ab47bc, #6a1b9a);
    background-size: 200% 100%;
    animation: xpShimmer 3s ease-in-out infinite;
    transition: width 0.5s ease;
    border-radius: 2px;
}

@keyframes xpShimmer {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

#xpText {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    color: #ddd;
    text-shadow: 0 1px 2px #000;
    font-family: sans-serif;
}

#levelDisplay {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 2px 0;
}

#levelNum {
    font-size: 0.75rem;
    color: var(--color-gold);
    font-weight: 700;
}

#talentPointsBadge {
    font-size: 0.7rem;
    color: var(--color-gold);
    background: rgba(255, 209, 0, 0.15);
    padding: 2px 8px;
    border-radius: 4px;
    animation: talentPulse 2s ease-in-out infinite;
}

@keyframes talentPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ============ OVERLAYS ============ */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
}

.overlay.hidden { display: none; }

/* ============ TALENT TREE ============ */
#talentTree {
    background: linear-gradient(180deg, #1a1a2e, #0e0e1a);
    border: 2px solid var(--color-gold-dim);
    border-radius: 12px;
    padding: 20px 16px;
    width: 94%;
    max-width: 420px;
    max-height: 90dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.talent-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 8px;
}

.talent-header h2 {
    font-size: 1.2rem;
    color: var(--color-gold);
    flex-shrink: 0;
}

#talentPointsAvail {
    font-size: 0.75rem;
    color: var(--color-gold);
    background: rgba(255, 209, 0, 0.1);
    padding: 4px 12px;
    border-radius: 4px;
    white-space: nowrap;
}

#closeTalents {
    background: none;
    border: none;
    color: var(--color-text);
    font-size: 1.8rem;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    flex-shrink: 0;
}

#talentColumns {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
}

.talent-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px 0;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
}

.branch-title {
    font-size: 0.55rem;
    color: var(--color-gold);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
    text-align: center;
    line-height: 1.3;
}

.talent-node {
    position: relative;
    width: 56px;
    height: 56px;
    border: 2px solid #333;
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.2s;
    opacity: 0.35;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.talent-node img {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    display: block;
    filter: grayscale(100%);
    transition: filter 0.3s;
}

.talent-node.available {
    opacity: 0.85;
    border-color: var(--color-gold-dim);
    animation: availablePulse 2s ease-in-out infinite;
}

.talent-node.available img { filter: grayscale(40%); }

@keyframes availablePulse {
    0%, 100% { box-shadow: 0 0 0 rgba(255, 209, 0, 0); }
    50% { box-shadow: 0 0 12px rgba(255, 209, 0, 0.25); }
}

.talent-node.learned {
    opacity: 1;
    border-color: var(--color-gold);
    box-shadow: 0 0 10px rgba(255, 209, 0, 0.3);
}

.talent-node.learned img { filter: none; }
.talent-node:active { transform: scale(0.92); }

.talent-connector {
    width: 2px;
    height: 12px;
    background: #333;
    flex-shrink: 0;
}

.talent-connector.active {
    background: var(--color-gold-dim);
    box-shadow: 0 0 4px rgba(255, 209, 0, 0.2);
}

.talent-tooltip {
    position: fixed;
    z-index: 200;
    background: linear-gradient(180deg, #1e1e36, #14142a);
    border: 2px solid var(--color-gold-dim);
    border-radius: 10px;
    padding: 14px 16px;
    max-width: 260px;
    width: calc(100vw - 32px);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    left: 50% !important;
    transform: translateX(-50%);
    bottom: 20px !important;
    top: auto !important;
}

.talent-tooltip.visible { opacity: 1; }
.talent-tooltip h3 { font-size: 0.85rem; color: var(--color-gold); margin-bottom: 6px; }
.talent-tooltip p { font-size: 0.75rem; color: var(--color-text); line-height: 1.4; font-family: sans-serif; }
.talent-tooltip .talent-req { font-size: 0.65rem; color: #f44; margin-top: 6px; }
.talent-tooltip .talent-type { font-size: 0.6rem; color: #888; margin-top: 4px; font-family: sans-serif; }

.reset-btn {
    display: block;
    margin: 20px auto 4px;
    font-family: 'Cinzel', serif;
    font-size: 0.7rem;
    color: #c44;
    background: rgba(200, 50, 50, 0.1);
    border: 1px solid #633;
    border-radius: 6px;
    padding: 8px 20px;
    cursor: pointer;
}

.reset-btn:active { background: rgba(200, 50, 50, 0.2); border-color: #c44; }

/* ============ PICK OVERLAY (HIGH ROLLER) ============ */
#pickContainer {
    background: linear-gradient(180deg, #1a1a2e, #0e0e1a);
    border: 2px solid var(--color-gold-dim);
    border-radius: 12px;
    padding: 20px 12px;
    text-align: center;
    width: 94%;
    max-width: 380px;
}

#pickContainer h3 {
    font-size: 1rem;
    color: var(--color-gold);
    margin-bottom: 16px;
}

#pickCards {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.pick-card {
    width: 100px;
    border: 2px solid;
    border-radius: 8px;
    padding: 10px 6px;
    cursor: pointer;
    background: #12121f;
    text-align: center;
    transition: transform 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.pick-card:active { transform: scale(0.95); }

.pick-card.rarity-common { border-color: var(--color-common); }
.pick-card.rarity-uncommon { border-color: var(--color-uncommon); }
.pick-card.rarity-rare { border-color: var(--color-rare); box-shadow: 0 0 10px rgba(0,112,221,0.2); }
.pick-card.rarity-epic { border-color: var(--color-epic); box-shadow: 0 0 10px rgba(163,53,238,0.3); }
.pick-card.rarity-legendary { border-color: var(--color-legendary); box-shadow: 0 0 15px rgba(255,128,0,0.4); }

.pick-card img {
    width: 48px;
    height: 48px;
    image-rendering: pixelated;
    border: 2px solid var(--color-gold-dim);
    border-radius: 4px;
}

.pick-name {
    font-size: 0.6rem;
    margin-top: 8px;
    font-weight: 700;
    line-height: 1.2;
}

.pick-rarity {
    font-size: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 4px;
}

/* ============ NOTIFICATIONS ============ */
.notification {
    position: fixed;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 20, 10, 0.9);
    color: var(--color-gold);
    border: 1px solid var(--color-gold-dim);
    padding: 8px 20px;
    border-radius: 6px;
    font-size: 0.8rem;
    z-index: 200;
    animation: notifFade 2s ease-out forwards;
    pointer-events: none;
    white-space: nowrap;
}

@keyframes notifFade {
    0% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
    15% { opacity: 1; transform: translateX(-50%) translateY(0); }
    70% { opacity: 1; }
    100% { opacity: 0; }
}

/* ============ LEVEL UP ============ */
#levelUpOverlay { pointer-events: none; z-index: 150; }

#levelUpContent {
    text-align: center;
    animation: levelUpBurst 2s ease-out forwards;
}

#levelUpText {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--color-gold);
    text-shadow: 0 0 30px rgba(255, 209, 0, 0.8), 0 0 60px rgba(255, 209, 0, 0.4);
    letter-spacing: 4px;
}

#levelUpLevel {
    font-size: 1.3rem;
    color: var(--color-gold);
    margin-top: 8px;
    opacity: 0.8;
}

@keyframes levelUpBurst {
    0% { transform: scale(0.5); opacity: 0; }
    15% { transform: scale(1.2); opacity: 1; }
    30% { transform: scale(1); opacity: 1; }
    80% { opacity: 1; }
    100% { opacity: 0; transform: scale(1) translateY(-20px); }
}

/* ============ HIDDEN ============ */
.hidden { display: none !important; }

/* ============ CARD DRAW ANIMATION ============ */
.card-container.drawing .card-inner { animation: cardSpin 0.6s ease; }

@keyframes cardSpin {
    0% { transform: rotateY(180deg) scale(1); }
    50% { transform: rotateY(270deg) scale(1.05); }
    100% { transform: rotateY(360deg) scale(1); }
}

.legendary-flash {
    position: fixed;
    inset: 0;
    background: radial-gradient(circle, rgba(255,128,0,0.4), transparent 70%);
    pointer-events: none;
    z-index: 50;
    animation: flashFade 1s ease-out forwards;
}

@keyframes flashFade {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 380px) {
    .card-container { width: 230px; height: 320px; }
    .card-icon-frame { width: 56px; height: 56px; }
    .card-name { font-size: 0.9rem; }
    .card-desc { font-size: 0.68rem; }
    #drawBtn { padding: 10px 28px; font-size: 0.9rem; }
    .talent-node { width: 48px; height: 48px; }
    .branch-title { font-size: 0.5rem; }
    .ability-btn { width: 38px; height: 38px; }
    .pick-card { width: 85px; padding: 8px 4px; }
    .pick-card img { width: 40px; height: 40px; }
}

@media (min-width: 500px) {
    .talent-tooltip {
        left: auto !important;
        transform: none;
        bottom: auto !important;
        max-width: 240px;
        width: auto;
    }
}
