/* Mobile HUD overlay on combat window */
.mobile-hud-overlay {
    position: absolute;
    top: 6px;
    left: 6px;
    right: 6px;
    display: none; /* hidden by default, enabled on mobile */
    flex-direction: column;
    gap: 6px;
    z-index: 40;
}
.mobile-hud-overlay .hp-bar.mobile {
    position: relative;
    height: 16px;
    border: 2px solid white;
    border-radius: 10px;
    background: rgba(0,0,0,0.25);
}
.mobile-hud-overlay .hp-text {
    font-size: 0.8em;
}

@media (max-width: 1024px) {
    .mobile-hud-overlay { display: flex; }
}

/* Mobile timer below submit button */
.timer-section.mobile { width: 100%; max-width: 300px; }
.timer-section.mobile .timer-display { font-size: 1em; margin-bottom: 4px; }
.timer-section.mobile .timer-bar { height: 10px; }
@font-face {
    font-family: 'MOBO';
    src: url('MOBO-Font11/MOBO-Regular.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'MOBO';
    src: url('MOBO-Font11/MOBO-Bold.otf') format('opentype');
    font-weight: bold;
    font-style: normal;
}

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

body {
    font-family: 'MOBO', Arial, sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background: linear-gradient(135deg, #531511 0%, #a12c28 25%, #ad3e2f 50%, #bb4632 75%, #ce643a 100%);
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

/* Hiragana Rain Effect */
.hiragana-rain {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}

.hiragana-rain .hiragana-char {
    position: absolute;
    font-size: 24px;
    color: rgba(255, 255, 255, 0.8);
    font-weight: normal;
    user-select: none;
    font-family: 'MOBO', Arial, sans-serif;
    will-change: transform;
    z-index: 1;
}

/* Background characters - smaller, blurred, more distant */
.hiragana-rain .hiragana-char.background-char {
    filter: blur(1px);
    color: rgba(255, 255, 255, 0.5);
    z-index: 0;
}


/* Matrix-style trail variations */
.hiragana-rain .hiragana-char.trail-light {
    color: rgba(255, 255, 255, 0.9);
    text-shadow:
        0 0 3px rgba(255, 255, 255, 0.6),
        0 1px 2px rgba(255, 255, 255, 0.4),
        0 2px 4px rgba(255, 255, 255, 0.2);
}

.hiragana-rain .hiragana-char.trail-medium {
    color: rgba(255, 255, 255, 0.9);
    text-shadow:
        0 0 5px rgba(255, 255, 255, 0.8),
        0 1px 3px rgba(255, 255, 255, 0.6),
        0 2px 6px rgba(255, 255, 255, 0.4),
        0 3px 9px rgba(255, 255, 255, 0.2);
}

.hiragana-rain .hiragana-char.trail-heavy {
    color: rgba(255, 255, 255, 0.9);
    text-shadow:
        0 0 5px rgba(255, 255, 255, 0.9),
        0 1px 3px rgba(255, 255, 255, 0.7),
        0 2px 6px rgba(255, 255, 255, 0.5),
        0 3px 9px rgba(255, 255, 255, 0.3),
        0 4px 12px rgba(255, 255, 255, 0.2),
        0 5px 15px rgba(255, 255, 255, 0.1);
}



.game-container {
    position: relative;
    width: 900px;
    height: 850px;
    background: linear-gradient(135deg,
        rgba(243, 228, 159, 0.95) 0%,    /* Warm Light Beige */
        rgba(231, 187, 99, 0.95) 80%,   /* Light Parchment */
        rgba(153, 104, 31, 0.95) 100%   /* Soft Antique Gold */
    );
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: auto;
    display: flex;
    flex-direction: column;
    z-index: 10;
}

/* Main Game UI */
.game-ui {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    grid-template-areas:
        "left right"
        "status status";
    gap: 15px;
    width: 100%;
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    min-height: 0;
    align-content: start;
}

/* Left Panel - Boggle Board and Controls */
.left-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
    grid-area: left;
}

/* Right Panel - Combat Window */
.right-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
    grid-area: right;
}

/* Combat Window - Square viewport for sprites and background */
.combat-window {
    aspect-ratio: 1;
    border: 3px solid #333;
    border-radius: 15px;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    background: url('assets/newassets/bggrass.png') center / cover no-repeat;
    image-rendering: pixelated;
}

/* Parallax Background Layer Containers */
.background-layer-container { display: none !important; }

/* Individual Background Layers (dual images) */
.background-layer { display: none !important; }

/* All layers use exactly double native size - default positioning with depth blur */
.background-sky,
.background-clouds,
.background-mountain_back,
.background-mountain_middle,
.background-mountain_front {
    background-size: 200% auto; /* Exactly double native size (353x180 -> 706x360) */
    background-position: center calc(100% - 40px); /* Default: 40px up from bottom */
    background-repeat: no-repeat;
    filter: blur(2.5px); /* 2.5px blur for distant elements */
}

.background-trees {
    background-size: 200% auto; /* Exactly double native size (353x180 -> 706x360) */
    background-position: center calc(100% - 40px); /* Default: 40px up from bottom */
    background-repeat: no-repeat;
    filter: blur(2px); /* 2px blur for mid-distance trees */
}

/* Individual layer positioning adjustments */
.background-ground {
    background-size: 200% auto;
    background-position: center calc(100% + 8px); /* Ground: moved down another 3px (8px below bottom) */
    background-repeat: no-repeat;
}

.background-backgroundTrees {
    background-size: 200% auto;
    background-position: center calc(100% - 50px); /* BackgroundTrees: moved down another 10px (50px up from bottom) */
    background-repeat: no-repeat;
    filter: blur(2.5px); /* 2.5px blur for background elements */
}

.background-grass {
    background-size: 200% auto;
    background-position: center bottom; /* Grass: moved down another 10px (0px up = bottom) */
    background-repeat: no-repeat;
    filter: blur(2px); /* 2px blur for grass foreground */
}

.background-shrine_single {
    background-size: 200% auto;
    background-position: 10% calc(100% - 50px); /* Scene 1: Far left (10% from left edge) */
    background-repeat: no-repeat;
    filter: blur(2.5px); /* 2.5px blur for scene landmarks */
}

.background-shrine_multiple {
    background-size: 200% auto;
    background-position: 15% calc(100% - 50px); /* Scene 1: Near shrine_single (15% from left edge) */
    background-repeat: no-repeat;
    filter: blur(2.5px); /* 2.5px blur for scene landmarks */
}

.background-house {
    background-size: 200% auto;
    background-position: 50% calc(100% - 40px); /* Scene 2: Center scene (50% from left edge) */
    background-repeat: no-repeat;
    filter: blur(2.5px); /* 2.5px blur for scene landmarks */
}

.background-fuji {
    background-size: 200% auto;
    background-position: 85% calc(100% - 40px); /* Scene 3: Far right scene (85% from left edge) */
    background-repeat: no-repeat;
    filter: blur(2.5px); /* 2.5px blur for scene landmarks */
}

/* Combat Message Display */
.combat-message {
    position: absolute;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    text-align: center;
    color: white;
    font-size: 1.1em;
    font-weight: bold;
    z-index: 25;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    backdrop-filter: blur(2px);
    
    /* Multiple text shadow for strong outline effect */
    text-shadow: 
        -1px -1px 0 #000,
        1px -1px 0 #000,
        -1px 1px 0 #000,
        1px 1px 0 #000,
        -2px -2px 0 #000,
        2px -2px 0 #000,
        -2px 2px 0 #000,
        2px 2px 0 #000;
    
    /* Animation for message changes */
    transition: all 0.3s ease;
    opacity: 1;
}

.combat-message.fade-in {
    animation: messageSlideIn 0.5s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.combat-message.success {
    color: #2ecc71;
    background: rgba(46, 204, 113, 0.2);
}

.combat-message.error {
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.2);
}

.combat-message.bonus {
    color: #f39c12;
    background: rgba(243, 156, 18, 0.2);
}


.board-section {
    background: rgba(250, 229, 172, 0.9);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.board-section h2 {
    text-align: center;
    margin-bottom: 20px;
    color: #333;
    font-size: 1.5em;
}

/* Boggle Board */
.boggle-board {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: 6px;
    margin: 10px auto;
    width: 280px;
    height: 280px;
    position: relative;
}

/* SVG overlay for tile connections */
.tile-connections {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    pointer-events: none !important;
    z-index: 5 !important;
    display: block !important;
    visibility: visible !important;
}

.connection-line {
    stroke: #4a90e2;
    stroke-width: 3;
    fill: none;
    opacity: 0.8;
    stroke-linecap: round;
}

.board-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 1.1em;
    font-weight: bold;
    color: #333;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* Smaller font for palatalized kana combinations */
.board-tile.palatalized {
    font-size: 1.1em;
}

.board-tile:hover {
    background: #f0f8ff;
    border-color: #66BB6A;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.board-tile.selected {
    background: linear-gradient(90deg, #4CAF50, #8BC34A);
    color: white;
    border: 2px solid #66BB6A;
    transform: scale(0.95);
}

.board-tile.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.board-tile.blocked-tile {
    background: linear-gradient(135deg, rgba(139, 0, 0, 0.6), rgba(178, 34, 34, 0.4)) !important;
    border: 2px solid #8B0000 !important;
    color: #FFB6C1 !important;
    cursor: not-allowed !important;
    position: relative;
    box-shadow: 0 0 15px rgba(139, 0, 0, 0.7) !important;
    animation: blockedPulse 2s ease-in-out infinite;
}

.board-tile.blocked-tile::after {
    content: '🚫';
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.6em;
    opacity: 0.8;
}

@keyframes blockedPulse {
    0%, 100% {
        box-shadow: 0 0 15px rgba(139, 0, 0, 0.7);
    }
    50% {
        box-shadow: 0 0 25px rgba(139, 0, 0, 0.9);
    }
}

/* Board Controls */
.board-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: center;
    margin: 12px 0 0 0;
    align-items: center;
}

.game-button {
    padding: 12px 24px;
    font-size: 1em;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'MOBO', Arial, sans-serif;
}

.game-button:not(:disabled) {
    background: linear-gradient(90deg, #4CAF50, #8BC34A);
    color: white;
}

.game-button:not(:disabled):hover {
    background: linear-gradient(90deg, #45a049, #7cb342);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.game-button:disabled {
    background: #ccc;
    color: #666;
    cursor: not-allowed;
}

/* Word Display */
.word-display {
    text-align: center;
    margin-top: 15px;
}

.word-display p {
    margin: 5px 0;
    font-size: 1.1em;
    color: #333;
}

.word-display span {
    font-weight: bold;
    color: #4a90e2;
}

/* Word Log Section */
.word-log-section {
    background: rgba(250, 229, 172, 0.9);
    border-radius: 10px;
    margin-top: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.word-log-section h3 {
    margin: 0;
    padding: 15px;
    background: linear-gradient(90deg, #4CAF50, #8BC34A);
    color: white;
    font-size: 1.2em;
    text-align: center;
}

.word-log {
    max-height: 200px;
    overflow-y: auto;
    padding: 10px;
    background: #f8f9fa;
}

.word-log-empty {
    text-align: center;
    color: #6c757d;
    font-style: italic;
    padding: 20px;
}

.word-log-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    margin: 4px 0;
    border-radius: 6px;
    font-size: 0.95em;
    transition: background-color 0.2s ease;
}

.word-log-entry:hover {
    background: rgba(52, 152, 219, 0.1);
}

.word-log-entry.valid {
    background: rgba(46, 204, 113, 0.1);
    border-left: 3px solid #2ecc71;
}

.word-log-entry.invalid {
    background: rgba(231, 76, 60, 0.1);
    border-left: 3px solid #e74c3c;
}

.word-log-word {
    font-weight: bold;
    color: #2c3e50;
}

.word-log-kanji {
    color: #8e44ad;
    font-weight: bold;
    margin-left: 5px;
}

.word-log-meaning {
    color: #34495e;
    font-size: 0.9em;
    flex: 1;
    margin-left: 10px;
}

.word-log-damage {
    color: #e67e22;
    font-weight: bold;
    font-size: 0.9em;
}

.word-log-stats {
    display: flex;
    justify-content: space-between;
    padding: 10px 15px;
    background: #ecf0f1;
    border-top: 1px solid #bdc3c7;
    font-size: 0.9em;
    color: #34495e;
}

/* Scrollbar styling for word log */
.word-log::-webkit-scrollbar {
    width: 6px;
}

.word-log::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.word-log::-webkit-scrollbar-thumb {
    background: #bdc3c7;
    border-radius: 3px;
}

.word-log::-webkit-scrollbar-thumb:hover {
    background: #95a5a6;
}

/* Combat Characters in Window */
.combat-characters { display: none; }

.combat-scene {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    align-items: end;
    justify-items: center;
    padding: 2% 6%;
    z-index: 20;
}

.platform {
    width: 100%;
    height: 60%;
    background: url('assets/newassets/platformgrass.png') center / contain no-repeat;
    image-rendering: pixelated;
}
.player-platform { grid-column: 1; grid-row: 2; background-image: url('assets/newassets/platformgrass.png'); transform: translate(-50px, 10px) scale(2.5); transform-origin: center bottom; }
.enemy-platform { grid-column: 2; grid-row: 1; transform: translateY(80px) scale(1.2); transform-origin: center bottom; }

.sprite {
    width: 128px;
    height: 128px;
    image-rendering: pixelated;
    background-repeat: no-repeat;
    background: none; /* eliminate background artifacts; we use <img> now */
}
.player-sprite { grid-column: 1; grid-row: 2; transform: translateY(-8%); width: 192px; height: 192px; }
.enemy-sprite { grid-column: 2; grid-row: 1; transform: translateY(80px); width: 112px; height: 112px; }

.character-sprite {
    width: 128px;
    height: 128px;
    position: relative;
    image-rendering: pixelated;
}

/* Facing direction transforms disabled to preserve position transforms */
.player-sprite { transform: translate(-10px, -50px) scale(1); }

.enemy-sprite { transform: translateY(60px); left: 0; right: auto; }
.enemy-sprite img#enemySpriteImg {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center bottom;
    image-rendering: pixelated;
    display: block;
    pointer-events: none;
    user-select: none;
}

/* Spritesheet Animation System */
.sprite-animated { background: none; animation: none; }

/* Player Animations */
.player-sprite { background-repeat: no-repeat; background-size: contain; background-position: center bottom; }
.player-idle { background-image: url('assets/newassets/playeridle.png'); }

.player-attack { background-image: url('assets/newassets/playerattack.png'); }

.player-walk { background-image: url('assets/newassets/playeridle.png'); }

/* Enemy Animations */
.enemy-idle { background: none; }

.enemy-attack { background: none; }

.enemy-hurt { background: none; }

/* Enemy death animations for different types */
.enemy-death.enemy-karasu {
    background-image: url('assets/newassets/oniattack2.png');
    /* animation disabled for static sprite */
}

.enemy-death.enemy-kitsune {
    background-image: url('assets/newassets/oniattack2.png');
    /* animation disabled for static sprite */
}

.enemy-death.enemy-tengu {
    background-image: url('assets/newassets/oniattack2.png');
    /* animation disabled for static sprite */
}

/* Fallback for any enemy type */
.enemy-death {
    animation: enemy-death-anim 1.0s steps(6, end) forwards; /* 6 frames, death animation plays once */
}

/* Spritesheet Keyframes - Simple start to end position, steps() handles the frames */
@keyframes player-idle-anim {
    from { background-position-x: 0; }
    to { background-position-x: -896px; } /* 7 frames * 128px = 896px */
}

@keyframes player-attack-anim {
    from { background-position-x: 0; }
    to { background-position-x: -768px; } /* 6 frames * 128px = 768px */
}

@keyframes player-walk-anim {
    from { background-position-x: 0; }
    to { background-position-x: -640px; } /* 5 frames * 128px = 640px */
}

@keyframes enemy-idle-anim {
    from { background-position-x: 0; }
    to { background-position-x: -768px; } /* 6 * 128px = 768px for steps(6, end) */
}

@keyframes enemy-attack-anim {
    from { background-position-x: 0; }
    to { background-position-x: -768px; } /* 6 frames * 128px = 768px */
}

@keyframes enemy-hurt-anim {
    from { background-position-x: 0; }
    to { background-position-x: -384px; } /* 3 frames * 128px = 384px */
}

@keyframes enemy-death-anim {
    from { background-position-x: 0; }
    to { background-position-x: -768px; } /* 6 frames * 128px = 768px */
}

.character-info {
    flex: 1;
    min-width: 200px;
}

.character-info h3 {
    margin-bottom: 10px;
    color: #333;
    font-size: 1.3em;
}

/* HP Bar */
.hp-bar {
    position: relative;
    width: 100%;
    height: 25px;
    background: #f5dca6;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid #8b7355;
}

.hp-fill {
    height: 100%;
    transition: width 0.5s ease;
    border-radius: 10px;
}

.player-hp {
    background: linear-gradient(90deg, #4CAF50, #8BC34A);
}

.enemy-hp {
    background: linear-gradient(90deg, #f44336, #FF5722);
}

.hp-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7);
}

/* Timer Section */
.timer-section {
    margin-top: 10px;
    text-align: center;
}

.timer-section h4 {
    margin: 0 0 4px 0;
    color: #333;
    font-size: 0.9em;
}

.timer-display {
    font-size: 1.2em;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 4px;
    font-family: 'Courier New', monospace;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.timer-display.warning {
    color: #e67e22;
    animation: pulse-warning 1s ease-in-out infinite;
}

.timer-display.danger {
    color: #e74c3c;
    animation: pulse-danger 0.5s ease-in-out infinite;
}

@keyframes pulse-warning {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes pulse-danger {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.timer-bar {
    position: relative;
    width: 100%;
    height: 12px;
    background: #ddd;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid #333;
}

.timer-fill {
    height: 100%;
    background: linear-gradient(90deg, #27ae60, #2ecc71);
    border-radius: 8px;
    transition: width 0.1s linear, background 0.3s ease;
    width: 100%;
}

.timer-fill.warning {
    background: linear-gradient(90deg, #e67e22, #f39c12);
}

.timer-fill.danger {
    background: linear-gradient(90deg, #e74c3c, #c0392b);
}

/* Word Display in Combat Window */
.word-display-combat {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 15px;
    font-size: 0.9em;
    backdrop-filter: blur(5px);
    z-index: 25;
}

.word-info {
    display: flex;
    gap: 15px;
    align-items: center;
}

.word-info span {
    white-space: nowrap;
}

.word-info strong {
    color: #4CAF50;
}

/* Word Log Section */
.word-log-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 200px;
    max-height: 400px;
}

.word-log-section h3 {
    margin: 0 0 10px 0;
    color: #333;
    font-size: 1.1em;
    flex-shrink: 0;
}

.word-log {
    flex: 1;
    overflow-y: auto;
    background: rgba(250, 229, 172, 0.9);
    border-radius: 10px;
    padding: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    min-height: 0;
}

.word-log-stats {
    flex-shrink: 0;
    margin-top: 8px;
    padding: 8px;
    background: rgba(250, 229, 172, 0.7);
    border-radius: 8px;
    font-size: 0.9em;
    display: flex;
    justify-content: space-between;
}

/* Game Status */
.game-status {
    background: rgba(250, 229, 172, 0.9);
    border-radius: 15px;
    padding: 20px;
    margin-top: 20px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.game-status p {
    margin: 10px 0;
    font-size: 1.1em;
    color: #333;
}

.game-status span {
    font-weight: bold;
    color: #4CAF50;
}

/* Animations */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

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

@keyframes damage {
    0% { transform: translateX(0); filter: brightness(1); }
    25% { transform: translateX(-10px); filter: brightness(1.5) hue-rotate(0deg); }
    50% { transform: translateX(10px); filter: brightness(1.5) hue-rotate(180deg); }
    75% { transform: translateX(-5px); filter: brightness(1.2) hue-rotate(90deg); }
    100% { transform: translateX(0); filter: brightness(1); }
}

@keyframes attack {
    0% { transform: scale(1) translateX(0); }
    50% { transform: scale(1.1) translateX(10px); }
    100% { transform: scale(1) translateX(0); }
}

.shake {
    animation: shake 0.5s ease-in-out;
}

.pulse {
    animation: pulse 0.3s ease-in-out;
}

.damage {
    animation: damage 0.6s ease-in-out;
}

.attack {
    animation: attack 0.4s ease-in-out;
}

/* Combat Info Section */
.combat-info {
    background: rgba(250, 229, 172, 0.9);
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.hp-section {
    display: flex;
    gap: 20px;
}

.player-hp-info, .enemy-hp-info {
    flex: 1;
}

.player-hp-info h4, .enemy-hp-info h4 {
    margin: 0 0 8px 0;
    color: #333;
    font-size: 1em;
    text-align: center;
}

/* Game Status Full Width */
.game-status-full {
    grid-area: status;
    background: rgba(250, 229, 172, 0.9);
    border-radius: 15px;
    padding: 15px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.game-status-full p {
    margin: 5px 0;
    font-size: 1em;
    color: #333;
}

.game-status-full span {
    font-weight: bold;
    color: #4a90e2;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .game-container {
        width: 95vw;
        height: 95vh;
        border-radius: 15px;
    }
    
    .game-ui {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto;
        grid-template-areas:
            "right"      /* combat window */
            "left"       /* board */
            "status"     /* status */
            "wordlog";   /* word log at bottom */
        gap: 12px;
        padding: 12px;
    }

    /* Allow children of right-panel to participate in the parent grid */
    .right-panel { display: contents; }
    .combat-window { grid-area: right; }
    .word-log-section { grid-area: wordlog; }
    /* Hide desktop HUD box entirely on mobile */
    .combat-info { display: none; }
    
    .combat-window {
        height: 35vh; /* reduce height so board can fit below */
        aspect-ratio: auto;
        position: relative;
        z-index: 10;
    }
    
    .character-sprite { width: 96px; height: 96px; }
    /* Ensure specific sprite sizes are preserved on mobile */
    .combat-scene .player-sprite { width: 192px !important; height: 192px !important; }
    .combat-scene .enemy-sprite { width: 112px !important; height: 112px !important; }
    
    .boggle-board {
        width: clamp(220px, 90vw, 300px);
        aspect-ratio: 1 / 1;
        height: auto;
        margin-top: 24px; /* push board down below battle box */
    }

    /* Make submit button about half size */
    .game-button {
        padding: 6px 12px;
        font-size: 0.85em;
        border-radius: 6px;
    }
    
    .board-tile { font-size: 1.15em; }

    /* HUD moved to overlays/timer under board; hide boxed HUD */

    /* Hide non-essential headers to save space */
    .board-section { padding: 12px; box-shadow: none; }
    .board-section h2, .hand-title { display: none; }
    .board-controls { margin-top: 8px; gap: 6px; }
    /* Ensure HUD (health/timer) renders above battle box */
    .combat-info {
        position: relative;
        z-index: 30;
    }

    /* Mobile-only tweak: lower enemy sprite by 10px */
    .enemy-sprite { transform: translateY(70px); }

    /* Mobile-only: enlarge enemy platform to 1.5x (force override) */
    .combat-scene .enemy-platform { transform: translateY(80px) scale(1.5) !important; transform-origin: center bottom !important; }
}

@media (max-width: 768px) {
    .left-panel, .right-panel { padding: 10px; }
    
    .boggle-board { width: clamp(200px, 92vw, 260px); aspect-ratio: 1/1; height: auto; margin-top: 18px; }
    .tile-connections { width: 100% !important; height: 100% !important; }
    
    .board-tile { font-size: 0.98em; }
    
    .character-area { gap: 10px; }
    
    .character-sprite { width: 60px; height: 60px; }
    /* Preserve per-sprite sizes on small phones */
    .combat-scene .player-sprite { width: 192px !important; height: 192px !important; }
    .combat-scene .enemy-sprite { width: 112px !important; height: 112px !important; }

    /* Extra tuning for smallest phones */
    .combat-info { padding: 8px; gap: 8px; }
    .hp-section { gap: 10px; }
    .hp-bar { height: 16px; }
    .hp-text { font-size: 0.85em; }
    .timer-section h4 { font-size: 0.9em; }
    .timer-display { font-size: 1.05em; }
    .timer-bar { height: 8px; }

    /* Smaller submit button on phones */
    .game-button { padding: 5px 10px; font-size: 0.8em; border-radius: 6px; }

    /* Also hide headers here */
    .board-section { padding: 10px; box-shadow: none; }
    .board-section h2, .hand-title { display: none; }
    .board-controls { margin-top: 6px; gap: 6px; }
    /* Keep HUD above battle box on smallest screens */
    .combat-window { position: relative; z-index: 10; height: 32vh; }
    .combat-info { position: relative; z-index: 30; }

    /* Extra small mobile: ensure enemy sprite lowered by 10px */
    .enemy-sprite { transform: translateY(70px); }

    /* Extra small mobile: keep enemy platform at 1.5x (force override) */
    .combat-scene .enemy-platform { transform: translateY(80px) scale(1.5) !important; transform-origin: center bottom !important; }
}

/* Card Reward Overlay */
.card-reward-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-reward-container {
    background: rgba(245, 215, 166, 0.95);
    border-radius: 15px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    border: 3px solid #8B4513;
    max-width: 800px;
    width: 90%;
}

.card-reward-container h2 {
    color: #8B4513;
    font-size: 2rem;
    margin-bottom: 30px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.card-reward-options {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.reward-card {
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.reward-card:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

.reward-card.card-selected {
    animation: cardSelected 0.8s ease-out;
}

@keyframes cardSelected {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 1;
    }
    100% {
        transform: scale(1.3);
        opacity: 0;
    }
}

/* Card System Styles */
.hand-title {
    margin: 10px 0 5px 0;
    color: #333;
    font-size: 1.1em;
    text-align: center;
}

.card-hand {
    display: flex;
    flex-wrap: wrap;
    gap: -15px; /* Negative gap creates overlap */
    padding: 15px 25px;
    background: rgba(250, 229, 172, 0.9);
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    min-height: 130px;
    align-items: flex-start;
    justify-content: center;
    margin-right: 10px; /* Extra space for the overlapping effect */
}

.card {
    width: 75px;
    height: 105px;
    background: linear-gradient(135deg, #f0e6d2 0%, #f8f4e9 50%, #f0e6d2 100%);
    border: 1px solid #d4c4a8;
    border-radius: 8px;
    padding: 8px;
    cursor: grab;
    transition: all 0.2s ease;
    position: relative;
    font-size: 0.65em;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.8),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}

.card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow:
        0 6px 20px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.9),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1);
    border-color: #e6c84a;
    z-index: 10;
}

/* Board tile reset animation */
.board-tile-reset {
    transform: translateY(-8px) scale(1.12) rotate(5deg);
    box-shadow:
        0 10px 30px rgba(0, 0, 0, 0.3),
        inset 0 2px 0 rgba(255, 255, 255, 0.9),
        inset 0 -2px 0 rgba(0, 0, 0, 0.3);
    border-color: #4CAF50 !important;
    background: linear-gradient(135deg, #4CAF50, #66BB6A) !important;
    color: white !important;
    z-index: 20;
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Blank tile styling for transition state */
.tile-blank {
    opacity: 0.3;
    background: linear-gradient(135deg, #f5f5f5, #e0e0e0);
    color: #999;
    border-color: #ccc;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.card:active {
    cursor: grabbing;
}

.card-disabled {
    opacity: 0.4;
    cursor: not-allowed !important;
    filter: grayscale(60%) brightness(0.9);
}

.card.dragging {
    transform: rotate(3deg) scale(1.08);
    z-index: 1003;
    opacity: 1;
    box-shadow:
        0 8px 25px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.9),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}

.card-header {
    margin-bottom: 4px;
}

.card-name {
    font-weight: bold;
    color: #2c3e50;
    font-size: 0.8em;
    line-height: 1.1;
    flex: 1;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}


.card-description {
    color: #34495e;
    font-size: 0.7em;
    line-height: 1.1;
    text-align: left;
    flex: 2;
}

/* Card Play Area */
.card-play-area {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 200px;
    height: 120px;
    background: rgba(206, 93, 41, 0.473);
    border: 3px dashed #f0b330;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1001;
}

.card-play-area.active {
    opacity: 1;
    pointer-events: all;
}

.play-area-text {
    color: #f0c330;
    font-weight: bold;
    text-align: center;
    font-size: 0.9em;
}

/* Background blur overlay when dragging cards */
.card-drag-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.card-drag-overlay.active {
    opacity: 1;
}

/* Blur effect for main game content during card drag */
.game-container.card-drag-blur {
    filter: blur(2px);
    transition: filter 0.3s ease;
}

.game-container.card-drag-blur .card-hand,
.game-container.card-drag-blur .combat-info,
.game-container.card-drag-blur .board-section,
.game-container.card-drag-blur .word-log-section,
.game-container.card-drag-blur .game-status,
.game-container.card-drag-blur .hp-bar,
.game-container.card-drag-blur .deck-counter {
    filter: blur(2px);
}

/* Exclude dragged card, play area, and description from blur */
.game-container.card-drag-blur .card.dragging,
.game-container.card-drag-blur .card-play-area,
.game-container.card-drag-blur .card-description-overlay {
    filter: none !important;
}

/* Card description overlay when dragging */
.card-description-overlay {
    position: fixed;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 20px 30px;
    border-radius: 15px;
    font-size: 1.2em;
    font-weight: bold;
    text-align: center;
    z-index: 1002;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    max-width: 400px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.card-description-overlay.active {
    opacity: 1;
    transform: translateX(-50%) translateY(-10px);
}

.card-description-overlay h3 {
    margin: 0 0 10px 0;
    color: #4CAF50;
    font-size: 1.1em;
}

.card-description-overlay p {
    margin: 0;
    line-height: 1.4;
    color: #ffffff;
}

/* Board greying out during card effects */
.boggle-board.card-effect-active .board-tile:not(.selectable-for-card) {
    opacity: 0.3;
    filter: grayscale(50%);
}

/* Tile selection for card effects */
.board-tile.selectable-for-card {
    border: 2px solid #e67e22 !important;
    background: rgba(230, 126, 34, 0.2) !important;
    cursor: pointer !important;
    pointer-events: auto !important;
    opacity: 0.7 !important;
    transition: all 0.2s ease;
    position: relative;
    z-index: 5;
}

.board-tile.selectable-for-card:hover {
    background: rgba(230, 126, 34, 0.5) !important;
    transform: scale(1.08);
    opacity: 1 !important;
    box-shadow: 0 6px 16px rgba(230, 126, 34, 0.4);
    z-index: 10;
    border-color: #d35400 !important;
}

/* Tile change animation */
.tile-changed {
    animation: tileChange 0.5s ease;
}

/* First selected tile for swapping */
.board-tile.first-selected-tile {
    border: 3px solid #27ae60 !important;
    background: rgba(39, 174, 96, 0.3) !important;
    box-shadow: 0 0 12px rgba(39, 174, 96, 0.6) !important;
    transform: scale(1.05) !important;
    z-index: 15 !important;
    animation: firstTileSelected 0.3s ease-out;
}

/* Adjacent tiles available for swapping */
.board-tile.adjacent-swap-target {
    border: 2px solid #f39c12 !important;
    background: rgba(243, 156, 18, 0.2) !important;
    box-shadow: 0 0 8px rgba(243, 156, 18, 0.4) !important;
    transform: scale(1.02) !important;
    z-index: 10 !important;
    animation: adjacentTargetPulse 1.5s ease-in-out infinite;
}

.board-tile.adjacent-swap-target:hover {
    background: rgba(243, 156, 18, 0.3) !important;
    box-shadow: 0 0 12px rgba(243, 156, 18, 0.6) !important;
    transform: scale(1.05) !important;
}

@keyframes firstTileSelected {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0px rgba(39, 174, 96, 0);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 0 15px rgba(39, 174, 96, 0.8);
    }
    100% {
        transform: scale(1.05);
        box-shadow: 0 0 12px rgba(39, 174, 96, 0.6);
    }
}

@keyframes adjacentTargetPulse {
    0%, 100% {
        opacity: 0.7;
        transform: scale(1.02);
    }
    50% {
        opacity: 1;
        transform: scale(1.04);
    }
}

@keyframes tileChange {
    0% { 
        background: #4CAF50;
        transform: scale(1);
    }
    50% { 
        background: #5bf060;
        transform: scale(1.1);
    }
    100% { 
        background: '';
        transform: scale(1);
    }
}

/* Card rarity colors */
.card.common {
    border-color: #6c757d;
}

.card.uncommon {
    border-color: #28a745;
}

.card.rare {
    border-color: #007bff;
}

.card.epic {
    border-color: #6f42c1;
}

.card.legendary {
    border-color: #fd7e14;
}

/* Kana Selector Overlay Styles */
.kana-selector {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    animation: kanaOverlayFadeIn 0.3s ease-out;
    padding: 2vh;
    box-sizing: border-box;
    overflow-y: auto;
}

@keyframes kanaOverlayFadeIn {
    from {
        opacity: 0;
        backdrop-filter: blur(0px);
        -webkit-backdrop-filter: blur(0px);
    }
    to {
        opacity: 1;
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }
}

.kana-selector-title {
    text-align: center;
    font-size: clamp(1.5em, 4vh, 2.2em);
    font-weight: bold;
    color: white;
    margin-bottom: clamp(15px, 3vh, 30px);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    animation: kanaTitleSlideIn 0.4s ease-out 0.1s both;
    flex-shrink: 0;
}

@keyframes kanaTitleSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.kana-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: clamp(4px, 0.8vh, 8px);
    max-width: min(85vw, 70vh);
    padding: clamp(5px, 1vh, 15px);
    animation: kanaGridSlideIn 0.5s ease-out 0.2s both;
    flex: 1;
    align-content: center;
    justify-content: center;
}

@keyframes kanaGridSlideIn {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.kana-button {
    width: clamp(30px, 4vh, 45px);
    height: clamp(30px, 4vh, 45px);
    background: linear-gradient(145deg, #f0f0f0, #d0d0d0);
    border: clamp(1px, 0.3vh, 2px) solid #8e44ad;
    border-radius: clamp(4px, 0.8vh, 8px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.8em, 1.8vh, 1.1em);
    font-weight: bold;
    color: #2c3e50;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    box-shadow: 0 clamp(1px, 0.4vh, 2px) clamp(2px, 0.8vh, 4px) rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
}

.kana-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transition: left 0.5s;
}

.kana-button:hover {
    background: linear-gradient(145deg, #9b59b6, #8e44ad);
    color: white;
    transform: scale(1.1) translateY(clamp(-1px, -0.2vh, -1px));
    border-color: #7d3c98;
    box-shadow: 0 clamp(2px, 0.8vh, 4px) clamp(4px, 1.5vh, 8px) rgba(142, 68, 173, 0.4);
}

.kana-button:hover::before {
    left: 100%;
}

.kana-button:active {
    transform: scale(0.95) translateY(clamp(0.5px, 0.2vh, 1px));
    box-shadow: 0 clamp(1px, 0.4vh, 2px) clamp(2px, 0.8vh, 4px) rgba(0, 0, 0, 0.3);
}

.kana-instruction {
    text-align: center;
    color: white;
    font-size: clamp(0.9em, 2.5vh, 1.1em);
    margin-top: clamp(10px, 2vh, 20px);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    animation: kanaInstructionFadeIn 0.6s ease-out 0.3s both;
    flex-shrink: 0;
}

@keyframes kanaInstructionFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Additional responsive adjustments for very small screens */
@media (max-height: 600px) {
    .kana-selector {
        justify-content: flex-start;
        padding: 1vh;
    }
    
    .kana-selector-title {
        margin-bottom: 1vh;
    }
    
    .kana-grid {
        padding: 1vh;
        gap: 4px;
    }
    
    .kana-instruction {
        margin-top: 1vh;
    }
}

@media (max-width: 480px) {
    .kana-grid {
        max-width: 95vw;
        gap: 3px;
    }
    
    .kana-button {
        width: clamp(25px, 12vw, 35px);
        height: clamp(25px, 12vw, 35px);
        font-size: clamp(0.8em, 3vw, 1.1em);
    }
}

/* Uncommon card styling */
.card.uncommon {
    border-color: #28a745;
    background: linear-gradient(135deg, #f8fff9 0%, #e8f5e8 100%);
}

/* Deck Counter Styles */
.deck-counter {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    background: rgba(250, 229, 172, 0.9);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-top: 10px;
    transition: all 0.3s ease;
}

.deck-counter.deck-updated {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.deck-icon {
    font-size: 1.5em;
    margin-bottom: 4px;
}

.deck-count {
    font-size: 1.4em;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 2px;
}

.deck-label {
    font-size: 0.9em;
    color: #6c757d;
    font-weight: 500;
}

/* Card Drawing Animation */
.card-drawing {
    transform: scale(0.8) rotate(-5deg);
    opacity: 0.9;
}

.card-drawing:not(.card-drawing) {
    transform: scale(1) rotate(0deg);
}

/* Enhanced card entrance animation */
.card.newly-drawn {
    animation: cardSlideIn 0.4s ease-out;
}

@keyframes cardSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}