* {
    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;
    padding: 20px;
}

.container {
    max-width: 600px;
    margin: 0 auto;
}

h1 {
    text-align: center;
    color: white;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    font-size: 2.5rem;
}

.panel {
    background: white;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    margin-bottom: 20px;
}

.hidden {
    display: none !important;
}

/* Setup Panel */
#setup-panel h2 {
    text-align: center;
    color: #333;
    margin-bottom: 20px;
}

.size-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
}

.size-btn {
    padding: 12px 24px;
    font-size: 1.1rem;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.size-btn:hover {
    background: #667eea;
    color: white;
}

.size-btn.active {
    background: #667eea;
    color: white;
}

.custom-size {
    display: flex;
    gap: 8px;
    align-items: center;
}

.custom-size input {
    width: 60px;
    padding: 12px 8px;
    font-size: 1rem;
    border: 2px solid #ddd;
    border-radius: 8px;
    text-align: center;
}

.custom-size span {
    color: #667eea;
    font-weight: bold;
    font-size: 1.2rem;
}

.custom-size input:focus {
    outline: none;
    border-color: #667eea;
}

#custom-size-btn {
    padding: 12px 16px;
    font-size: 1rem;
    border: none;
    background: #764ba2;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

#custom-size-btn:hover {
    background: #5a3d7a;
}

.start-btn {
    display: block;
    width: 100%;
    padding: 16px;
    font-size: 1.2rem;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

/* Game Panel */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.score-container {
    background: #667eea;
    padding: 8px 20px;
    border-radius: 8px;
    text-align: center;
}

.score-label {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
}

.score {
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
}

.restart-btn {
    padding: 10px 20px;
    font-size: 1rem;
    border: none;
    background: #f44336;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.restart-btn:hover {
    background: #d32f2f;
}

/* Turn Indicator */
.turn-indicator {
    text-align: center;
    padding: 12px;
    background: #f5f5f5;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 1.1rem;
}

.player-tag {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: bold;
    margin-right: 8px;
}

.player-tag.player1 {
    background: #4CAF50;
    color: white;
}

.player-tag.player2 {
    background: #2196F3;
    color: white;
}

/* Placer Controls */
.placer-controls {
    text-align: center;
    margin-bottom: 16px;
}

.value-btn {
    padding: 10px 24px;
    font-size: 1.2rem;
    border: 2px solid #4CAF50;
    background: white;
    color: #4CAF50;
    border-radius: 8px;
    cursor: pointer;
    margin: 0 8px;
    transition: all 0.3s ease;
    font-weight: bold;
}

.value-btn:hover {
    background: #4CAF50;
    color: white;
}

.value-btn.active {
    background: #4CAF50;
    color: white;
}

/* Mover Controls */
.mover-controls {
    text-align: center;
    margin-bottom: 16px;
}

.direction-buttons {
    margin-top: 10px;
    display: inline-block;
}

.dir-btn {
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
    border: none;
    background: #2196F3;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    margin: 4px;
    transition: all 0.3s ease;
}

.dir-btn:hover {
    background: #1976D2;
    transform: scale(1.1);
}

.dir-row {
    display: flex;
    justify-content: center;
}

/* Grid */
.grid-container {
    display: grid;
    gap: 8px;
    padding: 12px;
    background: #bbada0;
    border-radius: 8px;
    margin-bottom: 16px;
}

.cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    border-radius: 6px;
    transition: all 0.15s ease;
    cursor: default;
    user-select: none;
}

.cell.empty {
    background: rgba(238, 228, 218, 0.35);
}

.cell.empty.clickable {
    cursor: pointer;
}

.cell.empty.clickable:hover {
    background: rgba(238, 228, 218, 0.6);
    transform: scale(1.05);
}

.cell[data-value="2"] {
    background: #eee4da;
    color: #776e65;
}

.cell[data-value="4"] {
    background: #ede0c8;
    color: #776e65;
}

