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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-font-smoothing: antialiased;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

body {
    background: #1a5c2a;
    background-image: url('../img/background.png');
    background-size: 100% 100%;
    background-position: center;
    background-repeat: no-repeat;
    min-height: 100vh;
    transition: background-image 0.4s ease;
}

body.skin-wood {
    background-image: url('../img/background-wood.png');
}

/* Wood skin: menu overrides */
body.skin-wood .menu-container {
    background: rgba(0, 0, 0, 0.45);
    border-radius: 20px;
    padding: 40px 48px;
    backdrop-filter: blur(4px);
}

body.skin-wood #start-btn {
    background: linear-gradient(180deg, #3a3a3a 0%, #1a1a1a 100%);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255,255,255,0.15);
}

body.skin-wood #start-btn:hover {
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255,255,255,0.2);
}

body.skin-wood .difficulty-buttons {
    background: rgba(0, 0, 0, 0.35);
    border-color: rgba(255, 255, 255, 0.1);
}

body.skin-wood .diff-btn.active {
    background: rgba(255, 255, 255, 0.15);
}

/* Wood skin: game screen overrides */
body.skin-wood .board-container {
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.08);
}

body.skin-wood .score-display,
body.skin-wood .timer-display {
    background: rgba(0, 0, 0, 0.4);
}

body.skin-wood .toolbar-btn {
    background: rgba(0, 0, 0, 0.4);
    border-color: rgba(255, 255, 255, 0.12);
}

body.skin-wood .toolbar-btn:hover {
    background: rgba(0, 0, 0, 0.55);
}

body.skin-wood .card-slot.gap {
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.12);
}

body.skin-wood .card-slot.gap.valid-target {
    border-color: rgba(212, 168, 75, 0.6);
    background: rgba(212, 168, 75, 0.1);
    box-shadow: 0 0 12px rgba(212, 168, 75, 0.3);
}

body.skin-wood .card-slot.gap.drag-over {
    border-color: #d4a84b;
    background: rgba(212, 168, 75, 0.2);
    box-shadow: 0 0 20px rgba(212, 168, 75, 0.5);
}

body.skin-wood .btn-secondary {
    background: rgba(0, 0, 0, 0.35);
    border-color: rgba(255, 255, 255, 0.12);
}

body.skin-wood .btn-secondary:hover {
    background: rgba(0, 0, 0, 0.5);
}

/* ====== SCREENS ====== */
.screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 1;
}

.screen.visible {
    visibility: visible;
    opacity: 1;
}

.overlay {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 100;
}

.overlay-container {
    background: linear-gradient(145deg, #2c2c2c, #1a1a1a);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px;
    padding: 32px 40px;
    text-align: center;
    color: #fff;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.help-overlay-container {
    max-width: 520px;
    max-height: 80vh;
    overflow-y: auto;
    text-align: left;
}

.help-content {
    line-height: 1.6;
    font-size: 0.95rem;
    color: #ccc;
    margin: 16px 0;
}

.help-content h3 {
    color: #fff;
    margin: 16px 0 8px;
    font-size: 1.05rem;
}

/* ====== LANGUAGE TOGGLE ====== */
.lang-toggle {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 4px;
    z-index: 50;
    background: rgba(0,0,0,0.3);
    border-radius: 8px;
    padding: 3px;
}

.lang-btn {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.5);
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.lang-btn.active {
    background: rgba(255,255,255,0.15);
    color: #fff;
}

/* ====== MENU SCREEN ====== */
.menu-container {
    text-align: center;
    padding: 40px;
}

.game-title-img {
    display: block;
    margin: 0 auto 20px;
    width: min(320px, 70vw);
    height: auto;
    filter: drop-shadow(0 4px 12px rgba(0,0,0,0.4));
}

.menu-links {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin-top: 24px;
}

.menu-link {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: 0.5px;
    transition: color 0.2s;
}

.menu-link:hover {
    color: rgba(255,255,255,0.8);
}

.menu-credit {
    margin-top: 36px;
    font-size: 0.7rem;
    color: rgba(255,255,255,0.5);
    letter-spacing: 0.3px;
}

/* ====== DIFFICULTY SELECTOR ====== */
.difficulty-selector {
    margin-top: 32px;
    margin-bottom: 4px;
}

.difficulty-label {
    display: block;
    color: rgba(255,255,255,0.5);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 8px;
}

.difficulty-buttons {
    display: inline-flex;
    background: rgba(76, 175, 80, 0.25);
    border-radius: 25px;
    padding: 4px;
    gap: 2px;
    border: 1px solid rgba(76, 175, 80, 0.3);
}

.diff-btn {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.85);
    padding: 8px 22px;
    border-radius: 22px;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
}

