/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4a5568;
    --primary-hover: #2d3748;
    --secondary-color: #718096;
    --secondary-hover: #4a5568;
    --success-color: #48bb78;
    --error-color: #f56565;
    --bg-color: #f7fafc;
    --card-bg: #ffffff;
    --text-color: #2d3748;
    --text-light: #718096;
    --border-color: #e2e8f0;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
}

body.embedded {
    min-height: auto;
    padding: 0;
}

.game-container {
    width: 100%;
    max-width: 600px;
    min-height: 900px;
    max-height: 900px;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

body.embedded .game-container {
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
    box-shadow: none;
}

/* Header */
.game-header {
    background: linear-gradient(135deg, #1e40af 0%, #1e3a8a 100%);
    color: white;
    padding: 10px 16px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.game-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin: 0;
    white-space: nowrap;
}

.header-stats {
    display: flex;
    gap: 20px;
    align-items: center;
    flex: 1;
    justify-content: center;
}

.header-stats .stat-item {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
}

.header-stats .stat-label {
    font-size: 12px;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: white;
    white-space: nowrap;
}

.header-stats .stat-value {
    font-size: 18px;
    font-weight: 700;
    color: #fbbf24;
    min-width: 30px;
    text-align: right;
}

.mode-selector {
    display: flex;
    gap: 4px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 4px;
}

.mode-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    background: transparent;
    color: rgba(255, 255, 255, 0.7);
    font-family: inherit;
}

.mode-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.mode-btn.active {
    background: white;
    color: var(--primary-color);
}


.header-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    justify-content: flex-end;
    white-space: nowrap;
}

/* Buttons */
.btn {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    white-space: nowrap;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

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

.btn-primary {
    background: white;
    color: var(--primary-color);
}

.btn-primary:hover:not(:disabled) {
    background: #f7fafc;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.btn-primary.pulse {
    animation: pulseButton 1.5s ease-in-out infinite;
}

@keyframes pulseButton {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 4px 16px rgba(74, 85, 104, 0.4);
    }
}

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

.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.btn-hint {
    background: rgba(255, 193, 7, 0.9);
    color: #1e3a8a;
    border: 1px solid rgba(255, 193, 7, 1);
    font-weight: 700;
}

.btn-hint:hover:not(:disabled) {
    background: rgba(255, 193, 7, 1);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(255, 193, 7, 0.4);
}

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

/* Hint button pulse animation for failed attempts */
.btn-secondary.pulse-hint {
    animation: pulseHint 1.5s ease-in-out infinite;
}

@keyframes pulseHint {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.4);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 8px rgba(255, 255, 255, 0);
    }
}

/* Main Game Area */
.game-main {
    padding: 24px 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

/* Section Titles */
.section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 8px;
}

/* Available Letters Section */
.letters-section {
    width: 100%;
}

.available-letters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    padding: 12px;
    background: var(--bg-color);
    border-radius: 8px;
    min-height: 70px;
    align-items: center;
}

.letter-tile.board-letter {
    width: 100%;
    height: 100%;
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    cursor: pointer;
}

.letter-tile.board-letter:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.letter-tile.hint-highlight {
    background: rgba(255, 193, 7, 0.9) !important;
    border-color: rgba(255, 193, 7, 1) !important;
    color: #1e3a8a !important;
    animation: pulseHint 1s ease-in-out;
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(255, 193, 7, 0.6);
}

@keyframes pulseHint {
    0%, 100% {
        transform: scale(1.1);
        box-shadow: 0 0 15px rgba(255, 193, 7, 0.6);
    }
    50% {
        transform: scale(1.15);
        box-shadow: 0 0 20px rgba(255, 193, 7, 0.8);
    }
}

/* Game Board Section */
.board-section {
    width: 100%;
}

.game-board {
    display: grid;
    gap: 2px;
    background: var(--border-color);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 2px;
    width: 100%;
    aspect-ratio: 8 / 5; /* 8 columns : 5 rows */
}

.board-cell {
    aspect-ratio: 1;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    position: relative;
    min-height: 40px;
}

.board-cell:hover {
    background: rgba(74, 85, 104, 0.05);
    border-color: var(--primary-color);
}

