* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: 
        /* Circular maze pattern using SVG */
        url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="80" height="80"><defs><linearGradient id="g" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" style="stop-color:white"/><stop offset="100%" style="stop-color:black"/></linearGradient></defs><circle cx="20" cy="20" r="8" stroke="url(%23g)" stroke-width="2" fill="none"/><circle cx="60" cy="20" r="8" stroke="url(%23g)" stroke-width="2" fill="none"/><circle cx="20" cy="60" r="8" stroke="url(%23g)" stroke-width="2" fill="none"/><circle cx="60" cy="60" r="8" stroke="url(%23g)" stroke-width="2" fill="none"/><circle cx="40" cy="40" r="12" stroke="url(%23g)" stroke-width="2" fill="none"/><path d="M28 20h24 M20 28v24 M60 28v24 M28 60h24" stroke="url(%23g)" stroke-width="2"/></svg>'),
        /* Green gradient from light green (top-left) to dark green (bottom-right) */
        linear-gradient(135deg, #90EE90 0%, #004400 100%);
    background-size: 80px 80px, 100% 100%;
    background-repeat: repeat, no-repeat;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.screen {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hidden {
    display: none !important;
}

/* Login Screen */
.login-container {
    background: white;
    padding: 40px;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.login-container h1 {
    color: #667eea;
    margin-bottom: 30px;
    font-size: 2.5em;
}

.login-container input {
    width: 300px;
    padding: 12px;
    font-size: 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    margin-bottom: 20px;
}

.login-container input:focus {
    outline: none;
    border-color: #667eea;
}

.login-container button,
.game-controls button {
    padding: 12px 30px;
    font-size: 16px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.3s;
}

.login-container button:hover,
.game-controls button:hover:not(:disabled) {
    background: #5568d3;
}

.game-controls button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Game Screen */
.game-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: transparent;
}

.game-info {
    padding: 15px 20px;
    background: #2c3e50;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.player-info {
    display: flex;
    gap: 30px;
    font-size: 18px;
}

.player-info span span {
    font-weight: bold;
    color: #f39c12;
}

.game-controls {
    display: flex;
    gap: 10px;
}

.game-controls button {
    padding: 8px 16px;
    font-size: 14px;
}

/* Game Board Container - uses flexbox to maintain aspect ratio */
.game-board-container {
    flex: 1;
    display: flex;
    padding: 20px;
    gap: 20px;
    overflow: hidden;
    align-items: center;
    justify-content: center;
}

/* Game Board - 15x15 grid that fills available space */
.game-board {
    display: grid;
    grid-template-columns: repeat(15, 1fr);
    grid-template-rows: repeat(15, 1fr);
    gap: 2px;
    background: #000000;
    padding: 2px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    aspect-ratio: 1 / 1;
    max-height: calc(100vh - 100px);
    max-width: calc(100vh - 100px);
    height: min(calc(100vh - 100px), calc(100vw - 180px));
    width: min(calc(100vh - 100px), calc(100vw - 180px));
}

.cell {
    background: #ecf0f1;
    border: 1px solid #bdc3c7;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2vmin;
    font-weight: bold;
    color: #2c3e50;
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
    user-select: none;
}

.cell:hover {
    background: #d5dbdb;
}

.cell.drag-preview {
    background: rgba(200, 200, 200, 0.5) !important;
    box-shadow: inset 0 0 0 2px rgba(100, 100, 100, 0.6);
}

.cell.occupied {
    cursor: default;
}

.cell.occupied:hover {
    background: #ecf0f1;
}

.cell.temporary .tile {
    background: #fae2a0;
    border-color: #816006;
}

.cell.center {
    background: #e74c3c;
}

.cell.center::before {
    content: "★";
    position: absolute;
    font-size: 2vmin;
    color: white;
}

/* Special Squares - Words with Friends colors */
.cell.double-letter {
    background: #a7d8f0;
}

.cell.double-letter::before {
    content: "DL";
    position: absolute;
    font-size: 1.5vmin;
    color: #2c3e50;
    font-weight: bold;
}

.cell.triple-letter {
    background: #2841af;
}

.cell.triple-letter::before {
    content: "TL";
    position: absolute;
    font-size: 1.5vmin;
    color: white;
    font-weight: bold;
}

.cell.double-word {
    background: #f8b1cc;
}

.cell.double-word::before {
    content: "DW";
    position: absolute;
    font-size: 1.5vmin;
    color: #2c3e50;
    font-weight: bold;
}

.cell.triple-word {
    background: #bf4327;
}

.cell.triple-word::before {
    content: "TW";
    position: absolute;
    font-size: 1.5vmin;
    color: white;
    font-weight: bold;
}

/* When tiles are placed on special squares, show color as border */
.cell.double-letter.occupied .tile,
.cell.double-letter.temporary .tile {
    border-color: #a7d8f0;
    border-width: 3px;
}

.cell.triple-letter.occupied .tile,
.cell.triple-letter.temporary .tile {
    border-color: #2871af;
    border-width: 3px;
}

.cell.double-word.occupied .tile,
.cell.double-word.temporary .tile {
    border-color: #f8b1cc;
    border-width: 3px;
}

.cell.triple-word.occupied .tile,
.cell.triple-word.temporary .tile {
    border-color: #ff6347;
    border-width: 3px;
}

.cell.center.occupied .tile,
.cell.center.temporary .tile {
    border-color: #e74c3c;
    border-width: 3px;
}

/* Hide labels when cell is occupied */
.cell.occupied::before,
.cell.temporary::before {
    display: none;
}

.tile {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f39c12;
    border: 1px solid #d68910;
    border-radius: 4px;
    padding: 0;
}

.tile-letter {
    font-size: var(--letter-size, 5.0vmin);
    font-weight: bold;
    color: #000000;
    line-height: 0.8;
    margin: 0;
    padding: 0;
}

.tile-value {
    position: absolute;
    bottom: 2px;
    right: 3px;
    font-size: var(--value-size, 1.5vmin);
    color: #000000;
    font-weight: bold;
}

/* Letter Rack */
.letter-rack-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    justify-content: center;
}

.letter-rack-container h3 {
    color: #2c3e50;
    text-align: center;
}

.letter-rack {
    display: grid;
    grid-template-rows: repeat(7, 1fr);
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 20px;
    background: #34495e;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.rack-tile {
    aspect-ratio: 1 / 1;
    width: calc((min(calc(100vh - 100px), calc(100vw - 180px)) - 32px) / 15);
    height: calc((min(calc(100vh - 100px), calc(100vw - 180px)) - 32px) / 15);
    background: #f39c12;
    border: 2px solid #d68910;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: grab;
    transition: transform 0.2s;
    position: relative;
    user-select: none;
}

.rack-tile:hover {
    transform: scale(1.05);
}

.rack-tile.selected {
    background: #3498db;
    border-color: #2980b9;
    transform: scale(1.1);
}

.rack-tile.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.rack-tile-letter {
    font-size: var(--letter-size, 5.0vmin);
    font-weight: bold;
    color: #000000;
    transform: translateX(-8%) translateY(-8%);
}

.rack-tile-value {
    position: absolute;
    bottom: 2px;
    right: 0px;
    font-size: var(--value-size, 1.5vmin);
    color: #000000;
    font-weight: bold;
}

/* Responsive adjustments */
@media (max-width: 1200px), (max-aspect-ratio: 1/1) {
    .game-board-container {
        flex-direction: column;
        align-items: center;
    }
    
    .game-board {
        height: min(calc(100vh - 280px), 90vw);
        width: min(calc(100vh - 280px), 90vw);
        max-height: 90vw;
        max-width: 90vw;
    }
    
    .letter-rack-container {
        width: 100%;
        align-items: center;
    }
    
    .letter-rack {
        grid-template-columns: repeat(7, 1fr);
        grid-template-rows: 1fr;
        width: auto;
        height: calc((min(calc(100vh - 280px), 90vw) - 32px) / 15);
    }
    
    .rack-tile {
        width: calc((min(calc(100vh - 280px), 90vw) - 32px) / 15);
        height: calc((min(calc(100vh - 280px), 90vw) - 32px) / 15);
    }
}

@media (max-width: 768px) {
    .game-info {
        flex-direction: column;
        gap: 10px;
    }
    
    .player-info {
        flex-direction: column;
        gap: 5px;
        text-align: center;
    }
}

/* Mobile device optimization - remove padding */
.mobile-device .game-board-container {
    padding: 0;
    gap: 10px;
}

.mobile-device .game-board {
    max-height: 100vh;
    max-width: 100vw;
    height: min(100vh, 100vw);
    width: min(100vh, 100vw);
    border-radius: 0;
}