.diff-btn:hover {
    color: rgba(255,255,255,0.8);
}

.diff-btn.active {
    background: rgba(0,0,0,0.35);
    color: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* ====== BUTTONS ====== */
.btn {
    display: inline-block;
    padding: 14px 36px;
    border: none;
    border-radius: 25px;
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: linear-gradient(180deg, #4caf50 0%, #2e7d32 100%);
    color: #fff;
    box-shadow: 0 4px 16px rgba(46, 125, 50, 0.4), inset 0 1px 0 rgba(255,255,255,0.2);
    padding: 22px 72px;
    font-size: 1.35rem;
    margin: 40px 0 24px;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(46, 125, 50, 0.5), inset 0 1px 0 rgba(255,255,255,0.25);
}

.btn-primary:active {
    transform: translateY(0);
}

/* Confirm overlay buttons side-by-side */
.confirm-buttons {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.confirm-buttons .btn {
    flex: 1;
    padding: 14px 16px;
    font-size: 0.95rem;
    margin: 0;
}

.btn-secondary {
    background: rgba(0,0,0,0.3);
    color: rgba(255,255,255,0.85);
    border: 1px solid rgba(255,255,255,0.1);
}

.btn-secondary:hover {
    background: rgba(0,0,0,0.45);
    color: #fff;
}

.btn-accent {
    background: linear-gradient(135deg, #e53935, #c62828);
    color: #fff;
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.85rem;
}

/* ====== GAME SCREEN ====== */
#game-screen {
    flex-direction: column;
    padding: 8px 32px;
    gap: 8px;
}

#game-screen.visible {
    display: flex;
}

/* ====== TOP BAR ====== */
.game-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 1100px;
    padding: 4px 8px;
}

.topbar-left {
    display: flex;
    gap: 20px;
    align-items: center;
}

.score-display, .timer-display {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0,0,0,0.25);
    padding: 6px 14px;
    border-radius: 8px;
    color: #fff;
    font-size: 0.9rem;
}

.score-label, .timer-icon {
    opacity: 0.7;
}

.score-value, .timer-value {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* ====== BOARD ====== */
.board-container {
    display: grid;
    grid-template-columns: repeat(13, 1fr);
    grid-template-rows: repeat(4, auto);
    gap: 8px;
    max-width: 1200px;
    width: 100%;
    padding: 8px;
    background: rgba(0,0,0,0.12);
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.06);
}

/* ====== CARD SLOTS ====== */
.card-slot {
    border-radius: 5px;
    position: relative;
    aspect-ratio: 2.5 / 3.5;
    max-height: calc((100vh - 140px) / 4);
}

.card-slot.gap {
    background: rgba(0,0,0,0.15);
    border: 2px dashed rgba(255,255,255,0.15);
    border-radius: 6px;
}

.card-slot.gap.valid-target {
    border-color: rgba(76, 175, 80, 0.6);
    background: rgba(76, 175, 80, 0.1);
    box-shadow: 0 0 12px rgba(76, 175, 80, 0.3);
}

.card-slot.gap.drag-over {
    border-color: #4caf50;
    background: rgba(76, 175, 80, 0.2);
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.5);
    transform: scale(1.03);
    transition: all 0.15s ease;
}

/* ====== TOOLBAR ====== */
.game-toolbar {
    display: flex;
    justify-content: center;
    gap: 12px;
    width: 100%;
    max-width: 1100px;
    padding: 4px 0;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    color: #fff;
    padding: 8px 16px;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.toolbar-btn:hover {
    background: rgba(0,0,0,0.45);
    border-color: rgba(255,255,255,0.2);
}

.toolbar-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.toolbar-icon {
    font-size: 1.1rem;
}

.toolbar-count {
    background: rgba(255,255,255,0.15);
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 0.75rem;
    font-weight: 700;
}

/* ====== GAME OVER ====== */
.gameover-title {
    font-size: 1.8rem;
    margin-bottom: 8px;
}

.gameover-message {
    color: #aaa;
    margin-bottom: 20px;
}

.gameover-stats {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-bottom: 24px;
}

.gameover-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 0.8rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #fff;
}

