/**
 * Bilge Pumping - A Puzzle Pirates Tribute
 * Styles for the bilge pumping puzzle game
 */

/* ========================================
   CSS Custom Properties
   ======================================== */
:root {
    /* Colors - Pirate/Ocean theme */
    --color-bg-dark: #1a3a4a;
    --color-bg-medium: #2a5a6a;
    --color-bg-light: #3a7a8a;
    --color-wood-dark: #4a3528;
    --color-wood-medium: #6b4c3a;
    --color-wood-light: #8b6c4a;
    --color-gold: #d4a650;
    --color-gold-light: #f4c670;
    --color-water: #1a4a6a;
    --color-water-light: rgba(100, 180, 220, 0.4);
    --color-text: #f0e6d2;
    --color-text-dim: #a09080;

    /* Layout */
    --board-cols: 6;
    --board-rows: 12;
    --cell-size: 48px;
    --cell-gap: 2px;
    --border-radius: 8px;

    /* Animations */
    --transition-fast: 0.15s;
    --transition-medium: 0.25s;
    --transition-slow: 0.4s;
}

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

html {
    font-size: 16px;
}

body {
    font-family: 'Trebuchet MS', 'Lucida Sans', Arial, sans-serif;
    background: linear-gradient(180deg, var(--color-bg-dark) 0%, var(--color-bg-medium) 50%, var(--color-bg-light) 100%);
    min-height: 100vh;
    color: var(--color-text);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.25rem;
}

/* ========================================
   Game Container
   ======================================== */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    max-width: 900px;
    width: 100%;
}

/* ========================================
   Header
   ======================================== */
.game-header {
    text-align: center;
    padding: 0.5rem 2rem;
    background: linear-gradient(180deg, var(--color-wood-light) 0%, var(--color-wood-dark) 100%);
    border-radius: var(--border-radius);
    border: 3px solid var(--color-gold);
    box-shadow:
        0 4px 8px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.game-title {
    font-size: 2rem;
    font-weight: bold;
    color: var(--color-gold-light);
    text-shadow:
        2px 2px 0 var(--color-wood-dark),
        0 0 10px rgba(212, 166, 80, 0.5);
    letter-spacing: 2px;
}

.game-subtitle {
    font-size: 0.875rem;
    color: var(--color-text-dim);
    margin-top: 0.25rem;
}

/* ========================================
   Game Area Layout (Mobile-first: Grid)
   ======================================== */
.game-area {
    display: grid;
    grid-template-columns: 50px 1fr;
    gap: 0.5rem;
    align-items: stretch;
}

/* Hide debug panel by default (mobile) */
.sidebar-right {
    display: none;
}

/* ========================================
   Sidebars
   ======================================== */
.sidebar {
    width: auto;
}

.sidebar-left {
    width: 50px;
}

/* Score Bucket - Bilge Level */
.score-bucket {
    background: linear-gradient(180deg, var(--color-wood-medium) 0%, var(--color-wood-dark) 100%);
    border: 2px solid var(--color-gold);
    border-radius: var(--border-radius);
    padding: 0.5rem 0.3rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.bucket-label {
    font-size: 0.875rem;
    color: var(--color-gold-light);
    margin-bottom: 0.5rem;
    font-weight: bold;
}

.bucket-container {
    position: relative;
    width: 100%;
    max-width: 40px;
    /* Grow to fill available space in the score-bucket */
    flex: 1;
    margin: 0 auto;
    background: var(--color-wood-dark);
    border-radius: 0 0 12px 12px;
    border: 2px solid var(--color-wood-light);
    overflow: hidden;
}

.bucket-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100%;
    background: linear-gradient(180deg, #4a90c2 0%, #2a6090 100%);
    transform-origin: bottom;
    transform: scaleY(1);
    transition: transform var(--transition-medium);
    will-change: transform;
}

.bucket-fill::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 8px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.3) 0%, transparent 100%);
}

.score-display {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.score-label {
    font-size: 0.75rem;
    color: var(--color-text-dim);
}

.score-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--color-gold-light);
}

/* Debug Panel */
.debug-panel {
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid var(--color-gold);
    border-radius: var(--border-radius);
    padding: 0.75rem;
    font-size: 0.75rem;
}

.debug-title {
    color: var(--color-gold-light);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    text-align: center;
    border-bottom: 1px solid var(--color-gold);
    padding-bottom: 0.5rem;
}

.debug-section {
    margin-bottom: 0.75rem;
}