.board-cell.drag-over {
    background: rgba(74, 85, 104, 0.15);
    border-color: var(--primary-color);
    border-width: 2px;
    transform: scale(1.05);
}

.board-cell.has-letter {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.board-cell.pre-filled {
    background: rgba(120, 113, 108, 0.15) !important;
    border-color: rgba(120, 113, 108, 0.5) !important;
    border-style: solid !important;
    border-width: 2px !important;
}

.board-cell.pre-filled .letter-tile.pre-filled-letter,
.board-cell.pre-filled .letter-tile.board-letter.pre-filled-letter {
    background: linear-gradient(135deg, rgba(87, 83, 78, 0.95), rgba(120, 113, 108, 0.95)) !important;
    border: none !important;
    color: white !important;
    font-weight: 600 !important;
    cursor: not-allowed !important;
    box-shadow: 0 2px 6px rgba(87, 83, 78, 0.4) !important;
}

.board-cell.pre-filled:hover {
    background: rgba(120, 113, 108, 0.25) !important;
    border-color: rgba(120, 113, 108, 0.7) !important;
}

.board-cell.pre-filled .letter-tile.pre-filled-letter:hover {
    transform: none !important;
    background: linear-gradient(135deg, rgba(87, 83, 78, 0.95), rgba(120, 113, 108, 0.95)) !important;
}

.board-cell.has-letter .letter-tile.board-letter {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

/* Ensure pre-filled letters override regular letter styles */
.board-cell.pre-filled.has-letter .letter-tile.pre-filled-letter,
.board-cell.pre-filled.has-letter .letter-tile.board-letter.pre-filled-letter {
    background: linear-gradient(135deg, rgba(87, 83, 78, 0.95), rgba(120, 113, 108, 0.95)) !important;
    border: none !important;
    color: white !important;
}

.board-cell.correct {
    background: var(--success-color) !important;
    border-color: var(--success-color) !important;
    color: white;
}

.board-cell.correct .letter-tile.board-letter {
    background: var(--success-color) !important;
    border-color: var(--success-color) !important;
    color: white !important;
}

/* Pre-filled letters in correct rows should have green tint */
.board-cell.pre-filled.correct {
    background: var(--success-color) !important;
    border-color: var(--success-color) !important;
}

.board-cell.pre-filled.correct .letter-tile.pre-filled-letter,
.board-cell.pre-filled.correct .letter-tile.board-letter.pre-filled-letter {
    background: linear-gradient(135deg, rgba(72, 187, 120, 0.95), rgba(104, 211, 145, 0.95)) !important;
    border: none !important;
    color: white !important;
}

.board-cell.correct .letter-tile.board-letter:hover {
    background: var(--success-color) !important;
    transform: scale(1.05);
}

.board-cell.incorrect {
    background: rgba(245, 101, 101, 0.2);
    border-color: var(--error-color);
    animation: shakeRow 0.5s ease-in-out;
}

/* Pre-filled letters in incorrect words should have red border */
.board-cell.pre-filled.incorrect {
    background: rgba(245, 101, 101, 0.2) !important;
    border-color: var(--error-color) !important;
}

.board-cell.pre-filled.incorrect .letter-tile.pre-filled-letter,
.board-cell.pre-filled.incorrect .letter-tile.board-letter.pre-filled-letter {
    background: linear-gradient(135deg, rgba(87, 83, 78, 0.95), rgba(120, 113, 108, 0.95)) !important;
    border: none !important;
    color: white !important;
}

.board-cell.invalid-hint-highlight {
    background: rgba(245, 101, 101, 0.5) !important;
    border-color: rgba(245, 101, 101, 1) !important;
    border-width: 3px !important;
    animation: pulseInvalidHint 1s ease-in-out;
    box-shadow: 0 0 15px rgba(245, 101, 101, 0.6);
}

@keyframes pulseInvalidHint {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 15px rgba(245, 101, 101, 0.6);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 20px rgba(245, 101, 101, 0.8);
    }
}

.board-cell.hint-cell {
    background: rgba(255, 193, 7, 0.3) !important;
    border-color: rgba(255, 193, 7, 1) !important;
    border-width: 3px !important;
    animation: pulseHintCell 1s ease-in-out;
    box-shadow: 0 0 15px rgba(255, 193, 7, 0.6);
}

@keyframes pulseHintCell {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 15px rgba(255, 193, 7, 0.6);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 20px rgba(255, 193, 7, 0.8);
    }
}