/* ====== STATS OVERLAY ====== */
.stats-content {
    text-align: left;
    margin: 16px 0;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    font-size: 0.95rem;
}

.stats-row .label { color: #aaa; }
.stats-row .value { color: #fff; font-weight: 600; }

/* ====== CARD DRAGGING ====== */
.card.dragging {
    opacity: 0.7;
    z-index: 1000;
    cursor: grabbing;
    transform: scale(1.08) rotate(2deg);
    box-shadow: 0 12px 40px rgba(0,0,0,0.5) !important;
    transition: none !important;
    pointer-events: none;
}

.card.snap-back {
    transition: transform 0.3s ease, left 0.3s ease, top 0.3s ease;
}

.card.hint-highlight {
    animation: hintPulse 1s ease-in-out 5;
    z-index: 10;
}

@keyframes hintPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.08);
    }
}

.card.placed-correct {
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.5);
}

/* ====== WIN ANIMATION ====== */
@keyframes cardBounce {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
    15% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    85% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
}

@keyframes confettiFall {
    0% {
        transform: translateY(0) rotate(0deg) scale(1);
        opacity: 1;
    }
    25% {
        transform: translateY(25vh) rotate(180deg) translateX(30px) scale(0.95);
    }
    50% {
        transform: translateY(50vh) rotate(360deg) translateX(-20px) scale(0.9);
    }
    75% {
        transform: translateY(75vh) rotate(540deg) translateX(15px) scale(0.85);
        opacity: 0.8;
    }
    100% {
        transform: translateY(110vh) rotate(720deg) translateX(-10px) scale(0.8);
        opacity: 0;
    }
}

/* ====== RESPONSIVE ====== */
@media (max-width: 768px) {
    .board-container { gap: 3px; padding: 6px; }
    .game-topbar { padding: 2px 4px; }
    .toolbar-label { display: none; }
    .game-toolbar { gap: 8px; }
    .toolbar-btn { padding: 8px 12px; }
    .game-title { font-size: 2.5rem; }
}

@media (max-height: 500px) {
    .board-container { gap: 2px; padding: 4px; }
    .game-topbar { padding: 0 4px; }
    .game-toolbar { padding: 0; }
    .score-display, .timer-display { padding: 4px 10px; font-size: 0.8rem; }
}

/* Menu: allow scrolling on short screens */
#menu-screen {
    overflow-y: auto;
}

@media (max-height: 450px) {
    .menu-container {
        padding: 12px 20px;
    }
    .game-title-img {
        width: min(200px, 50vw);
        margin-bottom: 8px;
    }
    .btn-primary {
        padding: 12px 48px;
        font-size: 1rem;
        margin: 12px 0 8px;
    }
    .difficulty-selector {
        margin-top: 8px;
        margin-bottom: 2px;
    }
    .difficulty-label {
        font-size: 0.7rem;
        margin-bottom: 4px;
    }
    .diff-btn {
        padding: 5px 14px;
        font-size: 0.75rem;
    }
    .menu-links {
        margin-top: 10px;
        gap: 16px;
    }
    .menu-link {
        font-size: 0.85rem;
    }
    .menu-credit {
        margin-top: 10px;
        font-size: 0.6rem;
    }
    .lang-toggle {
        top: 6px;
    }
}

@media (max-height: 350px) {
    .menu-container {
        padding: 6px 16px;
    }
    .game-title-img {
        width: min(160px, 45vw);
        margin-bottom: 4px;
    }
    .btn-primary {
        padding: 8px 36px;
        font-size: 0.9rem;
        margin: 6px 0 4px;
    }
    .difficulty-selector {
        margin-top: 4px;
    }
    .menu-links {
        margin-top: 6px;
    }
    .menu-credit {
        margin-top: 6px;
    }
}