.debug-section h4 {
    color: var(--color-text-dim);
    font-size: 0.7rem;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.debug-item {
    display: flex;
    justify-content: space-between;
    padding: 0.125rem 0;
}

.debug-item.total {
    border-top: 1px solid var(--color-text-dim);
    margin-top: 0.25rem;
    padding-top: 0.25rem;
    font-weight: bold;
}

.debug-label {
    color: var(--color-text-dim);
}

.debug-value {
    color: var(--color-text);
    font-family: 'Courier New', monospace;
}

/* ========================================
   Game Board
   ======================================== */
.board-wrapper {
    flex-shrink: 0;
}

.board-frame {
    position: relative;
    background: linear-gradient(135deg, var(--color-gold) 0%, var(--color-gold-light) 50%, var(--color-gold) 100%);
    padding: 4px;
    border-radius: calc(var(--border-radius) + 4px);
    box-shadow:
        0 8px 16px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.game-board {
    display: grid;
    grid-template-columns: repeat(var(--board-cols), var(--cell-size));
    grid-template-rows: repeat(var(--board-rows), var(--cell-size));
    gap: var(--cell-gap);
    background: var(--color-bg-dark);
    padding: var(--cell-gap);
    border-radius: var(--border-radius);
    position: relative;
}

/* Water overlay */
.water-overlay {
    position: absolute;
    bottom: 4px;
    left: 4px;
    right: 4px;
    height: calc((var(--cell-size) + var(--cell-gap)) * 3);
    background: linear-gradient(180deg,
        transparent 0%,
        var(--color-water-light) 30%,
        rgba(50, 120, 180, 0.5) 100%
    );
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    pointer-events: none;
    z-index: 10;
}

/* ========================================
   Game Pieces - Base
   ======================================== */
.piece {
    width: var(--cell-size);
    height: var(--cell-size);
    border-radius: 6px;
    cursor: pointer;
    transition:
        transform var(--transition-fast),
        box-shadow var(--transition-fast),
        filter var(--transition-fast);
    position: relative;
    overflow: hidden;
}

/* Hover pair selection - highlight z-index */
.piece.hover-pair {
    z-index: 5;
}

/* Selection overlay - positioned by JavaScript */
.selection-overlay {
    position: absolute;
    border: 3px dashed #ff6040;
    border-radius: 8px;
    pointer-events: none;
    z-index: 100;
    box-sizing: border-box;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.3),
        inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.piece.selected {
    z-index: 6;
}

.piece.swapping {
    transition: transform var(--transition-medium) ease-out;
    z-index: 20;
}

.piece.falling {
    transition: transform var(--transition-slow) ease-in;
}

.piece.clearing {
    animation: clear 0.3s ease-out forwards;
    /* Disable transitions to prevent interference with animation */
    transition: none;
}

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

.piece.spawning {
    animation: spawn 0.3s ease-out;
}

@keyframes spawn {
    0% { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ========================================
   Piece Types - Highly Distinct Designs
   ======================================== */

/* Type 1: JELLYFISH - Rounded purple/pink with tentacles */
.piece[data-type="1"] {
    background: radial-gradient(ellipse 80% 60% at 50% 40%, #e8a0d0 0%, #c060a0 50%, #903070 100%);
    border-radius: 50% 50% 40% 40%;
    box-shadow:
        inset 2px 2px 8px rgba(255, 255, 255, 0.4),
        inset -2px -2px 6px rgba(0, 0, 0, 0.2),
        0 3px 6px rgba(0, 0, 0, 0.3);
}

.piece[data-type="1"]::before {
    content: '';
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    height: 35%;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 20'%3E%3Cpath d='M5 0 Q6 10, 5 18 M12 0 Q14 12, 12 20 M20 0 Q22 14, 20 18 M28 0 Q26 12, 28 20 M35 0 Q34 10, 35 18' stroke='%23c080b0' stroke-width='2' fill='none' opacity='0.7'/%3E%3C/svg%3E") center/contain no-repeat;
}

.piece[data-type="1"]::after {
    content: '';
    position: absolute;
    top: 20%;
    left: 25%;
    width: 15%;
    height: 20%;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
}

/* Type 2: CRAB - Orange/red square with claws */
.piece[data-type="2"] {
    background: linear-gradient(180deg, #f08040 0%, #d05020 50%, #a03010 100%);
    border-radius: 8px;
    box-shadow:
        inset 2px 2px 6px rgba(255, 200, 150, 0.4),
        inset -2px -2px 4px rgba(0, 0, 0, 0.3),
        0 3px 6px rgba(0, 0, 0, 0.3);
}

.piece[data-type="2"]::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 85%;
    height: 85%;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cellipse cx='20' cy='22' rx='12' ry='10' fill='%23c04020'/%3E%3Ccircle cx='14' cy='16' r='4' fill='%23101010'/%3E%3Ccircle cx='26' cy='16' r='4' fill='%23101010'/%3E%3Ccircle cx='15' cy='15' r='1.5' fill='white'/%3E%3Ccircle cx='27' cy='15' r='1.5' fill='white'/%3E%3Cpath d='M4 18 Q2 14, 6 12 L10 16' stroke='%23d05030' stroke-width='3' fill='none'/%3E%3Cpath d='M36 18 Q38 14, 34 12 L30 16' stroke='%23d05030' stroke-width='3' fill='none'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* Type 3: FISH - Teal/cyan fish shape */
.piece[data-type="3"] {
    background: linear-gradient(135deg, #40d0d0 0%, #20a0b0 50%, #107080 100%);
    border-radius: 50% 20% 50% 20%;
    box-shadow:
        inset 3px 3px 8px rgba(255, 255, 255, 0.3),
        inset -2px -2px 4px rgba(0, 0, 0, 0.2),
        0 3px 6px rgba(0, 0, 0, 0.3);
}

.piece[data-type="3"]::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    height: 90%;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Ccircle cx='28' cy='18' r='4' fill='%23103040'/%3E%3Ccircle cx='29' cy='17' r='1.5' fill='white'/%3E%3Cpath d='M2 20 L12 14 L12 26 Z' fill='%2330b0c0'/%3E%3Cpath d='M18 20 Q22 16, 26 20 Q22 24, 18 20' stroke='%2360e0e0' stroke-width='1' fill='none' opacity='0.6'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* Type 4: STARFISH - Yellow/gold star shape */
.piece[data-type="4"] {
    background: radial-gradient(circle at 50% 50%, #ffe060 0%, #e0b030 50%, #c09020 100%);
    border-radius: 6px;
    box-shadow:
        inset 2px 2px 6px rgba(255, 255, 200, 0.5),
        inset -2px -2px 4px rgba(0, 0, 0, 0.15),
        0 3px 6px rgba(0, 0, 0, 0.3);
}

.piece[data-type="4"]::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    height: 90%;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M20 2 L23 15 L36 15 L26 23 L30 36 L20 28 L10 36 L14 23 L4 15 L17 15 Z' fill='%23d09010' stroke='%23a07000' stroke-width='1'/%3E%3Ccircle cx='20' cy='20' r='4' fill='%23e0a020'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* Type 5: SHELL - Green spiral seashell */
.piece[data-type="5"] {
    background: linear-gradient(135deg, #80d080 0%, #40a060 50%, #208040 100%);
    border-radius: 40% 60% 60% 40%;
    box-shadow:
        inset 2px 2px 6px rgba(255, 255, 255, 0.3),
        inset -2px -2px 4px rgba(0, 0, 0, 0.2),
        0 3px 6px rgba(0, 0, 0, 0.3);
}

.piece[data-type="5"]::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    height: 80%;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M20 8 Q30 10, 32 20 Q30 30, 20 32 Q12 30, 12 22 Q14 16, 20 16 Q24 18, 22 22 Q20 24, 18 22' stroke='%2360c070' stroke-width='2.5' fill='none'/%3E%3Ccircle cx='19' cy='21' r='2' fill='%2340a050'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* Submerged pieces (below water line) */
.piece.submerged {
    filter: brightness(0.85) saturate(1.1);
}

.piece.submerged.hover-pair {
    filter: brightness(1.0) saturate(1.1);
}

/* ========================================
   Footer / Controls
   ======================================== */
.game-footer {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.btn {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: bold;
    border: 2px solid var(--color-gold);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(180deg, var(--color-gold-light) 0%, var(--color-gold) 100%);
    color: var(--color-wood-dark);
}

.btn-primary:hover {
    background: linear-gradient(180deg, var(--color-gold) 0%, var(--color-gold-light) 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.btn-secondary {
    background: linear-gradient(180deg, var(--color-wood-medium) 0%, var(--color-wood-dark) 100%);
    color: var(--color-text);
}

.btn-secondary:hover {
    background: linear-gradient(180deg, var(--color-wood-light) 0%, var(--color-wood-medium) 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

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

/* ========================================
   Responsive Design (Mobile-first)
   ======================================== */

/* Mobile bucket sizing - use same formula as desktop but will adapt to cell-size */
.bucket-container {
    width: 32px;
}

.score-bucket {
    padding: 0.3rem;
    /* Keep the calculated height formula - it adapts to --cell-size */
}

.bucket-label {
    font-size: 0.6rem;
    margin-bottom: 0.2rem;
}

.score-label {
    font-size: 0.5rem;
}

.score-value {
    font-size: 0.85rem;
}

/* Very small phones: up to 400px */
@media (max-width: 400px) {
    :root {
        --cell-size: 42px;
    }

    .game-area {
        grid-template-columns: 45px 1fr;
    }

    .sidebar-left {
        width: 45px;
    }

    .bucket-container {
        width: 28px;
    }

    .game-title {
        font-size: 1.2rem;
    }
}

/* Desktop: 769px and up - show 3-column flex layout with debug panel */
@media (min-width: 769px) {
    body {
        padding: 1rem;
    }

    .game-container {
        gap: 1rem;
    }

    .game-area {
        display: flex;
        gap: 1rem;
        align-items: flex-start;
    }

    .sidebar {
        width: 160px;
    }

    .sidebar-left {
        width: 160px;
    }

    .sidebar-right {
        display: block;
    }

    .score-bucket {
        padding: 0.75rem;
        /* Match board-frame height */
        height: calc(var(--board-rows) * var(--cell-size) + (var(--board-rows) - 1) * var(--cell-gap) + var(--cell-gap) * 2 + 8px);
    }

    .bucket-container {
        width: 80px;
        max-width: 80px;
        height: auto;
        flex: 1;
        border-radius: 0 0 20px 20px;
        border: 3px solid var(--color-wood-light);
    }

    .bucket-label {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
    }

    .score-label {
        font-size: 0.75rem;
    }

    .score-value {
        font-size: 1.5rem;
    }
}

/* ========================================
   Match highlighting
   ======================================== */
.piece.matched {
    animation: matched-glow 0.3s ease-out;
}

@keyframes matched-glow {
    0% { box-shadow: 0 0 0 0 rgba(255, 255, 200, 0.8); }
    50% { box-shadow: 0 0 20px 10px rgba(255, 255, 200, 0.6); }
    100% { box-shadow: 0 0 0 0 rgba(255, 255, 200, 0); }
}

/* Combo indicator */
.combo-text {
    position: absolute;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--color-gold-light);
    text-shadow: 2px 2px 0 var(--color-wood-dark);
    pointer-events: none;
    z-index: 100;
    animation: combo-pop 0.8s ease-out forwards;
}

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

/* ========================================
   Game Over Overlay
   ======================================== */
.game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 20, 40, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.5s ease-out;
}

.game-over-overlay.visible {
    opacity: 1;
}

.game-over-content {
    background: linear-gradient(180deg, var(--color-wood-light) 0%, var(--color-wood-dark) 100%);
    border: 4px solid var(--color-gold);
    border-radius: 16px;
    padding: 2rem 3rem;
    text-align: center;
    box-shadow:
        0 0 30px rgba(212, 175, 55, 0.4),
        inset 0 2px 4px rgba(255, 255, 255, 0.2);
    transform: scale(0.8);
    animation: game-over-pop 0.5s ease-out 0.2s forwards;
}

@keyframes game-over-pop {
    0% { transform: scale(0.8); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.game-over-title {
    font-size: 2.5rem;
    color: var(--color-gold-light);
    text-shadow:
        2px 2px 0 var(--color-wood-dark),
        0 0 20px rgba(212, 175, 55, 0.5);
    margin: 0 0 0.5rem 0;
}

.game-over-subtitle {
    font-size: 1.2rem;
    color: var(--color-text-muted);
    margin: 0 0 1.5rem 0;
}

.game-over-stats {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-label {
    color: var(--color-text-muted);
}

.stat-value {
    color: var(--color-text);
    font-weight: bold;
}

.stat-value.highlight {
    color: var(--color-gold-light);
    font-size: 1.3rem;
}

.play-again-btn {
    background: linear-gradient(180deg, var(--color-accent) 0%, #1565c0 100%);
    color: white;
    border: 2px solid var(--color-gold);
    border-radius: 8px;
    padding: 0.75rem 2rem;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.play-again-btn:hover {
    background: linear-gradient(180deg, #2196f3 0%, var(--color-accent) 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

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

