/* ═══════════════════════════════════════════════════════════
   FACTORS & MULTIPLES TUTORIAL (fm-tutorial.js)
   ═══════════════════════════════════════════════════════════ */

/* --- Overlay --- */
.fmt-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: linear-gradient(135deg, #0f172a 0%, #1a2744 50%, #0f172a 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.fmt-overlay.fmt-visible {
    opacity: 1;
}

.fmt-close-btn {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 2rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    line-height: 1;
}

.fmt-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* --- Modal mode --- */
.fmt-overlay.fmt-modal-mode {
    background: none;
}

.fmt-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.fmt-modal-container {
    position: relative;
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    background: linear-gradient(135deg, #0f172a 0%, #1a2744 50%, #0f172a 100%);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 1;
    aspect-ratio: 16 / 10;
}

.fmt-modal-container .fmt-close-btn {
    top: 0.75rem;
    right: 0.75rem;
    width: 36px;
    height: 36px;
    font-size: 1.5rem;
}

.fmt-modal-container .fmt-stage {
    padding: 1.5rem;
}

.fmt-modal-container .fmt-subtitle-bar {
    padding: 0 1.5rem 1rem;
    min-height: 60px;
}

.fmt-modal-container .fmt-subtitle-text {
    font-size: 1rem;
}

.fmt-modal-container .fmt-play-btn {
    padding: 1.5rem 2.5rem;
    font-size: 1rem;
    border-radius: 18px;
}

.fmt-modal-container .fmt-play-btn svg {
    width: 36px;
    height: 36px;
}

.fmt-modal-container .fmt-heading {
    font-size: 1.6rem;
}

.fmt-modal-container .fmt-title-text {
    font-size: 3.5rem;
}

.fmt-modal-container .fmt-mini-grid {
    gap: 2px;
    max-width: 280px;
}

.fmt-modal-container .fmt-example-grid,
.fmt-modal-container .fmt-trapped-grid-full {
    max-width: 260px;
}

.fmt-modal-container .fmt-grid-cell {
    font-size: 0.55rem;
    padding: 2px;
}

.fmt-modal-container .fmt-avatar {
    width: 56px;
    height: 56px;
    font-size: 1.5rem;
}

.fmt-modal-container .fmt-lb-row {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
}

/* --- Stage --- */
.fmt-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 900px;
    padding: 2rem;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.fmt-stage.fmt-fade-out {
    opacity: 0;
    transform: scale(0.96);
}

.fmt-stage.fmt-fade-in {
    animation: fmtFadeIn 0.4s ease both;
}

@keyframes fmtFadeIn {
    from { opacity: 0; transform: scale(0.96) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* --- Subtitle bar --- */
.fmt-subtitle-bar {
    width: 100%;
    max-width: 800px;
    min-height: 80px;
    padding: 0 2rem 1.5rem;
    text-align: center;
}

.fmt-subtitle-text {
    color: rgba(255, 255, 255, 0.85);
    font-size: 1.15rem;
    line-height: 1.5;
    transition: opacity 0.25s ease;
    margin: 0;
}

/* --- Progress bar --- */
.fmt-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
}

.fmt-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4f46e5, #06b6d4);
    width: 0%;
    transition: width 0.3s linear;
}

/* --- Play overlay --- */
.fmt-play-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    background: rgba(0, 0, 0, 0.3);
}

.fmt-play-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    background: linear-gradient(135deg, #4f46e5, #06b6d4);
    border: none;
    border-radius: 24px;
    padding: 2rem 3rem;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    color: white;
    font-size: 1.2rem;
    font-weight: 700;
    font-family: 'Poppins', sans-serif;
    box-shadow: 0 8px 40px rgba(79, 70, 229, 0.3);
}

.fmt-play-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 50px rgba(79, 70, 229, 0.4);
}

/* --- Scene: shared --- */
.fmt-scene {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 2rem;
    width: 100%;
}

.fmt-heading {
    font-size: 2.2rem;
    font-weight: 700;
    color: white;
    letter-spacing: -0.5px;
}

