:root {
    --bg-main: #0d0a16;
    --bg-board: #201a33;
    --accent-gold: #e0b64a;
    --accent-red: #d81e3f;
    --accent-blue: #2a4a7f;
    --text-main: #ece6f0;
    --hp-green: #3ec98a;
    --hp-bg: #3a3348;
}

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

/* ── Loading Screen ──────────────────────────────────────────────── */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999;
    background: #1a1030;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease;
}

#loading-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    margin: 0 auto;
    border: 4px solid rgba(224, 182, 74, 0.2);
    border-top-color: #e0b64a;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-main);
    font-family: 'Nunito', sans-serif;
    color: var(--text-main);

    overscroll-behavior: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* ── Wrapper & Scaling ────────────────────────────────────────── */
#game-wrapper {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle, #201a33 0%, #0d0a16 100%);
}

#game-board {
    width: 960px;
    height: 540px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transform-origin: center center;
    overflow: hidden;
    background-color: var(--bg-board);
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
}

.scene {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* ── UI Elements ─────────────────────────────────────────────── */
.menu-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    background: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4)), url('../assets/main_bg.webp');
    background-size: cover;
    background-position: center;
}


.btn-main {
    background: linear-gradient(180deg, #a3122f 0%, #56091a 100%);
    border: 2px solid var(--accent-gold);
    color: #fff;
    padding: 10px 25px;
    font-size: 25px;
    font-weight: 700;
    font-family: 'Nunito', ui-sans-serif;
    border-radius: 8px;
    cursor: pointer;
    width: 250px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.8);
    transition: transform 0.1s, filter 0.2s;
}

.btn-main:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(216, 30, 63, 0.6);
}

.btn-main:active {
    transform: scale(0.95);
}

.btn-secondary {
    background: transparent;
    border: 1px solid #666;
    color: #888;
    padding: 8px 20px;
    font-size: 16px;
    border-radius: 4px;
    cursor: pointer;
}

/* ── Попап уровней ────────────────────────────────────────────── */
.popup-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.popup-content {
    width: 80%;
    height: 90%;
    background: linear-gradient(135deg, #201a33 0%, #0d0a16 100%);
    border: 2px solid var(--accent-gold);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
    overflow: hidden;
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 10px;
    background: rgba(0, 0, 0, 0.5);
    border-bottom: 2px solid var(--accent-gold);
}

.popup-header h2 {
    color: var(--accent-gold);
    margin: 0;
    font-size: 20px;
}

.btn-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
}

.btn-close:hover {
    color: var(--accent-red);
}

.levels-grid {
    flex: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    padding: 20px;
}

/* Custom Scrollbar for grid */
.levels-grid::-webkit-scrollbar,
#skills-container::-webkit-scrollbar {
    width: 8px;
}

.levels-grid::-webkit-scrollbar-track,
#skills-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
}

.levels-grid::-webkit-scrollbar-thumb,
#skills-container::-webkit-scrollbar-thumb {
    background: var(--accent-gold);
    border-radius: 4px;
}

.level-card {
    background: #111;
    border: 2px solid #444;
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    position: relative;
    text-align: center;
}

.level-card:hover:not(.locked) {
    transform: scale(1.05);
    border-color: var(--accent-gold);
}

.level-card.locked {
    opacity: 0.6;
    cursor: default;
    filter: grayscale(100%);
}

.level-img-wrap {
    width: 80px;
    height: 110px;
    background: #222;
    border: 1px solid #555;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 4px;
}

.level-img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.level-name {
    font-size: 16px;
    font-weight: bold;
    color: #fff;
    margin-bottom: 5px;
}

.level-hp {
    font-size: 14px;
    color: var(--hp-green);
    font-weight: bold;
}

.lock-icon {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 6px;
}