@keyframes shakeRow {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

/* Found Words Section */
.words-section {
    width: 100%;
    max-height: 200px;
    overflow-y: auto;
}

.found-words {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: var(--bg-color);
    border-radius: 8px;
    min-height: 60px;
    max-height: 200px;
    overflow-y: auto;
}

.no-words-message {
    text-align: center;
    color: var(--text-light);
    font-size: 14px;
    padding: 20px;
}

.found-word-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--card-bg);
    border-radius: 6px;
    border-left: 3px solid var(--success-color);
    animation: slideIn 0.3s ease-out;
}

.word-text {
    font-weight: 600;
    color: var(--text-color);
    font-size: 16px;
    letter-spacing: 0.5px;
}

.word-score {
    font-weight: 700;
    color: var(--success-color);
    font-size: 14px;
}

.game-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
}


/* Scrollbar Styling */
.found-words::-webkit-scrollbar {
    width: 6px;
}

.found-words::-webkit-scrollbar-track {
    background: var(--bg-color);
    border-radius: 3px;
}

.found-words::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.found-words::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

.letter-tile {
    width: 48px;
    height: 48px;
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
    color: var(--text-color);
    cursor: grab;
    transition: var(--transition);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    box-shadow: var(--shadow);
    position: relative;
    touch-action: none;
    -webkit-touch-callout: none;
}

.letter-tile:active {
    cursor: grabbing;
}

.letter-tile:hover:not(.used):not(.dragging) {
    transform: translateY(-2px) scale(1.05);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.letter-tile.used {
    opacity: 0.4;
    cursor: not-allowed;
    transform: scale(0.9);
    background: var(--bg-color);
}

.letter-tile.dragging {
    opacity: 0.5;
    z-index: 1000;
    transform: scale(1.1);
    cursor: grabbing;
}

.letter-tile.drag-over {
    border-color: var(--primary-color);
    background: rgba(74, 85, 104, 0.1);
    transform: scale(1.05);
}

@media (max-width: 480px) {
    .letter-tile {
        width: 42px;
        height: 42px;
        font-size: 20px;
    }
}

/* Answer Container */
.answer-container {
    width: 100%;
}

.answer-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 8px;
}

.answer-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 56px;
}

.answer-tiles {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 40px 12px 16px;
    min-height: 56px;
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    align-items: center;
    transition: var(--transition);
    position: relative;
}

.answer-tiles.drag-over {
    border-color: var(--primary-color);
    background: rgba(74, 85, 104, 0.05);
    box-shadow: 0 0 0 3px rgba(74, 85, 104, 0.1);
}

.answer-tile {
    width: 44px;
    height: 44px;
    background: var(--primary-color);
    color: white;
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 700;
    cursor: grab;
    transition: var(--transition);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    box-shadow: var(--shadow);
    touch-action: none;
    -webkit-touch-callout: none;
    position: relative;
}

.answer-tile.correct {
    background: var(--success-color);
    border-color: var(--success-color);
}

.answer-tile.celebrate {
    animation: celebrateTile 0.6s ease-out;
}

@keyframes celebrateTile {
    0% {
        transform: scale(1) rotate(0deg);
    }
    50% {
        transform: scale(1.2) rotate(180deg) translateY(-10px);
    }
    100% {
        transform: scale(1) rotate(360deg);
    }
}

.celebrate-container {
    animation: celebrateContainer 0.5s ease-out;
}

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