.cell[data-value="8"] {
    background: #f2b179;
    color: #f9f6f2;
}

.cell[data-value="16"] {
    background: #f59563;
    color: #f9f6f2;
}

.cell[data-value="32"] {
    background: #f67c5f;
    color: #f9f6f2;
}

.cell[data-value="64"] {
    background: #f65e3b;
    color: #f9f6f2;
}

.cell[data-value="128"] {
    background: #edcf72;
    color: #f9f6f2;
}

.cell[data-value="256"] {
    background: #edcc61;
    color: #f9f6f2;
}

.cell[data-value="512"] {
    background: #edc850;
    color: #f9f6f2;
}

.cell[data-value="1024"] {
    background: #edc53f;
    color: #f9f6f2;
}

.cell[data-value="2048"] {
    background: #edc22e;
    color: #f9f6f2;
}

.cell.high-value {
    background: #3c3a32;
    color: #f9f6f2;
}

/* Game Over */
.game-over {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
}

#game-panel {
    position: relative;
}

.game-over-content {
    text-align: center;
}

.game-over-content h2 {
    font-size: 2rem;
    color: #776e65;
    margin-bottom: 16px;
}

.game-over-content p {
    font-size: 1.2rem;
    color: #776e65;
    margin-bottom: 20px;
}

/* Rules */
.rules {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 16px;
    padding: 20px;
}

.rules h3 {
    color: #333;
    margin-bottom: 12px;
}

.rules ul {
    padding-left: 20px;
    color: #555;
}

.rules li {
    margin-bottom: 8px;
    line-height: 1.5;
}

/* Mode Selection */
.mode-selection,
.role-selection,
.size-options {
    margin-bottom: 20px;
}

.mode-selection h3,
.role-selection h3,
.size-options h3 {
    text-align: center;
    color: #555;
    margin-bottom: 12px;
    font-size: 1rem;
}

.mode-buttons,
.size-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.mode-btn {
    padding: 12px 32px;
    font-size: 1.1rem;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.mode-btn:hover {
    background: #667eea;
    color: white;
}

.mode-btn.active {
    background: #667eea;
    color: white;
}

/* Role Selection */
.role-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

.role-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 20px;
    border: 2px solid #ddd;
    background: white;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 120px;
}

.role-btn:hover {
    border-color: #667eea;
    transform: translateY(-2px);
}

.role-btn.active {
    border-color: #667eea;
    background: #f0f4ff;
}

.role-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.role-name {
    font-weight: bold;
    color: #333;
    margin-bottom: 4px;
}

.role-desc {
    font-size: 0.8rem;
    color: #888;
    text-align: center;
}

/* Matchmaking Panel */
#matchmaking-panel {
    text-align: center;
}

#matchmaking-panel h2 {
    color: #333;
    margin-bottom: 20px;
}

.matchmaking-info {
    padding: 20px;
}

.matchmaking-info p {
    margin: 10px 0;
    color: #555;
    font-size: 1.1rem;
}

.wait-time {
    font-size: 1.3rem !important;
    color: #667eea !important;
    font-weight: bold;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

.small-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    display: inline-block;
    margin-right: 10px;
    vertical-align: middle;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.cancel-btn {
    padding: 12px 32px;
    font-size: 1rem;
    border: none;
    background: #f44336;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.cancel-btn:hover {
    background: #d32f2f;
}

/* Online Indicator */
.online-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #e8f5e9;
    border-radius: 20px;
    font-size: 0.9rem;
    color: #2e7d32;
}

