/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* Screen Management */
.screen {
    display: none;
    width: 100%;
    max-width: 1400px;
}

.screen.active {
    display: block;
}

/* Container */
.container {
    background: white;
    border-radius: 12px;
    padding: 40px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    max-width: 800px;
    margin: 0 auto;
}

/* Typography */
.title {
    font-size: 3em;
    text-align: center;
    color: #667eea;
    margin-bottom: 10px;
    font-weight: bold;
}

.subtitle {
    text-align: center;
    color: #666;
    margin-bottom: 40px;
    font-size: 1.2em;
}

h1, h2, h3 {
    margin-bottom: 20px;
    color: #333;
}

/* Menu Layout */
.menu {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 30px;
    align-items: start;
}

.menu-option {
    background: #f8f9fa;
    padding: 30px;
    border-radius: 8px;
    border: 2px solid #e9ecef;
}

.menu-option h2 {
    color: #667eea;
    margin-bottom: 20px;
    font-size: 1.5em;
}

.divider {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-weight: bold;
    font-size: 1.2em;
}

/* Form Elements */
label {
    display: block;
    margin-top: 15px;
    margin-bottom: 5px;
    font-weight: 600;
    color: #555;
}

input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 1em;
    transition: border-color 0.3s;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: #667eea;
}

input[type="range"] {
    width: 100%;
    margin: 10px 0;
}

/* Team Inputs */
.team-inputs {
    margin: 15px 0;
}

.team-input-group {
    margin-bottom: 10px;
}

.team-input-group input {
    margin-top: 5px;
}

/* Info Text */
.info-text {
    display: block;
    margin-top: 10px;
    color: #666;
    font-size: 0.9em;
}

.info-text.small {
    font-size: 0.85em;
    margin-top: 5px;
}

/* Buttons */
.btn {
    width: 100%;
    padding: 14px 28px;
    margin-top: 20px;
    border: none;
    border-radius: 6px;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-success {
    background: #4CAF50;
    color: white;
}

.btn-success:hover {
    background: #45a049;
}

.btn-danger {
    background: #f44336;
    color: white;
}

.btn-danger:hover {
    background: #da190b;
}

/* Game Code Display */
.game-code-display {
    text-align: center;
    margin: 30px 0;
}

.game-code {
    font-size: 3em;
    font-weight: bold;
    color: #667eea;
    letter-spacing: 8px;
    margin: 20px 0;
    font-family: monospace;
}

/* Team Status (Waiting Room) */
.team-status {
    margin: 30px 0;
}

.team-status-item {
    background: #f8f9fa;
    padding: 20px;
    margin: 15px 0;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.team-status-item strong {
    display: block;
    font-size: 1.2em;
    margin-bottom: 8px;
    color: #333;
}

.team-status-item span {
    color: #666;
    font-size: 0.9em;
}

.team-players {
    margin-top: 10px;
    color: #444;
    font-size: 0.95em;
}

/* Teams List (Join Game) */
.teams-list {
    margin: 15px 0;
}

.team-option {
    margin: 10px 0;
}

.team-option input[type="radio"] {
    display: none;
}

.team-option label {
    display: block;
    padding: 15px;
    background: #f8f9fa;
    border: 2px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    margin: 0;
}

.team-option label:hover {
    background: #e9ecef;
    border-color: #667eea;
}

.team-option input[type="radio"]:checked + label {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.team-option.team-full label {
    opacity: 0.6;
    cursor: not-allowed;
}

.team-capacity {
    float: right;
    font-size: 0.9em;
}

.team-full-badge {
    display: inline-block;
    background: #f44336;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    margin-left: 10px;
}

/* Game Container */
.game-container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
}

/* Game Header */
.game-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 20px;
    align-items: center;
    background: white;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Teams Display */
.teams-display {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.team-score {
    background: #f8f9fa;
    padding: 12px 15px;
    border-radius: 6px;
    border-left: 4px solid #667eea;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.team-score strong {
    font-size: 1.1em;
    color: #333;
}

.team-score span {
    color: #666;
    font-size: 0.95em;
}

/* Game Status */
.game-status {
    text-align: center;
}

.turn-indicator {
    font-size: 1.3em;
    font-weight: bold;
    color: #666;
    margin-bottom: 10px;
}

.turn-indicator.active {
    color: #4CAF50;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.timer-display {
    font-size: 1.5em;
    font-weight: bold;
    color: #667eea;
    margin-bottom: 10px;
}

.timer-display.timer-warning {
    color: #f44336;
    animation: blink 0.5s infinite;
}

@keyframes blink {
    0%, 50%, 100% { opacity: 1; }
    25%, 75% { opacity: 0.5; }
}

.game-info {
    color: #666;
    font-size: 0.95em;
}

/* Actions */
.actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.actions .btn {
    margin: 0;
    padding: 10px 20px;
    font-size: 0.95em;
}

/* Board Container */
.board-container {
    background: white;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    overflow-x: auto;
}

/* Game Board */
.game-board {
    display: grid;
    grid-template-columns: repeat(10, 60px);
    grid-template-rows: repeat(10, 84px);
    gap: 8px;
    background: transparent;
    padding: 10px;
    border-radius: 8px;
    margin: 0 auto;
    width: fit-content;
}

.board-cell {
    width: 60px;
    height: 84px;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
    padding: 0;
    overflow: visible;
}

.board-cell img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    display: block;
}

.board-cell:hover {
    transform: scale(1.05);
    z-index: 10;
}

.board-cell.free-corner {
    background: transparent;
}

.board-cell.free-corner::before {
    content: '★';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2em;
    color: #ffd700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    z-index: 1;
}

.board-cell.selected::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--chip-color, #667eea);
    opacity: 0.85;
    border: 3px solid white;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
    z-index: 2;
}

.board-cell.in-sequence::after {
    border: 3px solid gold;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
}

.board-cell.last-move::after {
    border: 4px solid #ffd700;
    box-shadow: 0 0 25px rgba(255, 215, 0, 0.9), 0 3px 10px rgba(0, 0, 0, 0.4);
}

.board-cell.valid-position {
    transform: scale(1.08);
}

.board-cell.valid-position img {
    box-shadow: 0 0 25px rgba(255, 215, 0, 0.9);
    border: 3px solid #ffd700;
}

.board-cell.cell-changed {
    animation: cellChanged 2s ease-out;
}

@keyframes cellChanged {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(76, 175, 80, 0);
    }
    50% {
        transform: scale(1.15);
        box-shadow: 0 0 30px rgba(76, 175, 80, 0.8);
    }
}

