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

:root {
    --bg-primary: #0f0f23;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --accent: #e94560;
    --accent-secondary: #0f3460;
    --text-primary: #eaeaea;
    --text-secondary: #a0a0a0;
    --cell-empty: #1a1a2e;
    --cell-filled: #e94560;
    --cell-vowel: #e94560;
    --cell-consonant: #3b82f6;
    --cell-other: #a855f7;
    --cell-preview: rgba(233, 69, 96, 0.4);
    --cell-flash: #4ade80;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

h1 {
    font-size: 3rem;
    color: var(--accent);
    text-shadow: 0 0 20px rgba(233, 69, 96, 0.5);
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.card h2 {
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    font-size: 1.5rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

input, select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border: 2px solid var(--accent-secondary);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
}

.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    text-align: center;
}

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

.btn-primary:hover {
    background: #d63a52;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(233, 69, 96, 0.4);
}

.btn-secondary {
    background: var(--accent-secondary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: #153a7a;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

.divider {
    text-align: center;
    margin: 1.5rem 0;
    color: var(--text-secondary);
    position: relative;
}

.divider::before,
.divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: var(--accent-secondary);
}

.divider::before {
    left: 0;
}

.divider::after {
    right: 0;
}

.room-code {
    font-size: 3rem;
    font-weight: bold;
    color: var(--accent);
    text-align: center;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    letter-spacing: 0.5rem;
    margin: 1rem 0;
}

.waiting-text {
    text-align: center;
    color: var(--text-secondary);
    margin: 1rem 0;
}

.player-item {
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-radius: 6px;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.player-item.me {
    border: 2px solid var(--accent);
}

.error {
    background: rgba(233, 69, 96, 0.2);
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 1rem;
    border-radius: 8px;
    margin-top: 1rem;
    text-align: center;
}

.hidden {
    display: none !important;
}

#playerList h3,
#joinedPlayerList h3 {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

#playerList,
#joinedPlayerList {
    margin-bottom: 1rem;
}

.game-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.game-header {
    background: var(--bg-secondary);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--accent-secondary);
}

.game-header h1 {
    font-size: 1.5rem;
    margin: 0;
}

.room-info {
    color: var(--text-secondary);
}

.room-info span {
    color: var(--accent);
    font-weight: bold;
}

.game-content {
    flex: 1;
    display: flex;
    padding: 1rem;
    gap: 1rem;
}

.main-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.board-container {
    background: var(--bg-card);
    padding: 1rem;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.game-board {
    display: grid;
    gap: 2px;
    background: var(--bg-primary);
    padding: 2px;
    border-radius: 4px;
}

.cell {
    width: 28px;
    height: 28px;
    background: var(--cell-empty);
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
}

.cell.filled {
    background: var(--cell-filled);
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.cell.filled[data-char-type="vowel"] { background: var(--cell-vowel); }
.cell.filled[data-char-type="consonant"] { background: var(--cell-consonant); }
.cell.filled[data-char-type="other"] { background: var(--cell-other); }

.cell.preview {
    background: var(--cell-preview);
}

.cell.nearest-hint {
    box-shadow: inset 0 0 0 2px rgba(80, 160, 255, 0.55);
}

.cell.nearest-hint-active {
    box-shadow: inset 0 0 0 2px rgba(80, 160, 255, 1);
    background-color: rgba(80, 160, 255, 0.18) !important;
}

.cell.falling {
    background: var(--cell-filled);
    color: white;
    opacity: 0.85;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.cell.falling[data-char-type="vowel"]     { background: var(--cell-vowel); }
.cell.falling[data-char-type="consonant"] { background: var(--cell-consonant); }
.cell.falling[data-char-type="other"]     { background: var(--cell-other); }

.cell.flash {
    background: var(--cell-flash) !important;
    animation: flashAnim 0.3s ease-out;
}

@keyframes flashAnim {
    0% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.cell.removing {
    animation: removeAnim 0.45s ease-out forwards;
    color: white;
    z-index: 2;
}

@keyframes removeAnim {
    0%   { transform: scale(1);   opacity: 1; }
    30%  { transform: scale(1.3); opacity: 1; background: var(--cell-flash); }
    100% { transform: scale(0);   opacity: 0; }
}

.block-preview {
    background: var(--bg-card);
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
}

.block-preview h3 {
    margin-bottom: 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.next-block-display {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60px;
    margin-bottom: 1rem;
}

.block-char {
    width: 40px;
    height: 40px;
    background: var(--accent);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 18px;
    color: white;
    margin: 0 2px;
}

.block-double {
    display: flex;
    gap: 4px;
}

.block-double.vertical {
    flex-direction: column;
    align-items: center;
}

.block-double.vertical .block-char {
    margin: 2px 0;
}

.side-panel {
    width: 280px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.players-section,
.nearest-section,
.score-section {
    background: var(--bg-card);
    padding: 1rem;
    border-radius: 8px;
}

.players-section h3,
.nearest-section h3,
.score-section h3 {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--accent-secondary);
    padding-bottom: 0.5rem;
}

.players-list {
    max-height: 200px;
    overflow-y: auto;
}

.player-item {
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border-radius: 4px;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.player-name {
    color: var(--text-primary);
}

.player-score {
    color: var(--accent);
    font-weight: bold;
    float: right;
}

.nearest-words {
    max-height: 250px;
    overflow-y: auto;
}

.nearest-word {
    padding: 0.5rem;
    background: var(--bg-secondary);
    border-radius: 4px;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
}

.word-text {
    font-family: monospace;
    letter-spacing: 1px;
}

.word-progress {
    color: var(--accent);
    font-weight: bold;
}

.no-words {
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-align: center;
    padding: 1rem;
}

.my-score {
    font-size: 2rem;
    font-weight: bold;
    color: var(--accent);
    text-align: center;
}

.timer-section {
    background: var(--bg-card);
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
}

.timer-section h3 {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--accent-secondary);
    padding-bottom: 0.5rem;
}

.timer-display {
    font-size: 2rem;
    font-weight: bold;
    color: var(--accent);
    font-family: monospace;
    letter-spacing: 2px;
}

.timer-display.timer-urgent {
    color: #e94560;
    animation: timerPulse 0.5s ease-in-out infinite alternate;
}

@keyframes timerPulse {
    from { opacity: 1; }
    to   { opacity: 0.5; }
}

.drop-cooldown-section {
    background: var(--bg-card);
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
    border: 2px solid #e94560;
}

.drop-cooldown-display {
    font-size: 2rem;
    font-weight: bold;
    color: #e94560;
    font-family: monospace;
    animation: timerPulse 0.5s ease-in-out infinite alternate;
}

.drop-cooldown-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.recent-words {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.recent-word {
    padding: 0.4rem 0.6rem;
    background: var(--bg-secondary);
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
}

.recent-word-text {
    font-family: monospace;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.recent-word-score {
    color: var(--accent);
    font-weight: bold;
}

.game-status {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
    color: var(--accent);
    font-weight: bold;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: 12px;
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.modal-content h2 {
    margin-bottom: 1.5rem;
    color: var(--accent);
}

.winner {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
}

#finalScores h4 {
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

#finalScores > div {
    padding: 0.25rem 0;
}

.modal-content .btn {
    margin-top: 1.5rem;
    width: 100%;
}

/* Touch controls */
.touch-controls {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 0.5rem;
    background: rgba(255,255,255,0.05);
    border-top: 1px solid rgba(255,255,255,0.1);
    user-select: none;
    -webkit-user-select: none;
}

.touch-btn-center {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    align-items: center;
}

.touch-btn {
    width: 64px;
    height: 64px;
    font-size: 1.6rem;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 12px;
    background: rgba(255,255,255,0.1);
    color: #fff;
    cursor: pointer;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s;
}

.touch-btn:active {
    background: rgba(255,255,255,0.3);
}

.touch-btn-rotate { background: rgba(100, 180, 255, 0.2); }
.touch-btn-rotate:active { background: rgba(100, 180, 255, 0.5); }
.touch-btn-drop { background: rgba(255, 200, 80, 0.2); }
.touch-btn-drop:active { background: rgba(255, 200, 80, 0.5); }
.touch-btn-harddrop { background: rgba(255, 100, 100, 0.2); }
.touch-btn-harddrop:active { background: rgba(255, 100, 100, 0.5); }

@media (max-width: 800px) {
    .game-content {
        flex-direction: column;
    }
    
    .side-panel {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .players-section,
    .nearest-section,
    .score-section {
        flex: 1;
        min-width: 200px;
    }
    
    .cell {
        width: 24px;
        height: 24px;
        font-size: 12px;
    }
}

@media (max-width: 500px) {
    .container {
        padding: 1rem;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    .card {
        padding: 1.5rem;
    }
    
    .room-code {
        font-size: 2rem;
        letter-spacing: 0.25rem;
    }
    
    .cell {
        width: 20px;
        height: 20px;
        font-size: 10px;
    }
}

@media (pointer: coarse) {
    .touch-controls {
        display: flex;
    }
}
