@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap');

#ttt-wrapper {
    font-family: 'Fredoka', sans-serif;
    width: 100%; min-height: 650px; 
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex; justify-content: center; align-items: center;
    padding: 10px; box-sizing: border-box;
}
#ttt-wrapper:fullscreen { width: 100vw; height: 100vh; border-radius: 0; padding: 0; }
#ttt-wrapper * { box-sizing: border-box; touch-action: manipulation; }

#ttt-container {
    width: 100%; max-width: 600px;
    background: #fff; border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
    display: flex; flex-direction: column; overflow: hidden; position: relative;
    min-height: 600px; height: 100%;
}

/* HEADER */
.ttt-header {
    padding: 10px 20px; background: #f8f9fa; border-bottom: 2px solid #e9ecef;
    display: flex; justify-content: space-between; align-items: center; height: 60px;
    flex-shrink: 0;
}
.ttt-header-left { display: flex; align-items: center; gap: 15px; }
.ttt-main-title { font-size: 1.4rem; color: #5b4b8a; margin: 0; font-weight: 700; }

#ttt-turn-box {
    display: flex; align-items: center; gap: 8px;
    background: #e9ecef; padding: 5px 15px; border-radius: 30px;
    font-size: 0.9rem; font-weight: 600; color: #495057;
}
#ttt-turn-token { width: 24px; height: 24px; border-radius: 4px; background: #ccc; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; font-weight: bold; }
#ttt-turn-token.x { color: #3b82f6; }
#ttt-turn-token.o { color: #ef4444; }

.ttt-icon-btn {
    width: 36px; height: 36px; border-radius: 50%; border: 1px solid #ced4da;
    background: white; cursor: pointer; font-size: 1.1rem; 
    display: flex; align-items: center; justify-content: center; color: #555; transition:0.2s;
}
.ttt-icon-btn:hover { background: #e9ecef; }

/* VUES & MODALES */
.ttt-view { 
    flex-grow: 1; width: 100%; display: flex; justify-content: center; align-items: center; 
    flex-direction: column; position: absolute; top: 60px; left: 0; bottom: 0;
    background: #fff; transition: opacity 0.3s; z-index: 1;
}
.ttt-hidden { display: none !important; opacity: 0; pointer-events: none; z-index: -1; }
.ttt-active { display: flex !important; opacity: 1; pointer-events: auto; z-index: 10; }
.ttt-overlay { background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(5px); z-index: 100; top: 0; height: 100%; }

/* CARTES */
.ttt-card {
    background: white; padding: 30px; border-radius: 20px;
    width: 90%; max-width: 400px; text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.1); border: 1px solid #eee;
    animation: popIn 0.3s ease-out;
}
@keyframes popIn { from { transform: scale(0.9); opacity:0; } to { transform: scale(1); opacity:1; } }

