/* 
   Scoping to .cfl-app ensures this CSS does NOT leak into your website's main theme 
*/
.cfl-app {
    --cfl-bg-main: #0f172a;
    --cfl-bg-panel: #1e293b;
    --cfl-bg-input: #0f172a;
    --cfl-accent: #3b82f6;       /* Blue */
    --cfl-accent-hover: #2563eb;
    --cfl-heads: #f59e0b;        /* Gold */
    --cfl-tails: #94a3b8;        /* Silver */
    --cfl-text-main: #f8fafc;
    --cfl-text-muted: #94a3b8;
    --cfl-border: #334155;
    --cfl-danger: #ef4444;
    --cfl-success: #10b981;
    
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--cfl-bg-main);
    color: var(--cfl-text-main);
    
    /* Full screen scaling mechanism */
    width: 100%;
    height: 100vh;
    min-height: 650px;
    display: flex;
    flex-direction: row;
    box-sizing: border-box;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--cfl-border);
    border-radius: 12px;
}

.cfl-app * {
    box-sizing: border-box;
}

/* --- Sidebar --- */
.cfl-sidebar {
    width: 360px;
    min-width: 360px;
    background-color: var(--cfl-bg-panel);
    border-right: 1px solid var(--cfl-border);
    display: flex;
    flex-direction: column;
    padding: 24px;
    overflow-y: auto;
    z-index: 10;
    box-shadow: 5px 0 20px rgba(0,0,0,0.3);
}

.cfl-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 32px;
}

.cfl-logo {
    background: linear-gradient(135deg, var(--cfl-accent), #8b5cf6);
    padding: 8px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cfl-header svg {
    width: 24px;
    height: 24px;
    color: white;
}

.cfl-title {
    font-size: 1.5rem;
    font-weight: 800;
    margin: 0;
    color: #ffffff;
    letter-spacing: -0.5px;
}

.cfl-title span {
    color: var(--cfl-accent);
}

.cfl-subtitle {
    font-size: 0.8rem;
    color: var(--cfl-text-muted);
    margin: 2px 0 0 0;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* --- Stats & Controls --- */
.cfl-stats-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 32px;
}

.cfl-section-title {
    font-size: 0.85rem;
    color: var(--cfl-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 0 0 4px 0;
}

.cfl-row {
    display: flex;
    gap: 12px;
}

.cfl-stat-box {
    flex: 1;
    background-color: var(--cfl-bg-input);
    border: 1px solid var(--cfl-border);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 4px;
}

.cfl-stat-heads { border-bottom: 3px solid var(--cfl-heads); }
.cfl-stat-tails { border-bottom: 3px solid var(--cfl-tails); }

.cfl-stat-label {
    font-size: 0.75rem;
    color: var(--cfl-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.cfl-stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--cfl-text-main);
    line-height: 1;
}

.cfl-stat-pct {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--cfl-accent);
}

/* Buttons */
.cfl-actions-container {
    margin-bottom: auto;
}

.cfl-bottom-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 32px;
}

.cfl-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: #ffffff;
    width: 100%;
}

.cfl-btn svg { width: 18px; height: 18px; }
.cfl-btn:active { transform: scale(0.97); }

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

.cfl-flip-btn {
    padding: 20px 16px !important;
    font-size: 1.2rem !important;
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.3);
}

.cfl-btn-danger {
    background-color: transparent;
    border: 1px solid var(--cfl-danger);
    color: var(--cfl-danger);
}
.cfl-btn-danger:hover { background-color: rgba(239, 68, 68, 0.1); }

.cfl-btn-success { background-color: var(--cfl-success); }
.cfl-btn-success:hover { background-color: #059669; }

/* --- Main Workspace --- */
.cfl-workspace {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background-image: radial-gradient(var(--cfl-border) 1px, transparent 1px);
    background-size: 24px 24px;
    overflow: hidden;
}

/* --- 3D Coin Stage --- */
.cfl-coin-stage {
    flex: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    perspective: 1000px; /* Crucial for 3D effect */
    padding: 40px;
    position: relative;
}

.cfl-coin {
    width: 220px;
    height: 220px;
    position: relative;
    transform-style: preserve-3d; /* Required to show faces */
    transition: transform 3s cubic-bezier(0.2, 0.8, 0.2, 1);
    cursor: pointer;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    border-radius: 50%;
}

.cfl-coin:hover {
    box-shadow: 0 20px 60px rgba(59, 130, 246, 0.3);
}

.cfl-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden; /* Hides back of face when rotated */
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 12px solid rgba(255,255,255,0.2);
}

.cfl-face-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.cfl-icon { font-size: 4rem; }

.cfl-heads {
    background: radial-gradient(circle at 30% 30%, #fcd34d, var(--cfl-heads), #92400e);
    color: white;
    font-size: 1.5rem;
    font-weight: 800;
}

.cfl-tails {
    background: radial-gradient(circle at 30% 30%, #e2e8f0, var(--cfl-tails), #334155);
    color: white;
    font-size: 1.5rem;
    font-weight: 800;
    transform: rotateX(180deg); /* Flip tails face backwards initially */
}

.cfl-result-display {
    margin-top: 40px;
    font-size: 2rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
    min-height: 40px;
    color: var(--cfl-accent);
    text-shadow: 0 0 20px rgba(59, 130, 246, 0.4);
    opacity: 1;
    transition: opacity 0.3s;
}

.cfl-fading { opacity: 0; } /* Used during animation */

/* --- History Log --- */
.cfl-history-container {
    flex: 1;
    background-color: var(--cfl-bg-panel);
    border-top: 1px solid var(--cfl-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.cfl-history-header {
    padding: 12px 24px;
    background-color: rgba(0,0,0,0.2);
    border-bottom: 1px solid var(--cfl-border);
}

.cfl-history-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--cfl-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.cfl-history-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cfl-history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--cfl-bg-input);
    padding: 12px 16px;
    border-radius: 8px;
    border-left: 4px solid var(--cfl-border);
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

.cfl-history-item.heads { border-left-color: var(--cfl-heads); }
.cfl-history-item.tails { border-left-color: var(--cfl-tails); }

.cfl-history-flip {
    font-size: 0.9rem;
    font-weight: 700;
}

.cfl-history-item.heads .cfl-history-flip { color: var(--cfl-heads); }
.cfl-history-item.tails .cfl-history-flip { color: var(--cfl-tails); }

.cfl-history-meta {
    font-size: 0.8rem;
    color: var(--cfl-text-muted);
    font-family: monospace;
}

.cfl-empty-state {
    text-align: center;
    color: var(--cfl-text-muted);
    padding: 20px;
    font-style: italic;
}

/* Toast */
.cfl-toast {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: var(--cfl-success);
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 600;
    font-size: 0.95rem;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 50;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.cfl-toast.cfl-show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Responsive */
@media (max-width: 860px) {
    .cfl-app {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }
    .cfl-sidebar {
        width: 100%;
        min-width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--cfl-border);
    }
    .cfl-workspace {
        min-height: 70vh;
    }
    .cfl-coin {
        width: 180px;
        height: 180px;
    }
    .cfl-history-container {
        min-height: 250px;
    }
}