/* Game Layout */
.game-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
    margin-bottom: 20px;
}

/* Player Hand */
.hand-container {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.hand-container h3 {
    margin-bottom: 15px;
    color: #333;
}

.player-hand {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.player-hand-vertical {
    flex-direction: column;
    align-items: center;
}

/* Desktop: Show left hand, hide bottom */
.hand-left {
    display: block;
    max-width: 180px;
}

.hand-bottom {
    display: none;
}

.card {
    width: 80px;
    height: 112px;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.2s;
    cursor: default;
    position: relative;
}

.card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card.selectable {
    cursor: pointer;
}

.card.selectable:hover {
    transform: translateY(-10px) scale(1.1);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.card.selected {
    transform: translateY(-10px) scale(1.1);
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.8);
    border: 3px solid #667eea;
    z-index: 10;
}

/* Dead Cards */
.card-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.card.dead-card {
    opacity: 0.5;
    filter: grayscale(50%);
    cursor: not-allowed;
}

.discard-btn {
    padding: 4px 12px;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.75em;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.discard-btn:hover {
    background: #d32f2f;
}

/* Winner Screen */
.winner-content {
    text-align: center;
    padding: 40px 0;
}

.winner-content h2 {
    font-size: 2.5em;
    color: #667eea;
    margin-bottom: 20px;
}

.winner-content p {
    font-size: 1.2em;
    color: #666;
}

/* Error Toast */
.error-toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: #f44336;
    color: white;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s;
    z-index: 1000;
    max-width: 400px;
}

.error-toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* Rules Section */
.rules-section {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 8px;
    margin-top: 40px;
    border-left: 4px solid #667eea;
}

.rules-section h3 {
    color: #667eea;
    margin-bottom: 15px;
}

.rules-section ul {
    list-style: none;
    padding-left: 0;
}

.rules-section li {
    padding: 8px 0;
    color: #555;
    line-height: 1.6;
}

.rules-section li::before {
    content: "•";
    color: #667eea;
    font-weight: bold;
    display: inline-block;
    width: 1em;
    margin-left: -1em;
    margin-right: 0.5em;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .game-board {
        grid-template-columns: repeat(10, 50px);
        grid-template-rows: repeat(10, 70px);
        gap: 6px;
    }

    .board-cell {
        width: 50px;
        height: 70px;
    }

    .board-cell.selected::after {
        width: 40px;
        height: 40px;
    }

    .board-cell.free-corner::before {
        font-size: 1.6em;
    }
}

@media (max-width: 900px) {
    .menu {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }

    .divider {
        order: 2;
        margin: 20px 0;
    }

    .game-header {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .teams-display {
        flex-direction: row;
        flex-wrap: wrap;
    }

    /* Mobile: Stack layout, hide left hand, show bottom */
    .game-layout {
        flex-direction: column;
        align-items: center;
    }

    .hand-left {
        display: none;
    }

    .hand-bottom {
        display: block;
    }

    .game-board {
        grid-template-columns: repeat(10, 42px);
        grid-template-rows: repeat(10, 59px);
        gap: 5px;
    }

    .board-cell {
        width: 42px;
        height: 59px;
    }

    .board-cell.selected::after {
        width: 35px;
        height: 35px;
    }

    .board-cell.free-corner::before {
        font-size: 1.4em;
    }

    .card {
        width: 70px;
        height: 98px;
    }
}

@media (max-width: 600px) {
    .container {
        padding: 20px;
    }

    .title {
        font-size: 2em;
    }

    .game-board {
        grid-template-columns: repeat(10, 30px);
        grid-template-rows: repeat(10, 42px);
        gap: 3px;
    }

    .board-cell {
        width: 30px;
        height: 42px;
    }

    .board-cell.selected::after {
        width: 24px;
        height: 24px;
    }

    .board-cell.free-corner::before {
        font-size: 1em;
    }

    .card {
        width: 60px;
        height: 84px;
    }

    .error-toast {
        bottom: 20px;
        right: 20px;
        left: 20px;
        max-width: none;
    }
}