/* ── Попап Навыков ────────────────────────────────────────────── */
.skills-branches {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.branch-col {
    flex: 1;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid #333;
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
}

.branch-title {
    color: var(--hp-green);
    font-size: 16px;
    font-weight: bold;
    text-align: left;
    border-bottom: 1px solid #444;
    padding-bottom: 5px;
    width: 100%;
}

.skill-card {
    background: #111;
    border: 2px solid #444;
    border-radius: 8px;
    padding: 8px;
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    transition: transform 0.2s, border-color 0.2s;
    position: relative;
}

.skill-card.unlocked {
    border-color: var(--hp-green);
    background: rgba(46, 204, 113, 0.15);
    box-shadow: 0 0 10px rgba(46, 204, 113, 0.6);
}

.skill-card.available {
    border-color: var(--accent-gold);
    box-shadow: 0 0 6px rgba(212, 175, 55, 0.4);
}

.btn-buy-skill {
    flex: 1 1 100%;
    background: linear-gradient(180deg, #a3122f 0%, #56091a 100%);
    border: 2px solid var(--accent-gold);
    color: #fff;
    padding: 5px;
    font-size: 13px;
    font-weight: 700;
    font-family: 'Nunito', sans-serif;
    border-radius: 4px;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
    margin-top: 2px;
    text-align: center;
    transition: filter 0.2s;
}

.btn-buy-skill:hover {
    filter: brightness(1.2);
}

.skill-card.locked {
    opacity: 0.5;
    filter: grayscale(100%);
    cursor: default;
}

.skill-icon {
    width: 50px;
    height: 50px;
    background: #222;
    border: 1px solid #555;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.skill-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.skill-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.skill-title {
    font-weight: bold;
    color: #fff;
    font-size: 14px;
    margin-bottom: 3px;
}

.skill-desc {
    color: #aaa;
    font-size: 12px;
    line-height: 1.2;
}

.skill-status {
    font-size: 16px;
    font-weight: bold;
    min-width: 40px;
    text-align: right;
}

/* ── Game Scene Layout ────────────────────────────────────────── */
#game-main-container {
    flex: 1;
    display: flex;
    flex-direction: row;
    height: 100%;
    /* Фоновая картинка с затемнением для читаемости */
    background: linear-gradient(rgba(0, 0, 0, 0.25), rgba(0, 0, 0, 0.25)), url('../assets/bg1.webp');
    background-size: cover;
    background-position: center;
}

#skills-sidebar {
    width: 120px;
    background: rgba(0, 0, 0, 0.4);
    border-right: 1px solid #333;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 100px;
    gap: 10px;
}

.sidebar-skill-slot {
    aspect-ratio: 1 / 1;
    background: #111;
    border-radius: 6px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #444;
}

.sidebar-skill-slot.unlocked {
    border-color: var(--accent-gold);
    box-shadow: 0 0 8px rgba(212, 175, 55, 0.6);
}

.sidebar-skill-slot.locked {
    opacity: 0.6;
    filter: grayscale(100%);
}

.skill-slot {
    width: 44px;
    height: 44px;
    background: #222;
    border: 2px solid var(--accent-gold);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.skill-slot:hover {
    transform: scale(1.1);
    background: #333;
}

.skill-slot span {
    font-size: 14px;
    font-weight: 900;
    color: var(--accent-gold);
}

#boss-sidebar {
    width: 220px;
    background: transparent;
    border-right: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    gap: 15px;
}

#boss-portrait {
    width: 160px;
    height: 220px;
    background: #111;
    border: 3px solid var(--accent-gold);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

#boss-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    -webkit-user-drag: none;
}

.boss-img-placeholder {
    font-size: 24px;
    font-weight: 900;
    color: #333;
}

#boss-info {
    width: 100%;
    text-align: center;
}

#boss-name {
    font-size: 18px;
    font-weight: 600;
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    letter-spacing: -0.2px;
    text-transform: none;
}

.hp-bar-container {
    width: 100%;
    height: 24px;
    background: var(--hp-bg);
    border: 2px solid #000;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
    margin-top: 8px;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.5);
}

.hp-bar {
    height: 100%;
    background: linear-gradient(90deg, #c0392b 0%, #e74c3c 100%);
    transition: width 0.3s ease;
}

#boss-hp-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 900;
    color: #fff;
    text-shadow: 1px 1px 2px #000;
}

#solitaire-board {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 5px;
    gap: 15px;
}

#top-row {
    display: flex;
    gap: 10px;
    height: 100px;
    justify-content: flex-start;
}

.pile-row {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
}

.pile {
    width: 75px;
    height: 112px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    position: relative;
    flex-shrink: 0;
    /* Полупрозрачная рубашка через градиент-наложение */
    background: linear-gradient(rgba(32, 26, 51, 0.6), rgba(32, 26, 51, 0.6)), url('../assets/back.webp');
    background-size: cover;
    background-position: center;
}

.tableau-column {
    height: 100%;
    min-height: 112px;
}

.spacer {
    width: 75px;
    /* Ширина ровно одной карты */
    flex-shrink: 0;
}