.ttt-card.no-shadow { box-shadow: none; border: none; background: transparent; }
.ttt-card-title { color: #5b4b8a; margin: 0 0 20px 0; font-size: 1.5rem; }
.ttt-btn-stack { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.ttt-row { display: flex; gap: 8px; justify-content: center; width: 100%; }

/* BOUTONS */
.ttt-btn { padding: 12px; border-radius: 12px; font-weight: bold; cursor: pointer; border: none; font-size: 0.95rem; width: 100%; transition: 0.2s; font-family: inherit; }
.ttt-start { background: #3b82f6; color: white; border-bottom: 4px solid #2563eb; }
.ttt-online { background: #e0f2fe; color: #0284c7; border: 2px solid #bae6fd; }
.ttt-online-small { background: #e0f2fe; color: #0284c7; border: 2px solid #bae6fd; font-size: 0.85rem; padding: 8px; }
.ttt-secondary { background: #f1f5f9; color: #475569; border: 2px solid #e2e8f0; }
.ttt-primary { background: #2ecc71; color: white; border-bottom: 4px solid #27ae60; }
.ttt-btn:hover { transform: translateY(-2px); filter: brightness(0.95); }
.ttt-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.big-btn { font-size: 1.1rem; padding: 15px; }

/* SELECTION DIFFICULTE */
.ttt-diff-area { margin-top: 10px; margin-bottom: 10px; animation: slideDown 0.3s; background: #f8f9fa; padding: 15px; border-radius: 12px; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.ttt-btn-diff { flex: 1; padding: 8px; border: 2px solid #e2e8f0; background: #fff; border-radius: 8px; cursor: pointer; font-size: 0.9rem; color: #666; font-weight: bold; transition:0.2s; }
.ttt-btn-diff:hover { border-color: #3b82f6; }
.ttt-btn-diff.ttt-selected { background: #3b82f6; color: white; border-color: #3b82f6; }

.ttt-separator { display: flex; align-items: center; color: #ccc; margin: 10px 0; font-size: 0.7rem; font-weight: bold; text-transform: uppercase; }
.ttt-separator::before, .ttt-separator::after { content: ''; flex: 1; border-bottom: 1px solid #eee; }
.ttt-separator span { padding: 0 10px; }

.ttt-input-small { width: 80px; padding: 0 10px; text-align: center; text-transform: uppercase; border: 2px solid #cbd5e1; border-radius: 8px; font-weight: bold; }
.ttt-code-display { font-family: monospace; font-size: 2.5rem; font-weight: bold; background: #2d3436; color: #55efc4; padding: 15px; border-radius: 10px; margin: 15px 0; letter-spacing: 5px; }
.ttt-loader { width: 40px; height: 40px; border: 4px solid #eee; border-top-color: #3b82f6; border-radius: 50%; animation: spin 1s infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* PLATEAU DE JEU */
.ttt-players-names { 
    width: 100%; display: flex; justify-content: space-around; align-items: center; 
    margin-bottom: 20px; font-weight: bold; font-size: 1.1rem; flex-shrink: 0; padding: 10px;
}
.vs-badge { background: #f1f5f9; padding: 2px 8px; border-radius: 10px; font-size: 0.8rem; color: #888; }
.p-name.p1 { color: #3b82f6; }
.p-name.p2 { color: #ef4444; }

.ttt-board-container {
    background: #f8fafc; padding: 20px; border-radius: 15px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    width: 90%; max-width: 450px; aspect-ratio: 1/1;
    display: flex; justify-content: center; align-items: center;
}

#ttt-grid {
    display: grid; 
    grid-template-columns: repeat(3, 1fr); 
    grid-template-rows: repeat(3, 1fr); 
    gap: 10px; 
    width: 100%; 
    height: 100%;
    max-width: 400px;
    max-height: 400px;
}

.ttt-cell {
    background: #ffffff; 
    border-radius: 15px; 
    cursor: pointer; 
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    font-weight: bold;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    position: relative;
}

.ttt-cell:hover:not(.ttt-filled) {
    background: #e0f2fe;
    transform: scale(1.05);
}

.ttt-cell.ttt-filled {
    cursor: not-allowed;
}

.ttt-cell.preview {
    background: #fef3c7;
}

.ttt-symbol {
    animation: symbolPop 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes symbolPop {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.ttt-symbol.x {
    color: #3b82f6;
}

.ttt-symbol.o {
    color: #ef4444;
}

.ttt-cell.win-cell {
    background: #fbbf24 !important;
    animation: winPulse 0.6s ease-in-out infinite;
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.8) !important;
}

@keyframes winPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 20px rgba(251, 191, 36, 0.8); }
    50% { transform: scale(1.1); box-shadow: 0 0 30px rgba(251, 191, 36, 1); }
}

/* ANIMATION PIECE */
.ttt-coin { width: 80px; height: 80px; margin: 10px auto; position: relative; transform-style: preserve-3d; transition: transform 2s; }
.ttt-side-a, .ttt-side-b { position: absolute; width: 100%; height: 100%; border-radius: 50%; backface-visibility: hidden; border: 4px solid white; box-shadow: 0 5px 15px rgba(0,0,0,0.2); display: flex; align-items: center; justify-content: center; font-size: 2.5rem; font-weight: bold; }
.ttt-side-a { background: #3b82f6; color: white; } 
.ttt-side-b { background: #ef4444; color: white; transform: rotateY(180deg); } 

.ttt-flip-p1 { animation: flipP1 2s forwards; }
.ttt-flip-p2 { animation: flipP2 2s forwards; }
@keyframes flipP1 { 0% { transform: rotateY(0); } 100% { transform: rotateY(1800deg); } }
@keyframes flipP2 { 0% { transform: rotateY(0); } 100% { transform: rotateY(1980deg); } }
.toss-text { color:#5b4b8a; margin-top:20px; opacity:0; transition: opacity 0.5s; background:white; padding:10px; border-radius:10px; }

.ttt-token-large { width: 80px; height: 80px; border-radius: 15px; margin: 0 auto 20px; border: 4px solid white; box-shadow: 0 5px 15px rgba(0,0,0,0.2); display: flex; align-items: center; justify-content: center; font-size: 3.5rem; font-weight: bold; }
.ttt-token-large.x { background: #3b82f6; color: white; }
.ttt-token-large.o { background: #ef4444; color: white; }
.ttt-token-large.draw { background: #f59e0b; color: white; }

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.pulse {
    animation: pulse 1s infinite;
}

@media(max-width: 600px) {
    #ttt-container { border-radius: 0; min-height: 100vh; }
    .ttt-board-container { padding: 10px; }
    .ttt-cell { font-size: 3rem; }
    #ttt-grid { gap: 8px; }
}