/* Confetti animation */
.confetti {
    position: fixed;
    width: 12px;
    height: 12px;
    background: #48bb78;
    top: -10px;
    z-index: 10000;
    border-radius: 2px;
    animation: confettiFall linear forwards;
    pointer-events: none;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

@keyframes confettiFall {
    0% {
        transform: translateY(0) translateX(0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(800px) translateX(var(--confetti-x, 0)) rotate(720deg);
        opacity: 0;
    }
}

.answer-tile:active {
    cursor: grabbing;
}

.answer-tile:hover:not(.dragging) {
    transform: translateY(-2px) scale(1.05);
    box-shadow: var(--shadow-lg);
    background: var(--primary-hover);
}

.answer-tile.dragging {
    opacity: 0.5;
    z-index: 1000;
    transform: scale(1.1);
    cursor: grabbing;
}

.answer-tile.drag-over {
    border-color: var(--success-color);
    background: rgba(72, 187, 120, 0.2);
    transform: scale(1.1);
}

.answer-input {
    width: 100%;
    padding: 14px 40px 14px 16px;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--card-bg);
    color: var(--text-color);
    transition: var(--transition);
    font-family: 'Courier New', monospace;
    text-align: center;
}

.answer-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 85, 104, 0.1);
}

.answer-input:disabled {
    background: var(--bg-color);
    cursor: not-allowed;
}

.btn-clear {
    position: absolute;
    right: 8px;
    width: 28px;
    height: 28px;
    border: none;
    background: var(--text-light);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: var(--transition);
    opacity: 0.7;
    z-index: 10;
}

.btn-clear:hover {
    opacity: 1;
    background: var(--error-color);
    transform: scale(1.1);
}

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

/* Message */
.message {
    min-height: 24px;
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    padding: 12px;
    border-radius: 8px;
    transition: var(--transition);
    opacity: 0;
    transform: translateY(-10px);
}

.message.show {
    opacity: 1;
    transform: translateY(0);
}

.message.success {
    background: rgba(72, 187, 120, 0.1);
    color: var(--success-color);
}

.message.success.win {
    background: linear-gradient(135deg, rgba(72, 187, 120, 0.2) 0%, rgba(72, 187, 120, 0.1) 100%);
    border: 2px solid var(--success-color);
    font-size: 18px;
    font-weight: 700;
    padding: 20px;
    animation: pulseWin 1s ease-in-out infinite;
}

@keyframes pulseWin {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(72, 187, 120, 0.4);
    }
    50% {
        transform: scale(1.02);
        box-shadow: 0 0 20px 5px rgba(72, 187, 120, 0.3);
    }
}

.message.error {
    background: rgba(245, 101, 101, 0.1);
    color: var(--error-color);
}

.message.info {
    background: rgba(74, 85, 104, 0.1);
    color: var(--primary-color);
}

/* Hint Display */
.hint-display {
    padding: 12px 16px;
    background: rgba(74, 85, 104, 0.05);
    border-left: 4px solid var(--primary-color);
    border-radius: 6px;
    font-size: 14px;
    color: var(--text-color);
    min-height: 20px;
    display: none;
}

.hint-display.show {
    display: block;
    animation: fadeIn 0.3s ease-in;
}

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

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

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

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

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

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

.letter-tile.new {
    animation: slideIn 0.3s ease-out;
}

/* Responsive Design */
@media (max-width: 480px) {
    .game-header {
        padding: 12px 16px;
        gap: 10px;
    }

    .game-header {
        flex-direction: column;
        gap: 10px;
        padding: 10px 12px;
    }

    .game-title {
        font-size: 16px;
        text-align: center;
        width: 100%;
    }

    .header-stats {
        width: 100%;
        justify-content: space-around;
    }

    .header-buttons {
        width: 100%;
        justify-content: center;
    }

    .btn {
        padding: 6px 12px;
        font-size: 13px;
        min-height: 32px;
        flex: 1;
        max-width: 120px;
    }

    .game-main {
        padding: 16px;
        gap: 16px;
    }

    .available-letters {
        padding: 10px;
        gap: 6px;
    }

    .game-board {
        gap: 1px;
        padding: 1px;
    }

    .board-cell {
        min-height: 35px;
        font-size: 16px;
    }

    .section-title {
        font-size: 14px;
    }

    .word-text {
        font-size: 14px;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .letter-tile {
        min-width: 48px;
        min-height: 48px;
    }

    .answer-tile {
        min-width: 44px;
        min-height: 44px;
    }

    .btn {
        min-height: 44px;
        padding: 10px 18px;
    }
}