/* ── CARD DOM STYLES ────────────────────────────────────────── */
.card {
    width: 75px;
    height: 112px;
    background: #fff;
    border-radius: 6px;
    position: absolute;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.6);
    /* Немного усилил тень */
    cursor: pointer;
    display: flex;
    flex-direction: column;
    padding: 8px;
    color: #000;
    font-weight: 700;
    transition: transform 0.1s;
    border: 2px solid #000;
    /* Четкая черная граница */
}

.card.face-down {
    background: #2c3e50;
    /* Фолбэк цвет */
    border: 2px solid #000;
}

.card.face-down * {
    display: none;
}

.card.red {
    color: var(--accent-red);
}

.card-rank {
    font-size: 18px;
    line-height: 1;
}

.card-suit-label {
    font-size: 10px;
    text-transform: uppercase;
}

.card-suit-bg {
    position: absolute;
    bottom: 5px;
    right: 5px;
    font-size: 24px;
    opacity: 0.1;
}

.card.selected {
    box-shadow: 0 0 15px var(--accent-gold);
    transform: translateY(-5px);
    z-index: 100;
}

.card-overlay {
    position: absolute;
    inset: 0;
    padding: 5px;
    background: rgba(255, 255, 255, 0.1);
    /* Легкий блик */
    pointer-events: none;
    display: flex;
    flex-direction: column;
}

.card-overlay .card-rank {
    font-size: 26px;
    line-height: 1;
    text-shadow:
        -2px -2px 0 #fff, 2px -2px 0 #fff,
        -2px 2px 0 #fff, 2px 2px 0 #fff,
        -2px 0 0 #fff, 2px 0 0 #fff,
        0 -2px 0 #fff, 0 2px 0 #fff,
        0 0 8px rgba(255, 255, 255, 0.9);
    color: #000;
    transition: color 0.2s;
}

.card.red .card-overlay .card-rank {
    color: var(--accent-red);
}

.card-overlay .card-suit-bg {
    position: absolute;
    bottom: 0px;
    right: 3px;
    font-size: 26px;
    opacity: 1;
    text-shadow:
        -2px -2px 0 #fff, 2px -2px 0 #fff,
        -2px 2px 0 #fff, 2px 2px 0 #fff,
        -2px 0 0 #fff, 2px 0 0 #fff,
        0 -2px 0 #fff, 0 2px 0 #fff,
        0 0 8px rgba(255, 255, 255, 0.9);
    color: #000;
    line-height: 25px;
}

.card.red .card-overlay .card-suit-bg {
    color: var(--accent-red);
}

.card.is-dragging {
    transition: none !important;
    pointer-events: none;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
    z-index: 9999 !important;
}

/* Вертикальное наложение в столбцах */
.tableau-column .card {
    position: absolute;
}

#player-progress-hud {
    position: absolute;
    top: 10px;
    left: 60px;
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid #444;
    color: #fff;
    z-index: 1000;
}

#boss-sidebar {
    width: 220px;
    background: transparent;
    border-right: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    margin-top: 80px;
    /* Смещаем вниз, чтобы не перекрывать HUD */
    gap: 15px;
}

.player-stats {
    display: flex;
    flex-direction: column;
    gap: 10px;
}


.stat-label {
    font-size: 16px;
    font-weight: 900;
    color: var(--accent-gold);
    letter-spacing: 1px;
}

#gold-count {
    font-size: 18px;
    font-weight: 900;
    color: #fff;
}

.btn-exit {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 40px;
    height: 40px;
    background: linear-gradient(180deg, #a3122f 0%, #56091a 100%);
    border: 2px solid var(--accent-gold);
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.8);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    transition: transform 0.2s, filter 0.2s;
}

.btn-exit img {
    width: 20px;
    height: 20px;
    object-fit: contain;
    filter: invert(1);
}

.btn-exit:hover {
    transform: scale(1.1);
    filter: brightness(1.2);
}

/* Custom In-Game Skill Tooltip */
.skill-tooltip {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 450px;
    background: linear-gradient(135deg, rgba(26, 22, 37, 0.95) 0%, rgba(10, 8, 13, 0.98) 100%);
    border: 2px solid var(--accent-gold);
    border-radius: 12px;
    display: flex;
    gap: 15px;
    padding: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.9), 0 0 15px rgba(212, 175, 55, 0.3);
    z-index: 5000;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.skill-tooltip.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
    display: flex !important;
    /* Overriding hidden's display:none to keep animation */
    pointer-events: none;
}

.tooltip-icon-wrap {
    width: 64px;
    height: 64px;
    background: #111;
    border: 2px solid #555;
    border-radius: 8px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
}

.tooltip-icon-wrap img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 4px;
}

