/* Import Google Font */
@import url('https://fonts.googleapis.com/css2?family=Raleway:wght@300;500;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Raleway', sans-serif;
    background: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    margin: 0;
    padding: 0;
}

.game-container {
    max-width: 414px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    position: relative;
    z-index: 2;
}

/* Optimized floating particles background */
.particle {
    position: absolute;
    background: rgba(0, 212, 255, 0.1);
    border-radius: 50%;
    animation: float 8s ease-in-out infinite;
    z-index: 1;
    will-change: transform, opacity;
}

.particle:nth-child(1) { width: 30px; height: 30px; top: 15%; left: 10%; animation-delay: 0s; }
.particle:nth-child(2) { width: 20px; height: 20px; top: 70%; left: 85%; animation-delay: 3s; }
.particle:nth-child(3) { width: 25px; height: 25px; top: 40%; left: 5%; animation-delay: 6s; }
.particle:nth-child(4) { width: 15px; height: 15px; top: 85%; left: 75%; animation-delay: 2s; }

@keyframes float {
    0%, 100% { 
        transform: translateY(0px) translateX(0px) rotate(0deg);
        opacity: 0.3;
    }
    25% { 
        transform: translateY(-20px) translateX(10px) rotate(90deg);
        opacity: 0.6;
    }
    50% { 
        transform: translateY(-10px) translateX(-15px) rotate(180deg);
        opacity: 0.8;
    }
    75% { 
        transform: translateY(-30px) translateX(5px) rotate(270deg);
        opacity: 0.4;
    }
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 30px;
    position: relative;
}

.title-section {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
    position: relative;
    z-index: 5;
}

.logo {
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(45deg, #00d4ff, #0099cc, #33ddff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 4px 20px rgba(0, 212, 255, 0.3);
    animation: oceanPulse 3s ease-in-out infinite;
    letter-spacing: 2px;
    margin: 0;
    will-change: transform, filter;
}

@keyframes oceanPulse {
    0%, 100% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.02); filter: brightness(1.1); }
}

.score-time {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.stat-card {
    flex: 1;
    background: rgba(0, 212, 255, 0.1);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 212, 255, 0.2);
    border-radius: 20px;
    padding: 15px;
    text-align: center;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(0, 212, 255, 0.1), transparent);
    animation: wave 4s linear infinite;
    will-change: left;
}

@keyframes wave {
    0% { left: -100%; }
    100% { left: 100%; }
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0, 212, 255, 0.2);
    border-color: rgba(0, 212, 255, 0.4);
}

.stat-label {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.7rem;
    font-weight: 500;
    margin-bottom: 5px;
    position: relative;
    z-index: 2;
}

.stat-value {
    color: #00d4ff;
    font-size: 1.2rem;
    font-weight: 700;
    text-shadow: 0 2px 10px rgba(0, 212, 255, 0.3);
    position: relative;
    z-index: 2;
}

/* Game Board */
.game-board {
    background: rgba(0, 212, 255, 0.05);
    backdrop-filter: blur(30px);
    border: 2px solid rgba(0, 212, 255, 0.15);
    border-radius: 25px;
    padding: 25px;
    margin-bottom: 25px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
}

.game-board::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(0, 212, 255, 0.05), transparent);
    animation: shimmer 6s linear infinite;
    will-change: transform;
}

@keyframes shimmer {
    0% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
    100% { transform: translateX(100%) translateY(100%) rotate(45deg); }
}

.letter-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    position: relative;
    z-index: 2;
}

.letter-tile {
    aspect-ratio: 1;
    background: rgba(0, 212, 255, 0.1);
    border: 2px solid rgba(0, 212, 255, 0.2);
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 700;
    color: #ffffff;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
    will-change: transform, background-color, border-color;
}

.letter-tile:hover, .letter-tile:focus {
    outline: none;
    transform: scale(1.1);
    background: rgba(0, 212, 255, 0.2);
    border-color: #00d4ff;
    box-shadow: 0 8px 25px rgba(0, 212, 255, 0.3);
    text-shadow: 0 2px 10px rgba(0, 212, 255, 0.5);
}

.letter-tile.selected {
    background: #00d4ff;
    color: #003d4d;
    transform: scale(1.05);
    box-shadow: 0 8px 25px rgba(0, 212, 255, 0.4);
    border-color: #33ddff;
    text-shadow: none;
}

.letter-tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.letter-tile:hover::before {
    left: 100%;
}

/* Keyboard navigation for letter tiles */
.letter-tile:focus {
    outline: 2px solid #00d4ff;
    outline-offset: 2px;
}

/* Current Word Display */
.current-word {
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 212, 255, 0.2);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 25px;
    text-align: center;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.current-word::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, #00d4ff, transparent);
    animation: currentWordGlow 2s ease-in-out infinite;
    will-change: opacity;
}