.online-dot {
    width: 8px;
    height: 8px;
    background: #4caf50;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* Room Info */
.room-info {
    display: flex;
    justify-content: space-between;
    padding: 10px 16px;
    background: #f5f5f5;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 0.9rem;
    color: #666;
}

/* Waiting Opponent */
.waiting-opponent {
    text-align: center;
    padding: 16px;
    background: #fff3e0;
    border-radius: 8px;
    margin-bottom: 16px;
    color: #e65100;
}

/* Responsive */
@media (max-width: 480px) {
    h1 {
        font-size: 1.8rem;
    }
    
    .panel {
        padding: 16px;
    }
    
    .size-options {
        flex-direction: column;
        align-items: center;
    }
    
    .dir-btn {
        width: 45px;
        height: 45px;
    }

    .role-buttons {
        flex-direction: column;
        align-items: center;
    }

    .role-btn {
        width: 100%;
        max-width: 200px;
    }

    .room-info {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }
}

/* Animations */
@keyframes pop {
    0% {
        transform: scale(0);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

.cell.new {
    animation: pop 0.2s ease;
}

@keyframes merge {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

.cell.merged {
    animation: merge 0.2s ease;
}

/* Items Toggle */
.items-toggle {
    margin-bottom: 20px;
}

.items-toggle h3 {
    text-align: center;
    color: #555;
    margin-bottom: 12px;
    font-size: 1rem;
}

.toggle-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.toggle-btn {
    padding: 12px 24px;
    font-size: 1rem;
    border: 2px solid #ff9800;
    background: white;
    color: #ff9800;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.toggle-btn:hover {
    background: #ff9800;
    color: white;
}

.toggle-btn.active {
    background: #ff9800;
    color: white;
}

/* Item Selection Panel */
#item-selection-panel h2 {
    text-align: center;
    color: #333;
    margin-bottom: 10px;
}

.item-selection-info {
    text-align: center;
    color: #666;
    margin-bottom: 16px;
}

.item-role-indicator {
    text-align: center;
    padding: 8px 16px;
    background: #f0f4ff;
    border-radius: 8px;
    margin-bottom: 16px;
    font-weight: bold;
    color: #667eea;
}

.available-items {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.item-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
    position: relative;
}

.item-card:hover {
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.item-card.selected {
    border-color: #4CAF50;
    background: #e8f5e9;
}

.item-card.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.item-card.role-restricted {
    opacity: 0.4;
    border-color: #ccc;
}

.item-card.role-restricted::after {
    content: '不可选';
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 0.7rem;
    background: #f44336;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
}

.item-emoji {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

.item-name {
    font-weight: bold;
    color: #333;
    margin-bottom: 4px;
    text-align: center;
}

.item-desc {
    font-size: 0.75rem;
    color: #888;
    text-align: center;
    line-height: 1.3;
}

.selected-items-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px;
    background: #f5f5f5;
    border-radius: 8px;
}

.selected-items-display {
    display: flex;
    gap: 8px;
}

.selected-items-display .item-emoji,
.selected-items-display .empty-slot {
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: 2px dashed #ddd;
    border-radius: 8px;
    font-size: 1.8rem;
}

.selected-items-display .empty-slot {
    font-size: 0.9rem;
    color: #999;
}

/* Items Panel in Game */
.items-panel {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
}

.items-section {
    flex: 1;
}

.items-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.items-title {
    font-weight: bold;
    color: #333;
    font-size: 0.9rem;
}

.items-container {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.item-slot {
    position: relative;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.item-slot:hover:not(.used):not(.opponent) {
    border-color: #667eea;
    transform: scale(1.1);
}

.item-slot.selected {
    border-color: #4CAF50;
    background: #e8f5e9;
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.4);
}

.item-slot.used {
    opacity: 0.3;
    cursor: not-allowed;
    text-decoration: line-through;
}

.item-slot.opponent {
    cursor: default;
}

.item-slot .item-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 12px;
    background: #333;
    color: white;
    border-radius: 6px;
    font-size: 0.8rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 100;
    max-width: 200px;
    white-space: normal;
    text-align: center;
}

.item-slot:hover .item-tooltip {
    opacity: 1;
}

.use-item-btn {
    padding: 6px 12px;
    font-size: 0.85rem;
    border: none;
    background: #4CAF50;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.use-item-btn:hover:not(:disabled) {
    background: #388E3C;
}

.use-item-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.opponent-items .items-container {
    opacity: 0.8;
}

/* Active Effects Banner */
.active-effects {
    background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
    border: 2px solid #ff9800;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
}

.effects-title {
    font-weight: bold;
    color: #e65100;
    margin-bottom: 8px;
    text-align: center;
}

.effects-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.effect-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: white;
    border-radius: 20px;
    font-size: 0.9rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.effect-badge .effect-emoji {
    font-size: 1.2rem;
}

/* Item Target Overlay */
.item-target-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 20px;
    border-radius: 8px;
    z-index: 10;
}

.target-prompt {
    background: #ff9800;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 1.1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.cell.target-selectable {
    cursor: crosshair !important;
    box-shadow: 0 0 0 3px #ff9800;
}

.cell.target-selected {
    box-shadow: 0 0 0 3px #4CAF50 !important;
}

.cell.frozen {
    box-shadow: inset 0 0 0 3px #00bcd4 !important;
    position: relative;
}

.cell.frozen::before {
    content: '❄️';
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.8rem;
}

.cell.has-mystery {
    position: relative;
}

.cell.has-mystery::after {
    content: '🎁';
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 0.8rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 24px;
    border-radius: 16px;
    text-align: center;
    max-width: 350px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-content h3 {
    font-size: 1.5rem;
    margin-bottom: 12px;
    color: #333;
}

.modal-content p {
    color: #666;
    margin-bottom: 8px;
}

.modal-note {
    font-size: 0.85rem;
    color: #999;
    margin-bottom: 16px !important;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.modal-btn {
    padding: 12px 24px;
    font-size: 1rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.modal-btn.yes {
    background: #4CAF50;
    color: white;
}

.modal-btn.yes:hover {
    background: #388E3C;
}

.modal-btn.no {
    background: #f5f5f5;
    color: #333;
}

.modal-btn.no:hover {
    background: #e0e0e0;
}

/* Game Log Panel */
.game-log-panel {
    background: #f5f5f5;
    border-radius: 8px;
    margin-top: 16px;
    overflow: hidden;
}

.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: #e0e0e0;
    font-weight: bold;
    color: #333;
}

.toggle-log-btn {
    padding: 4px 12px;
    font-size: 0.85rem;
    border: none;
    background: #667eea;
    color: white;
    border-radius: 4px;
    cursor: pointer;
}

.game-log {
    max-height: 200px;
    overflow-y: auto;
    padding: 12px 16px;
}

.game-log.collapsed {
    max-height: 0;
    padding: 0 16px;
}

.log-entry {
    padding: 6px 0;
    border-bottom: 1px solid #e0e0e0;
    font-size: 0.9rem;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.log-entry:last-child {
    border-bottom: none;
}

.log-time {
    color: #999;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.log-message {
    color: #333;
}

.log-message.placer {
    color: #4CAF50;
}

.log-message.mover {
    color: #2196F3;
}

.log-message.system {
    color: #ff9800;
    font-style: italic;
}

/* Speed Boost Indicator */
.speed-boost-active {
    animation: speedPulse 0.5s infinite alternate;
}

@keyframes speedPulse {
    from {
        box-shadow: 0 0 5px #ffeb3b;
    }
    to {
        box-shadow: 0 0 20px #ffeb3b;
    }
}

/* Responsive adjustments for items */
@media (max-width: 480px) {
    .items-panel {
        flex-direction: column;
    }
    
    .available-items {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .item-card {
        padding: 8px;
    }
    
    .item-emoji {
        font-size: 2rem;
    }
    
    .item-desc {
        display: none;
    }
    
    .modal-content {
        margin: 16px;
        max-width: none;
    }
    
    .game-log {
        max-height: 150px;
    }
}