/* --- Scene: Title --- */
.fmt-title-text {
    font-size: 5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #4f46e5, #06b6d4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.1;
    letter-spacing: -2px;
    animation: fmtTitleSlam 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.fmt-title-text-2 {
    animation-delay: 0.15s;
}

.fmt-title-sub {
    color: rgba(255, 255, 255, 0.5);
    font-size: 1.3rem;
    font-weight: 500;
    animation: fmtFadeUp 0.5s ease 0.4s both;
}

@keyframes fmtTitleSlam {
    from { opacity: 0; transform: scale(1.5); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes fmtFadeUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Scene: Pairing / VS --- */
.fmt-pairing-scene {
    flex-direction: row;
    gap: 2rem;
}

.fmt-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    color: white;
}

.fmt-avatar-you {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    animation: fmtSlideRight 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.fmt-avatar-opp {
    background: linear-gradient(135deg, #ec4899, #db2777);
    animation: fmtSlideLeft 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s both;
}

.fmt-vs-text {
    font-size: 2.5rem;
    font-weight: 800;
    color: #fbbf24;
    animation: fmtPopIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s both;
}

.fmt-avatar-label {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 0.5rem;
    animation: fmtFadeUp 0.3s ease 0.5s both;
}

.fmt-avatar-group {
    display: flex;
    flex-direction: column;
    align-items: center;
}

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

@keyframes fmtSlideLeft {
    from { opacity: 0; transform: translateX(80px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes fmtPopIn {
    from { opacity: 0; transform: scale(0); }
    to { opacity: 1; transform: scale(1); }
}

/* --- Scene: Grid --- */
.fmt-mini-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 3px;
    max-width: 400px;
    width: 100%;
}

.fmt-grid-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
    animation: fmtCellPop 0.3s ease var(--delay) both;
}

@keyframes fmtCellPop {
    from { opacity: 0; transform: scale(0); }
    to { opacity: 1; transform: scale(1); }
}

/* Grid cell game states (used in example + trapped scenes) */
.fmt-grid-cell.used {
    background: rgba(239, 68, 68, 0.4);
    color: rgba(255, 255, 255, 0.45);
    text-decoration: line-through;
    border-color: rgba(239, 68, 68, 0.35);
}

.fmt-grid-cell.last-move {
    text-decoration: none;
    color: white;
    font-weight: 700;
    border: 2px solid #fbbf24;
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
    animation: fmtCellPop 0.3s ease var(--delay) both, fmtPulseGold 1.5s ease 0.5s infinite;
}

.fmt-grid-cell.valid-hint {
    background: rgba(52, 211, 153, 0.25);
    border: 2px solid rgba(52, 211, 153, 0.6);
    color: #34d399;
    font-weight: 700;
    animation: fmtCellPop 0.3s ease var(--delay) both, fmtPulseGreen 1.5s ease 0.8s infinite;
}

/* Timed reveal: cells start neutral, gain this class via JS during audio */
.fmt-grid-cell.reveal-valid {
    background: rgba(52, 211, 153, 0.25);
    border: 2px solid rgba(52, 211, 153, 0.6);
    color: #34d399;
    font-weight: 700;
    animation: fmtRevealGlow 0.6s ease both, fmtPulseGreen 1.5s ease 0.6s infinite;
}

.fmt-grid-cell.reveal-taken {
    background: rgba(239, 68, 68, 0.2);
    border: 2px solid rgba(239, 68, 68, 0.5);
    color: rgba(239, 68, 68, 0.8);
    text-decoration: line-through;
    font-weight: 700;
    animation: fmtRevealGlow 0.6s ease both;
}

@keyframes fmtRevealGlow {
    0% { transform: scale(1); box-shadow: none; }
    40% { transform: scale(1.4); box-shadow: 0 0 16px rgba(52, 211, 153, 0.5); }
    100% { transform: scale(1); }
}

@keyframes fmtPulseGreen {
    0%, 100% { box-shadow: 0 0 6px rgba(52, 211, 153, 0.3); }
    50% { box-shadow: 0 0 14px rgba(52, 211, 153, 0.5); }
}

.fmt-grid-cell.taken-hint {
    text-decoration: line-through;
    position: relative;
    border: 2px solid rgba(239, 68, 68, 0.5);
    background: rgba(239, 68, 68, 0.2);
    color: rgba(239, 68, 68, 0.8);
}

/* --- Scene: Rules Demo --- */
.fmt-rules-scene {
    gap: 1.5rem;
}

.fmt-demo-grid {
    display: flex;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
    justify-content: center;
}

.fmt-demo-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.fmt-demo-number {
    width: 64px;
    height: 64px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 800;
    color: white;
    background: rgba(255, 255, 255, 0.1);
    border: 3px solid #fbbf24;
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.3);
    animation: fmtPulseGold 1.5s ease infinite;
}

@keyframes fmtPulseGold {
    0%, 100% { box-shadow: 0 0 20px rgba(251, 191, 36, 0.3); }
    50% { box-shadow: 0 0 35px rgba(251, 191, 36, 0.5); }
}

.fmt-demo-label {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.4);
    font-weight: 600;
}

.fmt-arrows-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.fmt-arrow-label {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.25rem;
}

.fmt-arrow-label.factors {
    color: #34d399;
}

.fmt-arrow-label.multiples {
    color: #60a5fa;
}

.fmt-valid-nums {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    justify-content: center;
}

.fmt-valid-num {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: white;
    animation: fmtPopIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) var(--delay) both;
}

.fmt-valid-num.factor {
    background: rgba(52, 211, 153, 0.2);
    border: 2px solid rgba(52, 211, 153, 0.5);
}

.fmt-valid-num.multiple {
    background: rgba(96, 165, 250, 0.2);
    border: 2px solid rgba(96, 165, 250, 0.5);
}

/* --- Scene: Example (grid with game in progress) --- */
.fmt-example-scene {
    gap: 1rem;
}

.fmt-example-layout {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.fmt-example-grid {
    max-width: 340px;
}

.fmt-example-legend {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.fmt-legend-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
    font-weight: 500;
    animation: fmtFadeUp 0.3s ease var(--delay) both;
}

.fmt-legend-swatch {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    flex-shrink: 0;
}

.fmt-legend-swatch.valid-hint {
    background: rgba(52, 211, 153, 0.25);
    border: 2px solid rgba(52, 211, 153, 0.6);
}

.fmt-legend-swatch.last-move {
    background: rgba(251, 191, 36, 0.3);
    border: 2px solid #fbbf24;
}

.fmt-legend-swatch.used {
    background: rgba(239, 68, 68, 0.4);
    border: 2px solid rgba(239, 68, 68, 0.35);
}

/* --- Scene: Trapped (full 10x10 grid, late game) --- */
.fmt-trapped-scene {
    gap: 1rem;
}

.fmt-trapped-layout {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.fmt-trapped-grid-full {
    max-width: 340px;
}

.fmt-trapped-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.fmt-trapped-x {
    font-size: 4rem;
    color: #ef4444;
    font-weight: 800;
    animation: fmtPopIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.4s both;
}

.fmt-trapped-text {
    color: #ef4444;
    font-weight: 700;
    font-size: 1.1rem;
    animation: fmtFadeUp 0.3s ease 0.6s both;
}

.fmt-trapped-explain {
    color: rgba(255, 255, 255, 0.45);
    font-size: 0.85rem;
    max-width: 180px;
    text-align: center;
    line-height: 1.4;
    animation: fmtFadeUp 0.3s ease 0.8s both;
}

/* --- Scene: Scoring --- */
.fmt-scoring-scene {
    gap: 1.5rem;
}

.fmt-score-items {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    justify-content: center;
}

.fmt-score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.2rem 1.5rem;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    animation: fmtPopIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) var(--delay) both;
}

.fmt-score-value {
    font-size: 2rem;
    font-weight: 800;
    color: white;
}

.fmt-score-value.bonus {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.fmt-score-desc {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.5);
    font-weight: 500;
}

.fmt-lb-preview {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    width: 100%;
    max-width: 320px;
}

.fmt-lb-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    animation: fmtSlideUp 0.3s ease var(--delay) both;
}

.fmt-lb-rank {
    font-weight: 700;
    color: #fbbf24;
    min-width: 20px;
}

.fmt-lb-name {
    flex: 1;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
}

.fmt-lb-pts {
    font-weight: 700;
    color: white;
}

@keyframes fmtSlideUp {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Scene: Outro --- */
.fmt-outro-scene .fmt-title-text {
    font-size: 4rem;
}

.fmt-outro-sub {
    color: rgba(255, 255, 255, 0.5);
    font-size: 1.3rem;
    font-style: italic;
    animation: fmtFadeUp 0.5s ease 0.3s both;
}

/* --- How to Play button --- */
.fmt-how-to-play-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(79, 70, 229, 0.1);
    border: 2px solid rgba(79, 70, 229, 0.3);
    color: #6366f1;
    padding: 0.6rem 1.2rem;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Poppins', sans-serif;
}

.fmt-how-to-play-btn:hover {
    background: rgba(79, 70, 229, 0.18);
    border-color: rgba(79, 70, 229, 0.5);
}

/* --- Responsive --- */
@media (max-width: 600px) {
    .fmt-title-text {
        font-size: 3rem;
    }
    .fmt-heading {
        font-size: 1.5rem;
    }
    .fmt-mini-grid {
        max-width: 280px;
        gap: 2px;
    }
    .fmt-grid-cell {
        font-size: 0.5rem;
    }
    .fmt-demo-number {
        width: 48px;
        height: 48px;
        font-size: 1.3rem;
    }
    .fmt-valid-num {
        width: 30px;
        height: 30px;
        font-size: 0.75rem;
    }
    .fmt-pairing-scene {
        gap: 1rem;
    }
    .fmt-avatar {
        width: 56px;
        height: 56px;
        font-size: 1.5rem;
    }
    .fmt-vs-text {
        font-size: 1.8rem;
    }
    .fmt-example-layout,
    .fmt-trapped-layout {
        flex-direction: column;
    }
    .fmt-example-grid,
    .fmt-trapped-grid-full {
        max-width: 260px;
    }
    .fmt-example-legend {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
    }
    .fmt-legend-item {
        font-size: 0.75rem;
    }
    .fmt-score-items {
        gap: 1rem;
    }
    .fmt-score-item {
        padding: 0.8rem 1rem;
    }
}