@keyframes currentWordGlow {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

.word-display {
    font-size: 1.8rem;
    font-weight: 600;
    color: #00d4ff;
    letter-spacing: 3px;
    text-transform: uppercase;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-shadow: 0 2px 15px rgba(0, 212, 255, 0.4);
}

.word-placeholder {
    color: rgba(0, 212, 255, 0.4);
    font-style: italic;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 15px;
    margin-bottom: 25px;
}

.btn {
    flex: 1;
    padding: 16px;
    border: none;
    border-radius: 20px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    will-change: transform, box-shadow;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn:focus {
    outline: 2px solid #00d4ff;
    outline-offset: 2px;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transition: all 0.3s ease;
    transform: translate(-50%, -50%);
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn-submit {
    background: linear-gradient(135deg, #00d4ff, #0099cc);
    color: white;
    border: 1px solid rgba(0, 212, 255, 0.3);
    box-shadow: 0 6px 20px rgba(0, 212, 255, 0.3);
}

.btn-submit:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(0, 212, 255, 0.4);
    background: linear-gradient(135deg, #33ddff, #00b8e6);
}

.btn-clear {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
}

.btn-clear:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

/* Found Words */
.found-words {
    background: rgba(0, 212, 255, 0.05);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 212, 255, 0.15);
    border-radius: 20px;
    padding: 20px;
    max-height: 200px;
    overflow-y: auto;
    min-height: 100px;
}

.found-words h3 {
    color: #00d4ff;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 15px;
    text-align: center;
    text-shadow: 0 2px 10px rgba(0, 212, 255, 0.3);
}

.words-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.word-tag {
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.15), rgba(0, 212, 255, 0.1));
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 15px;
    padding: 8px 12px;
    color: #00d4ff;
    font-size: 0.9rem;
    font-weight: 500;
    animation: fadeInUp 0.5s ease;
    backdrop-filter: blur(5px);
    transition: all 0.2s ease;
    will-change: transform;
}

.word-tag:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 212, 255, 0.2);
    border-color: rgba(0, 212, 255, 0.5);
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Message Display */
.message-display {
    background: rgba(0, 0, 0, 0.7);
    color: #00d4ff;
    padding: 15px;
    border-radius: 15px;
    text-align: center;
    margin-top: 15px;
    font-weight: 600;
    border: 1px solid rgba(0, 212, 255, 0.3);
    backdrop-filter: blur(10px);
    position: relative;
    z-index: 5;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Game Button Styling */
.game-button {
    font-family: 'Raleway', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.6em 1.2em;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    position: relative;
    z-index: 10;
    overflow: hidden;
    will-change: transform, box-shadow;
}

.game-button:focus {
    outline: 2px solid #00d4ff;
    outline-offset: 2px;
}

.game-button svg {
    width: 1em;
    height: 1em;
}

.game-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.game-button:active {
    transform: translateY(1px);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.game-button.primary {
    background: linear-gradient(135deg, #00d4ff, #0099cc);
    color: white;
    border: 1px solid rgba(0, 212, 255, 0.3);
}

.game-button.primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #33ddff, #00b8e6);
}

/* Custom Scrollbar */
.found-words::-webkit-scrollbar,
.solvable-words::-webkit-scrollbar {
    width: 6px;
}

.found-words::-webkit-scrollbar-track,
.solvable-words::-webkit-scrollbar-track {
    background: rgba(0, 212, 255, 0.1);
    border-radius: 10px;
}

.found-words::-webkit-scrollbar-thumb,
.solvable-words::-webkit-scrollbar-thumb {
    background: rgba(0, 212, 255, 0.3);
    border-radius: 10px;
}

.found-words::-webkit-scrollbar-thumb:hover,
.solvable-words::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 212, 255, 0.5);
}

/* Game Summary Overlay */
#gameSummaryOverlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

#gameSummaryContent {
    background: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
    padding: 2em;
    border-radius: 1em;
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    color: white;
    box-shadow: 0 0 2em rgba(0, 0, 0, 0.5);
    min-width: 20em;
    border: 2px solid rgba(0, 212, 255, 0.2);
}

#gameSummaryContent h2 {
    margin-top: 0;
    color: #00d4ff;
    text-align: center;
    text-shadow: 0 2px 10px rgba(0, 212, 255, 0.3);
}

#gameSummaryContent .stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1em;
    margin: 1em 0;
}

#gameSummaryContent .stat-item {
    background: rgba(0, 212, 255, 0.1);
    padding: 0.5em;
    border-radius: 0.5em;
    text-align: center;
    border: 1px solid rgba(0, 212, 255, 0.2);
}

#gameSummaryContent .solvable-words {
    margin-top: 0.5em;
    max-height: 40vh;
    overflow-y: auto;
    background: rgba(0, 212, 255, 0.1);
    padding: 1em;
    border-radius: 0.5em;
    border: 1px solid rgba(0, 212, 255, 0.2);
}

#gameSummaryContent .solvable-words h3 {
    margin-top: 0;
    color: #00d4ff;
    text-shadow: 0 2px 10px rgba(0, 212, 255, 0.3);
}

#gameSummaryContent .word-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em;
}