.tooltip-text-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

#tooltip-name {
    color: var(--hp-green);
    font-size: 18px;
    font-weight: 900;
    letter-spacing: 0.5px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

#tooltip-desc {
    color: #fff;
    font-size: 14px;
    font-weight: 700;
}

#tooltip-lore {
    color: #aaa;
    font-size: 12px;
    font-style: italic;
    margin-top: 4px;
    line-height: 1.3;
}
/* ── Заставка уровня перед боем ─────────────────────────────── */
.intro-content {
    width: 620px;
    height: auto;
    max-height: 92%;
    padding-bottom: 18px;
}

.intro-body {
    display: flex;
    gap: 18px;
    padding: 18px;
    align-items: flex-start;
    overflow-y: auto;
}

.intro-portrait {
    width: 150px;
    height: 210px;
    flex-shrink: 0;
    background: #111;
    border: 3px solid var(--accent-gold);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

.intro-portrait img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.intro-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

#intro-story {
    font-size: 16px;
    line-height: 1.55;
    color: var(--text-main);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.intro-hp {
    font-size: 14px;
    color: #9a92a8;
    letter-spacing: 0.3px;
}

.intro-hp b {
    color: var(--accent-red);
    font-size: 20px;
    font-weight: 900;
    margin-left: 4px;
}

#btn-intro-start {
    align-self: center;
    flex-shrink: 0;
}

/* ── Обучение на первом уровне ──────────────────────────────── */
#tutorial-layer {
    position: absolute;
    inset: 0;
    z-index: 900;
    pointer-events: none;
}

#tutorial-layer.hidden {
    display: none !important;
}

.tut-arrow {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.tut-path {
    stroke: var(--accent-gold);
    stroke-width: 4;
    stroke-linecap: round;
    stroke-dasharray: 10 9;
    filter: drop-shadow(0 0 5px rgba(224, 182, 74, 0.9));
    animation: tut-flow 0.7s linear infinite;
}

@keyframes tut-flow {
    to {
        stroke-dashoffset: -19;
    }
}

.tut-ring {
    position: absolute;
    border-radius: 7px;
    pointer-events: none;
}

.tut-source {
    box-shadow: 0 0 0 3px var(--accent-gold), 0 0 22px 6px rgba(224, 182, 74, 0.75);
    animation: tut-pulse 1.15s ease-in-out infinite;
}

@keyframes tut-pulse {
    0%, 100% {
        box-shadow: 0 0 0 3px var(--accent-gold), 0 0 18px 4px rgba(224, 182, 74, 0.55);
    }
    50% {
        box-shadow: 0 0 0 4px #fff3cd, 0 0 30px 10px rgba(224, 182, 74, 0.95);
    }
}

.tut-target {
    border: 3px dashed var(--accent-gold);
    background: rgba(224, 182, 74, 0.12);
    animation: tut-breathe 1.15s ease-in-out infinite;
}

@keyframes tut-breathe {
    0%, 100% {
        opacity: 0.55;
    }
    50% {
        opacity: 1;
    }
}

.tut-spark {
    position: absolute;
    width: 10px;
    height: 10px;
    margin: -5px 0 0 -5px;
    border-radius: 50%;
    background: radial-gradient(circle, #fff 0%, #ffe9a8 35%, rgba(224, 182, 74, 0.85) 60%, transparent 72%);
    animation: tut-spark 0.9s ease-out forwards;
}

@keyframes tut-spark {
    0% {
        transform: scale(0.2) rotate(0deg);
        opacity: 0;
    }
    25% {
        transform: scale(1.15) rotate(45deg);
        opacity: 1;
    }
    100% {
        transform: scale(0.3) rotate(160deg) translateY(-16px);
        opacity: 0;
    }
}

.tut-hint {
    position: absolute;
    padding: 10px 14px;
    background: linear-gradient(135deg, rgba(32, 26, 51, 0.97) 0%, rgba(13, 10, 22, 0.97) 100%);
    border: 2px solid var(--accent-gold);
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.75), 0 0 16px rgba(224, 182, 74, 0.3);
    color: var(--text-main);
    font-size: 14px;
    line-height: 1.4;
    text-align: center;
    animation: tut-appear 0.35s ease-out;
}

@keyframes tut-appear {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.94);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.tut-more {
    display: block;
    margin-top: 7px;
    font-size: 11px;
    font-style: normal;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--accent-gold);
    opacity: 0.75;
    animation: tut-breathe 1.6s ease-in-out infinite;
}