#gameSummaryContent .word-item {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.25em 0.5em;
    border-radius: 0.25em;
    font-size: 0.9em;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

#gameSummaryContent .word-item.found {
    background: #00d4ff;
    color: #003d4d;
    border-color: #33ddff;
}

.game-button.primary#summaryNewGameButton {
    display: block;
    margin: 0 auto 1em auto;
    width: fit-content;
}

/* Mini Board in Game Summary */
#summaryMiniBoard {
    margin: 1em auto;
    width: fit-content;
}

#summaryMiniBoard table {
    border-collapse: collapse;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0.5em;
    overflow: hidden;
    border: 1px solid rgba(0, 212, 255, 0.2);
}

#summaryMiniBoard td {
    width: 2em;
    height: 2em;
    text-align: center;
    font-weight: bold;
    color: white;
    border: 1px solid rgba(0, 212, 255, 0.3);
    font-size: 0.8em;
    transition: background-color 0.3s ease;
    text-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
}

/* Letter frequency visualization */
.letter-frequency-chart {
  margin-top: 10px;
  width: 100%;
}

.frequency-bar {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.frequency-bar span {
  width: 60px;
  text-align: left;
  font-size: 0.9em;
}

.bar {
  height: 15px;
  background-color: #00d4ff;
  border-radius: 3px;
  margin-left: 10px;
  transition: width 0.5s ease-out;
}

.common-letters-container {
  margin: 1em 0;
  padding: 1em;
  background: rgba(0, 212, 255, 0.1);
  border-radius: 0.5em;
  border: 1px solid rgba(0, 212, 255, 0.2);
}

.common-letters-container h3 {
  margin-top: 0;
  color: #00d4ff;
  font-size: 1.1em;
  text-align: center;
  text-shadow: 0 2px 10px rgba(0, 212, 255, 0.3);
}

.common-letters-container p {
  text-align: center;
  margin-bottom: 1em;
  font-size: 0.9em;
}

/* Optimize ripple effects */
@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

.ripple {
    position: absolute;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.6);
    transform: scale(0);
    animation: ripple 0.6s linear;
    pointer-events: none;
    z-index: 1;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .particle {
        animation: none;
    }
    
    .logo {
        animation: none;
    }
    
    .stat-card::before {
        animation: none;
    }
    
    .game-board::before {
        animation: none;
    }
    
    .current-word::after {
        animation: none;
    }
    
    .letter-tile {
        transition: none;
    }
    
    .word-tag {
        animation: none;
    }
}

/* Mobile responsive improvements */
@media (max-width: 480px) {
    .game-container {
        padding: 15px;
        max-width: 100%;
    }
    
    .logo {
        font-size: 1.6rem;
        letter-spacing: 1px;
    }
    
    .letter-tile {
        font-size: 1.4rem;
    }
    
    .word-display {
        font-size: 1.4rem;
        letter-spacing: 2px;
    }
    
    .title-section {
        flex-direction: column;
        gap: 15px;
        align-items: center;
        text-align: center;
        width: 100%;
    }
    
    .game-button {
        font-size: 0.8rem;
        padding: 0.5em 1em;
        white-space: nowrap;
    }
    
    .score-time {
        flex-direction: row;
        gap: 8px;
        width: 100%;
        justify-content: space-between;
    }
    
    .stat-card {
        min-width: 0;
        flex: 1;
        padding: 10px 8px;
    }
    
    .stat-label {
        font-size: 0.6rem;
    }
    
    .stat-value {
        font-size: 1rem;
    }
    
    .action-buttons {
        flex-direction: column;
        gap: 10px;
    }
    
    .btn {
        padding: 12px;
        font-size: 0.9rem;
    }
    
    .game-board {
        padding: 20px;
    }
    
    .letter-grid {
        gap: 8px;
    }
    
    .current-word {
        padding: 15px;
        min-height: 60px;
    }
    
    .found-words {
        padding: 15px;
        max-height: 150px;
    }
    
    #gameSummaryContent {
        max-width: 95%;
        padding: 1.5em;
        min-width: auto;
        margin: 10px;
    }
    
    #gameSummaryContent .stats {
        grid-template-columns: 1fr;
        gap: 0.5em;
    }
    
    #gameSummaryContent .stat-item {
        padding: 0.75em;
    }
}

@media (max-width: 375px) {
    .game-container {
        padding: 10px;
    }
    
    .logo {
        font-size: 1.4rem;
    }
    
    .letter-tile {
        font-size: 1.2rem;
    }
    
    .word-display {
        font-size: 1.2rem;
        letter-spacing: 1px;
    }
    
    .stat-label {
        font-size: 0.55rem;
    }
    
    .stat-value {
        font-size: 0.9rem;
    }
    
    .game-board {
        padding: 15px;
    }
    
    .letter-grid {
        gap: 6px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .letter-tile {
        border-width: 3px;
    }
    
    .btn {
        border-width: 2px;
    }
    
    .game-button {
        border: 2px solid currentColor;
    }
}
